@@ -30,6 +30,7 @@ import (
30
30
"github.com/cockroachdb/cockroach/pkg/server/serverpb"
31
31
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
32
32
"github.com/cockroachdb/cockroach/pkg/settings"
33
+ "github.com/cockroachdb/cockroach/pkg/settings/cluster"
33
34
"github.com/cockroachdb/cockroach/pkg/sql/appstatspb"
34
35
"github.com/cockroachdb/cockroach/pkg/sql/auditlogging"
35
36
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
@@ -3543,9 +3544,7 @@ func (ex *connExecutor) setTransactionModes(
3543
3544
if err := ex .state .setIsolationLevel (level ); err != nil {
3544
3545
return pgerror .WithCandidateCode (err , pgcode .ActiveSQLTransaction )
3545
3546
}
3546
- if (level != isolation .Serializable ) && ! allowBufferedWritesForWeakIsolation .Get (& ex .server .cfg .Settings .SV ) {
3547
- // TODO(#143497): we currently only support buffered writes under
3548
- // serializable isolation.
3547
+ if ! ex .bufferedWritesIsAllowedForIsolationLevel (ctx , level ) {
3549
3548
ex .state .mu .txn .SetBufferedWritesEnabled (false )
3550
3549
}
3551
3550
}
@@ -3731,6 +3730,28 @@ func (ex *connExecutor) bufferedWritesEnabled(ctx context.Context) bool {
3731
3730
return ex .sessionData ().BufferedWritesEnabled && ex .server .cfg .Settings .Version .IsActive (ctx , clusterversion .V25_2 )
3732
3731
}
3733
3732
3733
+ func (ex * connExecutor ) bufferedWritesIsAllowedForIsolationLevel (
3734
+ ctx context.Context , isoLevel isolation.Level ,
3735
+ ) bool {
3736
+ return bufferedWritesIsAllowedForIsolationLevel (ctx , ex .server .cfg .Settings , isoLevel )
3737
+ }
3738
+
3739
+ func bufferedWritesIsAllowedForIsolationLevel (
3740
+ ctx context.Context , st * cluster.Settings , isoLevel isolation.Level ,
3741
+ ) bool {
3742
+ if isoLevel == isolation .Serializable {
3743
+ return true
3744
+ }
3745
+
3746
+ // We are at a weaker isolation level that requires lock loss detection which
3747
+ // is only available on 25.3 or greater.
3748
+ if ! st .Version .IsActive (ctx , clusterversion .V25_3 ) {
3749
+ return false
3750
+ }
3751
+
3752
+ return allowBufferedWritesForWeakIsolation .Get (& st .SV )
3753
+ }
3754
+
3734
3755
// initEvalCtx initializes the fields of an extendedEvalContext that stay the
3735
3756
// same across multiple statements. resetEvalCtx must also be called before each
3736
3757
// statement, to reinitialize other fields.
0 commit comments