Skip to content

Commit 1b0d0ec

Browse files
craig[bot]spilchenyuzefovichdtrafiss
committed
154872: sql/inspect: fix progress tracking bugs causing over 100% completion r=spilchen a=spilchen Fix two bugs in INSPECT job progress tracking that caused inaccurate completion percentages, sometimes exceeding 100%. The first issue was in inspect_processor.go, where processSpan() checked the loop termination condition (!ok) before accounting for the final completed check. When the last check finished we would exit the loop before reporting the final check as complete. The second issue was in inspect_job.go, where initProgressFromPlan() calculated total checks using PK spans rather than the partitioned spans actually used by processors. The number of total checks that we think need to be complete were much lower than the partitioned spans. This caused us to report completion rates in excess of 100%. Epic: CRDB-30356 Informs: #154457 Release note: none 154878: sql: audit production callers of `rowenc.DatumToEncDatum` r=yuzefovich a=yuzefovich **sql: audit production callers of `rowenc.DatumToEncDatum`** This commit audits all callers of `rowenc.DatumToEncDatum` in order to replace possibly unsafe calls to `DatumToEncDatumEx` which requires explicit error handling (the former panics when the datum's resolved type is not equivalent to the passed-in type). I decided to not remove the former method altogether since it seems to be reasonable to use it when we're construcing the datum directly in the call site (and also in tests). Fixes: #154607. **rowenc: rename DatumToEncDatum methods** This commit does the following renaming: - `DatumToEncDatumEx` -> `DatumToEncDatum` - `DatumToEncDatum` -> `DatumToEncDatumUnsafe`. The goal is to encourage usage of safer version which requires explicit error handling (as opposed to panicking). The main use case (apart from tests) for the unsafe version has been documented. Release note: None 154917: invertedidx: harden geo code to avoid panicking r=yuzefovich a=yuzefovich Previously, we could panic when trying to construnct an inverted expression for a geo type. Such panics are not recovered from by the vectorized panic-catcher (since we haven't allow-listed the package), so it's better to propagate errors explicitly. In particular, this allows us to prevent a crash when trying to evaluate `st_dwithin`-like functions with infinite distance (this hits an error in geos, so now we'll return an error, matching postgres). Fixes: #151995. Release note: None 154963: sql/parser: fix bug parsing WITH READ VIRTUAL CLUSTER with other opts r=dt a=dt Release note (bug fix): Fix a bug that would cause WITH READ VIRTUAL CLUSTER to be ignored if any other options were passed when running CREATE VIRTUAL CLUSTER FROM REPLICATION. Epic: none. 154965: roachtest: fix test failure in DSC compat test r=rafiss a=rafiss The test was failing since it was renaming a table that is used by a view. fixes #154809 Release note: None Co-authored-by: Matt Spilchen <[email protected]> Co-authored-by: Yahor Yuzefovich <[email protected]> Co-authored-by: David Taylor <[email protected]> Co-authored-by: Rafi Shamim <[email protected]>
6 parents 481e179 + 926540b + 66eeb16 + 72ab42b + 41812a9 + 7962f01 commit 1b0d0ec

File tree

70 files changed

+448
-226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+448
-226
lines changed

pkg/backup/generative_split_and_scatter_processor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ func routingDatumsForSQLInstance(
253253
sqlInstanceID base.SQLInstanceID,
254254
) (rowenc.EncDatum, rowenc.EncDatum) {
255255
routingBytes := roachpb.Key(fmt.Sprintf("node%d", sqlInstanceID))
256-
startDatum := rowenc.DatumToEncDatum(types.Bytes, tree.NewDBytes(tree.DBytes(routingBytes)))
257-
endDatum := rowenc.DatumToEncDatum(types.Bytes, tree.NewDBytes(tree.DBytes(routingBytes.Next())))
256+
startDatum := rowenc.DatumToEncDatumUnsafe(types.Bytes, tree.NewDBytes(tree.DBytes(routingBytes)))
257+
endDatum := rowenc.DatumToEncDatumUnsafe(types.Bytes, tree.NewDBytes(tree.DBytes(routingBytes.Next())))
258258
return startDatum, endDatum
259259
}
260260

