Skip to content

Commit 06a4e6e

Browse files
authored
Merge pull request #151397 from arulajmani/backport25.3-151367
release-25.3: kv: include tracing for split QueryIntent requests
2 parents 86ab5dc + c5b5627 commit 06a4e6e

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

pkg/kv/kvclient/kvcoord/dist_sender.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,7 @@ func (ds *DistSender) divideAndSendParallelCommit(
15481548
} else {
15491549
ctx, hdl, err := ds.stopper.GetHandle(ctx, stop.TaskOpts{
15501550
TaskName: taskName,
1551+
SpanOpt: stop.ChildSpan,
15511552
})
15521553
if err != nil {
15531554
return nil, kvpb.NewError(err)

pkg/kv/kvclient/kvcoord/txn_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"bytes"
1010
"context"
1111
"fmt"
12+
"regexp"
1213
"sort"
1314
"sync/atomic"
1415
"testing"
@@ -26,19 +27,23 @@ import (
2627
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverbase"
2728
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/tscache"
2829
"github.com/cockroachdb/cockroach/pkg/roachpb"
30+
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
2931
"github.com/cockroachdb/cockroach/pkg/storage"
3032
"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
3133
"github.com/cockroachdb/cockroach/pkg/storage/mvccencoding"
3234
"github.com/cockroachdb/cockroach/pkg/testutils"
3335
"github.com/cockroachdb/cockroach/pkg/testutils/kvclientutils"
3436
"github.com/cockroachdb/cockroach/pkg/testutils/localtestcluster"
3537
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
38+
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster"
3639
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
3740
"github.com/cockroachdb/cockroach/pkg/util/hlc"
3841
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
3942
"github.com/cockroachdb/cockroach/pkg/util/log"
4043
"github.com/cockroachdb/cockroach/pkg/util/randutil"
4144
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
45+
"github.com/cockroachdb/cockroach/pkg/util/tracing"
46+
"github.com/cockroachdb/cockroach/pkg/util/tracing/tracingpb"
4247
"github.com/cockroachdb/cockroach/pkg/util/uuid"
4348
"github.com/cockroachdb/errors"
4449
"github.com/stretchr/testify/require"
@@ -2469,3 +2474,50 @@ func TestTxnBufferedWritesOmitAbortSpanChecks(t *testing.T) {
24692474
require.Error(t, err)
24702475
require.Regexp(t, "TransactionRetryWithProtoRefreshError: .*WriteTooOldError", err)
24712476
}
2477+
2478+
// TestTxnTracesSplitQueryIntents verifies that the split out QueryIntent
2479+
// requests are captured in the verbose tracing of a transaction.
2480+
func TestTxnTracesSplitQueryIntents(t *testing.T) {
2481+
defer leaktest.AfterTest(t)()
2482+
defer log.Scope(t).Close(t)
2483+
2484+
st := cluster.MakeTestingClusterSettings()
2485+
tc := testcluster.StartTestCluster(t, 1, base.TestClusterArgs{
2486+
ServerArgs: base.TestServerArgs{
2487+
Settings: st,
2488+
},
2489+
})
2490+
ctx := context.Background()
2491+
defer tc.Stopper().Stop(ctx)
2492+
// NB: Disable buffered writes to ensure writes are pipelined, and therefore
2493+
// there are QueryIntent requests to split.
2494+
kvcoord.BufferedWritesEnabled.Override(ctx, &st.SV, false)
2495+
2496+
db := tc.Server(0).DB()
2497+
2498+
tracer := tracing.NewTracer()
2499+
traceCtx, sp := tracer.StartSpanCtx(context.Background(), "test-txn", tracing.WithRecording(tracingpb.RecordingVerbose))
2500+
2501+
if err := db.Txn(traceCtx, func(ctx context.Context, txn *kv.Txn) error {
2502+
if err := txn.CPut(ctx, "a", "val", nil); err != nil {
2503+
return err
2504+
}
2505+
if err := txn.Put(ctx, "c", "d"); err != nil {
2506+
return err
2507+
}
2508+
return nil
2509+
}); err != nil {
2510+
t.Fatal(err)
2511+
}
2512+
collectedSpans := sp.FinishAndGetRecording(tracingpb.RecordingVerbose)
2513+
dump := collectedSpans.String()
2514+
// dump:
2515+
// 0.275ms 0.171ms sending split out pre-commit QueryIntent batch
2516+
found, err := regexp.MatchString(
2517+
// The (?s) makes "." match \n. This makes the test resilient to other log
2518+
// lines being interspersed.
2519+
`.*sending split out pre-commit QueryIntent batch`,
2520+
dump)
2521+
require.NoError(t, err)
2522+
require.True(t, found, "didn't match: %s", dump)
2523+
}

pkg/sql/opt/exec/execbuilder/testdata/show_trace

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ SELECT $$
4646
FROM [SHOW KV TRACE FOR SESSION]
4747
WHERE message NOT LIKE '%Z/%'
4848
AND operation NOT LIKE 'kv.DistSender: sending partial batch%'
49+
AND operation NOT LIKE 'kv.DistSender: sending pre-commit query intents%'
4950
AND message NOT SIMILAR TO '%(PushTxn|ResolveIntent|SystemConfigSpan)%'
5051
AND tag NOT LIKE '%intExec=%'
5152
AND tag NOT LIKE '%scExec%'

pkg/sql/opt/exec/execbuilder/testdata/upsert

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,7 @@ SET tracing = on,kv,results; UPSERT INTO t.kv(k, v) VALUES (2,3); SET tracing =
10761076
query TT
10771077
SELECT operation, message FROM [SHOW KV TRACE FOR SESSION]
10781078
WHERE operation != 'dist sender send' AND operation != 'kv.DistSender: sending partial batch'
1079+
AND operation NOT LIKE 'kv.DistSender: sending pre-commit query intents%'
10791080
----
10801081
colbatchscan Scan /Table/120/1/2/0 lock Exclusive (Block, Unreplicated)
10811082
count CPut /Table/120/1/2/0 -> /TUPLE/2:2:Int/3

0 commit comments

Comments
 (0)