-
Notifications
You must be signed in to change notification settings - Fork 112
fix: race condition among transactions when running parallely #2369
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
Conversation
314783f to
b7eac5f
Compare
b8ee5ed to
1f32e90
Compare
035d1d2 to
ab544ee
Compare
7382103 to
414cd05
Compare
e006a70 to
bd150db
Compare
system-test/spanner.ts
Outdated
| process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS = 'true'; | ||
| process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW = 'true'; |
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.
Why do we need this condition, we have 2 separate pipeline for mux and non-mux.
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.
yeah, it was for local testing. I have removed it
system-test/spanner.ts
Outdated
| while (sync.count !== sync.target) { | ||
| // wait for 500 milliseconds | ||
| await new Promise(resolve => setTimeout(resolve, 500)); | ||
| } |
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.
You need to add a wait after you receive precommittoken, so dont use mutation only case but execute a read before the commit
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.
thanks for this catch, I have updated the test to execute a read before mutations. now we will have a precommit token while committing the transactions
85133cd to
b645053
Compare
| /** Edition enum. */ | ||
| enum Edition { | ||
| EDITION_UNKNOWN = 0, | ||
| EDITION_LEGACY = 900, |
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.
What are these changes?
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.
owlbot is pushing these changes, these are not manual
system-test/spanner.ts
Outdated
| await Promise.all(promises); | ||
| }); | ||
|
|
||
| it('POSTGRESQL should insert and commit transactions when running parallely', async () => { |
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.
why do we have to write this specifically for PG_DIALECT? There's no difference between dialects here right?
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.
yeah, I have removed it
| }); | ||
|
|
||
| it('should pass back the session and txn', done => { | ||
| const fakeTxn = new FakeTransaction() as unknown as Transaction; |
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.
where are we mocking session.!transaction method? Ideally this test should fail since we removed the assignment right?
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.
we have removed the assignment but we are returning the transaction using transaction method defined in Session class.
session!.transaction((session!.parent as Database).queryOptions_),
test/spanner.ts
Outdated
| ); | ||
|
|
||
| // assert that seqNum is different in both the commit request | ||
| assert.notEqual( |
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.
why do you expect seqNum to be different?
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 guess because mockspanner return a random number for sequence number , randomInt(1, 1000),
But thats not a valid assertion. SeqNum may or maynot be same for 2 transactions running in parallel.
I am not sure if the seqNum is supposed to be an incremental number from 1...n . If yes, then mockSpanner should have followed the same logic.
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 am not sure if the seqNum is supposed to be an incremental number from 1...n
yes, I have updated the mock spanner logic and hence, the test case to run read before performing mutations. now we will be sure that precommit token is there for both the transactions while making commit request.
system-test/spanner.ts
Outdated
| commitTransaction(done, PG_DATABASE, postgreSqlTable); | ||
| }); | ||
|
|
||
| describe('when multiplexed session is enabled for read write', async () => { |
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.
This need not be specific to multiplexed session, the scenario we are trying to test here is that parallel transaction should work , for both mux and non-mux. So describe should mention that.
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.
yeah, correct
I have updated the test name, it will anyway will be running against both the pipelines, one with mux enabled and another with mux not enabled
c164ecb to
6459b9e
Compare
| precommitToken: { | ||
| precommitToken: fakeRetryToken, | ||
| seqNum: 1, | ||
| seqNum: 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.
| seqNum: 2, | |
| // Retry should have a higher sequence number | |
| seqNum: 2, |
914c308 to
225a84d
Compare
fixes: #2368