Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test rename table #124

Merged
merged 34 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
26b6dd7
Add sync schema on read
zanmato1984 Jul 16, 2019
d1ac4f4
Simplify schema syncer interface and adjust mock stuff
zanmato1984 Jul 16, 2019
d3e2298
Rename default schema version setting
zanmato1984 Jul 18, 2019
e690046
Compensate last commit
zanmato1984 Jul 18, 2019
2c57e8c
Merge dll branch
zanmato1984 Jul 18, 2019
49b3fdf
Remove curl library
zanmato1984 Jul 18, 2019
b5c2a85
Remove curl from builder image
zanmato1984 Jul 18, 2019
e515c30
Remove useless codes, init schema syncer based on pd config
zanmato1984 Jul 18, 2019
e084771
Minor fix to schema debug
zanmato1984 Jul 18, 2019
e89c697
Fix alter tmt and pass tests
zanmato1984 Jul 18, 2019
293c880
Merge ddl
zanmato1984 Jul 18, 2019
aa8072a
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 18, 2019
14bc79b
Merge ddl
zanmato1984 Jul 18, 2019
074f521
Fix build fail
zanmato1984 Jul 18, 2019
a1e9b57
Merge remote
zanmato1984 Jul 18, 2019
3140836
Add lock for mock schema syncer
zanmato1984 Jul 19, 2019
23ff96c
Fix schema sync service init context
zanmato1984 Jul 19, 2019
fb638a7
Adjust schema tests
zanmato1984 Jul 19, 2019
fc10c2e
Not sync if no schema change detected
zanmato1984 Jul 19, 2019
d3b0af9
Adjust txn mock tests
zanmato1984 Jul 19, 2019
9590357
Merge ddl
zanmato1984 Jul 19, 2019
f6c7275
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 19, 2019
517793b
Fix default value bug
zanmato1984 Jul 19, 2019
0e510f3
Rename some tests
zanmato1984 Jul 19, 2019
32e9f3d
Remove sync schema test
zanmato1984 Jul 19, 2019
bbe3743
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 19, 2019
c6d4f86
Remove a lot useless code
zanmato1984 Jul 19, 2019
9851e66
Refine schema sync on read, and add drop on read test
zanmato1984 Jul 20, 2019
b001bcc
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 20, 2019
d29f518
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 22, 2019
72aa0f2
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 22, 2019
11f261d
Support rename mock tidb table
zanmato1984 Jul 22, 2019
a689b8a
Add rename tests
zanmato1984 Jul 22, 2019
00bd504
Add mock truncate table and tests
zanmato1984 Jul 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dbms/src/Debug/DBGInvoker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ DBGInvoker::DBGInvoker()
regFunc("add_column_to_tidb_table", MockTiDBTable::dbgFuncAddColumnToTiDBTable);
regFunc("drop_column_from_tidb_table", MockTiDBTable::dbgFuncDropColumnFromTiDBTable);
regFunc("modify_column_in_tidb_table", MockTiDBTable::dbgFuncModifyColumnInTiDBTable);
regFunc("rename_tidb_table", MockTiDBTable::dbgFuncRenameTiDBTable);
regFunc("truncate_tidb_table", MockTiDBTable::dbgFuncTruncateTiDBTable);

regFunc("set_flush_threshold", dbgFuncSetFlushThreshold);

Expand Down
30 changes: 30 additions & 0 deletions dbms/src/Debug/MockTiDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,36 @@ void MockTiDB::modifyColumnInTable(const String & database_name, const String &
it->tp = column_info.tp;
}

void MockTiDB::renameTable(const String & database_name, const String & table_name, const String & new_table_name)
{
std::lock_guard lock(tables_mutex);

TablePtr table = getTableByNameInternal(database_name, table_name);
String qualified_name = database_name + "." + table_name;
String new_qualified_name = database_name + "." + new_table_name;

TableInfo new_table_info = table->table_info;
new_table_info.name = new_table_name;
auto new_table = std::make_shared<Table>(database_name, new_table_name, std::move(new_table_info));

tables_by_id[new_table->table_info.id] = new_table;
tables_by_name.erase(qualified_name);
tables_by_name.emplace(new_qualified_name, new_table);
}

