Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect conflict during named blob put operation before upload or stitch operation. #2704

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ankagrawal
Copy link
Collaborator

@ankagrawal ankagrawal commented Feb 1, 2024

If the upload or stitch operation of a named blob is done without x-ambry-named-upsert header set to true, then update to the named blob is not allowed, and Ambry should return http 409 Conflict error code.
When handling such requests, its efficient to first check for a conflict, and then do the work of saving the blob to storage node. This PR makes the change to first check for conflict, and do the upload only if there is no conflict.

@codecov-commenter
Copy link

codecov-commenter commented Feb 1, 2024

Codecov Report

Attention: Patch coverage is 53.33333% with 28 lines in your changes are missing coverage. Please review.

Project coverage is 31.88%. Comparing base (52ba813) to head (1d98605).
Report is 3 commits behind head on master.

Files Patch % Lines
...github/ambry/frontend/AmbryIdConverterFactory.java 61.11% 8 Missing and 6 partials ⚠️
...com/github/ambry/frontend/NamedBlobPutHandler.java 30.00% 11 Missing and 3 partials ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             master    #2704       +/-   ##
=============================================
- Coverage     64.24%   31.88%   -32.37%     
+ Complexity    10398     5348     -5050     
=============================================
  Files           840      840               
  Lines         71755    71822       +67     
  Branches       8611     8621       +10     
=============================================
- Hits          46099    22898    -23201     
- Misses        23004    47146    +24142     
+ Partials       2652     1778      -874     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ankagrawal ankagrawal force-pushed the ankuagra_check_named_conflict branch 2 times, most recently from 5d4f811 to 5653cfd Compare February 3, 2024 05:58
@ankagrawal ankagrawal changed the title [WIP] Detect conflict during named blob put operation before upload or stitch operation. Detect conflict during named blob put operation before upload or stitch operation. Feb 3, 2024
&& ((RestServiceException) e.getCause()).getErrorCode() == RestServiceErrorCode.NotFound) {
return false;
} else {
throw new RuntimeException(e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qq.. would it be better if we complete the detectionFuture with exception instead of throwing run time exception?

frontendMetrics.addDatasetVersionRate.mark();
addDatasetVersion(blobInfo.getBlobProperties(), restRequest);
}
idConverter.detectConflict(restRequest, detectConflictCallback(blobInfo));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this will result in checking for conflicts for regular named blob uploads as well, i.e. not just stitch requests? Wondering if it may increase latency of regular uploads due to additional call to mysql db. Would it be better to check for conflicts only for stitch requests?


detectionFuture = getNamedBlobDb().get(namedBlobPath.getAccountName(), namedBlobPath.getContainerName(),
namedBlobPath.getBlobName(), GetOption.Include_All).thenApply(namedBlobRecord -> {
LOGGER.info("A mapping for the namedBlob {} already exists. Original BlobId: {}",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about if the named blob is deleted?
If the named blob is deleted, we should allow upload even without the upsert option.
If it's the case, we need check the db record status.

private CompletionStage<Boolean> detectConflict(RestRequest restRequest) throws RestServiceException {
final CompletionStage<Boolean> detectionFuture;
frontendMetrics.idConverterDetectConflictRate.mark();
if (restRequest.getRestMethod() == RestMethod.PUT && RestUtils.getRequestPath(restRequest)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we verify the Dataset behavior?
Does it allow update with the same version number if upsert is not set?

@ankagrawal ankagrawal force-pushed the ankuagra_check_named_conflict branch from 3ec9fa9 to 1d98605 Compare May 2, 2024 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants