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

Fix data race for accessing database in some commands #253

Merged
merged 6 commits into from
May 10, 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
2 changes: 1 addition & 1 deletion src/redis_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ rocksdb::Status Set::Take(const Slice &user_key, std::vector<std::string> *membe
std::string ns_key;
AppendNamespacePrefix(user_key, &ns_key);

if (pop) LockGuard guard(storage_->GetLockManager(), ns_key);
ShooterIT marked this conversation as resolved.
Show resolved Hide resolved
LockGuard guard(storage_->GetLockManager(), ns_key);
SetMetadata metadata(false);
rocksdb::Status s = GetMetadata(ns_key, &metadata);
if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s;
Expand Down
6 changes: 4 additions & 2 deletions src/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ Status Server::Start() {
if (is_loading_ == false && ++counter % 600 == 0 // check every minute
&& config_->compaction_checker_range.Enabled()) {
auto now = std::time(nullptr);
auto local_time = std::localtime(&now);
std::tm *local_time;
localtime_r(&now, local_time);
if (local_time->tm_hour >= config_->compaction_checker_range.Start
&& local_time->tm_hour <= config_->compaction_checker_range.Stop) {
std::vector<std::string> cf_names = {Engine::kMetadataColumnFamilyName,
Expand Down Expand Up @@ -460,7 +461,8 @@ void Server::cron() {
// check every 20s (use 20s instead of 60s so that cron will execute in critical condition)
if (is_loading_ == false && counter != 0 && counter % 200 == 0) {
auto t = std::time(nullptr);
auto now = std::localtime(&t);
std::tm *now;
localtime_r(&t, now);
// disable compaction cron when the compaction checker was enabled
if (!config_->compaction_checker_range.Enabled()
&& config_->compact_cron.IsEnabled()
Expand Down
2 changes: 1 addition & 1 deletion src/worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void WorkerThread::Start() {
} else {
Util::ThreadSetName("worker");
}
this->worker_->Run(t_.get_id());
this->worker_->Run(std::this_thread::get_id());
});
} catch (const std::system_error &e) {
LOG(ERROR) << "[worker] Failed to start worker thread, err: " << e.what();
Expand Down