Skip to content

Commit

Permalink
logictest: add kv tracing to testcase for 131869
Browse files Browse the repository at this point in the history
This helps show what is happening. Also make the kvtrace option handle
keys with tenant prefixes.

Informs: #131860

Release note: None
  • Loading branch information
michae2 committed Oct 10, 2024
1 parent 2fe0179 commit 778da8a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
14 changes: 11 additions & 3 deletions pkg/sql/logictest/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ import (
// if kvtrace(CPut,Del,prefix=/Table/54,prefix=/Table/55), the
// results will be filtered to contain messages starting with
// CPut /Table/54, CPut /Table/55, Del /Table/54, Del /Table/55.
// Cannot be combined with noticetrace.
// Tenant IDs do not need to be included in prefixes and will be
// removed from results. Cannot be combined with noticetrace.
// - noticetrace: runs the query and compares only the notices that
// appear. Cannot be combined with kvtrace.
// - nodeidx=N: runs the query on node N of the cluster.
Expand Down Expand Up @@ -2748,6 +2749,9 @@ func (t *logicTest) processSubtest(
for _, c := range strings.Split(s, ",") {
if strings.HasPrefix(c, "prefix=") {
matched := strings.TrimPrefix(c, "prefix=")
if len(t.tenantApps) != 0 || t.cluster.StartedDefaultTestTenant() {
matched = "/Tenant/%" + matched
}
query.keyPrefixFilters = append(query.keyPrefixFilters, matched)
} else if isAllowedKVOp(c) {
query.kvOpTypes = append(query.kvOpTypes, c)
Expand Down Expand Up @@ -2927,7 +2931,11 @@ func (t *logicTest) processSubtest(
return err
}

queryPrefix := `SELECT message FROM [SHOW KV TRACE FOR SESSION] `
projection := `message`
if len(t.tenantApps) != 0 || t.cluster.StartedDefaultTestTenant() {
projection = `regexp_replace(message, '/Tenant/\d+', '')`
}
queryPrefix := fmt.Sprintf(`SELECT %s FROM [SHOW KV TRACE FOR SESSION] `, projection)
buildQuery := func(ops []string, keyFilters []string) string {
var sb strings.Builder
sb.WriteString(queryPrefix)
Expand All @@ -2941,7 +2949,7 @@ func (t *logicTest) processSubtest(
} else {
sb.WriteString("OR ")
}
sb.WriteString(fmt.Sprintf("message like '%s %s%%'", c, f))
sb.WriteString(fmt.Sprintf("message like '%s %s%%' ", c, f))
}
}
return sb.String()
Expand Down
18 changes: 14 additions & 4 deletions pkg/sql/logictest/testdata/logic_test/column_families
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,32 @@ fetched: /t/t_pkey/1/2/z -> /1
statement ok
CREATE TABLE abc (a INT NOT NULL, b FLOAT NOT NULL, c INT, FAMILY (a), FAMILY (b), FAMILY (c))

statement ok
query T regexp,kvtrace(prefix=/Table/109)
INSERT INTO abc VALUES (4, -0, 6)
----
CPut /Table/109/1/\d+/0 -> /TUPLE/1:1:Int/4
CPut /Table/109/1/\d+/1/1 -> /FLOAT/-0
CPut /Table/109/1/\d+/2/1 -> /INT/6

statement ok
ALTER TABLE abc ADD PRIMARY KEY (a, b)

statement ok
query T kvtrace(prefix=/Table/109)
UPDATE abc SET c = NULL WHERE a = 4 AND b = -0
----
Scan /Table/109/4/4/0{-/PrefixEnd} lock Exclusive (Block, Unreplicated)
Del /Table/109/4/4/0/2/1

query IFI
SELECT * FROM abc
----
4 -0 NULL

statement ok
UPDATE abc SET b = 0 WHERE a = 4 AND b = -0;
query T kvtrace(prefix=/Table/109)
UPDATE abc SET b = 0 WHERE a = 4 AND b = -0
----
Scan /Table/109/4/4/0{-/PrefixEnd} lock Exclusive (Block, Unreplicated)
Del /Table/109/4/4/0/1/1

query IFI
SELECT * FROM abc
Expand Down

0 comments on commit 778da8a

Please sign in to comment.