Search in sources :

Example 11 with InsufficientOperationalNodesException

use of voldemort.store.InsufficientOperationalNodesException in project voldemort by voldemort.

the class PerformSerialPutRequests method execute.

public void execute(Pipeline pipeline) {
    int currentNode = 0;
    List<Node> nodes = pipelineData.getNodes();
    long startMasterMs = -1;
    long startMasterNs = -1;
    if (logger.isDebugEnabled()) {
        startMasterMs = System.currentTimeMillis();
        startMasterNs = System.nanoTime();
    }
    if (logger.isDebugEnabled())
        logger.debug("Performing serial put requests to determine master");
    Node node = null;
    for (; currentNode < nodes.size(); currentNode++) {
        node = nodes.get(currentNode);
        pipelineData.incrementNodeIndex();
        VectorClock versionedClock = (VectorClock) versioned.getVersion();
        final Versioned<byte[]> versionedCopy = new Versioned<byte[]>(versioned.getValue(), versionedClock.incremented(node.getId(), time.getMilliseconds()));
        if (logger.isDebugEnabled())
            logger.debug("Attempt #" + (currentNode + 1) + " to perform put (node " + node.getId() + ")");
        long start = System.nanoTime();
        try {
            stores.get(node.getId()).put(key, versionedCopy, transforms);
            long requestTime = (System.nanoTime() - start) / Time.NS_PER_MS;
            pipelineData.incrementSuccesses();
            failureDetector.recordSuccess(node, requestTime);
            if (logger.isDebugEnabled())
                logger.debug("Put on node " + node.getId() + " succeeded, using as master");
            pipelineData.setMaster(node);
            pipelineData.setVersionedCopy(versionedCopy);
            pipelineData.getZoneResponses().add(node.getZoneId());
            currentNode++;
            break;
        } catch (Exception e) {
            long requestTime = (System.nanoTime() - start) / Time.NS_PER_MS;
            if (logger.isDebugEnabled())
                logger.debug("Master PUT at node " + currentNode + "(" + node.getHost() + ")" + " failed (" + e.getMessage() + ") in " + (System.nanoTime() - start) + " ns" + " (keyRef: " + System.identityHashCode(key) + ")");
            if (PipelineRoutedStore.isSlopableFailure(e)) {
                pipelineData.getSynchronizer().tryDelegateSlop(node);
            }
            if (handleResponseError(e, node, requestTime, pipeline, failureDetector))
                return;
        }
    }
    if (logger.isTraceEnabled()) {
        logger.trace("PUT {key:" + key + "} currentNode=" + currentNode + " nodes.size()=" + nodes.size());
    }
    if (pipelineData.getSuccesses() < 1) {
        List<Exception> failures = pipelineData.getFailures();
        pipelineData.setFatalError(new InsufficientOperationalNodesException("No master node succeeded!", failures.size() > 0 ? failures.get(0) : null));
        pipeline.abort();
        return;
    }
    // There aren't any more requests to make...
    if (currentNode == nodes.size()) {
        if (pipelineData.getSuccesses() < required) {
            pipelineData.setFatalError(new InsufficientOperationalNodesException(required + " " + pipeline.getOperation().getSimpleName() + "s required, but only " + pipelineData.getSuccesses() + " succeeded", pipelineData.getReplicationSet(), pipelineData.getNodes(), pipelineData.getFailedNodes(), pipelineData.getFailures()));
            pipeline.abort();
        } else {
            if (pipelineData.getZonesRequired() != null) {
                int zonesSatisfied = pipelineData.getZoneResponses().size();
                if (zonesSatisfied >= (pipelineData.getZonesRequired() + 1)) {
                    pipeline.addEvent(completeEvent);
                } else {
                    pipelineData.setFatalError(new InsufficientZoneResponsesException((pipelineData.getZonesRequired() + 1) + " " + pipeline.getOperation().getSimpleName() + "s required zone, but only " + zonesSatisfied + " succeeded"));
                    pipeline.abort();
                }
            } else {
                if (logger.isDebugEnabled())
                    logger.debug("Finished master PUT for key " + ByteUtils.toHexString(key.get()) + " (keyRef: " + System.identityHashCode(key) + "); started at " + startMasterMs + " took " + (System.nanoTime() - startMasterNs) + " ns on node " + (node == null ? "NULL" : node.getId()) + "(" + (node == null ? "NULL" : node.getHost()) + "); now complete");
                pipeline.addEvent(completeEvent);
            }
        }
    } else {
        if (logger.isDebugEnabled())
            logger.debug("Finished master PUT for key " + ByteUtils.toHexString(key.get()) + " (keyRef: " + System.identityHashCode(key) + "); started at " + startMasterMs + " took " + (System.nanoTime() - startMasterNs) + " ns on node " + (node == null ? "NULL" : node.getId()) + "(" + (node == null ? "NULL" : node.getHost()) + ")");
        pipeline.addEvent(masterDeterminedEvent);
    }
}
Also used : Versioned(voldemort.versioning.Versioned) InsufficientZoneResponsesException(voldemort.store.InsufficientZoneResponsesException) Node(voldemort.cluster.Node) VectorClock(voldemort.versioning.VectorClock) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) InsufficientZoneResponsesException(voldemort.store.InsufficientZoneResponsesException)