void MockTiDB::truncateTable(const String & database_name, const String & table_name)
{
std::lock_guard lock(tables_mutex);

TablePtr table = getTableByNameInternal(database_name, table_name);

TableID old_table_id = table->table_info.id;
table->table_info.id += 1000; // Just big enough is OK.

tables_by_id.erase(old_table_id);
tables_by_id.emplace(table->id(), table);
}

TablePtr MockTiDB::getTableByName(const String & database_name, const String & table_name)
{
std::lock_guard lock(tables_mutex);
Expand Down
4 changes: 4 additions & 0 deletions dbms/src/Debug/MockTiDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class MockTiDB : public ext::singleton<MockTiDB>

void modifyColumnInTable(const String & database_name, const String & table_name, const NameAndTypePair & column);

void renameTable(const String & database_name, const String & table_name, const String & new_table_name);

void truncateTable(const String & database_name, const String & table_name);

TablePtr getTableByName(const String & database_name, const String & table_name);

void traverseTables(std::function<void(TablePtr)> f);
Expand Down
31 changes: 31 additions & 0 deletions dbms/src/Debug/dbgFuncMockTiDBTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,35 @@ void MockTiDBTable::dbgFuncModifyColumnInTiDBTable(DB::Context & context, const
output(ss.str());
}

void MockTiDBTable::dbgFuncRenameTiDBTable(Context & /*context*/, const ASTs & args, DBGInvoker::Printer output)
{
if (args.size() != 3)
throw Exception("Args not matched, should be: database-name, table-name, new-table-name", ErrorCodes::BAD_ARGUMENTS);

const String & database_name = typeid_cast<const ASTIdentifier &>(*args[0]).name;
const String & table_name = typeid_cast<const ASTIdentifier &>(*args[1]).name;
const String & new_table_name = typeid_cast<const ASTIdentifier &>(*args[2]).name;

MockTiDB::instance().renameTable(database_name, table_name, new_table_name);

std::stringstream ss;
ss << "renamed table " << database_name << "." << table_name << " to " << database_name << "." << new_table_name;
output(ss.str());
}

void MockTiDBTable::dbgFuncTruncateTiDBTable(Context & /*context*/, const ASTs & args, DBGInvoker::Printer output)
{
if (args.size() != 2)
throw Exception("Args not matched, should be: database-name, table-name", ErrorCodes::BAD_ARGUMENTS);

const String & database_name = typeid_cast<const ASTIdentifier &>(*args[0]).name;
const String & table_name = typeid_cast<const ASTIdentifier &>(*args[1]).name;

MockTiDB::instance().truncateTable(database_name, table_name);

std::stringstream ss;
ss << "truncated table " << database_name << "." << table_name;
output(ss.str());
}

} // namespace DB
10 changes: 10 additions & 0 deletions dbms/src/Debug/dbgFuncMockTiDBTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ struct MockTiDBTable
// Usage:
// ./storages-client.sh "DBGInvoke modify_column_in_tidb_table(database_name, table_name, 'col type')"
static void dbgFuncModifyColumnInTiDBTable(Context & context, const ASTs & args, DBGInvoker::Printer output);

// Rename a TiDB table.
// Usage:
// ./storages-client.sh "DBGInvoke rename_tidb_table(database_name, table_name, new_table)"
static void dbgFuncRenameTiDBTable(Context & context, const ASTs & args, DBGInvoker::Printer output);

// Truncate a TiDB table.
// Usage:
// ./storages-client.sh "DBGInvoke truncate_tidb_table(database_name, table_name)"
static void dbgFuncTruncateTiDBTable(Context & context, const ASTs & args, DBGInvoker::Printer output);
};

} // namespace DB
25 changes: 25 additions & 0 deletions tests/mutable-test/txn_schema/rename_on_read.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
=> DBGInvoke __enable_schema_sync_service('false')

=> DBGInvoke __drop_tidb_table(default, test)
=> drop table if exists default.test

=> DBGInvoke __drop_tidb_table(default, test1)
=> drop table if exists default.test1

=> DBGInvoke __set_flush_threshold(1000000, 1000000)
=> DBGInvoke __mock_schema_syncer('true')

