Skip to content

Commit

Permalink
Merge #110236
Browse files Browse the repository at this point in the history
110236: testserver: populate startSingleNode param of RunInitialSQL correctly r=knz a=rafiss

RunInitialSQL accepts a flag that disables all replication in the cluster if it is true. This should be set for testservers that are a single node cluster.

Before this change, only `testserver.Cfg.DefaultZoneConfig.NumReplicas` would be set to 1, but not any of the other builtin ranges, like the meta or system ranges.

Epic: None
Release note: None

Co-authored-by: Rafi Shamim <[email protected]>
  • Loading branch information
craig[bot] and rafiss committed Sep 9, 2023
2 parents 0fd3da5 + 38ca035 commit 46feddd
Show file tree
Hide file tree
Showing 40 changed files with 192 additions and 283 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ write *eventpb.CreateIndex to event log:
mutationId: 1
sql:
descriptorId: 104
statement: CREATE INDEX ‹idx› ON ‹defaultdb›.‹public›.‹t› (‹id›, ‹name›) STORING
(‹money›) PARTITION BY LIST (‹id›) (PARTITION ‹p1› VALUES IN (‹1›))
statement: CREATE INDEX ‹idx› ON ‹defaultdb›.‹public›.‹t› (‹id›, ‹name›) STORING (‹money›) PARTITION BY LIST (‹id›) (PARTITION ‹p1› VALUES IN (‹1›))
tag: CREATE INDEX
user: root
tableName: defaultdb.public.t
Expand Down Expand Up @@ -141,10 +140,8 @@ upsert descriptor #104
+ name: t
+ relevantStatements:
+ - statement:
+ redactedStatement: CREATE INDEX ‹idx› ON ‹defaultdb›.‹public›.‹t› (‹id›, ‹name›)
+ STORING (‹money›) PARTITION BY LIST (‹id›) (PARTITION ‹p1› VALUES IN (‹1›))
+ statement: CREATE INDEX idx ON defaultdb.t (id, name) STORING (money) PARTITION
+ BY LIST (id) (PARTITION p1 VALUES IN (1))
+ redactedStatement: CREATE INDEX ‹idx› ON ‹defaultdb›.‹public›.‹t› (‹id›, ‹name›) STORING (‹money›) PARTITION BY LIST (‹id›) (PARTITION ‹p1› VALUES IN (‹1›))
+ statement: CREATE INDEX idx ON defaultdb.t (id, name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
+ statementTag: CREATE INDEX
+ revertible: true
+ targetRanks: <redacted>
Expand Down Expand Up @@ -364,10 +361,8 @@ upsert descriptor #104
- name: t
- relevantStatements:
- - statement:
- redactedStatement: CREATE INDEX ‹idx› ON ‹defaultdb›.‹public›.‹t› (‹id›, ‹name›)
- STORING (‹money›) PARTITION BY LIST (‹id›) (PARTITION ‹p1› VALUES IN (‹1›))
- statement: CREATE INDEX idx ON defaultdb.t (id, name) STORING (money) PARTITION
- BY LIST (id) (PARTITION p1 VALUES IN (1))
- redactedStatement: CREATE INDEX ‹idx› ON ‹defaultdb›.‹public›.‹t› (‹id›, ‹name›) STORING (‹money›) PARTITION BY LIST (‹id›) (PARTITION ‹p1› VALUES IN (‹1›))
- statement: CREATE INDEX idx ON defaultdb.t (id, name) STORING (money) PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1))
- statementTag: CREATE INDEX
- revertible: true
- targetRanks: <redacted>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ increment telemetry for sql.schema.drop_table
write *eventpb.DropTable to event log:
sql:
descriptorId: 108
statement: DROP TABLE ‹multi_region_test_db›.‹public›.‹table_regional_by_table›
CASCADE
statement: DROP TABLE ‹multi_region_test_db›.‹public›.‹table_regional_by_table› CASCADE
tag: DROP TABLE
user: root
tableName: multi_region_test_db.public.table_regional_by_table
Expand Down Expand Up @@ -96,10 +95,8 @@ upsert descriptor #108
+ name: table_regional_by_table
+ relevantStatements:
+ - statement:
+ redactedStatement: DROP TABLE ‹multi_region_test_db›.‹public›.‹table_regional_by_table›
+ CASCADE
+ statement: DROP TABLE multi_region_test_db.public.table_regional_by_table
+ CASCADE
+ redactedStatement: DROP TABLE ‹multi_region_test_db›.‹public›.‹table_regional_by_table› CASCADE
+ statement: DROP TABLE multi_region_test_db.public.table_regional_by_table CASCADE
+ statementTag: DROP TABLE
+ targetRanks: <redacted>
+ targets: <redacted>
Expand Down Expand Up @@ -155,10 +152,8 @@ upsert descriptor #108
- name: table_regional_by_table
- relevantStatements:
- - statement:
- redactedStatement: DROP TABLE ‹multi_region_test_db›.‹public›.‹table_regional_by_table›
- CASCADE
- statement: DROP TABLE multi_region_test_db.public.table_regional_by_table
- CASCADE
- redactedStatement: DROP TABLE ‹multi_region_test_db›.‹public›.‹table_regional_by_table› CASCADE
- statement: DROP TABLE multi_region_test_db.public.table_regional_by_table CASCADE
- statementTag: DROP TABLE
- targetRanks: <redacted>
- targets: <redacted>
Expand Down
6 changes: 6 additions & 0 deletions pkg/config/zonepb/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ func (z *ZoneConfig) ValidateTandemFields() error {
var minRangeMaxBytes = envutil.EnvOrDefaultInt64("COCKROACH_MIN_RANGE_MAX_BYTES",
64<<20 /* 64 MiB */)

func TestingSetMinRangeMaxBytes(v int64) func() {
old := minRangeMaxBytes
minRangeMaxBytes = v
return func() { minRangeMaxBytes = old }
}

// Validate returns an error if the ZoneConfig specifies a known-dangerous or
// disallowed configuration.
func (z *ZoneConfig) Validate() error {
Expand Down
10 changes: 10 additions & 0 deletions pkg/kv/kvserver/client_split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1235,9 +1235,13 @@ func TestStoreRangeSplitBackpressureWrites(t *testing.T) {

// Set maxBytes to something small so we can exceed the maximum split
// size without adding 2x64MB of data.
defer zonepb.TestingSetMinRangeMaxBytes(1 << 16)()
const minBytes = 1 << 12
const maxBytes = 1 << 17
zoneConfig := zonepb.DefaultZoneConfig()
zoneConfig.RangeMinBytes = proto.Int64(minBytes)
zoneConfig.RangeMaxBytes = proto.Int64(maxBytes)
zoneConfig.NumReplicas = proto.Int32(1)

testingRequestFilter :=
func(_ context.Context, ba *kvpb.BatchRequest) *kvpb.Error {
Expand Down Expand Up @@ -2577,18 +2581,24 @@ func TestUnsplittableRange(t *testing.T) {

ctx := context.Background()
ttl := 1 * time.Hour
defer zonepb.TestingSetMinRangeMaxBytes(1 << 16)()
const minBytes = 1 << 12
const maxBytes = 1 << 17
manualClock := hlc.NewHybridManualClock()
zoneConfig := zonepb.DefaultZoneConfig()
zoneConfig.RangeMinBytes = proto.Int64(minBytes)
zoneConfig.RangeMaxBytes = proto.Int64(maxBytes)
zoneConfig.GC = &zonepb.GCPolicy{
TTLSeconds: int32(ttl.Seconds()),
}
zoneConfig.NumReplicas = proto.Int32(1)
zoneSystemConfig := zonepb.DefaultSystemZoneConfig()
zoneSystemConfig.RangeMinBytes = proto.Int64(minBytes)
zoneSystemConfig.RangeMaxBytes = proto.Int64(maxBytes)
zoneSystemConfig.GC = &zonepb.GCPolicy{
TTLSeconds: int32(ttl.Seconds()),
}
zoneSystemConfig.NumReplicas = proto.Int32(1)
splitQueuePurgatoryChan := make(chan time.Time, 1)

s := serverutils.StartServerOnly(t, base.TestServerArgs{
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ func (ts *testServer) Activate(ctx context.Context) error {
}
// In tests we need some, but not all of RunInitialSQL functionality.
if err := ts.topLevelServer.RunInitialSQL(
ctx, false /* startSingleNode */, "" /* adminUser */, "", /* adminPassword */
ctx, !ts.params.PartOfCluster, "" /* adminUser */, "", /* adminPassword */
); err != nil {
return err
}
Expand Down
105 changes: 54 additions & 51 deletions pkg/sql/catalog/lease/lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import (

type leaseTest struct {
testing.TB
topServer serverutils.TestServerInterface
cluster serverutils.TestClusterInterface
server serverutils.ApplicationLayerInterface
db *gosql.DB
kvDB *kv.DB
Expand All @@ -96,25 +96,26 @@ func init() {

}

func newLeaseTest(tb testing.TB, params base.TestServerArgs) *leaseTest {
s, db, kvDB := serverutils.StartServer(tb, params)
leaseTest := &leaseTest{
TB: tb,
topServer: s,
server: s.ApplicationLayer(),
db: db,
kvDB: kvDB,
nodes: map[uint32]*lease.Manager{},
}
if params.Knobs.SQLLeaseManager != nil {
leaseTest.leaseManagerTestingKnobs =
*params.Knobs.SQLLeaseManager.(*lease.ManagerTestingKnobs)
}
return leaseTest
func newLeaseTest(tb testing.TB, params base.TestClusterArgs) *leaseTest {
c := serverutils.StartCluster(tb, 3, params)
lt := &leaseTest{
TB: tb,
cluster: c,
server: c.Server(0).ApplicationLayer(),
db: c.ServerConn(0),
kvDB: c.Server(0).DB(),
nodes: map[uint32]*lease.Manager{},
}

if params.ServerArgs.Knobs.SQLLeaseManager != nil {
lt.leaseManagerTestingKnobs =
*params.ServerArgs.Knobs.SQLLeaseManager.(*lease.ManagerTestingKnobs)
}
return lt
}

func (t *leaseTest) cleanup() {
t.topServer.Stopper().Stop(context.Background())
t.cluster.Stopper().Stop(context.Background())
}

func (t *leaseTest) getLeases(descID descpb.ID) string {
Expand Down Expand Up @@ -269,8 +270,8 @@ func TestLeaseManager(testingT *testing.T) {
defer log.Scope(testingT).Close(testingT)

removalTracker := lease.NewLeaseRemovalTracker()
var params base.TestServerArgs
params.Knobs = base.TestingKnobs{
var params base.TestClusterArgs
params.ServerArgs.Knobs = base.TestingKnobs{
SQLLeaseManager: &lease.ManagerTestingKnobs{
LeaseStoreTestingKnobs: lease.StorageTestingKnobs{
LeaseReleasedEvent: removalTracker.LeaseRemovedNotification,
Expand Down Expand Up @@ -380,20 +381,21 @@ func TestLeaseManagerReacquire(testingT *testing.T) {
defer log.Scope(testingT).Close(testingT)

ctx := context.Background()
var params base.TestServerArgs
params.Settings = cluster.MakeTestingClusterSettings()
var params base.TestClusterArgs
params.ServerArgs.Settings = cluster.MakeTestingClusterSettings()
// Set the lease duration such that the next lease acquisition will
// require the lease to be reacquired.
lease.LeaseDuration.Override(ctx, &params.SV, 0)
lease.LeaseDuration.Override(ctx, &params.ServerArgs.SV, 0)

removalTracker := lease.NewLeaseRemovalTracker()
params.Knobs = base.TestingKnobs{
params.ServerArgs.Knobs = base.TestingKnobs{
SQLLeaseManager: &lease.ManagerTestingKnobs{
LeaseStoreTestingKnobs: lease.StorageTestingKnobs{
LeaseReleasedEvent: removalTracker.LeaseRemovedNotification,
},
},
}

t := newLeaseTest(testingT, params)
defer t.cleanup()

Expand Down Expand Up @@ -429,7 +431,7 @@ func TestLeaseManagerPublishVersionChanged(testingT *testing.T) {
defer leaktest.AfterTest(testingT)()
defer log.Scope(testingT).Close(testingT)

t := newLeaseTest(testingT, base.TestServerArgs{})
t := newLeaseTest(testingT, base.TestClusterArgs{})
defer t.cleanup()

descID := t.makeTableForTest()
Expand Down Expand Up @@ -493,7 +495,7 @@ func TestLeaseManagerPublishIllegalVersionChange(testingT *testing.T) {
defer leaktest.AfterTest(testingT)()
defer log.Scope(testingT).Close(testingT)

t := newLeaseTest(testingT, base.TestServerArgs{})
t := newLeaseTest(testingT, base.TestClusterArgs{})
defer t.cleanup()

if _, err := t.node(1).Publish(
Expand All @@ -518,9 +520,9 @@ func TestLeaseManagerDrain(testingT *testing.T) {
defer leaktest.AfterTest(testingT)()
defer log.Scope(testingT).Close(testingT)

var params base.TestServerArgs
var params base.TestClusterArgs
leaseRemovalTracker := lease.NewLeaseRemovalTracker()
params.Knobs = base.TestingKnobs{
params.ServerArgs.Knobs = base.TestingKnobs{
SQLLeaseManager: &lease.ManagerTestingKnobs{
LeaseStoreTestingKnobs: lease.StorageTestingKnobs{
LeaseReleasedEvent: leaseRemovalTracker.LeaseRemovedNotification,
Expand Down Expand Up @@ -582,8 +584,8 @@ func TestCantLeaseDeletedTable(testingT *testing.T) {
var mu syncutil.Mutex
clearSchemaChangers := false

var params base.TestServerArgs
params.Knobs = base.TestingKnobs{
var params base.TestClusterArgs
params.ServerArgs.Knobs = base.TestingKnobs{
SQLSchemaChanger: &sql.SchemaChangerTestingKnobs{
SchemaChangeJobNoOp: func() bool {
mu.Lock()
Expand Down Expand Up @@ -1178,7 +1180,7 @@ func BenchmarkLeaseAcquireByNameCached(b *testing.B) {
defer leaktest.AfterTest(b)()
defer log.Scope(b).Close(b)

t := newLeaseTest(b, base.TestServerArgs{})
t := newLeaseTest(b, base.TestClusterArgs{})
defer t.cleanup()

if _, err := t.db.Exec(`
Expand Down Expand Up @@ -1236,8 +1238,8 @@ func TestLeaseRenewedAutomatically(testingT *testing.T) {

var testAcquiredCount int32
var testAcquisitionBlockCount int32
var params base.TestServerArgs
params.Knobs = base.TestingKnobs{
var params base.TestClusterArgs
params.ServerArgs.Knobs = base.TestingKnobs{
SQLLeaseManager: &lease.ManagerTestingKnobs{
LeaseStoreTestingKnobs: lease.StorageTestingKnobs{
// We want to track when leases get acquired and when they are renewed.
Expand All @@ -1259,14 +1261,14 @@ func TestLeaseRenewedAutomatically(testingT *testing.T) {
},
},
}
params.Settings = cluster.MakeTestingClusterSettings()
params.ServerArgs.Settings = cluster.MakeTestingClusterSettings()
// The lease jitter is set to ensure newer leases have higher
// expiration timestamps.
lease.LeaseJitterFraction.Override(ctx, &params.SV, 0)
lease.LeaseJitterFraction.Override(ctx, &params.ServerArgs.SV, 0)
// The renewal timeout is set to be the duration, so background
// renewal should begin immediately after accessing a lease.
lease.LeaseRenewalDuration.Override(ctx, &params.SV,
lease.LeaseDuration.Get(&params.SV))
lease.LeaseRenewalDuration.Override(ctx, &params.ServerArgs.SV,
lease.LeaseDuration.Get(&params.ServerArgs.SV))

t := newLeaseTest(testingT, params)
defer t.cleanup()
Expand Down Expand Up @@ -1727,7 +1729,7 @@ func TestModificationTimeTxnOrdering(testingT *testing.T) {
// Which table to exercise the test against.
const descID = keys.LeaseTableID

t := newLeaseTest(testingT, base.TestServerArgs{})
t := newLeaseTest(testingT, base.TestClusterArgs{})
defer t.cleanup()

if _, err := t.db.Exec(`
Expand Down Expand Up @@ -1820,8 +1822,8 @@ func TestLeaseRenewedPeriodically(testingT *testing.T) {
var testAcquisitionBlockCount int32
var expected catalog.DescriptorIDSet

var params base.TestServerArgs
params.Knobs = base.TestingKnobs{
var params base.TestClusterArgs
params.ServerArgs.Knobs = base.TestingKnobs{
SQLLeaseManager: &lease.ManagerTestingKnobs{
LeaseStoreTestingKnobs: lease.StorageTestingKnobs{
// We want to track when leases get acquired and when they are renewed.
Expand Down Expand Up @@ -1853,16 +1855,16 @@ func TestLeaseRenewedPeriodically(testingT *testing.T) {
},
},
}
params.Settings = cluster.MakeTestingClusterSettings()
params.ServerArgs.Settings = cluster.MakeTestingClusterSettings()

// The lease jitter is set to ensure newer leases have higher
// expiration timestamps.
lease.LeaseJitterFraction.Override(ctx, &params.SV, 0)
lease.LeaseJitterFraction.Override(ctx, &params.ServerArgs.SV, 0)
// Lease duration to something small.
lease.LeaseDuration.Override(ctx, &params.SV, 50*time.Millisecond)
lease.LeaseDuration.Override(ctx, &params.ServerArgs.SV, 50*time.Millisecond)
// Renewal timeout to 0 saying that the lease will get renewed only
// after the lease expires when a request requests the descriptor.
lease.LeaseRenewalDuration.Override(ctx, &params.SV, 0)
lease.LeaseRenewalDuration.Override(ctx, &params.ServerArgs.SV, 0)

t := newLeaseTest(testingT, params)
defer t.cleanup()
Expand Down Expand Up @@ -2066,8 +2068,8 @@ func TestDeleteOrphanedLeases(testingT *testing.T) {
defer leaktest.AfterTest(testingT)()
defer log.Scope(testingT).Close(testingT)

var params base.TestServerArgs
params.Knobs = base.TestingKnobs{
var params base.TestClusterArgs
params.ServerArgs.Knobs = base.TestingKnobs{
SQLLeaseManager: &lease.ManagerTestingKnobs{},
}

Expand Down Expand Up @@ -3132,14 +3134,14 @@ func TestLeaseBulkInsertWithImplicitTxn(t *testing.T) {

ctx := context.Background()

var params base.TestServerArgs
params.Settings = cluster.MakeTestingClusterSettings()
var params base.TestClusterArgs
params.ServerArgs.Settings = cluster.MakeTestingClusterSettings()
// Set the lease duration such that the next lease acquisition will
// require the lease to be reacquired.
lease.LeaseDuration.Override(ctx, &params.SV, 0)
lease.LeaseDuration.Override(ctx, &params.ServerArgs.SV, 0)
var leaseManager *lease.Manager
leaseTableID := uint64(0)
params.Knobs.SQLExecutor = &sql.ExecutorTestingKnobs{
params.ServerArgs.Knobs.SQLExecutor = &sql.ExecutorTestingKnobs{
// The before execute hook will be to set up to pause
// the beforeExecuteStmt, which will then be resumed
// when the beforeExecuteResumeStmt statement is observed.
Expand Down Expand Up @@ -3183,9 +3185,10 @@ func TestLeaseBulkInsertWithImplicitTxn(t *testing.T) {
},
}

srv, conn, _ := serverutils.StartServer(t, params)
srv := serverutils.StartCluster(t, 3, params)
defer srv.Stopper().Stop(ctx)
s := srv.ApplicationLayer()
s := srv.Server(0).ApplicationLayer()
conn := srv.ServerConn(0)
sql.SecondaryTenantSplitAtEnabled.Override(ctx, &s.ClusterSettings().SV, true)
// Setup tables for the test.
_, err := conn.Exec(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ PreCommitPhase stage 2 of 2 with 6 MutationType ops
RunningStatus: PostCommitPhase stage 1 of 2 with 1 ValidationType op pending
Statements:
- statement: ALTER TABLE t ADD CONSTRAINT check_b CHECK (f(b) > 1)
redactedstatement: ALTER TABLE ‹defaultdb›.public.‹t› ADD CONSTRAINT ‹check_b› CHECK
(f(‹b›) > ‹1›)
redactedstatement: ALTER TABLE ‹defaultdb›.public.‹t› ADD CONSTRAINT ‹check_b› CHECK (f(‹b›) > ‹1›)
statementtag: ALTER TABLE
PostCommitPhase stage 1 of 2 with 1 ValidationType op
transitions:
Expand Down
Loading

0 comments on commit 46feddd

Please sign in to comment.