Search in sources :

Example 11 with StoreRoutingPlan

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

the class ClusterForkLiftToolTest method testPrimaryResolvingForkLift.

@Test
public void testPrimaryResolvingForkLift() throws Exception {
    StoreRoutingPlan srcStoreInstance = new StoreRoutingPlan(srcCluster, primaryResolvingStoreDef);
    // populate data on the source cluster..
    for (Map.Entry<String, String> entry : kvPairs.entrySet()) {
        srcPrimaryResolvingStoreClient.put(entry.getKey(), entry.getValue());
    }
    // generate a conflict on the master partition
    int masterNode = srcStoreInstance.getNodeIdForPartitionId(srcStoreInstance.getMasterPartitionId(conflictKey.getBytes("UTF-8")));
    VectorClock losingClock = new VectorClock(Lists.newArrayList(new ClockEntry((short) 0, 5)), System.currentTimeMillis());
    VectorClock winningClock = new VectorClock(Lists.newArrayList(new ClockEntry((short) 1, 5)), losingClock.getTimestamp() + 1);
    srcAdminClient.storeOps.putNodeKeyValue(PRIMARY_RESOLVING_STORE_NAME, new NodeValue<ByteArray, byte[]>(masterNode, new ByteArray(conflictKey.getBytes("UTF-8")), new Versioned<byte[]>("losing value".getBytes("UTF-8"), losingClock)));
    srcAdminClient.storeOps.putNodeKeyValue(PRIMARY_RESOLVING_STORE_NAME, new NodeValue<ByteArray, byte[]>(masterNode, new ByteArray(conflictKey.getBytes("UTF-8")), new Versioned<byte[]>("winning value".getBytes("UTF-8"), winningClock)));
    // do a write to destination cluster
    dstPrimaryResolvingStoreClient.put(firstKey, "before forklift");
    // perform the forklifting..
    ClusterForkLiftTool forkLiftTool = new ClusterForkLiftTool(srcBootStrapUrl, dstBootStrapUrl, false, // ignoreSchemaMismatch
    false, 10000, 1, 1000, Lists.newArrayList(PRIMARY_RESOLVING_STORE_NAME), null, ClusterForkLiftTool.ForkLiftTaskMode.primary_resolution);
    forkLiftTool.run();
    // do a write to destination cluster
    dstPrimaryResolvingStoreClient.put(lastKey, "after forklift");
    // verify data on the destination is as expected
    for (Map.Entry<String, String> entry : kvPairs.entrySet()) {
        if (entry.getKey().equals(firstKey)) {
            assertEquals("Online write overwritten", dstPrimaryResolvingStoreClient.get(firstKey).getValue(), "before forklift");
        } else if (entry.getKey().equals(lastKey)) {
            assertEquals("can't update value after forklift", dstPrimaryResolvingStoreClient.get(lastKey).getValue(), "after forklift");
        } else if (entry.getKey().equals(conflictKey)) {
            assertEquals("Conflict resolution incorrect", dstPrimaryResolvingStoreClient.get(conflictKey).getValue(), "winning value");
        } else {
            assertEquals("fork lift data missing", dstPrimaryResolvingStoreClient.get(entry.getKey()).getValue(), entry.getValue());
        }
    }
}
Also used : StoreRoutingPlan(voldemort.routing.StoreRoutingPlan) Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) HashMap(java.util.HashMap) Map(java.util.Map) ClockEntry(voldemort.versioning.ClockEntry) Test(org.junit.Test)

Example 12 with StoreRoutingPlan

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

the class ClusterForkLiftToolTest method testNoresolutionForkLift.