Example 12 with InsufficientOperationalNodesException

use of voldemort.store.InsufficientOperationalNodesException in project voldemort by voldemort.

the class RoutedStoreTest method testGetTimeout.

@Test
public void testGetTimeout() throws Exception {
    int timeout = 50;
    StoreDefinition definition = new StoreDefinitionBuilder().setName("test").setType("foo").setKeySerializer(new SerializerDefinition("test")).setValueSerializer(new SerializerDefinition("test")).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(3).setPreferredReads(3).setRequiredReads(3).setPreferredWrites(3).setRequiredWrites(3).build();
    Map<Integer, Store<ByteArray, byte[], byte[]>> stores = new HashMap<Integer, Store<ByteArray, byte[], byte[]>>();
    List<Node> nodes = new ArrayList<Node>();
    int totalDelay = 0;
    for (int i = 0; i < 3; i++) {
        int delay = 4 + i * timeout;
        totalDelay += delay;
        Store<ByteArray, byte[], byte[]> store = new SleepyStore<ByteArray, byte[], byte[]>(delay, new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test"));
        stores.put(i, store);
        List<Integer> partitions = Arrays.asList(i);
        nodes.add(new Node(i, "none", 0, 0, 0, partitions));
    }
    setFailureDetector(stores);
    routedStoreThreadPool = Executors.newFixedThreadPool(3);
    RoutedStoreFactory routedStoreFactory = createFactory();
    RoutedStore routedStore = routedStoreFactory.create(new Cluster("test", nodes), definition, stores, failureDetector, createConfig(timeout));
    long start = System.nanoTime();
    try {
        routedStore.get(new ByteArray("test".getBytes()), null);
        fail("Should have thrown");
    } catch (InsufficientOperationalNodesException e) {
        long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
        assertTrue(elapsed + " < " + totalDelay, elapsed < totalDelay);
    }
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) HashMap(java.util.HashMap) Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) Store(voldemort.store.Store) SleepyStore(voldemort.store.SleepyStore) StatTrackingStore(voldemort.store.stats.StatTrackingStore) InconsistencyResolvingStore(voldemort.store.versioned.InconsistencyResolvingStore) FailingStore(voldemort.store.FailingStore) FailingReadsStore(voldemort.store.FailingReadsStore) VoldemortTestConstants.getNineNodeCluster(voldemort.VoldemortTestConstants.getNineNodeCluster) Cluster(voldemort.cluster.Cluster) SleepyStore(voldemort.store.SleepyStore) StoreDefinition(voldemort.store.StoreDefinition) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) ByteArray(voldemort.utils.ByteArray) SerializerDefinition(voldemort.serialization.SerializerDefinition) AbstractByteArrayStoreTest(voldemort.store.AbstractByteArrayStoreTest) Test(org.junit.Test)

Example 13 with InsufficientOperationalNodesException

use of voldemort.store.InsufficientOperationalNodesException in project voldemort by voldemort.

the class RoutedStoreTest method testPutTimeout.

