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

add schema_version for TableInfo #122

Merged
merged 3 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion dbms/src/Storages/Transaction/SchemaBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ inline AlterCommands detectSchemaChanges(Logger * log, const TiDB::TableInfo & t

void SchemaBuilder::applyAlterTableImpl(TiDB::TableInfoPtr table_info, const String & db_name, StorageMergeTree * storage)
{
table_info->schema_version = target_version;
auto orig_table_info = storage->getTableInfo();
auto commands = detectSchemaChanges(log, *table_info, orig_table_info);

Expand Down Expand Up @@ -308,8 +309,9 @@ void SchemaBuilder::applyCreateTable(TiDB::DBInfoPtr db_info, Int64 table_id)
applyCreateTableImpl(*db_info, *table_info);
}

void SchemaBuilder::applyCreateTableImpl(const TiDB::DBInfo & db_info, const TiDB::TableInfo & table_info)
void SchemaBuilder::applyCreateTableImpl(const TiDB::DBInfo & db_info, TiDB::TableInfo & table_info)
{
table_info.schema_version = target_version;
if (table_info.is_partition_table)
{
// create partition table.
Expand Down
8 changes: 5 additions & 3 deletions dbms/src/Storages/Transaction/SchemaBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ struct SchemaBuilder

std::unordered_map<DB::DatabaseID, String> & databases;

Int64 target_version;

Logger * log;

SchemaBuilder(SchemaGetter & getter_, Context & context_, std::unordered_map<DB::DatabaseID, String> & dbs_)
: getter(getter_), context(context_), databases(dbs_), log(&Logger::get("SchemaBuilder"))
SchemaBuilder(SchemaGetter & getter_, Context & context_, std::unordered_map<DB::DatabaseID, String> & dbs_, Int64 version)
: getter(getter_), context(context_), databases(dbs_), target_version(version), log(&Logger::get("SchemaBuilder"))
{}

void applyDiff(const SchemaDiff & diff);
Expand Down Expand Up @@ -47,7 +49,7 @@ struct SchemaBuilder

void applyCreatePhysicalTableImpl(const TiDB::DBInfo & db_info, const TiDB::TableInfo & table_info);

void applyCreateTableImpl(const TiDB::DBInfo & db_info, const TiDB::TableInfo & table_info);
void applyCreateTableImpl(const TiDB::DBInfo & db_info, TiDB::TableInfo & table_info);

void applyDropTableImpl(const String &, const String &);
};
Expand Down
5 changes: 5 additions & 0 deletions dbms/src/Storages/Transaction/TiDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ String TableInfo::serialize(bool escaped) const try
json->set("partition", Poco::Dynamic::Var());
}

json->set("schema_version", schema_version);

json->stringify(buf);

if (!escaped)
Expand Down Expand Up @@ -329,6 +331,9 @@ void TableInfo::deserialize(const String & json_str) try
belonging_table_id = obj->getValue<TableID>("belonging_table_id");
partition.deserialize(partition_obj);
}
if (obj->has("schema_version")) {
zanmato1984 marked this conversation as resolved.
Show resolved Hide resolved
schema_version = obj->getValue<Int64>("schema_version");
}
}
catch (const Poco::Exception & e)
{
Expand Down
8 changes: 4 additions & 4 deletions dbms/src/Storages/Transaction/TiDBSchemaSyncer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct TiDBSchemaSyncer : public SchemaSyncer
LOG_INFO(log, "try to sync schema version to: " + std::to_string(version));
if (!tryLoadSchemaDiffs(getter, version, context))
{
loadAllSchema(getter, context);
loadAllSchema(getter, version, context);
}
cur_version = version;
return true;
Expand All @@ -61,7 +61,7 @@ struct TiDBSchemaSyncer : public SchemaSyncer

LOG_DEBUG(log, "try load schema diffs.");

SchemaBuilder builder(getter, context, databases);
SchemaBuilder builder(getter, context, databases, version);

Int64 used_version = cur_version;
std::vector<SchemaDiff> diffs;
Expand All @@ -78,7 +78,7 @@ struct TiDBSchemaSyncer : public SchemaSyncer
return true;
}

bool loadAllSchema(SchemaGetter & getter, Context & context)
bool loadAllSchema(SchemaGetter & getter, Int64 version, Context & context)
{
LOG_DEBUG(log, "try load all schemas.");

Expand All @@ -89,7 +89,7 @@ struct TiDBSchemaSyncer : public SchemaSyncer
LOG_DEBUG(log, "Load schema : " + db_info->name);
}

SchemaBuilder builder(getter, context, databases);
SchemaBuilder builder(getter, context, databases, version);

std::set<TiDB::DatabaseID> db_ids;
for (auto db : all_schema)
Expand Down
Loading