Skip to content

Commit 37243f5

Browse files
craig[bot]paulniziolekmsbutlerrickystewart
committed
151773: sql: add ltree value encoding tests r=paulniziolek a=paulniziolek #### sql: add ltree value encoding tests This was forgotten when we first implemented the ltree datum. Epic: None Fixes: None Release note: None 152509: crosscluster/physical: always destroy reader tenant on cutover r=jeffswenson a=msbutler Previously, a reader tenant would only get automatically destroyed if a user specified an explicit cutover time. This UX is confusing. Now, the reader tenant will always get destroyed on cutover. Fixes #149684 Release note (ops change): the PCR reader tenant is always destroyed on cutover 152518: sqlstatsccl: bump test pool size r=kyle-a-wong a=rickystewart This test has hit an OOM. Epic: none Release note: None Co-authored-by: Paul Niziolek <[email protected]> Co-authored-by: Michael Butler <[email protected]> Co-authored-by: Ricky Stewart <[email protected]>
4 parents ff8cc3f + f3a5363 + b30386a + 988ece8 commit 37243f5

File tree

7 files changed

+73
-42
lines changed

7 files changed

+73
-42
lines changed

pkg/ccl/testccl/sqlstatsccl/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ load("@io_bazel_rules_go//go:def.bzl", "go_test")
22

