use of com.github.ambry.clustermap.PartitionId in project ambry by linkedin.
the class AmbryServerRequests method handleRequestControlRequest.
/**
* Handles {@link com.github.ambry.protocol.AdminRequestOrResponseType#RequestControl}.
* @param requestStream the serialized bytes of the request.
* @param adminRequest the {@link AdminRequest} received.
* @return the {@link AdminResponse} to the request.
* @throws IOException if there is any I/O error reading from the {@code requestStream}.
*/
private AdminResponse handleRequestControlRequest(DataInputStream requestStream, AdminRequest adminRequest) throws IOException {
RequestControlAdminRequest controlRequest = RequestControlAdminRequest.readFrom(requestStream, adminRequest);
RequestOrResponseType toControl = controlRequest.getRequestTypeToControl();
ServerErrorCode error;
Collection<PartitionId> partitionIds;
if (!requestsDisableInfo.containsKey(toControl)) {
metrics.badRequestError.inc();
error = ServerErrorCode.Bad_Request;
} else {
error = ServerErrorCode.No_Error;
if (controlRequest.getPartitionId() != null) {
error = validateRequest(controlRequest.getPartitionId(), RequestOrResponseType.AdminRequest, false);
partitionIds = Collections.singletonList(controlRequest.getPartitionId());
} else {
partitionIds = storeManager.getLocalPartitions();
}
if (!error.equals(ServerErrorCode.Partition_Unknown)) {
controlRequestForPartitions(EnumSet.of(toControl), partitionIds, controlRequest.shouldEnable());
for (PartitionId partitionId : partitionIds) {
logger.info("Enable state for {} on {} is {}", toControl, partitionId, isRequestEnabled(toControl, partitionId));
}
}
}
return new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), error);
}
use of com.github.ambry.clustermap.PartitionId in project ambry by linkedin.
the class AmbryServerRequests method handleReplicationControlRequest.
/**
* Handles {@link com.github.ambry.protocol.AdminRequestOrResponseType#ReplicationControl}.
* @param requestStream the serialized bytes of the request.
* @param adminRequest the {@link AdminRequest} received.
* @return the {@link AdminResponse} to the request.
* @throws IOException if there is any I/O error reading from the {@code requestStream}.
*/
private AdminResponse handleReplicationControlRequest(DataInputStream requestStream, AdminRequest adminRequest) throws IOException {
Collection<PartitionId> partitionIds;
ServerErrorCode error = ServerErrorCode.No_Error;
ReplicationControlAdminRequest replControlRequest = ReplicationControlAdminRequest.readFrom(requestStream, adminRequest);
if (replControlRequest.getPartitionId() != null) {
error = validateRequest(replControlRequest.getPartitionId(), RequestOrResponseType.AdminRequest, false);
partitionIds = Collections.singletonList(replControlRequest.getPartitionId());
} else {
partitionIds = storeManager.getLocalPartitions();
}
if (!error.equals(ServerErrorCode.Partition_Unknown)) {
if (replicationEngine.controlReplicationForPartitions(partitionIds, replControlRequest.getOrigins(), replControlRequest.shouldEnable())) {
error = ServerErrorCode.No_Error;
} else {
logger.error("Could not set enable status for replication of {} from {} to {}. Check partition validity and" + " origins list", partitionIds, replControlRequest.getOrigins(), replControlRequest.shouldEnable());
error = ServerErrorCode.Bad_Request;
}
}
return new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), error);
}
use of com.github.ambry.clustermap.PartitionId in project ambry by linkedin.
the class AmbryServerRequestsTest method listOfOriginalStoreKeysGetTest.
/**
* Tests blobIds can be converted as expected and works correctly with GetRequest.
* If all blobIds can be converted correctly, no error is expected.
* If any blobId can't be converted correctly, Blob_Not_Found is expected.
* @throws InterruptedException
* @throws IOException
*/
@Test
public void listOfOriginalStoreKeysGetTest() throws InterruptedException, IOException {
int numIds = 10;
PartitionId partitionId = clusterMap.getAllPartitionIds(null).get(0);
List<BlobId> blobIds = new ArrayList<>();
for (int i = 0; i < numIds; i++) {
BlobId originalBlobId = new BlobId(CommonTestUtils.getCurrentBlobIdVersion(), BlobId.BlobIdType.NATIVE, ClusterMap.UNKNOWN_DATACENTER_ID, Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM), partitionId, false, BlobId.BlobDataType.DATACHUNK);
BlobId convertedBlobId = new BlobId(CommonTestUtils.getCurrentBlobIdVersion(), BlobId.BlobIdType.CRAFTED, ClusterMap.UNKNOWN_DATACENTER_ID, originalBlobId.getAccountId(), originalBlobId.getContainerId(), partitionId, false, BlobId.BlobDataType.DATACHUNK);
conversionMap.put(originalBlobId, convertedBlobId);
validKeysInStore.add(convertedBlobId);
blobIds.add(originalBlobId);
}
sendAndVerifyGetOriginalStoreKeys(blobIds, ServerErrorCode.No_Error);
// test with duplicates
List<BlobId> blobIdsWithDups = new ArrayList<>(blobIds);
// add the same blob ids
blobIdsWithDups.addAll(blobIds);
// add converted ids
conversionMap.values().forEach(id -> blobIdsWithDups.add((BlobId) id));
sendAndVerifyGetOriginalStoreKeys(blobIdsWithDups, ServerErrorCode.No_Error);
// store must not have received duplicates
assertEquals("Size is not as expected", blobIds.size(), MockStorageManager.idsReceived.size());
for (int i = 0; i < blobIds.size(); i++) {
BlobId key = blobIds.get(i);
StoreKey converted = conversionMap.get(key);
assertEquals(key + "/" + converted + " was not received at the store", converted, MockStorageManager.idsReceived.get(i));
}
// Check a valid key mapped to null
BlobId originalBlobId = new BlobId(CommonTestUtils.getCurrentBlobIdVersion(), BlobId.BlobIdType.NATIVE, ClusterMap.UNKNOWN_DATACENTER_ID, Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM), partitionId, false, BlobId.BlobDataType.DATACHUNK);
blobIds.add(originalBlobId);
conversionMap.put(originalBlobId, null);
validKeysInStore.add(originalBlobId);
sendAndVerifyGetOriginalStoreKeys(blobIds, ServerErrorCode.No_Error);
// Check a invalid key mapped to null
originalBlobId = new BlobId(CommonTestUtils.getCurrentBlobIdVersion(), BlobId.BlobIdType.NATIVE, ClusterMap.UNKNOWN_DATACENTER_ID, Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM), partitionId, false, BlobId.BlobDataType.DATACHUNK);
blobIds.add(originalBlobId);
conversionMap.put(originalBlobId, null);
sendAndVerifyGetOriginalStoreKeys(blobIds, ServerErrorCode.Blob_Not_Found);
// Check exception
storeKeyConverterFactory.setException(new Exception("StoreKeyConverter Mock Exception"));
sendAndVerifyGetOriginalStoreKeys(blobIds, ServerErrorCode.Unknown_Error);
}
use of com.github.ambry.clustermap.PartitionId 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.clustermap.PartitionId 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;
}
Aggregations