diff --git a/ambry-router/src/main/java/com/github/ambry/router/NonBlockingRouter.java b/ambry-router/src/main/java/com/github/ambry/router/NonBlockingRouter.java index 1d49e5c616..5f3bc884f2 100644 --- a/ambry-router/src/main/java/com/github/ambry/router/NonBlockingRouter.java +++ b/ambry-router/src/main/java/com/github/ambry/router/NonBlockingRouter.java @@ -586,36 +586,32 @@ public Future updateBlobTtl(RestRequest restRequest, String blobId, String } proceedWithTtlUpdate(null, blobId, serviceId, expiresAtMs, callback, futureResult, quotaChargeCallback); } else { - //if the blobId is not named blob based, it could bypass the first round of d converter logic by checking InternalKeys.BLOB_ID. - //First round is to convert named blob to blob Id. - if (restRequest.getArgs().get(RestUtils.InternalKeys.BLOB_ID) != null) { - String blobIdStr = - removeLeadingSlashIfNeeded(restRequest.getArgs().get(RestUtils.InternalKeys.BLOB_ID).toString()); - proceedWithTtlUpdate(restRequest, blobIdStr, serviceId, expiresAtMs, callback, futureResult, - quotaChargeCallback); - } else { - try { - //If the blobId is named blob, need to go through convert first. - String blobIdStr = - removeLeadingSlashIfNeeded(RestUtils.getHeader(restRequest.getArgs(), RestUtils.Headers.BLOB_ID, true)); - // Convert asynchronously and proceed once blobId is available - idConverter.convert(restRequest, blobIdStr, null, new Callback() { - @Override - public void onCompletion(String convertedBlobId, Exception exception) { - if (exception != null) { - callback.onCompletion(null, exception); - } else { - // Call proceedWithTtlUpdate once blobId is available - proceedWithTtlUpdate(restRequest, convertedBlobId, serviceId, expiresAtMs, callback, futureResult, - quotaChargeCallback); - } - } - }); - return futureResult; // Return early since we're waiting for the async operation - } catch (Exception e) { - callback.onCompletion(null, e); - return futureResult; + try { + String blobIdStr; + //if update ttl request coming from two phase put. + if (restRequest.getArgs().get(RestUtils.InternalKeys.BLOB_ID) != null) { + blobIdStr = restRequest.getArgs().get(RestUtils.InternalKeys.BLOB_ID).toString(); + } else { + blobIdStr = RestUtils.getHeader(restRequest.getArgs(), RestUtils.Headers.BLOB_ID, true); } + + // Convert asynchronously and proceed once blobId is available + idConverter.convert(restRequest, blobIdStr, null, new Callback() { + @Override + public void onCompletion(String convertedBlobId, Exception exception) { + if (exception != null) { + callback.onCompletion(null, exception); + } else { + // Call proceedWithTtlUpdate once blobId is available + proceedWithTtlUpdate(restRequest, convertedBlobId, serviceId, expiresAtMs, callback, futureResult, + quotaChargeCallback); + } + } + }); + return futureResult; // Return early since we're waiting for the async operation + } catch (Exception e) { + callback.onCompletion(null, e); + return futureResult; } } diff --git a/ambry-test-utils/src/main/java/com/github/ambry/router/InMemoryRouter.java b/ambry-test-utils/src/main/java/com/github/ambry/router/InMemoryRouter.java index 1cf5a18b05..f5497a80dc 100644 --- a/ambry-test-utils/src/main/java/com/github/ambry/router/InMemoryRouter.java +++ b/ambry-test-utils/src/main/java/com/github/ambry/router/InMemoryRouter.java @@ -351,37 +351,33 @@ public Future updateBlobTtl(RestRequest restRequest, String blobId, String if (restRequest == null) { proceedWithTtlUpdate(null, blobId, serviceId, expiresAtMs, callback, futureResult); } else { - // Extract blobId or convert it if necessary - if (restRequest.getArgs().get(RestUtils.InternalKeys.BLOB_ID) != null) { - // Blob ID is already available - String blobIdStr = - removeLeadingSlashIfNeeded(restRequest.getArgs().get(RestUtils.InternalKeys.BLOB_ID).toString()); - proceedWithTtlUpdate(restRequest, blobIdStr, serviceId, expiresAtMs, callback, futureResult); - } else { - // Blob ID is not available, use idConverter to get it - try { - //If the blobId is named blob, need to go through convert first. - String blobIdStr = - removeLeadingSlashIfNeeded(RestUtils.getHeader(restRequest.getArgs(), RestUtils.Headers.BLOB_ID, true)); - - // Call idConverter to get blobId asynchronously - idConverter.convert(restRequest, blobIdStr, null, new Callback() { - @Override - public void onCompletion(String convertedBlobId, Exception exception) { - if (exception != null) { - // Handle error in conversion - callback.onCompletion(null, exception); - } else { - // Continue with TTL update once blobId is available - proceedWithTtlUpdate(restRequest, convertedBlobId, serviceId, expiresAtMs, callback, futureResult); - } - } - }); - } catch (Exception e) { - // Handle synchronous errors during header extraction - callback.onCompletion(null, e); - return futureResult; + // Blob ID is not available, use idConverter to get it + try { + String blobIdStr; + //if update ttl request coming from two phase put. + if (restRequest.getArgs().get(RestUtils.InternalKeys.BLOB_ID) != null) { + blobIdStr = restRequest.getArgs().get(RestUtils.InternalKeys.BLOB_ID).toString(); + } else { + blobIdStr = RestUtils.getHeader(restRequest.getArgs(), RestUtils.Headers.BLOB_ID, true); } + + // Call idConverter to get blobId asynchronously + idConverter.convert(restRequest, blobIdStr, null, new Callback() { + @Override + public void onCompletion(String convertedBlobId, Exception exception) { + if (exception != null) { + // Handle error in conversion + callback.onCompletion(null, exception); + } else { + // Continue with TTL update once blobId is available + proceedWithTtlUpdate(restRequest, convertedBlobId, serviceId, expiresAtMs, callback, futureResult); + } + } + }); + } catch (Exception e) { + // Handle synchronous errors during header extraction + callback.onCompletion(null, e); + return futureResult; } } return futureResult;