Skip to content

Commit

Permalink
fix ddl sync for table drop and truncate (#109)
Browse files Browse the repository at this point in the history
* when we drop a table when flash server is closed, we should sync this
drop when restart flash server.
  • Loading branch information
hanfei1991 authored and zanmato1984 committed Jul 18, 2019
1 parent 9314f91 commit 149a114
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dbms/src/Storages/Transaction/SchemaBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,22 @@ void SchemaBuilder::updateDB(TiDB::DBInfoPtr db_info)
}
auto tables = getter.listTables(db_info->id);
auto & tmt_context = context.getTMTContext();

std::set<TableID> table_ids;

for (auto table : tables)
table_ids.insert(table->id);

auto storage_map = tmt_context.getStorages().getAllStorage();
for (auto it = storage_map.begin(); it != storage_map.end(); it++) {
auto storage = it->second;
if(storage->getDatabaseName() == db_info->name && table_ids.count(storage->getTableInfo().id) == 0) {
// Drop Table
applyDropTableImpl(db_info->name, storage->getTableName());
LOG_DEBUG(log, "Table " + db_info->name + "." + storage->getTableName() + " is dropped during schema all schemas");
}
}

for (auto table : tables)
{
auto storage = static_cast<StorageMergeTree *>(tmt_context.getStorages().get(table->id).get());
Expand All @@ -373,6 +389,7 @@ void SchemaBuilder::updateDB(TiDB::DBInfoPtr db_info)
applyAlterTableImpl(table, db_info->name, storage);
}
}

}

// end namespace
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Storages/Transaction/TiDBSchemaSyncer.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct TiDBSchemaSyncer : public SchemaSyncer
builder.updateDB(db);
db_ids.insert(db->id);
}
// Drop databases;
for (auto it = databases.begin(); it != databases.end(); it++)
{
if (db_ids.count(it->first) == 0)
Expand Down

0 comments on commit 149a114

Please sign in to comment.