33
go_test(
44
name = "sqlstatsccl_test",
5-
# Explicitly indicate timeout as some of the tests (ie TestSQLStatsRegions) might take up to 3 min to run.
6-
timeout = "moderate",
5+
size = "medium",
76
srcs = [
87
"main_test.go",
98
"sql_stats_test.go",
109
],
10+
exec_properties = {"test.Pool": "large"},
1111
deps = [
1212
"//pkg/base",
1313
"//pkg/ccl",

pkg/crosscluster/physical/standby_read_ts_poller_job_test.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"fmt"
1111
"net/url"
1212
"testing"
13-
"time"
1413

1514
apd "github.com/cockroachdb/apd/v3"
1615
"github.com/cockroachdb/cockroach/pkg/crosscluster/replicationtestutils"
@@ -217,16 +216,9 @@ INSERT INTO a VALUES (1);
217216
`)
218217

219218
waitForPollerJobToStartDest(t, c, ingestionJobID)
220-
if cutoverToLatest {
221-
observeValueInReaderTenant(t, c.ReaderTenantSQL)
222-
c.Cutover(ctx, producerJobID, ingestionJobID, time.Time{}, false)
223-
jobutils.WaitForJobToSucceed(t, c.DestSysSQL, jobspb.JobID(ingestionJobID))
224-
observeValueInReaderTenant(t, c.ReaderTenantSQL)
225-
} else {
226-
c.Cutover(ctx, producerJobID, ingestionJobID, c.SrcCluster.Server(0).Clock().Now().GoTime(), false)
227-
waitToRemoveTenant(t, c.DestSysSQL, readerTenantName)
228-
jobutils.WaitForJobToSucceed(t, c.DestSysSQL, jobspb.JobID(ingestionJobID))
229-
}
219+
c.Cutover(ctx, producerJobID, ingestionJobID, c.SrcCluster.Server(0).Clock().Now().GoTime(), false)
220+
waitToRemoveTenant(t, c.DestSysSQL, readerTenantName)
221+
jobutils.WaitForJobToSucceed(t, c.DestSysSQL, jobspb.JobID(ingestionJobID))
230222
})
231223
}
232224

pkg/crosscluster/physical/stream_ingestion_job.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,11 @@ func maybeRevertToCutoverTimestamp(
456456
// existed in the record at the point of the update rather the
457457
// value that may be in the job record before the update.
458458
var (
459-
shouldRevertToCutover bool
460-
cutoverTimestamp hlc.Timestamp
461-
originalSpanToRevert roachpb.Span
462-
remainingSpansToRevert roachpb.Spans
463-
replicatedTimeAtCutover hlc.Timestamp
464-
readerTenantID roachpb.TenantID
459+
shouldRevertToCutover bool
460+
cutoverTimestamp hlc.Timestamp
461+
originalSpanToRevert roachpb.Span
462+
remainingSpansToRevert roachpb.Spans
463+
readerTenantID roachpb.TenantID
465464
)
466465
if err := ingestionJob.NoTxn().Update(ctx,
467466
func(txn isql.Txn, md jobs.JobMetadata, ju *jobs.JobUpdater) error {
@@ -478,7 +477,6 @@ func maybeRevertToCutoverTimestamp(
478477
}
479478

480479
cutoverTimestamp = streamIngestionProgress.CutoverTime
481-
replicatedTimeAtCutover = streamIngestionProgress.ReplicatedTimeAtCutover
482480
readerTenantID = streamIngestionDetails.ReadTenantID
483481
originalSpanToRevert = streamIngestionDetails.Span
484482
remainingSpansToRevert = streamIngestionProgress.RemainingCutoverSpans
@@ -500,9 +498,7 @@ func maybeRevertToCutoverTimestamp(
500498
if !shouldRevertToCutover {
501499
return cutoverTimestamp, false, nil
502500
}
503-
// Identical cutoverTimestamp and replicatedTimeAtCutover implies that
504-
// CUTOVER TO LATEST command was run. Destroy reader tenant if not CUTOVER TO LATEST.
505-
if !cutoverTimestamp.Equal(replicatedTimeAtCutover) && readerTenantID.IsSet() {
501+
if readerTenantID.IsSet() {
506502
if err := stopTenant(ctx, p.ExecCfg(), readerTenantID); err != nil {
507503
return cutoverTimestamp, false, errors.Wrapf(err, "failed to stop reader tenant")
508504
}

pkg/sql/randgen/datum.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -316,25 +316,7 @@ func RandDatumWithNullChance(
316316
case types.OidFamily:
317317
return tree.NewDOidWithType(oid.Oid(rng.Uint32()), typ)
318318
case types.LTreeFamily:
319-
length := rng.Intn(10)
320-
if length == 1 && rng.Intn(4) == 0 {
321-
return tree.NewDLTree(ltree.Empty)
322-
}
323-
labels := make([]string, length)
324-
for i := range labels {
325-
// Labels cannot be empty.
326-
labelLen := rng.Intn(9) + 1
327-
p := make([]byte, labelLen)
328-
for j := range p {
329-
p[j] = charSet[rng.Intn(len(charSet))]
330-
}
331-
labels[i] = string(p)
332-
}
333-
l, err := tree.ParseDLTree(strings.Join(labels, ltree.PathSeparator))
334-
if err != nil {
335-
return nil
336-
}
337-
return l
319+
return tree.NewDLTree(ltree.RandLTree(rng))
338320
case types.UnknownFamily:
339321
return tree.DNull
340322
case types.ArrayFamily:

pkg/util/encoding/encoding.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3644,6 +3644,13 @@ func PrettyPrintValueEncoded(b []byte) ([]byte, string, error) {
36443644
var s string
36453645
b, s, err = PrettyPrintTupleValueEncoded(b)
36463646
return b, s, err
3647+
case LTree:
3648+
var l ltree.T
3649+
b, l, err = DecodeLTreeValue(b)
3650+
if err != nil {
3651+
return b, "", err
3652+
}
3653+
return b, l.String(), nil
36473654
default:
36483655
return b, "", errors.Errorf("unknown type %s", typ)
36493656
}

pkg/util/encoding/encoding_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,10 @@ func (rd randData) ipAddr() ipaddr.IPAddr {
17251725
return ipaddr.RandIPAddr(rd.Rand)
17261726
}
17271727

1728+
func (rd randData) ltree() ltree.T {
1729+
return ltree.RandLTree(rd.Rand)
1730+
}
1731+
17281732
func BenchmarkEncodeUint32(b *testing.B) {
17291733
rng, _ := randutil.NewTestRand()
17301734

@@ -2251,6 +2255,25 @@ func TestValueEncodeDecodeDuration(t *testing.T) {
22512255
}
22522256
}
22532257

2258+
func TestValueEncodeDecodeLTree(t *testing.T) {
2259+
rng, seed := randutil.NewTestRand()
2260+
rd := randData{rng}
2261+
tests := make([]ltree.T, 1000)
2262+
for i := range tests {
2263+
tests[i] = rd.ltree()
2264+
}
2265+
for _, test := range tests {
2266+
buf := EncodeLTreeValue(nil, NoColumnID, test)
2267+
_, x, err := DecodeLTreeValue(buf)
2268+
if err != nil {
2269+
t.Fatal(err)
2270+
}
2271+
if x.Compare(test) != 0 {
2272+
t.Errorf("seed %d: expected %s got %s", seed, test.String(), x.String())
2273+
}
2274+
}
2275+
}
2276+
22542277
func BenchmarkEncodeNonsortingVarint(b *testing.B) {
22552278
bytes := make([]byte, 0, b.N*MaxNonsortingVarintLen)
22562279
rng, _ := randutil.NewTestRand()
@@ -2456,6 +2479,9 @@ func randValueEncode(rd randData, buf []byte, colID uint32, typ Type) ([]byte, i
24562479
case IPAddr:
24572480
x := rd.ipAddr()
24582481
return EncodeIPAddrValue(buf, colID, x), x, true
2482+
case LTree:
2483+
x := rd.ltree()
2484+
return EncodeLTreeValue(buf, colID, x), x, true
24592485
default:
24602486
return buf, nil, false
24612487
}
@@ -2611,6 +2637,8 @@ func TestValueEncodingRand(t *testing.T) {
26112637
buf, decoded, err = DecodeBitArrayValue(buf)
26122638
case IPAddr:
26132639
buf, decoded, err = DecodeIPAddrValue(buf)
2640+
case LTree:
2641+
buf, decoded, err = DecodeLTreeValue(buf)
26142642
default:
26152643
err = errors.Errorf("unknown type %s", typ)
26162644
}
@@ -2641,6 +2669,12 @@ func TestValueEncodingRand(t *testing.T) {
26412669
if bitarray.Compare(d, val) != 0 {
26422670
t.Fatalf("seed %d: %s got %v expected %v", seed, typ, decoded, value)
26432671
}
2672+
case LTree:
2673+
d := decoded.(ltree.T)
2674+
val := value.(ltree.T)
2675+
if d.Compare(val) != 0 {
2676+
t.Fatalf("seed %d: %s got %v expected %v", seed, typ, decoded, value)
2677+
}
26442678
default:
26452679
if decoded != value {
26462680
t.Fatalf("seed %d: %s got %v expected %v", seed, typ, decoded, value)

pkg/util/ltree/ltree.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package ltree
77

88
import (
99
"bytes"
10+
"math/rand"
1011
"strings"
1112

1213
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
@@ -136,6 +137,25 @@ func (lt T) Copy() T {
136137
return T{path: copiedLabels}
137138
}
138139

140+
func RandLTree(rng *rand.Rand) T {
141+
charSet := "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
142+
length := rng.Intn(10)
143+
if length == 0 {
144+
return Empty
145+
}
146+
labels := make([]string, length)
147+
for i := range labels {
148+
// Labels cannot be empty.
149+
labelLen := rng.Intn(9) + 1
150+
p := make([]byte, labelLen)
151+
for j := range p {
152+
p[j] = charSet[rng.Intn(len(charSet))]
153+
}
154+
labels[i] = string(p)
155+
}
156+
return T{path: labels}
157+
}
158+
139159
// validateLabel checks if a label is valid and returns an error if it is not,
140160
// otherwise, it returns nil.
141161
// A label is valid if it:

0 commit comments

Comments
 (0)