Skip to content

Commit

Permalink
Merge branch 'master' into support_lm_ut
Browse files Browse the repository at this point in the history
  • Loading branch information
ywqzzy authored Jan 4, 2023
2 parents 77cace2 + 3be5d52 commit 720f95e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 37 deletions.
17 changes: 6 additions & 11 deletions dbms/src/Common/Config/ConfigReloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <Common/Config/ConfigObject.h>
#include <Common/Config/ConfigProcessor.h>
#include <Common/FileChangesTracker.h>
#include <Common/Logger.h>
#include <time.h>

#include <condition_variable>
Expand All @@ -28,12 +29,6 @@
#include <string>
#include <thread>


namespace Poco
{
class Logger;
}

namespace DB
{
class Context;
Expand Down Expand Up @@ -78,7 +73,10 @@ class ConfigReloader
private:
static constexpr auto reload_interval = std::chrono::seconds(2);

Poco::Logger * log = &Poco::Logger::get(name);
LoggerPtr log = Logger::get(name);

/// Locked inside reloadIfNewer.
std::mutex reload_mutex;

std::string path;
FilesChangesTracker files;
Expand All @@ -89,11 +87,8 @@ class ConfigReloader
// If they are updated, the reloadIfNewer will be called.
std::vector<std::shared_ptr<ConfigObject>> config_objects;

std::atomic<bool> quit{false};
std::atomic_bool quit{false};
std::thread thread;

/// Locked inside reloadIfNewer.
std::mutex reload_mutex;
};

} // namespace DB
54 changes: 29 additions & 25 deletions dbms/src/Common/tests/gtest_config_reloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,26 @@ cert_allowed_cn="tidb"
)";

int call_times = 0;
auto main_config_reloader = std::make_unique<ConfigReloader>(
path,
[&](ConfigurationPtr config [[maybe_unused]]) {
call_times++;
},
/* already_loaded = */ false);
{
auto main_config_reloader = std::make_unique<ConfigReloader>(
path,
[&](ConfigurationPtr config [[maybe_unused]]) {
++call_times;
},
/* already_loaded = */ false);

auto other_config_reloader = std::make_unique<ConfigReloader>(
path,
[&](ConfigurationPtr config [[maybe_unused]]) {
call_times++;
},
/* already_loaded = */ false,
"otherCfgLoader");
auto other_config_reloader = std::make_unique<ConfigReloader>(
path,
[&](ConfigurationPtr config [[maybe_unused]]) {
++call_times;
},
/* already_loaded = */ false,
"otherCfgLoader");

main_config_reloader->start();
other_config_reloader->start();
std::this_thread::sleep_for(std::chrono::seconds(3));
main_config_reloader->start();
other_config_reloader->start();
std::this_thread::sleep_for(std::chrono::seconds(3));
}
ASSERT_EQ(call_times, 2);
}

Expand Down Expand Up @@ -101,15 +103,17 @@ max_memory_usage = 0
)";

int call_times = 0;
auto main_config_reloader = std::make_unique<ConfigReloader>(
path,
[&](ConfigurationPtr config [[maybe_unused]]) {
call_times++;
},
/* already_loaded = */ false);
main_config_reloader->addConfigObject(std::make_shared<TestConfigObject>());
main_config_reloader->start();
std::this_thread::sleep_for(std::chrono::seconds(3));
{
auto main_config_reloader = std::make_unique<ConfigReloader>(
path,
[&](ConfigurationPtr config [[maybe_unused]]) {
++call_times;
},
/* already_loaded = */ false);
main_config_reloader->addConfigObject(std::make_shared<TestConfigObject>());
main_config_reloader->start();
std::this_thread::sleep_for(std::chrono::seconds(3));
}
ASSERT_EQ(call_times, 2);
}
} // namespace tests
Expand Down
5 changes: 5 additions & 0 deletions dbms/src/TiDB/Schema/SchemaBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,11 @@ void SchemaBuilder<Getter, NameMapper>::applyDiff(const SchemaDiff & diff)
return;
}

if (diff.type == SchemaActionType::ActionFlashbackCluster)
{
return;
}

auto db_info = getter.getDatabase(diff.schema_id);
if (db_info == nullptr)
{
Expand Down
2 changes: 2 additions & 0 deletions dbms/src/TiDB/Schema/SchemaGetter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ void SchemaDiff::deserialize(const String & data)
old_table_id = obj->getValue<Int64>("old_table_id");
old_schema_id = obj->getValue<Int64>("old_schema_id");

regenerate_schema_map = obj->getValue<bool>("regenerate_schema_map");

affected_opts.clear();
auto affected_arr = obj->getArray("affected_options");
if (!affected_arr.isNull())
Expand Down
9 changes: 8 additions & 1 deletion dbms/src/TiDB/Schema/SchemaGetter.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,17 @@ enum class SchemaActionType : Int8
AlterNoCacheTable = 59,
CreateTables = 60,
ActionMultiSchemaChange = 61,
ActionFlashbackCluster = 62,
ActionRecoverSchema = 63,
ActionReorganizePartition = 64,
ActionAlterTTLInfo = 65,
ActionAlterTTLRemove = 67,


// If we supporte new type from TiDB.
// MaxRecognizedType also needs to be changed.
// It should always be equal to the maximum supported type + 1
MaxRecognizedType = 62,
MaxRecognizedType = 68,
};

struct AffectedOption
Expand All @@ -122,6 +128,7 @@ struct SchemaDiff

TableID old_table_id;
DatabaseID old_schema_id;
bool regenerate_schema_map{false};

std::vector<AffectedOption> affected_opts;

Expand Down
9 changes: 9 additions & 0 deletions dbms/src/TiDB/Schema/TiDBSchemaSyncer.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ struct TiDBSchemaSyncer : public SchemaSyncer
// Return Values
// - if latest schema diff is not empty, return the (latest_version)
// - if latest schema diff is empty, return the (latest_version - 1)
// - if schema_diff.regenerate_schema_map == true, need reload all schema info from TiKV, return (-1)
// - if error happend, return (-1)
Int64 tryLoadSchemaDiffs(Getter & getter, Int64 latest_version, Context & context)
{
Expand Down Expand Up @@ -213,6 +214,14 @@ struct TiDBSchemaSyncer : public SchemaSyncer
LOG_WARNING(log, "Skip the schema diff from version {}. ", cur_version + diff_index + 1);
continue;
}

if (schema_diff->regenerate_schema_map)
{
// If `schema_diff.regenerate_schema_map` == true, return `-1` direclty, let TiFlash reload schema info from TiKV.
LOG_INFO(log, "Meets a schema diff with regenerate_schema_map flag");
return -1;
}

builder.applyDiff(*schema_diff);
}
}
Expand Down

0 comments on commit 720f95e

Please sign in to comment.