@@ -399,7 +399,7 @@ func (gssp *generativeSplitAndScatterProcessor) Next() (
399399

400400
row := rowenc.EncDatumRow{
401401
routingDatum,
402-
rowenc.DatumToEncDatum(types.Bytes, tree.NewDBytes(tree.DBytes(entryBytes))),
402+
rowenc.DatumToEncDatumUnsafe(types.Bytes, tree.NewDBytes(tree.DBytes(entryBytes))),
403403
}
404404
return row, nil
405405
}

pkg/ccl/changefeedccl/avro/avro.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,10 @@ func (r *DataRecord) rowFromNative(native interface{}) (rowenc.EncDatumRow, erro
995995
if err != nil {
996996
return nil, err
997997
}
998-
row[r.colIdxByFieldIdx[fieldIdx]] = rowenc.DatumToEncDatum(field.typ, decoded)
998+
row[r.colIdxByFieldIdx[fieldIdx]], err = rowenc.DatumToEncDatum(field.typ, decoded)
999+
if err != nil {
1000+
return nil, err
1001+
}
9991002
}
10001003
return row, nil
10011004
}

pkg/ccl/changefeedccl/avro/avro_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func parseValues(tableDesc catalog.TableDescriptor, values string) ([]rowenc.Enc
119119
if err != nil {
120120
return nil, errors.Wrapf(err, "evaluating %s", typedExpr)
121121
}
122-
row = append(row, rowenc.DatumToEncDatum(col.GetType(), datum))
122+
row = append(row, rowenc.DatumToEncDatumUnsafe(col.GetType(), datum))
123123
}
124124
rows = append(rows, row)
125125
}
@@ -951,8 +951,8 @@ func randEncDatumRow(typ *types.T) rowenc.EncDatumRow {
951951
const notNull = false
952952
rnd, _ := randutil.NewTestRand()
953953
return rowenc.EncDatumRow{
954-
rowenc.DatumToEncDatum(typ, randgen.RandDatum(rnd, typ, allowNull)),
955-
rowenc.DatumToEncDatum(types.Int, randgen.RandDatum(rnd, types.Int, notNull)),
954+
rowenc.DatumToEncDatumUnsafe(typ, randgen.RandDatum(rnd, typ, allowNull)),
955+
rowenc.DatumToEncDatumUnsafe(types.Int, randgen.RandDatum(rnd, types.Int, notNull)),
956956
}
957957
}
958958

@@ -1059,7 +1059,7 @@ func BenchmarkEncodeDecimal(b *testing.B) {
10591059
d := &tree.DDecimal{}
10601060
coeff := int64(rand.Uint64()) % 10000
10611061
d.Decimal.SetFinite(coeff, 2)
1062-
encRow[0] = rowenc.DatumToEncDatum(typ, d)
1062+
encRow[0] = rowenc.DatumToEncDatumUnsafe(typ, d)
10631063
benchmarkEncodeType(b, typ, encRow)
10641064
}
10651065

