use of com.github.ambry.clustermap.ReplicaId in project ambry by linkedin.
the class AmbryServerRequests method handleRemoveStoreRequest.
/**
* Handles admin request that removes a BlobStore from current node
* @param partitionId the {@link PartitionId} associated with BlobStore
* @return {@link ServerErrorCode} represents result of handling admin request.
*/
private ServerErrorCode handleRemoveStoreRequest(PartitionId partitionId) throws StoreException, IOException {
ServerErrorCode errorCode = ServerErrorCode.No_Error;
ReplicaId replicaId = storeManager.getReplica(partitionId.toPathString());
if (replicaId == null) {
logger.error("{} doesn't exist on current node", partitionId);
return ServerErrorCode.Partition_Unknown;
}
// Attempt to remove replica from stats manager. If replica doesn't exist, log info but don't fail the request
statsManager.removeReplica(replicaId);
// Attempt to remove replica from replication manager. If replica doesn't exist, log info but don't fail the request
((ReplicationManager) replicationEngine).removeReplica(replicaId);
Store store = ((StorageManager) storeManager).getStore(partitionId, true);
// Attempt to remove store from storage manager.
if (storeManager.removeBlobStore(partitionId) && store != null) {
((BlobStore) store).deleteStoreFiles();
for (ReplicaStatusDelegate replicaStatusDelegate : ((BlobStore) store).getReplicaStatusDelegates()) {
// Remove store from sealed and stopped list (if present)
logger.info("Removing store from sealed and stopped list(if present)");
replicaStatusDelegate.unseal(replicaId);
replicaStatusDelegate.unmarkStopped(Collections.singletonList(replicaId));
}
} else {
errorCode = ServerErrorCode.Unknown_Error;
}
return errorCode;
}
use of com.github.ambry.clustermap.ReplicaId in project ambry by linkedin.
the class AmbryServerRequestsTest method addBlobStoreFailureTest.
@Test
public void addBlobStoreFailureTest() throws Exception {
// create newPartition1 that no replica sits on current node.
List<MockDataNodeId> dataNodes = clusterMap.getDataNodes().stream().filter(node -> !node.getHostname().equals(dataNodeId.getHostname()) || node.getPort() != dataNodeId.getPort()).collect(Collectors.toList());
PartitionId newPartition1 = clusterMap.createNewPartition(dataNodes);
// test that getting new replica from cluster map fails
sendAndVerifyStoreControlRequest(newPartition1, BlobStoreControlAction.AddStore, (short) 0, ServerErrorCode.Replica_Unavailable);
// create newPartition2 that has one replica on current node
PartitionId newPartition2 = clusterMap.createNewPartition(clusterMap.getDataNodes());
// test that adding store into StorageManager fails
storageManager.returnValueOfAddBlobStore = false;
sendAndVerifyStoreControlRequest(newPartition2, BlobStoreControlAction.AddStore, (short) 0, ServerErrorCode.Unknown_Error);
storageManager.returnValueOfAddBlobStore = true;
// test that adding replica into ReplicationManager fails (we first add replica into ReplicationManager to trigger failure)
ReplicaId replicaToAdd = clusterMap.getBootstrapReplica(newPartition2.toPathString(), dataNodeId);
replicationManager.addReplica(replicaToAdd);
sendAndVerifyStoreControlRequest(newPartition2, BlobStoreControlAction.AddStore, (short) 0, ServerErrorCode.Unknown_Error);
assertTrue("Remove replica from replication manager should succeed.", replicationManager.removeReplica(replicaToAdd));
// test that adding replica into StatsManager fails
statsManager.returnValOfAddReplica = false;
sendAndVerifyStoreControlRequest(newPartition2, BlobStoreControlAction.AddStore, (short) 0, ServerErrorCode.Unknown_Error);
statsManager.returnValOfAddReplica = true;
}
use of com.github.ambry.clustermap.ReplicaId in project ambry by linkedin.
the class AmbryServerRequestsTest method miscUndeleteFailuresTest.
/**
* Exercises various failure paths for UNDELETEs
* @throws Exception
*/
private void miscUndeleteFailuresTest() throws Exception {
PartitionId id = clusterMap.getWritablePartitionIds(DEFAULT_PARTITION_CLASS).get(0);
// store exceptions
for (StoreErrorCodes code : StoreErrorCodes.values()) {
MockStorageManager.storeException = code == StoreErrorCodes.ID_Undeleted ? new IdUndeletedStoreException("expected", (short) 1) : new StoreException("expected", code);
ServerErrorCode expectedErrorCode = ErrorMapping.getStoreErrorMapping(code);
sendAndVerifyOperationRequest(RequestOrResponseType.UndeleteRequest, Collections.singletonList(id), expectedErrorCode, true, null);
MockStorageManager.storeException = null;
}
// runtime exception
MockStorageManager.runtimeException = new RuntimeException("expected");
sendAndVerifyOperationRequest(RequestOrResponseType.UndeleteRequest, Collections.singletonList(id), ServerErrorCode.Unknown_Error, true, null);
MockStorageManager.runtimeException = null;
// store is not started/is stopped/otherwise unavailable - Replica_Unavailable
storageManager.returnNullStore = true;
sendAndVerifyOperationRequest(RequestOrResponseType.UndeleteRequest, Collections.singletonList(id), ServerErrorCode.Replica_Unavailable, false, null);
storageManager.returnNullStore = false;
// PartitionUnknown is hard to simulate without betraying knowledge of the internals of MockClusterMap.
// disk down
ReplicaId replicaId = findReplica(id);
clusterMap.onReplicaEvent(replicaId, ReplicaEventType.Disk_Error);
sendAndVerifyOperationRequest(RequestOrResponseType.UndeleteRequest, Collections.singletonList(id), ServerErrorCode.Disk_Unavailable, false, null);
clusterMap.onReplicaEvent(replicaId, ReplicaEventType.Disk_Ok);
// request disabled is checked in request control tests
}
use of com.github.ambry.clustermap.ReplicaId 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.ReplicaId in project ambry by linkedin.
the class AmbryServerRequestsTest method miscTtlUpdateFailuresTest.
/**
* Exercises various failure paths for TTL updates
* @throws InterruptedException
* @throws IOException
*/
private void miscTtlUpdateFailuresTest() throws InterruptedException, IOException {
PartitionId id = clusterMap.getWritablePartitionIds(DEFAULT_PARTITION_CLASS).get(0);
// store exceptions
for (StoreErrorCodes code : StoreErrorCodes.values()) {
MockStorageManager.storeException = new StoreException("expected", code);
ServerErrorCode expectedErrorCode = ErrorMapping.getStoreErrorMapping(code);
sendAndVerifyOperationRequest(RequestOrResponseType.TtlUpdateRequest, Collections.singletonList(id), expectedErrorCode, true, null);
MockStorageManager.storeException = null;
}
// runtime exception
MockStorageManager.runtimeException = new RuntimeException("expected");
sendAndVerifyOperationRequest(RequestOrResponseType.TtlUpdateRequest, Collections.singletonList(id), ServerErrorCode.Unknown_Error, true, null);
MockStorageManager.runtimeException = null;
// store is not started/is stopped/otherwise unavailable - Replica_Unavailable
storageManager.returnNullStore = true;
sendAndVerifyOperationRequest(RequestOrResponseType.TtlUpdateRequest, Collections.singletonList(id), ServerErrorCode.Replica_Unavailable, false, null);
storageManager.returnNullStore = false;
// PartitionUnknown is hard to simulate without betraying knowledge of the internals of MockClusterMap.
// disk down
ReplicaId replicaId = findReplica(id);
clusterMap.onReplicaEvent(replicaId, ReplicaEventType.Disk_Error);
sendAndVerifyOperationRequest(RequestOrResponseType.TtlUpdateRequest, Collections.singletonList(id), ServerErrorCode.Disk_Unavailable, false, null);
clusterMap.onReplicaEvent(replicaId, ReplicaEventType.Disk_Ok);
// request disabled is checked in request control tests
}
Aggregations