Skip to content

Commit

Permalink
Refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
zanmato1984 committed Jul 15, 2019
1 parent 45831f6 commit 745850e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions dbms/src/Common/ErrorCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ namespace ErrorCodes
extern const int VERSION_ERROR = 10001;
extern const int REGION_MISS = 10002;
extern const int SCHEMA_SYNC_ERROR = 10003;
extern const int SCHEMA_VERSION_ERROR = 10004;
}

}
2 changes: 1 addition & 1 deletion dbms/src/Debug/MockSchemaSyncer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MockSchemaSyncer : public SchemaSyncer

bool syncSchemas(Context & context) override;

void syncSchema(Context & context, TableID table_id, bool lock = true) override;
void syncSchema(Context & context, TableID table_id, bool) override;

TableID getTableIdByName(const std::string & database_name, const std::string & table_name)
{
Expand Down
10 changes: 5 additions & 5 deletions dbms/src/Debug/dbgFuncSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void dbgFuncRefreshSchema(Context & context, const ASTs & args, DBGInvoker::Prin
// Table t was synced to CH already, then t was renamed (name changed) and truncated (ID changed).
// Then this function was called with the new name given, the table will be synced to a new table.
// User must manually call this function with the old name to remove the dangling table in CH.
mock_schema_syncer->syncSchema(context, table_id);
mock_schema_syncer->syncSchema(context, table_id, true);

log(table_id);

Expand All @@ -87,7 +87,7 @@ void dbgFuncRefreshSchema(Context & context, const ASTs & args, DBGInvoker::Prin
{
// Table exists in CH, but does not exist in TiDB.
// Just sync it using the storage's ID, syncer will then remove it.
mock_schema_syncer->syncSchema(context, storage->getTableInfo().id);
mock_schema_syncer->syncSchema(context, storage->getTableInfo().id, true);

log(table_id);

Expand All @@ -99,8 +99,8 @@ void dbgFuncRefreshSchema(Context & context, const ASTs & args, DBGInvoker::Prin
{
// Table in TiDB is not the old one, i.e. dropped/renamed then recreated.
// Sync the old one in CH first, then sync the new one.
mock_schema_syncer->syncSchema(context, storage->getTableInfo().id);
mock_schema_syncer->syncSchema(context, table_id);
mock_schema_syncer->syncSchema(context, storage->getTableInfo().id, true);
mock_schema_syncer->syncSchema(context, table_id, true);

log(table_id);

Expand All @@ -109,7 +109,7 @@ void dbgFuncRefreshSchema(Context & context, const ASTs & args, DBGInvoker::Prin

// Table in TiDB is the same one as in CH.
// Just sync it.
mock_schema_syncer->syncSchema(context, table_id);
mock_schema_syncer->syncSchema(context, table_id, true);

log(table_id);
}
Expand Down
9 changes: 4 additions & 5 deletions dbms/src/Interpreters/InterpreterSelectQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace ErrorCodes
extern const int TOO_MANY_COLUMNS;
extern const int LOGICAL_ERROR;
extern const int NOT_IMPLEMENTED;
extern const int SCHEMA_VERSION_ERROR;
}

InterpreterSelectQuery::InterpreterSelectQuery(
Expand Down Expand Up @@ -193,21 +194,19 @@ void InterpreterSelectQuery::alignStorageSchema(Int64 schema_version)
if (schema_version == DEFAULT_SCHEMA_VERSION || !storage)
return;

const StorageMergeTree * merge_tree = dynamic_cast<const StorageMergeTree *>(storage.get());
const auto merge_tree = dynamic_cast<const StorageMergeTree *>(storage.get());
if (!merge_tree || merge_tree->getData().merging_params.mode != MergeTreeData::MergingParams::Txn)
return;

auto storage_schema_version = merge_tree->getTableInfo().schema_version;
if (storage_schema_version < schema_version)
{
LOG_TRACE(log, __PRETTY_FUNCTION__ << " storage schema version: " << storage_schema_version << ", query schema version: " << schema_version << ", syncing schema.");
// TODO: Adapt to new schema syncer API, and use the lock-less one.
context.getTMTContext().getSchemaSyncer()->syncSchema(context, merge_tree->getTableInfo().id);
context.getTMTContext().getSchemaSyncer()->syncSchema(context, merge_tree->getTableInfo().id, false);
}

if (storage_schema_version > schema_version)
// TODO: Use SCHEMA_ERROR error code.
throw Exception("Storage schema version " + std::to_string(storage_schema_version) + " newer than query schema version " + std::to_string(schema_version));
throw Exception("Storage schema version " + std::to_string(storage_schema_version) + " newer than query schema version " + std::to_string(schema_version), ErrorCodes::SCHEMA_VERSION_ERROR);
}


Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/Transaction/SchemaSyncer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SchemaSyncer
* @param context
* @param table_id
*/
virtual void syncSchema(Context & context, TableID table_id, bool lock = true) = 0;
virtual void syncSchema(Context & context, TableID table_id, bool lock) = 0;
};

using SchemaSyncerPtr = std::shared_ptr<SchemaSyncer>;
Expand Down

0 comments on commit 745850e

Please sign in to comment.