Search in sources :

Example 1 with ReplicaState

use of com.github.ambry.clustermap.ReplicaState in project ambry by linkedin.

the class AmbryServerRequestsTest method validateRequestsTest.

/**
 * Tests that requests are validated based on local store state.
 */
@Test
public void validateRequestsTest() {
    // choose several replicas and make them in different states (there are 10 replicas on current node)
    List<ReplicaId> localReplicas = clusterMap.getReplicaIds(dataNodeId);
    Map<ReplicaState, ReplicaId> stateToReplica = new HashMap<>();
    int cnt = 0;
    for (ReplicaState state : EnumSet.complementOf(EnumSet.of(ReplicaState.ERROR))) {
        stateToReplica.put(state, localReplicas.get(cnt));
        cnt++;
    }
    // set store state
    for (Map.Entry<ReplicaState, ReplicaId> entry : stateToReplica.entrySet()) {
        storageManager.getStore(entry.getValue().getPartitionId()).setCurrentState(entry.getKey());
    }
    for (RequestOrResponseType request : EnumSet.of(RequestOrResponseType.PutRequest, RequestOrResponseType.GetRequest, RequestOrResponseType.DeleteRequest, RequestOrResponseType.TtlUpdateRequest, RequestOrResponseType.UndeleteRequest)) {
        for (Map.Entry<ReplicaState, ReplicaId> entry : stateToReplica.entrySet()) {
            if (request == RequestOrResponseType.PutRequest) {
                // for PUT request, it is not allowed on OFFLINE,BOOTSTRAP and INACTIVE when validateRequestOnStoreState = true
                if (AmbryServerRequests.PUT_ALLOWED_STORE_STATES.contains(entry.getKey())) {
                    assertEquals("Error code is not expected for PUT request", ServerErrorCode.No_Error, ambryRequests.validateRequest(entry.getValue().getPartitionId(), request, false));
                } else {
                    assertEquals("Error code is not expected for PUT request", validateRequestOnStoreState ? ServerErrorCode.Temporarily_Disabled : ServerErrorCode.No_Error, ambryRequests.validateRequest(entry.getValue().getPartitionId(), request, false));
                }
            } else if (AmbryServerRequests.UPDATE_REQUEST_TYPES.contains(request)) {
                // for UNDELETE/DELETE/TTL Update request, they are not allowed on OFFLINE,BOOTSTRAP and INACTIVE when validateRequestOnStoreState = true
                if (AmbryServerRequests.UPDATE_ALLOWED_STORE_STATES.contains(entry.getKey())) {
                    assertEquals("Error code is not expected for DELETE/TTL Update", ServerErrorCode.No_Error, ambryRequests.validateRequest(entry.getValue().getPartitionId(), request, false));
                } else {
                    assertEquals("Error code is not expected for DELETE/TTL Update", validateRequestOnStoreState ? ServerErrorCode.Temporarily_Disabled : ServerErrorCode.No_Error, ambryRequests.validateRequest(entry.getValue().getPartitionId(), request, false));
                }
            } else {
                // for GET request, all states should be allowed
                assertEquals("Error code is not expected for GET request", ServerErrorCode.No_Error, ambryRequests.validateRequest(entry.getValue().getPartitionId(), request, false));
            }
        }
    }
    // reset all stores state to STANDBY
    for (Map.Entry<ReplicaState, ReplicaId> entry : stateToReplica.entrySet()) {
        storageManager.getStore(entry.getValue().getPartitionId()).setCurrentState(ReplicaState.STANDBY);
    }
}
Also used : AdminRequestOrResponseType(com.github.ambry.protocol.AdminRequestOrResponseType) RequestOrResponseType(com.github.ambry.protocol.RequestOrResponseType) HashMap(java.util.HashMap) ReplicaState(com.github.ambry.clustermap.ReplicaState) Map(java.util.Map) HashMap(java.util.HashMap) ClusterMap(com.github.ambry.clustermap.ClusterMap) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) ReplicaId(com.github.ambry.clustermap.ReplicaId) MockReplicaId(com.github.ambry.clustermap.MockReplicaId) Test(org.junit.Test) MessageInfoTest(com.github.ambry.store.MessageInfoTest) MessageFormatInputStreamTest(com.github.ambry.messageformat.MessageFormatInputStreamTest)

Example 2 with ReplicaState

use of com.github.ambry.clustermap.ReplicaState in project ambry by linkedin.

the class OperationTrackerTest method getOperationWithReplicaStateTest.

