Search in sources :

Example 11 with BaseStoreRoutingPlan

use of voldemort.routing.BaseStoreRoutingPlan in project voldemort by voldemort.

the class ZonedRebalanceNonContiguousZonesTest method populateData.

private void populateData(Cluster cluster, StoreDefinition storeDef) throws Exception {
    // Create SocketStores for each Node first
    Map<Integer, Store<ByteArray, byte[], byte[]>> storeMap = new HashMap<Integer, Store<ByteArray, byte[], byte[]>>();
    for (Node node : cluster.getNodes()) {
        storeMap.put(node.getId(), getSocketStore(storeDef.getName(), node.getHost(), node.getSocketPort()));
    }
    BaseStoreRoutingPlan storeInstance = new BaseStoreRoutingPlan(cluster, storeDef);
    for (Entry<String, String> entry : testEntries.entrySet()) {
        ByteArray keyBytes = new ByteArray(ByteUtils.getBytes(entry.getKey(), "UTF-8"));
        List<Integer> preferenceNodes = storeInstance.getReplicationNodeList(keyBytes.get());
        // Go over every node
        for (int nodeId : preferenceNodes) {
            try {
                storeMap.get(nodeId).put(keyBytes, new Versioned<byte[]>(ByteUtils.getBytes(entry.getValue(), "UTF-8")), null);
            } catch (ObsoleteVersionException e) {
                logger.info("Why are we seeing this at all here ?? ");
                e.printStackTrace();
            }
        }
    }
    // close all socket stores
    for (Store<ByteArray, byte[], byte[]> store : storeMap.values()) {
        store.close();
    }
}
Also used : HashMap(java.util.HashMap) Node(voldemort.cluster.Node) Store(voldemort.store.Store) MetadataStore(voldemort.store.metadata.MetadataStore) ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) ByteArray(voldemort.utils.ByteArray) BaseStoreRoutingPlan(voldemort.routing.BaseStoreRoutingPlan)

Example 12 with BaseStoreRoutingPlan

use of voldemort.routing.BaseStoreRoutingPlan in project voldemort by voldemort.

the class RedirectingStore method getProxyNode.

/**
     * Wrapper around
     * {@link RedirectingStore#getProxyNode(BaseStoreRoutingPlan, StoreDefinition, byte[])}
     * 
     * @param key
     * @return
     */
private Integer getProxyNode(byte[] key) {
    Cluster currentCluster = metadata.getCluster();
    StoreDefinition storeDef = metadata.getStoreDef(getName());
    // TODO Ideally, this object construction should be done only when
    // metadata changes using a listener mechanism
    BaseStoreRoutingPlan currentRoutingPlan = new BaseStoreRoutingPlan(currentCluster, storeDef);
    return getProxyNode(currentRoutingPlan, storeDef, key);
}
Also used : StoreDefinition(voldemort.store.StoreDefinition) Cluster(voldemort.cluster.Cluster) BaseStoreRoutingPlan(voldemort.routing.BaseStoreRoutingPlan)

Example 13 with BaseStoreRoutingPlan

use of voldemort.routing.BaseStoreRoutingPlan in project voldemort by voldemort.

the class RoutedStoreTest method testReadRepairWithFailuresZZZ.

/**
     * Test to ensure that read repair happens correctly across zones in case of
     * inconsistent writes in a 3 zone cluster.
     * 
     * @throws Exception
     */