=> DBGInvoke __mock_tidb_table(default, test, 'col_1 String')
=> DBGInvoke __refresh_schemas()
=> select * from default.test
=> DBGInvoke __rename_tidb_table(default, test, test1)
=> select * from default.test
=> select * from default.test " --schema_version "100
Received exception from server (version {#WORD}):
Code: 60. DB::Exception: Received from {#WORD} DB::Exception: Table default.test doesn't exist..
=> select * from default.test1
=> select * from default.test1 " --schema_version "100

=> DBGInvoke __drop_tidb_table(default, test1)
=> drop table if exists default.test1
=> DBGInvoke __enable_schema_sync_service('true')
30 changes: 30 additions & 0 deletions tests/mutable-test/txn_schema/rename_on_write.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
=> DBGInvoke __enable_schema_sync_service('false')

=> DBGInvoke __drop_tidb_table(default, test)
=> drop table if exists default.test

=> DBGInvoke __drop_tidb_table(default, test1)
=> drop table if exists default.test1

=> DBGInvoke __set_flush_threshold(1000000, 1000000)
=> DBGInvoke __mock_schema_syncer('true')

=> DBGInvoke __mock_tidb_table(default, test, 'col_1 String')
=> DBGInvoke __refresh_schemas()
=> DBGInvoke __put_region(4, 0, 100, default, test)
=> select col_1 from default.test
=> DBGInvoke __add_column_to_tidb_table(default, test, 'col_2 Nullable(Int8)')
=> DBGInvoke __raft_insert_row(default, test, 4, 50, 'test1', 1)
=> DBGInvoke __rename_tidb_table(default, test, test1)
=> DBGInvoke __try_flush_region(4)
=> select * from default.test
Received exception from server (version {#WORD}):
Code: 60. DB::Exception: Received from {#WORD} DB::Exception: Table default.test doesn't exist..
=> select * from default.test1
┌─col_1─┬─_tidb_rowid─┬─col_2─┐
│ test1 │ 50 │ 1 │
└───────┴─────────────┴───────┘

=> DBGInvoke __drop_tidb_table(default, test1)
=> drop table if exists default.test1
=> DBGInvoke __enable_schema_sync_service('true')
26 changes: 26 additions & 0 deletions tests/mutable-test/txn_schema/truncate_on_read.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=> DBGInvoke __enable_schema_sync_service('false')

=> DBGInvoke __drop_tidb_table(default, test)
=> drop table if exists default.test

=> DBGInvoke __set_flush_threshold(1000000, 1000000)
=> DBGInvoke __mock_schema_syncer('true')

=> DBGInvoke __mock_tidb_table(default, test, 'col_1 String')
=> DBGInvoke __refresh_schemas()
=> DBGInvoke __put_region(4, 0, 100, default, test)
=> DBGInvoke __raft_insert_row(default, test, 4, 50, 'test1')
=> select * from default.test
┌─col_1─┬─_tidb_rowid─┐
│ test1 │ 50 │
└───────┴─────────────┘
=> DBGInvoke __truncate_tidb_table(default, test)
=> select * from default.test
┌─col_1─┬─_tidb_rowid─┐
│ test1 │ 50 │
└───────┴─────────────┘
=> select * from default.test " --schema_version "100

=> DBGInvoke __drop_tidb_table(default, test)
=> drop table if exists default.test
=> DBGInvoke __enable_schema_sync_service('true')
25 changes: 25 additions & 0 deletions tests/mutable-test/txn_schema/truncate_on_write.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
=> DBGInvoke __enable_schema_sync_service('false')

=> DBGInvoke __drop_tidb_table(default, test)
=> drop table if exists default.test

=> DBGInvoke __set_flush_threshold(1000000, 1000000)
=> DBGInvoke __mock_schema_syncer('true')

=> DBGInvoke __mock_tidb_table(default, test, 'col_1 String')
=> DBGInvoke __refresh_schemas()
=> DBGInvoke __put_region(4, 0, 100, default, test)
=> DBGInvoke __raft_insert_row(default, test, 4, 50, 'test1')
=> select col_1 from default.test
┌─col_1─┐
│ test1 │
└───────┘
=> DBGInvoke __add_column_to_tidb_table(default, test, 'col_2 Nullable(Int8)')
=> DBGInvoke __raft_insert_row(default, test, 4, 51, 'test1', 1)
=> DBGInvoke __truncate_tidb_table(default, test)
=> DBGInvoke __try_flush_region(4)
=> select * from default.test

=> DBGInvoke __drop_tidb_table(default, test)
=> drop table if exists default.test
=> DBGInvoke __enable_schema_sync_service('true')