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

Revert Lazily Init Store #2011

Merged
merged 4 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
29 changes: 0 additions & 29 deletions dbms/src/Server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,33 +347,6 @@ struct RaftStoreProxyRunner : boost::noncopyable
Logger * log;
};

// We only need this task run once.
void backgroundInitStores(Context & global_context, Logger * log)
{
auto initStores = [&global_context, log]() {
auto storages = global_context.getTMTContext().getStorages().getAllStorage();
int init_cnt = 0;
int err_cnt = 0;
for (auto & [table_id, storage] : storages)
{
try
{
init_cnt += storage->initStoreIfDataDirExist() ? 1 : 0;
LOG_INFO(log, "Storage inited done [table_id=" << table_id << "]");
}
catch (...)
{
err_cnt++;
tryLogCurrentException(log, "Storage inited fail, [table_id=" + DB::toString(table_id) + "]");
}
}
LOG_INFO(log,
"Storage inited finish. [total_count=" << storages.size() << "] [init_count=" << init_cnt << "] [error_count=" << err_cnt
<< "]");
};
std::thread(initStores).detach();
}

int Server::main(const std::vector<std::string> & /*args*/)
{
setThreadName("TiFlashMain");
Expand Down Expand Up @@ -780,8 +753,6 @@ int Server::main(const std::vector<std::string> & /*args*/)
}
LOG_DEBUG(log, "Sync schemas done.");

backgroundInitStores(*global_context, log);

// After schema synced, set current database.
global_context->setCurrentDatabase(default_database);

Expand Down
3 changes: 0 additions & 3 deletions dbms/src/Storages/IManageableStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ class IManageableStorage : public IStorage

// `limit` is the max number of segments to gc, return value is the number of segments gced
virtual UInt64 onSyncGc(Int64 /*limit*/) { throw Exception("Unsupported"); }

// Return true is data dir exist
virtual bool initStoreIfDataDirExist() { throw Exception("Unsupported"); }

virtual void mergeDelta(const Context &) { throw Exception("Unsupported"); }

Expand Down
50 changes: 2 additions & 48 deletions dbms/src/Storages/StorageDeltaMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,8 +1128,8 @@ void StorageDeltaMerge::modifyASTStorage(ASTStorage * storage_ast, const TiDB::T
else if (args->children.size() == 3)
args->children.at(1) = literal;
else
throw Exception(
"Wrong arguments num: " + DB::toString(args->children.size()) + " in table: " + this->getTableName() + " in modifyASTStorage",
throw Exception("Wrong arguments num: " + DB::toString(args->children.size())
+ " in table: " + getAndMaybeInitStore()->getTableName() + " in modifyASTStorage",
ErrorCodes::BAD_ARGUMENTS);
}

Expand Down Expand Up @@ -1296,50 +1296,4 @@ DeltaMergeStorePtr & StorageDeltaMerge::getAndMaybeInitStore()
}
return _store;
}

bool StorageDeltaMerge::initStoreIfDataDirExist()
{
if (shutdown_called.load(std::memory_order_relaxed) || isTombstone())
{
return false;
}
// If store is inited, we don't need to check data dir.
if (store_inited.load(std::memory_order_relaxed))
{
return true;
}
if (!dataDirExist())
{
return false;
}
getAndMaybeInitStore();
return true;
}

bool StorageDeltaMerge::dataDirExist()
{
String db_name, table_name;
{
std::lock_guard<std::mutex> lock(store_mutex);
// store is inited after lock acquired.
if (store_inited.load(std::memory_order_acquire))
{
return true;
}
db_name = table_column_info->db_name;
table_name = table_column_info->table_name;
}

auto path_pool = global_context.getPathPool().withTable(db_name, table_name, data_path_contains_database_name);
auto path_delegate = path_pool.getStableDiskDelegator();
for (const auto & root_path : path_delegate.listPaths())
{
int r = ::access(root_path.c_str(), F_OK);
if (r == 0)
{
return true;
}
}
return false;
}
} // namespace DB
5 changes: 1 addition & 4 deletions dbms/src/Storages/StorageDeltaMerge.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ class StorageDeltaMerge : public ext::shared_ptr_helper<StorageDeltaMerge>, publ
bool isCommonHandle() const override { return is_common_handle; }

size_t getRowKeyColumnSize() const override { return rowkey_column_size; }

bool initStoreIfDataDirExist() override;

protected:
StorageDeltaMerge( //
Expand Down Expand Up @@ -141,8 +139,6 @@ class StorageDeltaMerge : public ext::shared_ptr_helper<StorageDeltaMerge>, publ
bool storeInited() const { return store_inited.load(); }
void updateTableColumnInfo();
DM::ColumnDefines getStoreColumnDefines() const;

bool dataDirExist();
private:
struct TableColumnInfo
{
Expand Down Expand Up @@ -179,6 +175,7 @@ class StorageDeltaMerge : public ext::shared_ptr_helper<StorageDeltaMerge>, publ
std::atomic<UInt64> next_version = 1; //TODO: remove this!!!

Context & global_context;

Logger * log;
};

Expand Down