Skip to content

Commit

Permalink
Add switch for lazily init store and enable it by default. (pingcap#2531
Browse files Browse the repository at this point in the history
)
  • Loading branch information
JinheLin authored Aug 3, 2021
1 parent 4e5730c commit 9fc8ef3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
17 changes: 13 additions & 4 deletions dbms/src/Server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,9 @@ struct RaftStoreProxyRunner : boost::noncopyable
};

// We only need this task run once.
void backgroundInitStores(Context & global_context, Logger * log)
void initStores(Context & global_context, Logger * log, bool lazily_init_store)
{
auto initStores = [&global_context, log]() {
auto do_init_stores = [&global_context, log]() {
auto storages = global_context.getTMTContext().getStorages().getAllStorage();
int init_cnt = 0;
int err_cnt = 0;
Expand All @@ -469,7 +469,16 @@ void backgroundInitStores(Context & global_context, Logger * log)
"Storage inited finish. [total_count=" << storages.size() << "] [init_count=" << init_cnt << "] [error_count=" << err_cnt
<< "]");
};
std::thread(initStores).detach();
if (lazily_init_store)
{
LOG_INFO(log, "Lazily init store.");
std::thread(do_init_stores).detach();
}
else
{
LOG_INFO(log, "Not lazily init store.");
do_init_stores();
}
}

class Server::FlashGrpcServerHolder
Expand Down Expand Up @@ -1228,7 +1237,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
}
LOG_DEBUG(log, "Sync schemas done.");

backgroundInitStores(*global_context, log);
initStores(*global_context, log, storage_config.lazily_init_store);

// After schema synced, set current database.
global_context->setCurrentDatabase(default_database);
Expand Down
3 changes: 3 additions & 0 deletions dbms/src/Server/StorageConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ void TiFlashStorageConfig::parse(const String & storage, Poco::Logger * log)

if (auto version = table->get_qualified_as<UInt64>("format_version"); version)
format_version = *version;

if (auto lazily_init = table->get_qualified_as<Int32>("lazily_init_store"); lazily_init)
lazily_init_store = (*lazily_init != 0);
}

Strings TiFlashStorageConfig::getAllNormalPaths() const
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Server/StorageConfigParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct TiFlashStorageConfig

UInt64 bg_task_io_rate_limit = 0;
UInt64 format_version = 0;

bool lazily_init_store = true;
public:
TiFlashStorageConfig() {}

Expand Down

0 comments on commit 9fc8ef3

Please sign in to comment.