@Test
public void testReadRepairWithFailuresZZZ() throws Exception {
    cluster = VoldemortTestConstants.getSixNodeClusterWith3Zones();
    HashMap<Integer, Integer> zoneReplicationFactor = Maps.newHashMap();
    zoneReplicationFactor.put(0, cluster.getNumberOfNodesInZone(0));
    zoneReplicationFactor.put(1, cluster.getNumberOfNodesInZone(0));
    zoneReplicationFactor.put(2, cluster.getNumberOfNodesInZone(0));
    // PR = RR = 6
    // PW = RW = 4
    // Zone Reads = # Zones - 1
    // Zone Writes = 1
    // Threads = 1
    RoutedStore routedStore = getStore(cluster, 6, 4, cluster.getNumberOfZones() - 1, 1, 1, zoneReplicationFactor);
    Store<ByteArray, byte[], byte[]> store = new InconsistencyResolvingStore<ByteArray, byte[], byte[]>(routedStore, new VectorClockInconsistencyResolver<byte[]>());
    BaseStoreRoutingPlan routingPlan = new BaseStoreRoutingPlan(cluster, this.storeDef);
    List<Integer> replicatingNodes = routingPlan.getReplicationNodeList(aKey.get());
    try {
        // Do the initial put with all nodes up
        store.put(aKey, new Versioned<byte[]>(aValue), null);
        List<Version> initialVersions = store.getVersions(aKey);
        assertEquals(6, initialVersions.size());
        Version mainVersion = initialVersions.get(0);
        for (int i = 1; i < initialVersions.size(); i++) {
            assertEquals(mainVersion, initialVersions.get(i));
        }
        // Do another put with all nodes in the zone 0 marked as
        // unavailable. This will force the put to use a different pseudo
        // master than before.
        byte[] anotherValue = "john".getBytes();
        // In this cluster, nodes 0 and 1 are in Zone 0. Mark them
        // unavailable
        recordException(failureDetector, cluster.getNodeById(0));
        recordException(failureDetector, cluster.getNodeById(1));
        Version newVersion = ((VectorClock) mainVersion).clone();
        store.put(aKey, new Versioned<byte[]>(anotherValue, newVersion), null);
        waitForOperationToComplete(500);
        // Mark the nodes in Zone 0 as available and do a get. The Required
        // reads = 4 and Zone count reads = 2 will force the client to read
        // from all the zones and do the essential read repairs.
        recordSuccess(failureDetector, cluster.getNodeById(0));
        recordSuccess(failureDetector, cluster.getNodeById(1));
        List<Versioned<byte[]>> versioneds = store.get(aKey, null);
        assertEquals(1, versioneds.size());
        assertEquals(new ByteArray(anotherValue), new ByteArray(versioneds.get(0).getValue()));
        // Read repairs are done asynchronously, so we sleep for a short
        // period. It may be a good idea to use a synchronous executor
        // service.
        Thread.sleep(500);
        for (Map.Entry<Integer, Store<ByteArray, byte[], byte[]>> innerStoreEntry : routedStore.getInnerStores().entrySet()) {
            // Only look at the nodes in the pref list
            if (replicatingNodes.contains(innerStoreEntry.getKey())) {
                List<Versioned<byte[]>> innerVersioneds = innerStoreEntry.getValue().get(aKey, null);
                assertEquals(1, versioneds.size());
                assertEquals(new ByteArray(anotherValue), new ByteArray(innerVersioneds.get(0).getValue()));
            }
        }
    } catch (VoldemortException ve) {
        fail("Unexpected error occurred : " + ve);
    }
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) 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) VoldemortException(voldemort.VoldemortException) InconsistencyResolvingStore(voldemort.store.versioned.InconsistencyResolvingStore) Version(voldemort.versioning.Version) ByteArray(voldemort.utils.ByteArray) BaseStoreRoutingPlan(voldemort.routing.BaseStoreRoutingPlan) Map(java.util.Map) HashMap(java.util.HashMap) AbstractByteArrayStoreTest(voldemort.store.AbstractByteArrayStoreTest) Test(org.junit.Test)

Example 14 with BaseStoreRoutingPlan

use of voldemort.routing.BaseStoreRoutingPlan in project voldemort by voldemort.

the class ExceededQuotaSlopTest method generateKeysForMasterNode.

private HashMap<String, String> generateKeysForMasterNode(int numKeys) throws IOException {
    // Assumes master node is 0 and generates keys that goes to master node
    HashMap<String, String> keyValuePairs = new HashMap<String, String>();
    StoreDefinitionsMapper storedDefMapper = new StoreDefinitionsMapper();
    List<StoreDefinition> storeDefs = storedDefMapper.readStoreList(new File(storesxml));
    StoreDefinition testStoreDef = storeDefs.get(0);
    BaseStoreRoutingPlan baseStoreRoutingPlan = new BaseStoreRoutingPlan(cluster, testStoreDef);
    /*
         * Generating simple key values pairs of the form 3:3 where key and
         * value are same but route to the Master node's partition
         */
    int key = 0;
    int partiionId = -1;
    for (int count = 0; count < numKeys; ) {
        byte[] keyBytes = Integer.toString(key).getBytes();
        partiionId = baseStoreRoutingPlan.getMasterPartitionId(keyBytes);
        if (partitionToNodeMap.get(partiionId) == 0) {
            keyValuePairs.put(String.valueOf(key), String.valueOf(key));
            count++;
        }
        key++;
    }
    return keyValuePairs;
}
Also used : HashMap(java.util.HashMap) StoreDefinition(voldemort.store.StoreDefinition) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) BaseStoreRoutingPlan(voldemort.routing.BaseStoreRoutingPlan) File(java.io.File)

Aggregations

BaseStoreRoutingPlan (voldemort.routing.BaseStoreRoutingPlan)14 StoreDefinition (voldemort.store.StoreDefinition)7 ByteArray (voldemort.utils.ByteArray)7 HashMap (java.util.HashMap)6 Store (voldemort.store.Store)6 Node (voldemort.cluster.Node)5 Versioned (voldemort.versioning.Versioned)5 Test (org.junit.Test)4 Cluster (voldemort.cluster.Cluster)4 File (java.io.File)3 MetadataStore (voldemort.store.metadata.MetadataStore)3 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)3 VectorClock (voldemort.versioning.VectorClock)3 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 VoldemortException (voldemort.VoldemortException)2 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)2