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);
}
}
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());
}
}
}
Aggregations