Skip to content

Commit 36fa9e4

Browse files
committed
sql: allow runnig TestErrorOnRollback with buffered writes
This test was using a proposal filter. When this test is run using buffered writes, we actually end up with an empty raft command -- the only lock that's acquired is local and unreplicated, which allows us to elide writing an EndTxn record as Aborted. Contrast this to a non-buffered writes run, where a replicated intent needs to be removed. Using a post evaluation filter here does the trick. References #144866 Release note: None
1 parent 4ca3bfe commit 36fa9e4

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

pkg/sql/conn_executor_test.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -329,26 +329,24 @@ func TestErrorOnRollback(t *testing.T) {
329329
params := base.TestServerArgs{
330330
Knobs: base.TestingKnobs{
331331
Store: &kvserver.StoreTestingKnobs{
332-
TestingProposalFilter: func(fArgs kvserverbase.ProposalFilterArgs) *kvpb.Error {
333-
if !fArgs.Req.IsSingleRequest() {
332+
EvalKnobs: kvserverbase.BatchEvalTestingKnobs{
333+
TestingPostEvalFilter: func(fArgs kvserverbase.FilterArgs) *kvpb.Error {
334+
etReq, ok := fArgs.Req.(*kvpb.EndTxnRequest)
335+
// We only inject the error once. Turns out that during the life of
336+
// the test there's two EndTxns being sent - one is the direct
337+
// result of the test's call to tx.Rollback(), the second is sent by
338+
// the TxnCoordSender - indirectly triggered by the fact that, on
339+
// the server side, the transaction's context gets canceled at the
340+
// SQL layer.
341+
if ok &&
342+
etReq.Header().Key.String() == targetKeyString.Load().(string) &&
343+
atomic.LoadInt64(&injectedErr) == 0 {
344+
345+
atomic.StoreInt64(&injectedErr, 1)
346+
return kvpb.NewErrorf("test injected error")
347+
}
334348
return nil
335-
}
336-
req := fArgs.Req.Requests[0]
337-
etReq, ok := req.GetInner().(*kvpb.EndTxnRequest)
338-
// We only inject the error once. Turns out that during the
339-
// life of the test there's two EndTxns being sent - one is
340-
// the direct result of the test's call to tx.Rollback(),
341-
// the second is sent by the TxnCoordSender - indirectly
342-
// triggered by the fact that, on the server side, the
343-
// transaction's context gets canceled at the SQL layer.
344-
if ok &&
345-
etReq.Header().Key.String() == targetKeyString.Load().(string) &&
346-
atomic.LoadInt64(&injectedErr) == 0 {
347-
348-
atomic.StoreInt64(&injectedErr, 1)
349-
return kvpb.NewErrorf("test injected error")
350-
}
351-
return nil
349+
},
352350
},
353351
},
354352
},

0 commit comments

Comments
 (0)