Skip to content

Commit

Permalink
refactor logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Guo committed Oct 31, 2024
1 parent 4bcdaf1 commit 4f8749e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -586,36 +586,32 @@ public Future<Void> 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<String>() {
@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<String>() {
@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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,37 +351,33 @@ public Future<Void> 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<String>() {
@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<String>() {
@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;
Expand Down

0 comments on commit 4f8749e

Please sign in to comment.