pkg/ccl/changefeedccl/cdcevent/event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ func TestingMakeEventRowFromDatums(datums tree.Datums) Row {
810810
for i, d := range datums {
811811
desc.cols = append(desc.cols, ResultColumn{ord: i})
812812
desc.valueCols = append(desc.valueCols, i)
813-
encRow = append(encRow, rowenc.DatumToEncDatum(d.ResolvedType(), d))
813+
encRow = append(encRow, rowenc.DatumToEncDatumUnsafe(d.ResolvedType(), d))
814814
}
815815
return Row{
816816
EventDescriptor: &desc,

pkg/ccl/changefeedccl/encoder_protobuf_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ func Test_ProtoEncoderAllTypes(t *testing.T) {
158158

159159
targets := mkTargets(tableDesc)
160160
row := cdcevent.TestingMakeEventRow(tableDesc, 0, rowenc.EncDatumRow{
161-
rowenc.DatumToEncDatum(types.Int, tree.NewDInt(1)),
162-
rowenc.DatumToEncDatum(tc.typ, tc.datum),
161+
rowenc.DatumToEncDatumUnsafe(types.Int, tree.NewDInt(1)),
162+
rowenc.DatumToEncDatumUnsafe(tc.typ, tc.datum),
163163
}, false)
164164

165165
opts := changefeedbase.EncodingOptions{Envelope: changefeedbase.OptEnvelopeBare}
@@ -442,7 +442,7 @@ func Test_ProtoEncoder_Escaping(t *testing.T) {
442442

443443
targets := mkTargets(tableDesc)
444444
row := cdcevent.TestingMakeEventRow(tableDesc, 0, rowenc.EncDatumRow{
445-
rowenc.DatumToEncDatum(types.Int, tree.NewDInt(123)),
445+
rowenc.DatumToEncDatumUnsafe(types.Int, tree.NewDInt(123)),
446446
}, false)
447447

448448
opts := changefeedbase.EncodingOptions{Envelope: changefeedbase.OptEnvelopeBare}
@@ -470,8 +470,8 @@ func TestProtoEncoder_BareEnvelope_WithMetadata(t *testing.T) {
470470
require.NoError(t, err)
471471

472472
encRow := rowenc.EncDatumRow{
473-
rowenc.DatumToEncDatum(types.Int, tree.NewDInt(1)),
474-
rowenc.DatumToEncDatum(types.String, tree.NewDString("Alice")),
473+
rowenc.DatumToEncDatumUnsafe(types.Int, tree.NewDInt(1)),
474+
rowenc.DatumToEncDatumUnsafe(types.String, tree.NewDString("Alice")),
475475
}
476476
row := cdcevent.TestingMakeEventRow(tableDesc, 0, encRow, false)
477477

pkg/ccl/changefeedccl/kcjsonschema/kafka_connect_json_schema_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func parseValues(tableDesc catalog.TableDescriptor, values string) ([]rowenc.Enc
239239
if err != nil {
240240
return nil, errors.Wrapf(err, "evaluating %s", typedExpr)
241241
}
242-
row = append(row, rowenc.DatumToEncDatum(col.GetType(), datum))
242+
row = append(row, rowenc.DatumToEncDatumUnsafe(col.GetType(), datum))
243243
}
244244
rows = append(rows, row)
245245
}

pkg/cmd/roachtest/tests/mixed_version_job_compatibility_in_declarative_schema_changer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ func executeSupportedDDLs(
116116
// DDLs supported in V25_4.
117117
v254DDLs := []string{
118118
`TRUNCATE testdb.testsc.t3`,
119-
`ALTER TABLE testdb.testsc.t RENAME TO t_renamed`,
120-
`ALTER TABLE testdb.testsc.t_renamed RENAME TO t`,
119+
`ALTER TABLE testdb.testsc.t2 RENAME TO t2_renamed`,
120+
`ALTER TABLE testdb.testsc.t2_renamed RENAME TO t2`,
121121
`ALTER TABLE testdb.testsc.t2 ALTER COLUMN j SET ON UPDATE j + 1`,
122122
`ALTER TABLE testdb.testsc.t2 RENAME COLUMN k TO k_renamed`,
123123
`ALTER TABLE testdb.testsc.t2 RENAME COLUMN k_renamed TO k`,

pkg/crosscluster/logical/logical_replication_writer_processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ func (lrw *logicalReplicationWriterProcessor) Next() (
376376
return nil, lrw.DrainHelper()
377377
}
378378
row := rowenc.EncDatumRow{
379-
rowenc.DatumToEncDatum(types.Bytes, tree.NewDBytes(tree.DBytes(progressBytes))),
379+
rowenc.DatumToEncDatumUnsafe(types.Bytes, tree.NewDBytes(tree.DBytes(progressBytes))),
380380
}
381381
return row, nil
382382
} else {

pkg/crosscluster/logical/offline_initial_scan_processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func (o *offlineInitialScanProcessor) Next() (rowenc.EncDatumRow, *execinfrapb.P
269269
return nil, o.DrainHelper()
270270
}
271271
row := rowenc.EncDatumRow{
272-
rowenc.DatumToEncDatum(types.Bytes, tree.NewDBytes(tree.DBytes(progressBytes))),
272+
rowenc.DatumToEncDatumUnsafe(types.Bytes, tree.NewDBytes(tree.DBytes(progressBytes))),
273273
}
274274
return row, nil
275275
}

pkg/crosscluster/physical/stream_ingestion_processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ func (sip *streamIngestionProcessor) Next() (rowenc.EncDatumRow, *execinfrapb.Pr
532532
return nil, sip.DrainHelper()
533533
}
534534
row := rowenc.EncDatumRow{
535-
rowenc.DatumToEncDatum(types.Bytes, tree.NewDBytes(tree.DBytes(progressBytes))),
535+
rowenc.DatumToEncDatumUnsafe(types.Bytes, tree.NewDBytes(tree.DBytes(progressBytes))),
536536
}
537537
return row, nil
538538
}

0 commit comments

Comments
 (0)