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

bug: write bsos contained within a commit after the batch has been commited. #980

Merged
merged 11 commits into from
Feb 10, 2021

Conversation

jrconlin
Copy link
Member

@jrconlin jrconlin commented Jan 23, 2021

Description

The client may sometimes include bsos in the batch
commit message. The problem is that due to the way
that data is written to spanner, mutations do not
retain the ability to see data previously written
in the same transaction. This causes collisions.

To solve this, treat the bsos included in the commit
as another batch update, then commit all the data.
This does run the risk of bumping up against the
mutation limit, but it ensures the best chance of
data consistency.

Writing the commit bsos prior to batch commit will
result in the "newer" records being overwritten by
"older" ones in the batch.

Writing the commit bsos after the batch commit runs
the same mutation index conflict problem.

Testing

Unit test included

Issue(s)

Closes #882

The client may sometimes include bsos in the batch
commit message. The problem is that due to the way
that data is written to spanner, mutations do not
retain the ability to see data previously written
in the same transaction. This causes collisions.

To solve this, treat the bsos included in the commit
as another batch update, then commit all the data.
This does run the risk of bumping up against the
mutation limit, but it ensures the best chance of
data consistency.

Writing the commit bsos prior to batch commit will
result in the "newer" records being overwritten by
"older" ones in the batch.

Writing the commit bsos after the batch commit runs
the same mutation index conflict problem.

Closes #882
…mmited.

An alternate approach to #882.

This approach has sometimes produced index collisions.
@jrconlin jrconlin requested a review from a team January 23, 2021 00:50
Comment on lines 332 to 333
if !breq.commit {
if !coll.bsos.valid.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
if !breq.commit {
if !coll.bsos.valid.is_empty() {
if !breq.commit && !coll.bsos.valid.is_empty() {

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm concerned about this. !breq.commit includes both the append call at line 333 , and building the possible response at line 367. Collapsing the if skips the possible early return for requests that do not specify a commit, and run the risk of committing early.

src/web/handlers.rs Outdated Show resolved Hide resolved
src/web/handlers.rs Outdated Show resolved Hide resolved
@@ -416,6 +394,54 @@ pub async fn post_collection_batch(
return Err(ApiError::from(err).into());
};

// write the BSOs contained in the commit request.
if !coll.bsos.valid.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

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

should only happen on commit:

Suggested change
if !coll.bsos.valid.is_empty() {
if commit && !coll.bsos.valid.is_empty() {

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, that's why I was asking about the change to line 321 which handles the "not commit" messages. That should capture all non-commit messages, no? Meaning that anything that got as far as here should be a commit. I could make things a bit clearer by wrapping this whole section in an else for !breq.commit, but I'm not sure that matches the style we've used before.

src/web/handlers.rs Outdated Show resolved Hide resolved
@jrconlin jrconlin requested a review from pjenvey February 1, 2021 21:46
@jrconlin jrconlin dismissed pjenvey’s stale review February 2, 2021 20:12

update and counter-concern

@tublitzed
Copy link
Contributor

@jrconlin - is this related to #822 - I see it's linked above?

@jrconlin
Copy link
Member Author

jrconlin commented Feb 3, 2021

Yes, slightly. A byproduct of that issue generated a number of the sort of conflicts that this issue addresses.

@tublitzed
Copy link
Contributor

Hmmm. That issue was a feature request that was never merged? Are we talking about the same #822 ?

@jrconlin
Copy link
Member Author

jrconlin commented Feb 3, 2021

Ah, no, you're right. It should refer to #882

which the original commit message gets right, at least: 8756cc9

src/web/handlers.rs Outdated Show resolved Hide resolved
@jrconlin jrconlin requested a review from pjenvey February 9, 2021 17:27
@jrconlin jrconlin merged commit ba6e5f4 into master Feb 10, 2021
@jrconlin jrconlin deleted the bug/882-bso-collision-2 branch February 10, 2021 02:42
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.

Batch commit causes INVALID_ARGUMENT Row.. was already created in table bsos
3 participants