@Test
public void testNoresolutionForkLift() throws Exception {
    int versions = 0;
    StoreRoutingPlan srcStoreInstance = new StoreRoutingPlan(srcCluster, nonResolvingStoreDef);
    // generate a conflict on the master partition
    int masterNode = srcStoreInstance.getNodeIdForPartitionId(srcStoreInstance.getMasterPartitionId(conflictKey.getBytes("UTF-8")));
    VectorClock losingClock = new VectorClock(Lists.newArrayList(new ClockEntry((short) 0, 5)), System.currentTimeMillis());
    VectorClock winningClock = new VectorClock(Lists.newArrayList(new ClockEntry((short) 1, 5)), losingClock.getTimestamp() + 1);
    srcAdminClient.storeOps.putNodeKeyValue(MULTIPLE_VERSIONS_STORE_NAME, new NodeValue<ByteArray, byte[]>(masterNode, new ByteArray(conflictKey.getBytes("UTF-8")), new Versioned<byte[]>("losing value".getBytes("UTF-8"), losingClock)));
    srcAdminClient.storeOps.putNodeKeyValue(MULTIPLE_VERSIONS_STORE_NAME, new NodeValue<ByteArray, byte[]>(masterNode, new ByteArray(conflictKey.getBytes("UTF-8")), new Versioned<byte[]>("winning value".getBytes("UTF-8"), winningClock)));
    // perform the forklifting..
    ClusterForkLiftTool forkLiftTool = new ClusterForkLiftTool(srcBootStrapUrl, dstBootStrapUrl, false, // ignoreSchemaMismatch
    false, 10000, 1, 1000, Lists.newArrayList(MULTIPLE_VERSIONS_STORE_NAME), null, ClusterForkLiftTool.ForkLiftTaskMode.no_resolution);
    forkLiftTool.run();
    AdminClient dstAdminClient = new AdminClient(dstBootStrapUrl);
    for (Node node : dstAdminClient.getAdminClientCluster().getNodes()) {
        Iterator<Pair<ByteArray, Versioned<byte[]>>> entryItr = dstAdminClient.bulkFetchOps.fetchEntries(node.getId(), MULTIPLE_VERSIONS_STORE_NAME, node.getPartitionIds(), null, true);
        while (entryItr.hasNext()) {
            Pair<ByteArray, Versioned<byte[]>> record = entryItr.next();
            ByteArray key = record.getFirst();
            Versioned<byte[]> versioned = record.getSecond();
            versions++;
        }
    }
    assertEquals("Both conflicting versions present", versions, 2);
}
Also used : StoreRoutingPlan(voldemort.routing.StoreRoutingPlan) Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) Node(voldemort.cluster.Node) ClockEntry(voldemort.versioning.ClockEntry) AdminClient(voldemort.client.protocol.admin.AdminClient) Test(org.junit.Test)

Example 13 with StoreRoutingPlan

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

the class VersionedPutPruningTest method setup.

@Before
public void setup() throws Exception {
    cluster = VoldemortTestConstants.getNineNodeCluster();
    StringReader reader = new StringReader(VoldemortTestConstants.getSingleStore322Xml());
    storeDef = new StoreDefinitionsMapper().readStoreList(reader).get(0);
    routingPlan = new StoreRoutingPlan(cluster, storeDef);
    key = "key1".getBytes();
    keyReplicas = Lists.newArrayList(0, 2, 1);
}
Also used : StoreRoutingPlan(voldemort.routing.StoreRoutingPlan) StringReader(java.io.StringReader) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) Before(org.junit.Before)

Example 14 with StoreRoutingPlan

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

the class FetchPartitionFileStreamRequestHandler method handleNextPartition.

private StreamRequestHandlerState handleNextPartition() {
    StreamRequestHandlerState handlerState = StreamRequestHandlerState.WRITING;
    if (partitionIterator.hasNext()) {
        // Start a new partition
        Integer partitionId = partitionIterator.next();
        int nodeId = metadataStore.getNodeId();
        int zoneId = metadataStore.getCluster().getNodeById(nodeId).getZoneId();
        StoreDefinition storeDef = metadataStore.getStoreDef(request.getStoreName());
        StoreRoutingPlan storeRoutingPlan = new StoreRoutingPlan(metadataStore.getCluster(), storeDef);
        int getZoneNary = storeRoutingPlan.getZoneNaryForNodesPartition(zoneId, nodeId, partitionId);
        currentPair = Pair.create(getZoneNary, partitionId);
        currentChunkId = 0;
        // First check if bucket exists
        if (!bucketToNumChunks.containsKey(Pair.create(currentPair.getSecond(), currentPair.getFirst()))) {
            throw new VoldemortException("Bucket [ partition = " + currentPair.getSecond() + ", replica = " + currentPair.getFirst() + " ] does not exist for store " + request.getStoreName());
        }
        numChunks = bucketToNumChunks.get(Pair.create(currentPair.getSecond(), currentPair.getFirst()));
        dataFile = indexFile = null;
        fetchStatus = FetchStatus.SEND_DATA_FILE;
    } else {
        // We are done since we have gone through the entire
        // partition list
        logger.info("Finished streaming files for partitions tuples " + partitionIds);
        handlerState = StreamRequestHandlerState.COMPLETE;
    }
    return handlerState;
}
Also used : StoreRoutingPlan(voldemort.routing.StoreRoutingPlan) StoreDefinition(voldemort.store.StoreDefinition) VoldemortException(voldemort.VoldemortException)

Aggregations

StoreRoutingPlan (voldemort.routing.StoreRoutingPlan)14 StoreDefinition (voldemort.store.StoreDefinition)8 Test (org.junit.Test)6 Versioned (voldemort.versioning.Versioned)5 HashMap (java.util.HashMap)4 VoldemortException (voldemort.VoldemortException)4 ClockEntry (voldemort.versioning.ClockEntry)4 VectorClock (voldemort.versioning.VectorClock)4 Map (java.util.Map)3 Cluster (voldemort.cluster.Cluster)3 Node (voldemort.cluster.Node)3 ByteArray (voldemort.utils.ByteArray)2 File (java.io.File)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MutableBoolean (org.apache.commons.lang.mutable.MutableBoolean)1 Before (org.junit.Before)1