Skip to content

Commit

Permalink
Move this to ttl update handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Guo committed Aug 17, 2023
1 parent 90d2f5c commit 90af4af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,6 @@ private CompletionStage<String> convertId(String input, RestRequest restRequest,
// on delete requests we can soft delete the record from NamedBlobDb and get the blob ID in one step.
conversionFuture = getNamedBlobDb().delete(namedBlobPath.getAccountName(), namedBlobPath.getContainerName(),
namedBlobPath.getBlobName()).thenApply(DeleteResult::getBlobId);
} else if (restRequest.getRestMethod() == RestMethod.PUT && RestUtils.getRequestPath(restRequest)
.matchesOperation(Operations.UPDATE_TTL)) {
NamedBlobRecord record = new NamedBlobRecord(namedBlobPath.getAccountName(), namedBlobPath.getContainerName(),
namedBlobPath.getBlobName(), null, Infinite_Time);
// Set named blob state as 'IN_PROGRESS', will set the state to be 'READY' in the ttlUpdate success callback: routerTtlUpdateCallback
NamedBlobState state = NamedBlobState.IN_PROGRESS;
// Always enable upsert to ttl update request.
conversionFuture = getNamedBlobDb().ttlUpdate(record, state).thenApply(result -> {
restRequest.setArg(RestUtils.InternalKeys.NAMED_BLOB_VERSION, result.getInsertedRecord().getVersion());
restRequest.setArg(RestUtils.InternalKeys.NAMED_BLOB_MAPPED_ID, result.getInsertedRecord().getBlobId());
return result.getInsertedRecord().getBlobId();
});
} else {
conversionFuture = getNamedBlobDb().get(namedBlobPath.getAccountName(), namedBlobPath.getContainerName(),
namedBlobPath.getBlobName(), getOption).thenApply(NamedBlobRecord::getBlobId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ public CompletableFuture<PutResult> put(NamedBlobRecord record, NamedBlobState s
return future;
}

@Override
public CompletableFuture<PutResult> ttlUpdate(NamedBlobRecord record, NamedBlobState state) {
//TODO: implement later
return null;
}

@Override
public CompletableFuture<PutResult> updateBlobStateToReady(NamedBlobRecord record) {
CompletableFuture<PutResult> future = new CompletableFuture<>();
Expand Down Expand Up @@ -174,26 +180,6 @@ public CompletableFuture<DeleteResult> delete(String accountName, String contain
return future;
}

@Override
public CompletableFuture<PutResult> ttlUpdate(NamedBlobRecord record, NamedBlobState state) {
CompletableFuture<PutResult> future = new CompletableFuture<>();
if (exception != null) {
future.completeExceptionally(exception);
return future;
}
Pair<NamedBlobRecord, Long> recordFromDb = getInternal(record.getAccountName(), record.getContainerName(), record.getBlobName());
if (recordFromDb == null) {
future.completeExceptionally(new RestServiceException("NotFound", RestServiceErrorCode.NotFound));
} else if (recordFromDb.getSecond() != 0 && recordFromDb.getSecond() < time.milliseconds()) {
future.completeExceptionally(new RestServiceException("Deleted", RestServiceErrorCode.Deleted));
} else {
record.setBlobId(recordFromDb.getFirst().getBlobId());
putInternal(record, NamedBlobState.IN_PROGRESS, 0L);
future.complete(new PutResult(record));
}
return future;
}

@Override
public CompletableFuture<List<StaleNamedBlob>> pullStaleBlobs() {
CompletableFuture<List<StaleNamedBlob>> future = new CompletableFuture<>();
Expand Down

0 comments on commit 90af4af

Please sign in to comment.