feat(spanner): add support for multiplexed session for r/w transactions#2351
feat(spanner): add support for multiplexed session for r/w transactions#2351alkatrivedi merged 6 commits intomainfrom
Conversation
f75ccb3 to
7f0670b
Compare
7f0670b to
5434347
Compare
5434347 to
902df50
Compare
9f9b5f3 to
006ca6a
Compare
006ca6a to
510ba68
Compare
|
Ideally with this PR every method should use session factory. Below are the methods which are not updated CreateBatchTransaction - https://github.com/googleapis/nodejs-spanner/blob/main/src/database.ts#L909 |
Also makePooledStreamingRequest_ and makePooledRequest_ |
| (res.resultSet as protobuf.ResultSet).precommitToken = | ||
| precommitToken; |
There was a problem hiding this comment.
precommitToken is always retruned if session is multiplexed ?
There was a problem hiding this comment.
yes, we will always get a precommitToken in the PartialResultSet if the multiplexed session is enabled
test/mockserver/mockspanner.ts
Outdated
| this.pushRequest(call.request!, call.metadata); | ||
| this.simulateExecutionTime(this.beginTransaction.name) | ||
| .then(() => { | ||
| this.begin = call.request.mutationKey ? true : false; |
There was a problem hiding this comment.
What does this begin mean here ? Is this for mutation only case?
There was a problem hiding this comment.
yeah, I have changed the naming now to this.mutationOnly
test/spanner.ts
Outdated
| // get the type of mutation key | ||
| const mutationType = Object.keys(selectedMutationKey!)[0]; | ||
|
|
||
| // assert that mutation key is not insert |
There was a problem hiding this comment.
nit: this assert is not required, below should be enough
e8256ec to
1ebf7fe
Compare
1ebf7fe to
aa52698
Compare
b9c2cef to
6be3719
Compare
4561cf9 to
505999b
Compare
src/session-factory.ts
Outdated
| /** | ||
| * Retrieves a session for pooled request(via, makePooledRequest_), selecting the appropriate session type | ||
| * based on whether multiplexed sessions are enabled. | ||
| * | ||
| * If the multiplexed sessions are disabled, a session is retrieved from the regular session pool. | ||
| * | ||
| * @param {GetSessionCallback} callback The callback function. | ||
| */ | ||
| getSessionForPooledRequest(callback: GetSessionCallback): void { | ||
| const getSessionFn = this.isMultiplexedRW | ||
| ? this.getSessionForReadWrite | ||
| : this.isMultiplexedPartitionOps | ||
| ? this.getSessionForPartitionedOps | ||
| : this.isMultiplexed | ||
| ? this.getSession | ||
| : this.pool_.getSession.bind(this.pool_); | ||
|
|
||
| getSessionFn(callback); | ||
| } | ||
|
|
There was a problem hiding this comment.
Why do we need this, I am not getting ?
There was a problem hiding this comment.
based on our discussion over chat, I have removed this method
505999b to
72dfd6a
Compare
This PR introduces support for multiplexed sessions for read-write transactions.
The following public methods have been updated as part of this change:
getTransactionrunTransactionrunTransactionAsyncbatchWriteAtLeastOnceother methods which have been updated are:
makePooledRequest_makePooledStreamingRequest_In addition to the changes in the public API, the implementation has been fully tested to ensure correctness and stability.
To enable multiplexed session set the environment variable GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS and GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW to true