MCPcopy
hub / github.com/pingcap/tidb / TestRefreshMetaBasic

Function TestRefreshMetaBasic

pkg/ddl/table_test.go:822–947  ·  view source on GitHub ↗

TestRefreshMetaBasic tests few scenarios of meta kv inconsistent with infoschema.

(t *testing.T)

Source from the content-addressed store, hash-verified

820
821// TestRefreshMetaBasic tests few scenarios of meta kv inconsistent with infoschema.
822func TestRefreshMetaBasic(t *testing.T) {
823 store, domain := testkit.CreateMockStoreAndDomain(t)
824 de := domain.DDLExecutor()
825 tk := testkit.NewTestKit(t, store)
826 sctx := testkit.NewTestKit(t, store).Session()
827
828 // get t1 table info
829 tk.MustExec("create placement policy p1 followers=1")
830 tk.MustExec("create placement policy p2 followers=2")
831 tk.MustExec("create database test1 placement policy p1")
832 tk.MustExec("use test1")
833 tk.MustExec("create table t1(id int)")
834 dbInfo, ok := domain.InfoSchema().SchemaByName(pmodel.NewCIStr("test1"))
835 require.True(t, ok)
836 clonedTableInfo := getClonedTableInfoFromDomain(t, "test1", "t1", domain)
837 // update t1 table name to t2 by txn
838 clonedTableInfo.Name = pmodel.NewCIStr("t2")
839 updateTableMeta(t, store, dbInfo.ID, clonedTableInfo)
840 t2TableInfo := testutil.GetTableInfoByTxn(t, store, dbInfo.ID, clonedTableInfo.ID)
841 require.Equal(t, clonedTableInfo, t2TableInfo)
842 // validate infoschema doesn't conatain t2 table info
843 _, err := domain.InfoSchema().TableByName(context.Background(), pmodel.NewCIStr("test1"), pmodel.NewCIStr("t2"))
844 require.ErrorContains(t, err, "Table 'test1.t2' doesn't exist")
845 // refresh meta, validate infoschema store table t2 and schema version increase 1
846 oldSchemaVer := getSchemaVer(t, sctx)
847 testutil.RefreshMeta(sctx, t, de, dbInfo.ID, clonedTableInfo.ID, dbInfo.Name.O, clonedTableInfo.Name.O)
848 newSchemaVer := getSchemaVer(t, sctx)
849 require.Equal(t, oldSchemaVer+1, newSchemaVer)
850 _, err = domain.InfoSchema().TableByName(context.Background(), pmodel.NewCIStr("test1"), pmodel.NewCIStr("t2"))
851 require.NoError(t, err)
852
853 // table not exists in kv, exists in infoschema
854 tk.MustExec("create table t3(id int) placement policy p2")
855 txn, err := store.Begin()
856 require.NoError(t, err)
857 clonedTableInfo = getClonedTableInfoFromDomain(t, "test1", "t3", domain)
858 // drop table t3 by txn
859 err = meta.NewMutator(txn).DropTableOrView(dbInfo.ID, clonedTableInfo.ID)
860 require.NoError(t, err)
861 txn.Commit(context.Background())
862 txn, err = store.Begin()
863 require.NoError(t, err)
864 kvTableInfo, err := meta.NewMutator(txn).GetTable(dbInfo.ID, clonedTableInfo.ID)
865 require.NoError(t, err)
866 require.Nil(t, kvTableInfo)
867 // t3 table info exists in infoschema
868 _, ok = domain.InfoSchema().TableByID(context.Background(), clonedTableInfo.ID)
869 require.True(t, ok)
870 // after refresh meta, t3 table info should be not exists in infoschema
871 testutil.RefreshMeta(sctx, t, de, dbInfo.ID, clonedTableInfo.ID, dbInfo.Name.O, clonedTableInfo.Name.O)
872 _, ok = domain.InfoSchema().TableByID(context.Background(), clonedTableInfo.ID)
873 require.False(t, ok)
874 _, ok = domain.InfoSchema().PlacementBundleByPhysicalTableID(clonedTableInfo.ID)
875 require.False(t, ok)
876
877 // table exists in kv, not exists in infoschema
878 clonedTableInfo.Name = pmodel.NewCIStr("t4")
879 clonedTableInfo.ID = 40000

Callers

nothing calls this directly

Calls 15

MustExecMethod · 0.95
CreateMockStoreAndDomainFunction · 0.92
NewTestKitFunction · 0.92
GetTableInfoByTxnFunction · 0.92
RefreshMetaFunction · 0.92
NewMutatorFunction · 0.92
getSchemaVerFunction · 0.85
getClonedDatabaseFunction · 0.85
DDLExecutorMethod · 0.80
InfoSchemaMethod · 0.80
DropTableOrViewMethod · 0.80

Tested by

no test coverage detected