Skip to content

Commit 6bae06f

Browse files
craig[bot]rafissnavsetlur
committed
128833: workload/schemachange: avoid commmenting on transient check constraints r=rafiss a=rafiss These check constraints are added temporarily while adding a non-nullable column. We have seen flakes caused by the workload trying to refer to them. informs #128615 Release note: None 128834: workload/schemachange: only allow PK change in single statement transactions r=rafiss a=rafiss This will avoid errors of the form: "cannot perform other schema changes in the same transaction as a primary key change." informs: #128615 Release note: None 128851: roachtest: Fix ycsb workload to avoid column families r=dt a=navsetlur The update_heavy test had failures because the ycsb workload was using column families, which aren't supported for LDR. Release note: none Fixes: #128740 128855: schemachanger: remove unneeded function r=rafiss a=rafiss fallBackIfDescColInRowLevelTTLTables is no longer needed as of e5b30e4. Epic: None Release note: None Co-authored-by: Rafi Shamim <rafi@cockroachlabs.com> Co-authored-by: Naveen Setlur <naveen.setlur@cockroachlabs.com>
5 parents f6b88f5 + aff5d21 + 0c84c13 + 55ed1c8 + c4b1b74 commit 6bae06f

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

pkg/cmd/roachtest/tests/logical_data_replication.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ type ycsbWorkload struct {
4444
}
4545

4646
func (ycsb ycsbWorkload) sourceInitCmd(tenantName string, nodes option.NodeListOption) string {
47-
cmd := roachtestutil.NewCommand(`./cockroach workload init ycsb`).
47+
cmd := roachtestutil.NewCommand(`./cockroach workload init ycsb --families=false`).
4848
MaybeFlag(ycsb.initRows > 0, "insert-count", ycsb.initRows).
4949
MaybeFlag(ycsb.initSplits > 0, "splits", ycsb.initSplits).
5050
Arg("{pgurl%s:%s}", nodes, tenantName)
5151
return cmd.String()
5252
}
5353