@Test
public void testPutTimeout() throws Exception {
    int timeout = 50;
    StoreDefinition definition = new StoreDefinitionBuilder().setName("test").setType("foo").setKeySerializer(new SerializerDefinition("test")).setValueSerializer(new SerializerDefinition("test")).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(3).setPreferredReads(3).setRequiredReads(3).setPreferredWrites(3).setRequiredWrites(3).build();
    Map<Integer, Store<ByteArray, byte[], byte[]>> stores = new HashMap<Integer, Store<ByteArray, byte[], byte[]>>();
    List<Node> nodes = new ArrayList<Node>();
    int totalDelay = 0;
    for (int i = 0; i < 3; i++) {
        int delay = 4 + i * timeout;
        totalDelay += delay;
        Store<ByteArray, byte[], byte[]> store = new SleepyStore<ByteArray, byte[], byte[]>(delay, new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test"));
        stores.put(i, store);
        List<Integer> partitions = Arrays.asList(i);
        nodes.add(new Node(i, "none", 0, 0, 0, partitions));
    }
    setFailureDetector(stores);
    routedStoreThreadPool = Executors.newFixedThreadPool(3);
    RoutedStoreFactory routedStoreFactory = createFactory();
    RoutedStore routedStore = routedStoreFactory.create(new Cluster("test", nodes), definition, stores, failureDetector, createConfig(timeout));
    long start = System.nanoTime();
    try {
        routedStore.put(new ByteArray("test".getBytes()), new Versioned<byte[]>(new byte[] { 1 }), null);
        fail("Should have thrown");
    } catch (InsufficientOperationalNodesException e) {
        long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
        assertTrue(elapsed + " < " + totalDelay, elapsed < totalDelay);
    }
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) HashMap(java.util.HashMap) Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) Store(voldemort.store.Store) SleepyStore(voldemort.store.SleepyStore) StatTrackingStore(voldemort.store.stats.StatTrackingStore) InconsistencyResolvingStore(voldemort.store.versioned.InconsistencyResolvingStore) FailingStore(voldemort.store.FailingStore) FailingReadsStore(voldemort.store.FailingReadsStore) VoldemortTestConstants.getNineNodeCluster(voldemort.VoldemortTestConstants.getNineNodeCluster) Cluster(voldemort.cluster.Cluster) SleepyStore(voldemort.store.SleepyStore) StoreDefinition(voldemort.store.StoreDefinition) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) ByteArray(voldemort.utils.ByteArray) SerializerDefinition(voldemort.serialization.SerializerDefinition) AbstractByteArrayStoreTest(voldemort.store.AbstractByteArrayStoreTest) Test(org.junit.Test)

Example 14 with InsufficientOperationalNodesException

use of voldemort.store.InsufficientOperationalNodesException in project voldemort by voldemort.

the class RoutedStoreTest method testGetAndPutTimeoutZZZ.

