Search in sources :

Example 1 with HandoffToAnyStrategy

use of voldemort.store.slop.strategy.HandoffToAnyStrategy in project voldemort by voldemort.

the class StreamingClient method streamingSlopPut.

/**
     * This is a method to stream slops to "slop" store when a node is detected
     * faulty in a streaming session
     * 
     * @param key -- original key
     * @param value -- original value
     * @param storeName -- the store for which we are registering the slop
     * @param failedNodeId -- the faulty node ID for which we register a slop
     * @throws IOException
     */
protected synchronized void streamingSlopPut(ByteArray key, Versioned<byte[]> value, String storeName, int failedNodeId) throws IOException {
    Slop slop = new Slop(storeName, Slop.Operation.PUT, key, value.getValue(), null, failedNodeId, new Date());
    ByteArray slopKey = slop.makeKey();
    Versioned<byte[]> slopValue = new Versioned<byte[]>(slopSerializer.toBytes(slop), value.getVersion());
    Node failedNode = adminClient.getAdminClientCluster().getNodeById(failedNodeId);
    HandoffToAnyStrategy slopRoutingStrategy = new HandoffToAnyStrategy(adminClient.getAdminClientCluster(), true, failedNode.getZoneId());
    // node Id which will receive the slop
    int slopDestination = slopRoutingStrategy.routeHint(failedNode).get(0).getId();
    VAdminProto.PartitionEntry partitionEntry = VAdminProto.PartitionEntry.newBuilder().setKey(ProtoUtils.encodeBytes(slopKey)).setVersioned(ProtoUtils.encodeVersioned(slopValue)).build();
    VAdminProto.UpdatePartitionEntriesRequest.Builder updateRequest = VAdminProto.UpdatePartitionEntriesRequest.newBuilder().setStore(SLOP_STORE).setPartitionEntry(partitionEntry);
    DataOutputStream outputStream = nodeIdStoreToOutputStreamRequest.get(new Pair<String, Integer>(SLOP_STORE, slopDestination));
    if (nodeIdStoreInitialized.get(new Pair<String, Integer>(SLOP_STORE, slopDestination))) {
        ProtoUtils.writeMessage(outputStream, updateRequest.build());
    } else {
        ProtoUtils.writeMessage(outputStream, VAdminProto.VoldemortAdminRequest.newBuilder().setType(VAdminProto.AdminRequestType.UPDATE_PARTITION_ENTRIES).setUpdatePartitionEntries(updateRequest).build());
        outputStream.flush();
        nodeIdStoreInitialized.put(new Pair<String, Integer>(SLOP_STORE, slopDestination), true);
    }
    throttler.maybeThrottle(1);
}
Also used : Versioned(voldemort.versioning.Versioned) DataOutputStream(java.io.DataOutputStream) Node(voldemort.cluster.Node) HandoffToAnyStrategy(voldemort.store.slop.strategy.HandoffToAnyStrategy) Date(java.util.Date) ByteArray(voldemort.utils.ByteArray) VAdminProto(voldemort.client.protocol.pb.VAdminProto) Slop(voldemort.store.slop.Slop)

Example 2 with HandoffToAnyStrategy

use of voldemort.store.slop.strategy.HandoffToAnyStrategy in project voldemort by voldemort.

the class HandoffToAnyStrategyTest method testRouteHint.

@Test
public void testRouteHint() {
    Cluster cluster = VoldemortTestConstants.getNineNodeCluster();
    HintedHandoffStrategy handoffStrategy = new HandoffToAnyStrategy(cluster, false, 0);
    for (Node origin : cluster.getNodes()) {
        List<Node> nodes = handoffStrategy.routeHint(origin);
        assertTrue("hint preflist is correctly sized", nodes.size() == cluster.getNumberOfNodes() - 1);
        assertFalse("hint preflist doesn't include self", nodes.contains(origin));
    }
}
Also used : Node(voldemort.cluster.Node) Cluster(voldemort.cluster.Cluster) HandoffToAnyStrategy(voldemort.store.slop.strategy.HandoffToAnyStrategy) HintedHandoffStrategy(voldemort.store.slop.strategy.HintedHandoffStrategy) Test(org.junit.Test)

Example 3 with HandoffToAnyStrategy

use of voldemort.store.slop.strategy.HandoffToAnyStrategy in project voldemort by voldemort.

the class HandoffToAnyStrategyTest method testRouteHintWithZones.

@Test
public void testRouteHintWithZones() {
    Cluster cluster = VoldemortTestConstants.getEightNodeClusterWithZones();
    HintedHandoffStrategy handoffStrategy0 = new HandoffToAnyStrategy(cluster, true, 0);
    HintedHandoffStrategy handoffStrategy1 = new HandoffToAnyStrategy(cluster, true, 1);
    List<Node> zone0Nodes = Lists.newArrayList();
    List<Node> zone1Nodes = Lists.newArrayList();
    for (int nodeId : ImmutableList.of(0, 1, 2, 3)) zone0Nodes.add(cluster.getNodeById(nodeId));
    for (int nodeId : ImmutableList.of(4, 5, 6, 7)) zone1Nodes.add(cluster.getNodeById(nodeId));
    for (Node origin : zone0Nodes) {
        List<Node> nodes = handoffStrategy0.routeHint(origin);
        assertFalse("hint preflist doesn't include self", nodes.contains(origin));
        for (Node node : nodes) assertFalse("local hints not routed remotely", zone1Nodes.contains(node));
        nodes = handoffStrategy1.routeHint(origin);
        assertFalse("hint preflist doesn't include self", nodes.contains(origin));
        for (Node node : nodes) assertTrue("remote hints routed locally", zone1Nodes.contains(node));
    }
    for (Node origin : zone1Nodes) {
        List<Node> nodes = handoffStrategy1.routeHint(origin);
        assertFalse("hint preflist doesn't include self", nodes.contains(origin));
        for (Node node : nodes) assertFalse("local hints not routed remotely", zone0Nodes.contains(node));
        nodes = handoffStrategy0.routeHint(origin);
        assertFalse("hint preflist doesn't include self", nodes.contains(origin));
        for (Node node : nodes) assertTrue("remote hints routed locally", zone0Nodes.contains(node));
    }
}
Also used : Node(voldemort.cluster.Node) Cluster(voldemort.cluster.Cluster) HandoffToAnyStrategy(voldemort.store.slop.strategy.HandoffToAnyStrategy) HintedHandoffStrategy(voldemort.store.slop.strategy.HintedHandoffStrategy) Test(org.junit.Test)

Aggregations

Node (voldemort.cluster.Node)3 HandoffToAnyStrategy (voldemort.store.slop.strategy.HandoffToAnyStrategy)3 Test (org.junit.Test)2 Cluster (voldemort.cluster.Cluster)2 HintedHandoffStrategy (voldemort.store.slop.strategy.HintedHandoffStrategy)2 DataOutputStream (java.io.DataOutputStream)1 Date (java.util.Date)1 VAdminProto (voldemort.client.protocol.pb.VAdminProto)1 Slop (voldemort.store.slop.Slop)1 ByteArray (voldemort.utils.ByteArray)1 Versioned (voldemort.versioning.Versioned)1