use of com.github.ambry.store.BlobStore in project ambry by linkedin.
the class AmbryServerRequestsTest method removeBlobStoreFailureTest.
@Test
public void removeBlobStoreFailureTest() throws Exception {
// first, create new partition but don't add to current node
PartitionId newPartition = clusterMap.createNewPartition(clusterMap.getDataNodes());
// test store removal failure because store doesn't exist
sendAndVerifyStoreControlRequest(newPartition, BlobStoreControlAction.RemoveStore, (short) 0, ServerErrorCode.Partition_Unknown);
// add store on current node for store removal testing
sendAndVerifyStoreControlRequest(newPartition, BlobStoreControlAction.AddStore, (short) 0, ServerErrorCode.No_Error);
// mock exception in StorageManager
storageManager.returnValueOfRemoveBlobStore = false;
sendAndVerifyStoreControlRequest(newPartition, BlobStoreControlAction.RemoveStore, (short) 0, ServerErrorCode.Unknown_Error);
storageManager.returnValueOfRemoveBlobStore = true;
// mock exception when deleting files of removed store
BlobStore mockStore = Mockito.mock(BlobStore.class);
storageManager.overrideStoreToReturn = mockStore;
doThrow(new IOException()).when(mockStore).deleteStoreFiles();
sendAndVerifyStoreControlRequest(newPartition, BlobStoreControlAction.RemoveStore, (short) 0, ServerErrorCode.Unknown_Error);
// test store removal success case
doNothing().when(mockStore).deleteStoreFiles();
Mockito.when(mockStore.getReplicaStatusDelegates()).thenReturn(Collections.singletonList(mockDelegate));
sendAndVerifyStoreControlRequest(newPartition, BlobStoreControlAction.RemoveStore, (short) 0, ServerErrorCode.No_Error);
storageManager.overrideStoreToReturn = null;
}
use of com.github.ambry.store.BlobStore 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.store.BlobStore in project ambry by linkedin.
the class AmbryServerRequestsTest method controlBlobStoreSuccessTest.
/**
* Tests for the response received on a {@link BlobStoreControlAdminRequest} for successful case
* @throws InterruptedException
* @throws IOException
*/
@Test
public void controlBlobStoreSuccessTest() throws Exception {
// Recreate storage manager and ambryRequest to pass in HelixParticipant
storageManager.shutdown();
helixParticipant.overrideDisableReplicaMethod = true;
storageManager = new MockStorageManager(validKeysInStore, clusterMap, dataNodeId, findTokenHelper, helixParticipant);
ambryRequests = new AmbryServerRequests(storageManager, requestResponseChannel, clusterMap, dataNodeId, clusterMap.getMetricRegistry(), serverMetrics, findTokenHelper, null, replicationManager, null, serverConfig, storeKeyConverterFactory, statsManager, helixParticipant);
List<? extends PartitionId> partitionIds = clusterMap.getAllPartitionIds(null);
PartitionId id = partitionIds.get(0);
List<? extends ReplicaId> replicaIds = id.getReplicaIds();
assertTrue("This test needs more than one replica for the first partition to work", replicaIds.size() > 1);
long acceptableLagInBytes = 0;
short numReplicasCaughtUpPerPartition = 3;
replicationManager.reset();
replicationManager.controlReplicationReturnVal = true;
generateLagOverrides(0, acceptableLagInBytes);
// stop BlobStore
sendAndVerifyStoreControlRequest(id, BlobStoreControlAction.StopStore, numReplicasCaughtUpPerPartition, ServerErrorCode.No_Error);
// verify APIs are called in the process of stopping BlobStore
assertEquals("Compaction on store should be disabled after stopping the BlobStore", false, storageManager.compactionEnableVal);
assertEquals("Partition disabled for compaction not as expected", id, storageManager.compactionControlledPartitionId);
assertTrue("Origins list should be empty", replicationManager.originsVal.isEmpty());
assertEquals("Replication on given BlobStore should be disabled", false, replicationManager.enableVal);
assertEquals("Partition shutdown not as expected", id, storageManager.shutdownPartitionId);
assertEquals("Partition disabled not as expected", id.toPathString(), helixParticipant.getDisabledReplicas().get(0));
// start BlobStore
sendAndVerifyStoreControlRequest(id, BlobStoreControlAction.StartStore, numReplicasCaughtUpPerPartition, ServerErrorCode.No_Error);
// verify APIs are called in the process of starting BlobStore
assertEquals("Partition started not as expected", id, storageManager.startedPartitionId);
assertEquals("Replication on given BlobStore should be enabled", true, replicationManager.enableVal);
assertEquals("Partition controlled for compaction not as expected", id, storageManager.compactionControlledPartitionId);
assertEquals("Compaction on store should be enabled after starting the BlobStore", true, storageManager.compactionEnableVal);
// add BlobStore (create a new partition and add one of its replicas to server)
PartitionId newPartition = clusterMap.createNewPartition(clusterMap.getDataNodes());
sendAndVerifyStoreControlRequest(newPartition, BlobStoreControlAction.AddStore, numReplicasCaughtUpPerPartition, ServerErrorCode.No_Error);
// remove BlobStore (remove previously added store)
BlobStore mockStore = Mockito.mock(BlobStore.class);
storageManager.overrideStoreToReturn = mockStore;
doNothing().when(mockStore).deleteStoreFiles();
Mockito.when(mockStore.getReplicaStatusDelegates()).thenReturn(Collections.singletonList(mockDelegate));
sendAndVerifyStoreControlRequest(newPartition, BlobStoreControlAction.RemoveStore, numReplicasCaughtUpPerPartition, ServerErrorCode.No_Error);
storageManager.overrideStoreToReturn = null;
helixParticipant.overrideDisableReplicaMethod = false;
}
use of com.github.ambry.store.BlobStore in project ambry by linkedin.
the class AmbryServerRequests method handleStopStoreRequest.
/**
* Handles admin request that stops BlobStore
* @param partitionId the {@link PartitionId} associated with BlobStore
* @param numReplicasCaughtUpPerPartition the minimum number of peer replicas per partition that should catch up with
* local store before stopping it.
* @return {@link ServerErrorCode} represents result of handling admin request.
*/
private ServerErrorCode handleStopStoreRequest(PartitionId partitionId, short numReplicasCaughtUpPerPartition) {
ServerErrorCode error = validateRequest(partitionId, RequestOrResponseType.AdminRequest, false);
if (!error.equals(ServerErrorCode.No_Error)) {
logger.debug("Validate request fails for {} with error code {} when trying to stop store", partitionId, error);
return error;
}
if (numReplicasCaughtUpPerPartition < 0) {
logger.debug("The number of replicas to catch up should not be less than zero {}", numReplicasCaughtUpPerPartition);
return ServerErrorCode.Bad_Request;
}
if (!storeManager.controlCompactionForBlobStore(partitionId, false)) {
logger.error("Disable compaction fails on given BlobStore {}", partitionId);
return ServerErrorCode.Unknown_Error;
}
Collection<PartitionId> partitionIds = Collections.singletonList(partitionId);
controlRequestForPartitions(EnumSet.of(RequestOrResponseType.PutRequest, RequestOrResponseType.DeleteRequest, RequestOrResponseType.TtlUpdateRequest), partitionIds, false);
if (!replicationEngine.controlReplicationForPartitions(partitionIds, Collections.<String>emptyList(), false)) {
logger.error("Could not disable replication on {}", partitionIds);
return ServerErrorCode.Unknown_Error;
}
if (!isRemoteLagLesserOrEqual(partitionIds, 0, numReplicasCaughtUpPerPartition)) {
logger.debug("Catchup not done on {}", partitionIds);
return ServerErrorCode.Retry_After_Backoff;
}
controlRequestForPartitions(EnumSet.of(RequestOrResponseType.ReplicaMetadataRequest, RequestOrResponseType.GetRequest), partitionIds, false);
// Shutdown the BlobStore completely
if (storeManager.shutdownBlobStore(partitionId)) {
logger.info("Store is successfully shutdown for partition: {}", partitionId);
List<PartitionId> failToUpdateList = storeManager.setBlobStoreStoppedState(Collections.singletonList(partitionId), true);
if (!failToUpdateList.isEmpty() && clusterParticipant != null) {
logger.error("Fail to add BlobStore(s) {} to stopped list after stop operation completed", failToUpdateList.toArray());
error = ServerErrorCode.Unknown_Error;
}
// is adopted. The intention here is to force Helix to re-elect a new leader replica if necessary.
if (storeManager instanceof StorageManager && clusterParticipant != null) {
// Previous operation has guaranteed the store is not null
Store store = ((StorageManager) storeManager).getStore(partitionId, true);
// Setting disable state will trigger transition error at the very beginning of STANDBY -> INACTIVE transition.
// Thus it doesn't go through decommission process.
((BlobStore) store).setDisableState(true);
clusterParticipant.setReplicaDisabledState(storeManager.getReplica(partitionId.toPathString()), true);
}
} else {
error = ServerErrorCode.Unknown_Error;
logger.error("Shutting down BlobStore fails on {}", partitionId);
}
return error;
}
Aggregations