5454
func (ycsb ycsbWorkload) sourceRunCmd(tenantName string, nodes option.NodeListOption) string {
55-
cmd := roachtestutil.NewCommand(`./cockroach workload run ycsb`).
55+
cmd := roachtestutil.NewCommand(`./cockroach workload run ycsb --families=false`).
5656
Option("tolerate-errors").
5757
Flag("workload", ycsb.workloadType).
5858
MaybeFlag(ycsb.debugRunDuration > 0, "duration", ycsb.debugRunDuration).

pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_alter_primary_key.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func alterPrimaryKey(b BuildCtx, tn *tree.TableName, tbl *scpb.Table, t alterPri
7171
fallBackIfShardedIndexExists(b, t, tbl.TableID)
7272
fallBackIfPartitionedIndexExists(b, t, tbl.TableID)
7373
fallBackIfRegionalByRowTable(b, t.n, tbl.TableID)
74-
fallBackIfDescColInRowLevelTTLTables(b, tbl.TableID, t)
7574
fallBackIfSubZoneConfigExists(b, t.n, tbl.TableID)
7675

7776
inflatedChain := getInflatedPrimaryIndexChain(b, tbl.TableID)
@@ -446,15 +445,6 @@ func fallBackIfRegionalByRowTable(b BuildCtx, t tree.NodeFormatter, tableID cati
446445
}
447446
}
448447

449-
// fallBackIfDescColInRowLevelTTLTables panics with an unimplemented
450-
// error if the table is a (row-level-ttl table && (it has a descending
451-
// key column || it has any inbound/outbound FK constraint)).
452-
func fallBackIfDescColInRowLevelTTLTables(b BuildCtx, tableID catid.DescID, t alterPrimaryKeySpec) {
453-
if _, _, rowLevelTTLElem := scpb.FindRowLevelTTL(b.QueryByID(tableID)); rowLevelTTLElem == nil {
454-
return
455-
}
456-
}
457-
458448
func mustRetrieveCurrentPrimaryIndexElement(
459449
b BuildCtx, tableID catid.DescID,
460450
) (res *scpb.PrimaryIndex) {

pkg/workload/schemachange/operation_generator.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func (og *operationGenerator) getSupportedDeclarativeOp(
182182
// stochastic attempts and if verbosity is >= 2 the unsuccessful attempts are
183183
// recorded in `log` to help with debugging of the workload.
184184
func (og *operationGenerator) randOp(
185-
ctx context.Context, tx pgx.Tx, useDeclarativeSchemaChanger, allowDML bool,
185+
ctx context.Context, tx pgx.Tx, useDeclarativeSchemaChanger bool, numOpsInTxn int,
186186
) (stmt *opStmt, err error) {
187187
for {
188188
var op opType
@@ -195,8 +195,11 @@ func (og *operationGenerator) randOp(
195195
} else {
196196
op = opType(og.params.ops.Int())
197197
}
198-
if !allowDML && isDMLOpType(op) {
199-
continue
198+
if numOpsInTxn != 1 {
199+
// DML and legacy PK changes are only allowed in single-statement transactions.
200+
if isDMLOpType(op) || (op == alterTableAlterPrimaryKey && !useDeclarativeSchemaChanger) {
201+
continue
202+
}
200203
}
201204

202205
og.resetOpState(useDeclarativeSchemaChanger)
@@ -2785,6 +2788,8 @@ func (og *operationGenerator) commentOn(ctx context.Context, tx pgx.Tx) (*opStmt
27852788
SELECT 'INDEX ' || quote_ident(schema_name) || '.' || quote_ident(table_name) || '@' || quote_ident("index"->>'name') FROM indexes
27862789
UNION ALL
27872790
SELECT 'CONSTRAINT ' || quote_ident("constraint"->>'name') || ' ON ' || quote_ident(schema_name) || '.' || quote_ident(table_name) FROM constraints
2791+
-- Avoid temporary CHECK constraints created while adding NOT NULL columns.
2792+
WHERE "constraint"->>'name' NOT LIKE '%%auto_not_null'
27882793
%s`, onType))
27892794

27902795
commentables, err := Collect(ctx, og, tx, pgx.RowTo[string], q)

pkg/workload/schemachange/schemachange.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,12 @@ func (w *schemaChangeWorker) runInTxn(
456456
) error {
457457
w.logger.startLog(w.id)
458458
w.logger.writeLog("BEGIN")
459-
opsNum := 1 + w.opGen.randIntn(w.maxOpsPerWorker)
460-
if useDeclarativeSchemaChanger && opsNum > w.workload.declarativeSchemaMaxStmtsPerTxn {
461-
opsNum = w.workload.declarativeSchemaMaxStmtsPerTxn
459+
numOps := 1 + w.opGen.randIntn(w.maxOpsPerWorker)
460+
if useDeclarativeSchemaChanger && numOps > w.workload.declarativeSchemaMaxStmtsPerTxn {
461+
numOps = w.workload.declarativeSchemaMaxStmtsPerTxn
462462
}
463463

464-
for i := 0; i < opsNum; i++ {
464+
for i := 0; i < numOps; i++ {
465465
// Terminating this loop early if there are expected commit errors prevents unexpected commit behavior from being
466466
// hidden by subsequent operations. Consider the case where there are expected commit errors.
467467
// It is possible that committing the transaction now will fail the workload because the error does not occur
@@ -474,8 +474,7 @@ func (w *schemaChangeWorker) runInTxn(
474474
break
475475
}
476476

477-
// Only allow DML for single-statement transactions.
478-
op, err := w.opGen.randOp(ctx, tx, useDeclarativeSchemaChanger, opsNum == 1)
477+
op, err := w.opGen.randOp(ctx, tx, useDeclarativeSchemaChanger, numOps)
479478
if pgErr := new(pgconn.PgError); errors.As(err, &pgErr) &&
480479
pgcode.MakeCode(pgErr.Code) == pgcode.SerializationFailure {
481480
return errors.Mark(err, errRunInTxnRbkSentinel)

0 commit comments

Comments
 (0)