/**
 * Test GET operation is able to try on OFFLINE replicas if routerOperationTrackerIncludeDownReplicas is true.
 */
@Test
public void getOperationWithReplicaStateTest() {
    assumeTrue(replicasStateEnabled);
    List<Port> portList = Collections.singletonList(new Port(PORT, PortType.PLAINTEXT));
    List<String> mountPaths = Collections.singletonList("mockMountPath");
    datanodes = new ArrayList<>(Arrays.asList(new MockDataNodeId(portList, mountPaths, "dc-0"), new MockDataNodeId(portList, mountPaths, "dc-1")));
    mockPartition = new MockPartitionId();
    for (ReplicaState state : EnumSet.of(ReplicaState.BOOTSTRAP, ReplicaState.STANDBY, ReplicaState.LEADER, ReplicaState.INACTIVE, ReplicaState.OFFLINE)) {
        populateReplicaList(1, state);
    }
    localDcName = datanodes.get(0).getDatacenterName();
    mockClusterMap = new MockClusterMap(false, datanodes, 1, Collections.singletonList(mockPartition), localDcName);
    // 1. include down replicas (OFFLINE replicas are eligible for GET)
    OperationTracker ot = getOperationTracker(true, 1, 1, RouterOperation.GetBlobOperation, true);
    // make sure 4 requests fails and last one succeeds. (This is to verify operation tracker adds offline replica into replica pool as well)
    ReplicaId inflightReplica;
    for (int i = 0; i < 4; ++i) {
        sendRequests(ot, 1, false);
        inflightReplica = inflightReplicas.poll();
        // verify that the first 4 replicas are not OFFLINE replica. (OFFLINE replica should be added to the end of queue)
        assertNotSame("Replica state should not be OFFLINE ", mockPartition.replicaAndState.get(inflightReplica), ReplicaState.OFFLINE);
        ot.onResponse(inflightReplica, TrackedRequestFinalState.FAILURE);
        assertFalse("Operation should not complete", ot.isDone());
    }
    sendRequests(ot, 1, false);
    inflightReplica = inflightReplicas.poll();
    assertEquals("The last replica should be OFFLINE", ReplicaState.OFFLINE, mockPartition.replicaAndState.get(inflightReplica));
    ot.onResponse(inflightReplica, TrackedRequestFinalState.SUCCESS);
    assertTrue("Operation should be done", ot.isDone());
    // 2. exclude down replicas
    repetitionTracker.clear();
    ot = getOperationTracker(true, 1, 1, RouterOperation.GetBlobOperation, false);
    for (int i = 0; i < 4; ++i) {
        sendRequests(ot, 1, false);
        inflightReplica = inflightReplicas.poll();
        // verify that none of these replicas is OFFLINE replica.
        assertNotSame("Replica state should not be OFFLINE ", mockPartition.replicaAndState.get(inflightReplica), ReplicaState.OFFLINE);
        ot.onResponse(inflightReplica, TrackedRequestFinalState.FAILURE);
        if (i < 3) {
            assertFalse("Operation should not complete", ot.isDone());
        } else {
            assertTrue("Operation should complete", ot.isDone());
        }
    }
}
Also used : MockPartitionId(com.github.ambry.clustermap.MockPartitionId) Port(com.github.ambry.network.Port) MockDataNodeId(com.github.ambry.clustermap.MockDataNodeId) ReplicaState(com.github.ambry.clustermap.ReplicaState) MockReplicaId(com.github.ambry.clustermap.MockReplicaId) ReplicaId(com.github.ambry.clustermap.ReplicaId) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Aggregations

MockClusterMap (com.github.ambry.clustermap.MockClusterMap)2 MockReplicaId (com.github.ambry.clustermap.MockReplicaId)2 ReplicaId (com.github.ambry.clustermap.ReplicaId)2 ReplicaState (com.github.ambry.clustermap.ReplicaState)2 Test (org.junit.Test)2 ClusterMap (com.github.ambry.clustermap.ClusterMap)1 MockDataNodeId (com.github.ambry.clustermap.MockDataNodeId)1 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)1 MessageFormatInputStreamTest (com.github.ambry.messageformat.MessageFormatInputStreamTest)1 Port (com.github.ambry.network.Port)1 AdminRequestOrResponseType (com.github.ambry.protocol.AdminRequestOrResponseType)1 RequestOrResponseType (com.github.ambry.protocol.RequestOrResponseType)1 MessageInfoTest (com.github.ambry.store.MessageInfoTest)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1