use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class NonBlockingRouterTest method testBlobTtlUpdateErrors.
/**
* Test for most error cases involving TTL updates
* @throws Exception
*/
@Test
public void testBlobTtlUpdateErrors() throws Exception {
try {
String updateServiceId = "update-service";
MockServerLayout layout = new MockServerLayout(mockClusterMap);
setRouter(getNonBlockingRouterProperties("DC1"), layout, new LoggingNotificationSystem());
setOperationParams();
String blobId = router.putBlob(putBlobProperties, putUserMetadata, putChannel, new PutBlobOptionsBuilder().build()).get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
Map<ServerErrorCode, RouterErrorCode> testsAndExpected = new HashMap<>();
testsAndExpected.put(ServerErrorCode.Blob_Not_Found, RouterErrorCode.BlobDoesNotExist);
testsAndExpected.put(ServerErrorCode.Blob_Deleted, RouterErrorCode.BlobDeleted);
testsAndExpected.put(ServerErrorCode.Blob_Expired, RouterErrorCode.BlobExpired);
testsAndExpected.put(ServerErrorCode.Disk_Unavailable, RouterErrorCode.BlobDoesNotExist);
testsAndExpected.put(ServerErrorCode.Replica_Unavailable, RouterErrorCode.AmbryUnavailable);
testsAndExpected.put(ServerErrorCode.Unknown_Error, RouterErrorCode.UnexpectedInternalError);
// return BlobDoesNotExist because all disks are down (which should be extremely rare) and blob is gone.
for (Map.Entry<ServerErrorCode, RouterErrorCode> testAndExpected : testsAndExpected.entrySet()) {
layout.getMockServers().forEach(mockServer -> mockServer.setServerErrorForAllRequests(testAndExpected.getKey()));
TestCallback<Void> testCallback = new TestCallback<>();
Future<Void> future = router.updateBlobTtl(blobId, updateServiceId, Utils.Infinite_Time, testCallback, null);
assertFailureAndCheckErrorCode(future, testCallback, testAndExpected.getValue());
}
layout.getMockServers().forEach(mockServer -> mockServer.setServerErrorForAllRequests(null));
// bad blob id
TestCallback<Void> testCallback = new TestCallback<>();
Future<Void> future = router.updateBlobTtl("bad-blob-id", updateServiceId, Utils.Infinite_Time, testCallback, null);
assertFailureAndCheckErrorCode(future, testCallback, RouterErrorCode.InvalidBlobId);
} finally {
if (router != null) {
router.close();
}
}
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class NonBlockingRouterTest method testUnsuccessfulPutDataChunkDelete.
/**
* Test that if a composite blob put fails, the successfully put data chunks are deleted.
*/
@Test
public void testUnsuccessfulPutDataChunkDelete() throws Exception {
try {
// Ensure there are 4 chunks.
maxPutChunkSize = PUT_CONTENT_SIZE / 4;
Properties props = getNonBlockingRouterProperties("DC1");
VerifiableProperties verifiableProperties = new VerifiableProperties((props));
RouterConfig routerConfig = new RouterConfig(verifiableProperties);
MockClusterMap mockClusterMap = new MockClusterMap();
MockTime mockTime = new MockTime();
MockServerLayout mockServerLayout = new MockServerLayout(mockClusterMap);
// Since this test wants to ensure that successfully put data chunks are deleted when the overall put operation
// fails, it uses a notification system to track the deletions.
final CountDownLatch deletesDoneLatch = new CountDownLatch(2);
final Map<String, String> blobsThatAreDeleted = new HashMap<>();
LoggingNotificationSystem deleteTrackingNotificationSystem = new LoggingNotificationSystem() {
@Override
public void onBlobDeleted(String blobId, String serviceId, Account account, Container container) {
blobsThatAreDeleted.put(blobId, serviceId);
deletesDoneLatch.countDown();
}
};
router = new NonBlockingRouter(routerConfig, new NonBlockingRouterMetrics(mockClusterMap, routerConfig), new MockNetworkClientFactory(verifiableProperties, mockSelectorState, MAX_PORTS_PLAIN_TEXT, MAX_PORTS_SSL, CHECKOUT_TIMEOUT_MS, mockServerLayout, mockTime), deleteTrackingNotificationSystem, mockClusterMap, kms, cryptoService, cryptoJobHandler, accountService, mockTime, MockClusterMap.DEFAULT_PARTITION_CLASS);
setOperationParams();
List<DataNodeId> dataNodeIds = mockClusterMap.getDataNodeIds();
List<ServerErrorCode> serverErrorList = new ArrayList<>();
// There are 4 chunks for this blob.
// All put operations make one request to each local server as there are 3 servers overall in the local DC.
// Set the state of the mock servers so that they return success for the first 2 requests in order to succeed
// the first two chunks.
serverErrorList.add(ServerErrorCode.No_Error);
serverErrorList.add(ServerErrorCode.No_Error);
// fail requests for third and fourth data chunks including the slipped put attempts:
serverErrorList.add(ServerErrorCode.Unknown_Error);
serverErrorList.add(ServerErrorCode.Unknown_Error);
serverErrorList.add(ServerErrorCode.Unknown_Error);
serverErrorList.add(ServerErrorCode.Unknown_Error);
// all subsequent requests (no more puts, but there will be deletes) will succeed.
for (DataNodeId dataNodeId : dataNodeIds) {
MockServer server = mockServerLayout.getMockServer(dataNodeId.getHostname(), dataNodeId.getPort());
server.setServerErrors(serverErrorList);
}
// Submit the put operation and wait for it to fail.
try {
router.putBlob(putBlobProperties, putUserMetadata, putChannel, new PutBlobOptionsBuilder().build()).get();
} catch (ExecutionException e) {
Assert.assertEquals(RouterErrorCode.AmbryUnavailable, ((RouterException) e.getCause()).getErrorCode());
}
// Now, wait until the deletes of the successfully put blobs are complete.
Assert.assertTrue("Deletes should not take longer than " + AWAIT_TIMEOUT_MS, deletesDoneLatch.await(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
for (Map.Entry<String, String> blobIdAndServiceId : blobsThatAreDeleted.entrySet()) {
Assert.assertEquals("Unexpected service ID for deleted blob", BackgroundDeleteRequest.SERVICE_ID_PREFIX + putBlobProperties.getServiceId(), blobIdAndServiceId.getValue());
}
} finally {
if (router != null) {
router.close();
assertClosed();
Assert.assertEquals("All operations should have completed", 0, router.getOperationsCount());
}
}
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class DeleteManagerTest method testVariousServerErrorCode.
/**
* Test if the {@link RouterErrorCode} is as expected for different {@link ServerErrorCode}.
*/
@Test
public void testVariousServerErrorCode() throws Exception {
HashMap<ServerErrorCode, RouterErrorCode> map = new HashMap<>();
map.put(ServerErrorCode.Blob_Expired, RouterErrorCode.BlobExpired);
map.put(ServerErrorCode.Blob_Not_Found, RouterErrorCode.BlobDoesNotExist);
map.put(ServerErrorCode.Disk_Unavailable, RouterErrorCode.BlobDoesNotExist);
map.put(ServerErrorCode.Replica_Unavailable, RouterErrorCode.AmbryUnavailable);
map.put(ServerErrorCode.Blob_Authorization_Failure, RouterErrorCode.BlobAuthorizationFailure);
for (ServerErrorCode serverErrorCode : ServerErrorCode.values()) {
if (serverErrorCode != ServerErrorCode.No_Error && serverErrorCode != ServerErrorCode.Blob_Deleted && !map.containsKey(serverErrorCode)) {
map.put(serverErrorCode, RouterErrorCode.UnexpectedInternalError);
}
}
for (Map.Entry<ServerErrorCode, RouterErrorCode> entity : map.entrySet()) {
testWithErrorCodes(Collections.singletonMap(entity.getKey(), 9), serverLayout, entity.getValue(), deleteErrorCodeChecker);
}
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class DeleteManagerTest method testVariousServerErrorCodesForThreeParallelism.
/**
* The parallelism is set to 3 not 9.
*
* Test the case where servers return different {@link ServerErrorCode}, and the {@link DeleteOperation}
* is able to resolve and conclude the correct {@link RouterErrorCode}. The {link ServerErrorCode} tested
* are those could be mapped to {@link RouterErrorCode#AmbryUnavailable}. The order of received responses
* is the same as defined in {@code serverErrorCodes}.
*/
@Test
public void testVariousServerErrorCodesForThreeParallelism() throws Exception {
assertCloseCleanup(router);
Properties props = getNonBlockingRouterProperties();
props.setProperty("router.delete.request.parallelism", "3");
VerifiableProperties vProps = new VerifiableProperties(props);
RouterConfig routerConfig = new RouterConfig(vProps);
router = new NonBlockingRouter(routerConfig, new NonBlockingRouterMetrics(clusterMap, routerConfig), new MockNetworkClientFactory(vProps, mockSelectorState, MAX_PORTS_PLAIN_TEXT, MAX_PORTS_SSL, CHECKOUT_TIMEOUT_MS, serverLayout, mockTime), new LoggingNotificationSystem(), clusterMap, null, null, null, new InMemAccountService(false, true), mockTime, MockClusterMap.DEFAULT_PARTITION_CLASS);
ServerErrorCode[] serverErrorCodes = new ServerErrorCode[9];
serverErrorCodes[0] = ServerErrorCode.Blob_Not_Found;
serverErrorCodes[1] = ServerErrorCode.Data_Corrupt;
serverErrorCodes[2] = ServerErrorCode.IO_Error;
serverErrorCodes[3] = ServerErrorCode.Partition_Unknown;
serverErrorCodes[4] = ServerErrorCode.Disk_Unavailable;
serverErrorCodes[5] = ServerErrorCode.No_Error;
serverErrorCodes[6] = ServerErrorCode.Data_Corrupt;
serverErrorCodes[7] = ServerErrorCode.Unknown_Error;
serverErrorCodes[8] = ServerErrorCode.Disk_Unavailable;
testWithErrorCodes(serverErrorCodes, partition, serverLayout, RouterErrorCode.AmbryUnavailable, deleteErrorCodeChecker);
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class DeleteManagerTest method testOriginDcNotFoundError.
/**
* Test the case when getting NOT_FOUND error from origin DC while termination on NOT_FOUND is enabled.
*/
@Test
public void testOriginDcNotFoundError() throws Exception {
assertCloseCleanup(router);
Properties props = getNonBlockingRouterProperties();
props.setProperty("router.delete.request.parallelism", "1");
props.setProperty("router.operation.tracker.terminate.on.not.found.enabled", "true");
VerifiableProperties vProps = new VerifiableProperties(props);
RouterConfig routerConfig = new RouterConfig(vProps);
router = new NonBlockingRouter(routerConfig, new NonBlockingRouterMetrics(clusterMap, routerConfig), new MockNetworkClientFactory(vProps, mockSelectorState, MAX_PORTS_PLAIN_TEXT, MAX_PORTS_SSL, CHECKOUT_TIMEOUT_MS, serverLayout, mockTime), new LoggingNotificationSystem(), clusterMap, null, null, null, new InMemAccountService(false, true), mockTime, MockClusterMap.DEFAULT_PARTITION_CLASS);
blobId = new BlobId(routerConfig.routerBlobidCurrentVersion, BlobId.BlobIdType.NATIVE, (byte) 0, Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM), partition, false, BlobId.BlobDataType.DATACHUNK);
blobIdString = blobId.getID();
ServerErrorCode[] serverErrorCodes = new ServerErrorCode[9];
Arrays.fill(serverErrorCodes, ServerErrorCode.No_Error);
serverErrorCodes[0] = ServerErrorCode.Blob_Not_Found;
serverErrorCodes[1] = ServerErrorCode.Blob_Not_Found;
serverErrorCodes[2] = ServerErrorCode.Blob_Not_Found;
// The first two responses are blob not found and they are from the local dc and originating dc.
// So even if the rest of servers returns No_Error, router will not send any requests to them.
testWithErrorCodes(serverErrorCodes, partition, serverLayout, RouterErrorCode.BlobDoesNotExist, deleteErrorCodeChecker);
}
Aggregations