@@ -375,29 +375,36 @@ func RunNemesis(
375
375
// Initialize table rows by repeatedly running the `openTxn` transition,
376
376
// then randomly either committing or rolling back transactions. This will
377
377
// leave some committed rows.
378
- for i := 0 ; i < ns .rowCount * 5 ; i ++ {
379
- payload , err := newOpenTxnPayload (ns )
380
- if err != nil {
381
- return nil , err
382
- }
383
- if err := openTxn (fsm.Args {Ctx : ctx , Extended : ns , Payload : payload }); err != nil {
384
- return nil , err
385
- }
386
- // Randomly commit or rollback, but commit at least one row to the table.
387
- if rand .Intn (3 ) < 2 || i == 0 {
388
- if err := commit (fsm.Args {Ctx : ctx , Extended : ns }); err != nil {
378
+ // If sql smith is enabled, we'll insert rows below instead.
379
+ if ! nOp .EnableSQLSmith {
380
+ for i := 0 ; i < ns .rowCount * 5 ; i ++ {
381
+ payload , err := newOpenTxnPayload (ns )
382
+ if err != nil {
389
383
return nil , err
390
384
}
391
- } else {
392
- if err := rollback (fsm.Args {Ctx : ctx , Extended : ns }); err != nil {
385
+ if err := openTxn (fsm.Args {Ctx : ctx , Extended : ns , Payload : payload }); err != nil {
393
386
return nil , err
394
387
}
388
+ // Randomly commit or rollback, but commit at least one row to the table.
389
+ if rand .Intn (3 ) < 2 || i == 0 {
390
+ if err := commit (fsm.Args {Ctx : ctx , Extended : ns }); err != nil {
391
+ return nil , err
392
+ }
393
+ } else {
394
+ if err := rollback (fsm.Args {Ctx : ctx , Extended : ns }); err != nil {
395
+ return nil , err
396
+ }
397
+ }
395
398
}
396
399
}
397
400
398
401
if nOp .EnableSQLSmith {
402
+ // Some unsafe queries can hang, so avoid them.
403
+ if _ , err := db .Exec ("SET sql_safe_updates=true" ); err != nil {
404
+ return nil , err
405
+ }
399
406
queryGen , _ := sqlsmith .NewSmither (db , rng ,
400
- sqlsmith .MutationsOnly (),
407
+ sqlsmith .InsUpdDelOnly (),
401
408
sqlsmith .SetScalarComplexity (0.5 ),
402
409
sqlsmith .SetComplexity (0.1 ),
403
410
// TODO(#129072): Reenable cross joins when the likelihood of generating
@@ -408,6 +415,7 @@ func RunNemesis(
408
415
// supported under the serializable isolation.
409
416
sqlsmith .DisableIsolationChange (),
410
417
)
418
+
411
419
defer queryGen .Close ()
412
420
const numInserts = 100
413
421
time := timeutil .Now ()
@@ -422,6 +430,28 @@ func RunNemesis(
422
430
continue
423
431
}
424
432
}
433
+ // Reenable unsafe queries, since the test sometimes alters tables.
434
+ if _ , err := db .Exec ("SET sql_safe_updates=false" ); err != nil {
435
+ return nil , err
436
+ }
437
+ }
438
+
439
+ // Print the contents of the table in a way that can be reproduced.
440
+ rows , err := db .Query ("SELECT * FROM foo" )
441
+ if err != nil {
442
+ return nil , err
443
+ }
444
+ defer rows .Close ()
445
+
446
+ // Iterate over the rows and print them
447
+ for rows .Next () {
448
+ var id int
449
+ var ts string
450
+ if err := rows .Scan (& id , & ts ); err != nil {
451
+ log .Infof (ctx , "# skipping row because error: %s" , err )
452
+ continue
453
+ }
454
+ log .Infof (ctx , "INSERT INTO foo (id,ts) VALUES (%d, %s);" , id , ts )
425
455
}
426
456
427
457
cfo := newChangefeedOption (testName )
0 commit comments