-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Implement Detection and Prevention of Concurrent Overwritesinitial commit #207
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
base: development
Are you sure you want to change the base?
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
i think it's optimistic lock. (Description of changes in PR) |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
src/main/java/com/epam/aidial/cfg/domain/service/ModelService.java
Outdated
Show resolved
Hide resolved
src/main/java/com/epam/aidial/cfg/domain/service/ModelService.java
Outdated
Show resolved
Hide resolved
src/main/java/com/epam/aidial/cfg/domain/service/ModelService.java
Outdated
Show resolved
Hide resolved
src/main/java/com/epam/aidial/cfg/domain/service/ModelService.java
Outdated
Show resolved
Hide resolved
src/main/java/com/epam/aidial/cfg/exception/PreconditionFailedException.java
Outdated
Show resolved
Hide resolved
src/main/java/com/epam/aidial/cfg/service/hashing/HashCalculator.java
Outdated
Show resolved
Hide resolved
.writer(); | ||
} | ||
|
||
public String calculateHash(Object body) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd add tests which compare result with some etalon. not only verifying ignored fields
src/main/java/com/epam/aidial/cfg/service/hashing/HashCalculator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/epam/aidial/cfg/domain/service/ModelService.java
Outdated
Show resolved
Hide resolved
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
src/main/java/com/epam/aidial/cfg/domain/service/ModelService.java
Outdated
Show resolved
Hide resolved
src/main/java/com/epam/aidial/cfg/web/controller/ModelController.java
Outdated
Show resolved
Hide resolved
src/main/java/com/epam/aidial/cfg/domain/service/ModelService.java
Outdated
Show resolved
Hide resolved
src/main/java/com/epam/aidial/cfg/service/hashing/HashCalculator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/epam/aidial/cfg/domain/model/ModelWithHash.java
Outdated
Show resolved
Hide resolved
src/test/java/com/epam/aidial/cfg/functional/config/FunctionalTestConfiguration.java
Outdated
Show resolved
Hide resolved
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
…on-of-Concurrent-Overwrites-3
src/main/java/com/epam/aidial/cfg/domain/service/ModelService.java
Outdated
Show resolved
Hide resolved
src/test/java/com/epam/aidial/cfg/service/hashing/HashCalculatorTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/epam/aidial/cfg/web/controller/none/ModelControllerTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/epam/aidial/cfg/web/controller/none/ModelControllerTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/epam/aidial/cfg/web/controller/none/ModelControllerTest.java
Outdated
Show resolved
Hide resolved
public String updateModel(String modelName, Model model, String hash) { | ||
if (hash == null) { | ||
throw new IllegalArgumentException( | ||
"Hash must not be null. Use \"*\" to skip optimistic check."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Use "*" to skip optimistic check." - are we sure we would like to provide clients with such hack?
@siarhei-fedziukovich
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it'll be useful for some automatization case. but it's not strong willing. we can remove it if you see more harm than good
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
src/test/java/com/epam/aidial/cfg/service/hashing/HashCalculatorTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/epam/aidial/cfg/web/controller/none/ModelControllerTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/epam/aidial/cfg/web/controller/none/ModelControllerTest.java
Show resolved
Hide resolved
src/main/java/com/epam/aidial/cfg/service/hashing/HashCalculator.java
Outdated
Show resolved
Hide resolved
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
public static final String ANY_HASH = "*"; | ||
private static final Set<String> IGNORED_FIELDS = Set.of("createdAt", "updatedAt"); | ||
private final ObjectWriter writer; | ||
private final Base64.Encoder base64Encoder = Base64.getUrlEncoder().withoutPadding(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double whitespace after =
I'd suggest to assign the value inside constructor to align with ObjectWriter
? ResponseEntity.status(HttpStatus.NOT_MODIFIED).eTag(dtoWithHash.hash()) | ||
.build() | ||
: ResponseEntity.status(HttpStatus.OK).eTag(dtoWithHash.hash()) | ||
.body(dtoWithHash.dto()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange formatting, I think it can be formatted like
return dtoWithHash.hash().equals(StringUtils.unwrap(previousHash, '"'))
? ResponseEntity.status(HttpStatus.NOT_MODIFIED).eTag(dtoWithHash.hash()).build()
: ResponseEntity.status(HttpStatus.OK).eTag(dtoWithHash.hash()).body(dtoWithHash.dto());
or at least .build()
and .body(dtoWithHash.dto());
should have the same indentation
modelFacade.updateModel(modelName, modelDto); | ||
@RequestBody @Valid ModelDto modelDto, | ||
@RequestHeader(value = "If-Match") | ||
String previousHash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can @RequestHeader(value = "If-Match")
and String previousHash
be on the same line?
|
||
when(modelFacade.updateModel(eq("test_model"), any(), eq("1"))).thenReturn( | ||
"2"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't that fit signle line?
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
return result; | ||
public ResponseEntity<ModelDto> getModel(HttpServletResponse response, | ||
@PathVariable("modelName") String modelName, | ||
@RequestHeader(value = "If-None-Match") String previousHash) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's mark PR as breaking change and add description of it's changes (helps build release notes)
also update docs/samle/http-requests/AdminPanel.http
Applicable issues
Description of changes
An optimistic lock has been added when updating entities
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.