Skip to content

Commit 407a4de

Browse files
committed
workloadcccl: fix two regressions in fixtures make/load
The SQL database for all the tables in the BACKUPs created by `fixtures make` used to be "csv" (an artifact of the way we made them), but as of #37343 it's the name of the generator. This seems better so change `fixtures load` to match. The same PR also (accidentally) started adding foreign keys in the BACKUPs, but since there's one table per BACKUP (another artifact of the way we used to make fixtures), we can't restore the foreign keys. It'd be nice to switch to one BACKUP with all tables and get the foreign keys, but the UX of the postLoad hook becomes tricky and I don't have time right now to sort it all out. So, revert to the previous behavior (no fks in fixtures) for now. Release note: None
1 parent d871bda commit 407a4de

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

pkg/ccl/workloadccl/allccl/all_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
directIngestion = true
2727
oneFilePerNode = 1
2828
noInjectStats = false
29+
noSkipPostLoad = false
2930
skipCSVRoundtrip = ``
3031
)
3132

@@ -84,7 +85,8 @@ func TestAllRegisteredImportFixture(t *testing.T) {
8485
sqlutils.MakeSQLRunner(db).Exec(t, `CREATE DATABASE d`)
8586

8687
if _, err := workloadccl.ImportFixture(
87-
ctx, db, gen, `d`, directIngestion, oneFilePerNode, noInjectStats, skipCSVRoundtrip,
88+
ctx, db, gen, `d`, directIngestion, oneFilePerNode, noInjectStats, noSkipPostLoad,
89+
skipCSVRoundtrip,
8890
); err != nil {
8991
t.Fatal(err)
9092
}

pkg/ccl/workloadccl/bench_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ func benchmarkImportFixture(b *testing.B, gen workload.Generator) {
3333

3434
b.StartTimer()
3535
const filesPerNode = 1
36+
const directIngest, noInjectStats, skipPostLoad, csvServer = true, false, true, ``
3637
importBytes, err := ImportFixture(
37-
ctx, db, gen, `d`, true /* directIngestion */, filesPerNode, false, /* injectStats */
38-
``, /* csvServer */
38+
ctx, db, gen, `d`, directIngest, filesPerNode, noInjectStats, skipPostLoad, csvServer,
3939
)
4040
require.NoError(b, err)
4141
bytes += importBytes

pkg/ccl/workloadccl/cliccl/fixtures.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,10 @@ func fixturesImport(gen workload.Generator, urls []string, dbName string) error
333333
directIngestion := *fixturesImportDirectIngestionTable
334334
filesPerNode := *fixturesImportFilesPerNode
335335
injectStats := *fixturesImportInjectStats
336+
noSkipPostLoad := false
336337
csvServer := *fixturesMakeImportCSVServerURL
337338
bytes, err := workloadccl.ImportFixture(
338-
ctx, sqlDB, gen, dbName, directIngestion, filesPerNode, injectStats, csvServer,
339+
ctx, sqlDB, gen, dbName, directIngestion, filesPerNode, injectStats, noSkipPostLoad, csvServer,
339340
)
340341
if err != nil {
341342
return errors.Wrap(err, `importing fixture`)

pkg/ccl/workloadccl/fixture.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,10 @@ func MakeFixture(
258258
if _, err := sqlDB.Exec(`CREATE DATABASE IF NOT EXISTS ` + dbName); err != nil {
259259
return Fixture{}, err
260260
}
261-
const direct, stats, csvServer = false, false, ""
262-
if _, err := ImportFixture(ctx, sqlDB, gen, dbName, direct, filesPerNode, stats, csvServer); err != nil {
261+
const direct, stats, skipPostLoad, csvServer = false, false, true, ""
262+
if _, err := ImportFixture(
263+
ctx, sqlDB, gen, dbName, direct, filesPerNode, stats, skipPostLoad, csvServer,
264+
); err != nil {
263265
return Fixture{}, err
264266
}
265267
g := ctxgroup.WithContext(ctx)
@@ -293,6 +295,7 @@ func ImportFixture(
293295
directIngestion bool,
294296
filesPerNode int,
295297
injectStats bool,
298+
skipPostLoad bool,
296299
csvServer string,
297300
) (int64, error) {
298301
for _, t := range gen.Tables() {
@@ -339,8 +342,10 @@ func ImportFixture(
339342
if err := g.Wait(); err != nil {
340343
return 0, err
341344
}
342-
if err := runPostLoadSteps(ctx, sqlDB, gen); err != nil {
343-
return 0, err
345+
if !skipPostLoad {
346+
if err := runPostLoadSteps(ctx, sqlDB, gen); err != nil {
347+
return 0, err
348+
}
344349
}
345350
return atomic.LoadInt64(&bytesAtomic), nil
346351
}
@@ -449,13 +454,12 @@ func RestoreFixture(
449454
) (int64, error) {
450455
var bytesAtomic int64
451456
g := ctxgroup.WithContext(ctx)
457+
genName := fixture.Generator.Meta().Name
452458
for _, table := range fixture.Tables {
453459
table := table
454460
g.GoCtx(func(ctx context.Context) error {
455-
// The IMPORT ... CSV DATA command generates a backup with the table in
456-
// database `csv`.
457461
start := timeutil.Now()
458-
importStmt := fmt.Sprintf(`RESTORE csv.%s FROM $1 WITH into_db=$2`, table.TableName)
462+
importStmt := fmt.Sprintf(`RESTORE %s.%s FROM $1 WITH into_db=$2`, genName, table.TableName)
459463
var rows, index, tableBytes int64
460464
var discard interface{}
461465
if err := sqlDB.QueryRow(importStmt, table.BackupURI, database).Scan(

pkg/ccl/workloadccl/fixture_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,11 @@ func TestImportFixture(t *testing.T) {
183183
}
184184

185185
const filesPerNode = 1
186+
const noSkipPostLoad = false
186187
sqlDB.Exec(t, `CREATE DATABASE distsort`)
187188
_, err := ImportFixture(
188189
ctx, db, gen, `distsort`, false /* directIngestion */, filesPerNode, true, /* injectStats */
189-
``, /* csvServer */
190+
noSkipPostLoad, ``, /* csvServer */
190191
)
191192
require.NoError(t, err)
192193
sqlDB.CheckQueryResults(t,
@@ -203,7 +204,7 @@ func TestImportFixture(t *testing.T) {
203204
sqlDB.Exec(t, `CREATE DATABASE direct`)
204205
_, err = ImportFixture(
205206
ctx, db, gen, `direct`, true /* directIngestion */, filesPerNode, false, /* injectStats */
206-
``, /* csvServer */
207+
noSkipPostLoad, ``, /* csvServer */
207208
)
208209
require.NoError(t, err)
209210
sqlDB.CheckQueryResults(t,
@@ -240,9 +241,10 @@ func TestImportFixtureCSVServer(t *testing.T) {
240241
}
241242

242243
const filesPerNode = 1
244+
const noDirectIngest, noInjectStats, noSkipPostLoad = false, false, true
243245
sqlDB.Exec(t, `CREATE DATABASE d`)
244246
_, err := ImportFixture(
245-
ctx, db, gen, `d`, false /* directIngestion */, filesPerNode, false /* injectStats */, ts.URL,
247+
ctx, db, gen, `d`, noDirectIngest, filesPerNode, noInjectStats, noSkipPostLoad, ts.URL,
246248
)
247249
require.NoError(t, err)
248250
sqlDB.CheckQueryResults(t,

0 commit comments

Comments
 (0)