@Test
public void testGetAndPutTimeoutZZZ() throws Exception {
    int timeout = 50;
    // Set replication factors for a 3 zone cluster
    HashMap<Integer, Integer> zoneReplicationFactor = Maps.newHashMap();
    zoneReplicationFactor.put(0, 1);
    zoneReplicationFactor.put(1, 1);
    zoneReplicationFactor.put(2, 1);
    // Create a store with RF=3, Required reads = 3 and zone count reads = 2
    // This ensures that a GET operation requires a response from all 3
    // nodes (from the respective 3 zones)
    StoreDefinition definition = new StoreDefinitionBuilder().setName("test").setType("foo").setKeySerializer(new SerializerDefinition("test")).setValueSerializer(new SerializerDefinition("test")).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.ZONE_STRATEGY).setHintedHandoffStrategy(HintedHandoffStrategyType.PROXIMITY_STRATEGY).setReplicationFactor(3).setPreferredReads(3).setRequiredReads(3).setPreferredWrites(3).setRequiredWrites(3).setZoneCountReads(2).setZoneCountWrites(2).setZoneReplicationFactor(zoneReplicationFactor).build();
    Map<Integer, Store<ByteArray, byte[], byte[]>> stores = new HashMap<Integer, Store<ByteArray, byte[], byte[]>>();
    List<Node> nodes = new ArrayList<Node>();
    int totalDelay = 0;
    for (int i = 0; i < 3; i++) {
        int delay = 4 + i * timeout;
        totalDelay += delay;
        Store<ByteArray, byte[], byte[]> store = new SleepyStore<ByteArray, byte[], byte[]>(delay, new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test"));
        stores.put(i, store);
        List<Integer> partitions = Arrays.asList(i);
        nodes.add(new Node(i, "none", 0, 0, 0, i, partitions));
    }
    setFailureDetector(stores);
    routedStoreThreadPool = Executors.newFixedThreadPool(3);
    RoutedStoreFactory routedStoreFactory = createFactory();
    List<Zone> zones = Lists.newArrayList();
    for (int i = 0; i < 3; i++) {
        LinkedList<Integer> zoneProximityList = Lists.newLinkedList();
        Set<Integer> zoneIds = Sets.newHashSet(0, 1, 2);
        zoneIds.remove(i);
        zoneProximityList.addAll(zoneIds);
        zones.add(new Zone(i, zoneProximityList));
    }
    RoutedStore routedStore = routedStoreFactory.create(new Cluster("test", nodes, zones), definition, stores, failureDetector, createConfig(timeout));
    long start = System.nanoTime();
    try {
        routedStore.get(new ByteArray("test".getBytes()), null);
        fail("Should have thrown");
    } catch (InsufficientOperationalNodesException e) {
        long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
        assertTrue(elapsed + " < " + totalDelay, elapsed < totalDelay);
    }
    start = System.nanoTime();
    try {
        routedStore.put(new ByteArray("test".getBytes()), new Versioned<byte[]>(new byte[] { 1 }), null);
        fail("Should have thrown");
    } catch (InsufficientOperationalNodesException e) {
        long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
        assertTrue(elapsed + " < " + totalDelay, elapsed < totalDelay);
    }
}
Also used : HashMap(java.util.HashMap) Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) Store(voldemort.store.Store) SleepyStore(voldemort.store.SleepyStore) StatTrackingStore(voldemort.store.stats.StatTrackingStore) InconsistencyResolvingStore(voldemort.store.versioned.InconsistencyResolvingStore) FailingStore(voldemort.store.FailingStore) FailingReadsStore(voldemort.store.FailingReadsStore) StoreDefinition(voldemort.store.StoreDefinition) ByteArray(voldemort.utils.ByteArray) StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) Zone(voldemort.cluster.Zone) VoldemortTestConstants.getNineNodeCluster(voldemort.VoldemortTestConstants.getNineNodeCluster) Cluster(voldemort.cluster.Cluster) SleepyStore(voldemort.store.SleepyStore) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) SerializerDefinition(voldemort.serialization.SerializerDefinition) AbstractByteArrayStoreTest(voldemort.store.AbstractByteArrayStoreTest) Test(org.junit.Test)

Example 15 with InsufficientOperationalNodesException

use of voldemort.store.InsufficientOperationalNodesException in project voldemort by voldemort.

the class ZoneCountWriteTest method testFastPath.

@Test
public void testFastPath() {
    try {
        client.put("AB", new Versioned<String>("CD"), null);
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        for (Integer nodeId : vservers.keySet()) {
            VoldemortServer vs = vservers.get(nodeId);
            Store<ByteArray, byte[], byte[]> store = vs.getStoreRepository().getLocalStore(storeDef.getName());
            byte[] real = store.get(new ByteArray("AB".getBytes()), null).get(0).getValue();
            assertTrue(Arrays.equals(real, "CD".getBytes()));
        }
    } catch (InsufficientOperationalNodesException e) {
        fail("Failed with exception: " + e);
    }
}
Also used : InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) ByteArray(voldemort.utils.ByteArray) VoldemortServer(voldemort.server.VoldemortServer) Test(org.junit.Test)

Aggregations

InsufficientOperationalNodesException (voldemort.store.InsufficientOperationalNodesException)26 Node (voldemort.cluster.Node)17 ByteArray (voldemort.utils.ByteArray)16 Test (org.junit.Test)10 VoldemortException (voldemort.VoldemortException)9 UnreachableStoreException (voldemort.store.UnreachableStoreException)7 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 ExecutionException (java.util.concurrent.ExecutionException)5 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)5 InsufficientZoneResponsesException (voldemort.store.InsufficientZoneResponsesException)5 VectorClock (voldemort.versioning.VectorClock)5 Versioned (voldemort.versioning.Versioned)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 VoldemortApplicationException (voldemort.VoldemortApplicationException)4 VoldemortTestConstants.getNineNodeCluster (voldemort.VoldemortTestConstants.getNineNodeCluster)4 Cluster (voldemort.cluster.Cluster)4 SerializerDefinition (voldemort.serialization.SerializerDefinition)4 FailingReadsStore (voldemort.store.FailingReadsStore)4