@@ -1538,14 +1538,19 @@ func (t *ReadWriteTransaction) setSessionEligibilityForLongRunning(sh *sessionHa
1538
1538
}
1539
1539
1540
1540
func beginTransaction (ctx context.Context , opts transactionBeginOptions ) (transactionID , * sppb.MultiplexedSessionPrecommitToken , error ) {
1541
+ readWriteOptions := & sppb.TransactionOptions_ReadWrite {
1542
+ ReadLockMode : opts .txOptions .ReadLockMode ,
1543
+ }
1544
+
1545
+ if opts .multiplexEnabled {
1546
+ readWriteOptions .MultiplexedSessionPreviousTransactionId = opts .previousTx
1547
+ }
1548
+
1541
1549
res , err := opts .client .BeginTransaction (ctx , & sppb.BeginTransactionRequest {
1542
1550
Session : opts .sessionID ,
1543
1551
Options : & sppb.TransactionOptions {
1544
1552
Mode : & sppb.TransactionOptions_ReadWrite_ {
1545
- ReadWrite : & sppb.TransactionOptions_ReadWrite {
1546
- ReadLockMode : opts .txOptions .ReadLockMode ,
1547
- MultiplexedSessionPreviousTransactionId : opts .previousTx ,
1548
- },
1553
+ ReadWrite : readWriteOptions ,
1549
1554
},
1550
1555
ExcludeTxnFromChangeStreams : opts .txOptions .ExcludeTxnFromChangeStreams ,
1551
1556
},
@@ -1609,11 +1614,12 @@ func (t *ReadWriteTransaction) begin(ctx context.Context, mutation *sppb.Mutatio
1609
1614
sh .updateLastUseTime ()
1610
1615
}
1611
1616
tx , precommitToken , err = beginTransaction (contextWithOutgoingMetadata (ctx , sh .getMetadata (), t .disableRouteToLeader ), transactionBeginOptions {
1612
- sessionID : sh .getID (),
1613
- client : sh .getClient (),
1614
- txOptions : t .txOpts ,
1615
- mutation : mutation ,
1616
- previousTx : previousTx ,
1617
+ multiplexEnabled : t .sp .isMultiplexedSessionForRWEnabled (),
1618
+ sessionID : sh .getID (),
1619
+ client : sh .getClient (),
1620
+ txOptions : t .txOpts ,
1621
+ mutation : mutation ,
1622
+ previousTx : previousTx ,
1617
1623
})
1618
1624
if isSessionNotFoundError (err ) {
1619
1625
sh .destroy ()
@@ -2089,9 +2095,10 @@ func isAbortedErr(err error) bool {
2089
2095
2090
2096
// transactionBeginOptions holds the parameters for beginning a transaction.
2091
2097
type transactionBeginOptions struct {
2092
- sessionID string
2093
- client spannerClient
2094
- txOptions TransactionOptions
2095
- previousTx transactionID
2096
- mutation * sppb.Mutation
2098
+ multiplexEnabled bool
2099
+ sessionID string
2100
+ client spannerClient
2101
+ txOptions TransactionOptions
2102
+ previousTx transactionID
2103
+ mutation * sppb.Mutation
2097
2104
}
0 commit comments