(t *testing.T)
| 565 | } |
| 566 | |
| 567 | func TestCreateTableConsistent(t *testing.T) { |
| 568 | ctx := context.Background() |
| 569 | allocator := testAllocator(0) |
| 570 | s := utiltest.CreateRestoreSchemaSuite(t) |
| 571 | tk := testkit.NewTestKit(t, s.Mock.Storage) |
| 572 | tk.MustExec("use test") |
| 573 | tk.MustExec("set @@sql_mode=''") |
| 574 | |
| 575 | db, supportPolicy, err := preallocdb.NewDB(gluetidb.New(), s.Mock.Storage, "STRICT") |
| 576 | require.NoError(t, err) |
| 577 | require.True(t, supportPolicy) |
| 578 | defer db.Close() |
| 579 | |
| 580 | getTableInfo := func(name string) (*model.DBInfo, *model.TableInfo) { |
| 581 | info, err := s.Mock.Domain.GetSnapshotInfoSchema(math.MaxUint64) |
| 582 | require.NoError(t, err) |
| 583 | dbInfo, exists := info.SchemaByName(pmodel.NewCIStr("test")) |
| 584 | require.True(t, exists) |
| 585 | tableInfo, err := info.TableByName(context.Background(), pmodel.NewCIStr("test"), pmodel.NewCIStr(name)) |
| 586 | require.NoError(t, err) |
| 587 | return dbInfo, tableInfo.Meta() |
| 588 | } |
| 589 | tk.MustExec("create sequence test.s increment by 1 minvalue = 10;") |
| 590 | dbInfo, seqInfo := getTableInfo("s") |
| 591 | tk.MustExec("drop sequence test.s;") |
| 592 | |
| 593 | preallocId := func(tables []*metautil.Table) { |
| 594 | ids, allocErr := prealloctableid.New(tables) |
| 595 | require.NoError(t, allocErr) |
| 596 | ids.PreallocIDs(&allocator) |
| 597 | db.RegisterPreallocatedIDs(ids) |
| 598 | allocator += testAllocator(len(tables)) |
| 599 | } |
| 600 | |
| 601 | newSeqInfo := seqInfo.Clone() |
| 602 | newSeqInfo.ID += 100 |
| 603 | newTables := []*metautil.Table{ |
| 604 | { |
| 605 | DB: dbInfo.Clone(), |
| 606 | Info: newSeqInfo, |
| 607 | }, |
| 608 | } |
| 609 | |
| 610 | preallocId(newTables) |
| 611 | err = db.CreateTables(ctx, newTables, nil, false, nil) |
| 612 | require.NoError(t, err) |
| 613 | r11 := tk.MustQuery("select nextval(s)").Rows() |
| 614 | r12 := tk.MustQuery("show create table test.s").Rows() |
| 615 | |
| 616 | tk.MustExec("drop sequence test.s;") |
| 617 | |
| 618 | newSeqInfo = seqInfo.Clone() |
| 619 | newSeqInfo.ID += 100 |
| 620 | newTable := &metautil.Table{DB: dbInfo.Clone(), Info: newSeqInfo} |
| 621 | preallocId([]*metautil.Table{newTable}) |
| 622 | err = db.CreateTable(ctx, newTable, nil, false, nil) |
| 623 | require.NoError(t, err) |
| 624 | r21 := tk.MustQuery("select nextval(s)").Rows() |
nothing calls this directly
no test coverage detected