Repository navigation
Add Collection#upsertAndReturnOlderDocument for atomic pre-write snap… #328
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
Open
bhubam
wants to merge
6
commits into
main
Choose a base branch
from
AAP-13921-upsert-return-older
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,154
−2
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
70abb05
Add Collection#upsertAndReturnOlderDocument for atomic pre-write snap…
bhubam 81a2aef
Keep Collection#upsertAndReturnOlderDocument source-compatible and av…
bhubam a8de2b7
Fix Spotless formatting in PostgresCollection.
bhubam 4537f35
AAP-13921: Return before and after documents from a single atomic write
bhubam 46ae7db
AAP-13921: Select returned documents with UpsertOptions and drop upse…
bhubam b96ad4a
AAP-13921: Address review comments on UpsertOptions write-and-return
bhubam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
336 changes: 335 additions & 1 deletion
336
...grationTest/java/org/hypertrace/core/documentstore/MongoPostgresWriteConsistencyTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
document-store/src/main/java/org/hypertrace/core/documentstore/DocumentChange.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package org.hypertrace.core.documentstore; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * The document images returned by a single atomic write. Which images are present depends on the | ||
| * requested {@link org.hypertrace.core.documentstore.model.options.UpsertOptions.ReturnDocuments}. | ||
| */ | ||
| public final class DocumentChange { | ||
|
|
||
| @Nullable private final Document before; | ||
| @Nullable private final Document after; | ||
|
|
||
| private DocumentChange(@Nullable final Document before, @Nullable final Document after) { | ||
| this.before = before; | ||
| this.after = after; | ||
| } | ||
|
|
||
| /** | ||
| * @param before the document before the write; null if not requested or if the write created the | ||
| * document | ||
| * @param after the document after the write; null if not requested | ||
| */ | ||
| public static DocumentChange of(@Nullable final Document before, @Nullable final Document after) { | ||
| return new DocumentChange(before, after); | ||
| } | ||
|
|
||
| /** Empty when the before-image was not requested, or when the write created the document. */ | ||
| public Optional<Document> getBefore() { | ||
| return Optional.ofNullable(before); | ||
| } | ||
|
|
||
| /** Empty when the after-image was not requested. */ | ||
| public Optional<Document> getAfter() { | ||
| return Optional.ofNullable(after); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(final Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| DocumentChange that = (DocumentChange) o; | ||
| return Objects.equals(before, that.before) && Objects.equals(after, that.after); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(before, after); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "DocumentChange{before=" + before + ", after=" + after + '}'; | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
...nt-store/src/main/java/org/hypertrace/core/documentstore/model/options/UpsertOptions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package org.hypertrace.core.documentstore.model.options; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Builder.Default; | ||
| import lombok.Value; | ||
|
|
||
| @Value | ||
| @Builder | ||
| public class UpsertOptions { | ||
| public static UpsertOptions DEFAULT_UPSERT_OPTIONS = | ||
| UpsertOptions.builder().returnDocuments(ReturnDocuments.AFTER).build(); | ||
|
|
||
| @Default ReturnDocuments returnDocuments = ReturnDocuments.AFTER; | ||
|
|
||
| public enum ReturnDocuments { | ||
| BEFORE, | ||
| AFTER, | ||
| BOTH, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[medium] New Mongo upsert stores client
_lastUpdateTimeinstead of$currentDateupsertAndReturn(Key, Document, UpsertOptions)is documented as the same merge-upsert asupsert().prepareUpsertsets_lastUpdateTimewith$currentDate(Mongo server clock).prepareUpsertWithExplicitLastUpdateTimestoresnew Date(now)from the client so the BOTH after-image can be derived locally. Callers that switch to this method change the stored field, and mixed with rows still written byupsert(),_lastUpdateTimecan move backwards when the client clock and the server clock disagree.Rule: upsert-semantics
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.
Addressed in b96ad4a. BEFORE and AFTER now send exactly the same update as
upsert()(prepareUpsert, with$currentDate). Only BOTH sets_lastUpdateTimefrom the client clock, because that's what lets the after-image be derived exactly from the server-returned before-image without a second read. The javadoc states this, and unit tests assert$currentDatefor BEFORE/AFTER and the literal value for BOTH.