Skip to content

Commit

Permalink
delete flushsubdb
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixficsol committed Mar 25, 2024
1 parent 1cd069f commit ac8e1dc
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 43 deletions.
5 changes: 1 addition & 4 deletions include/pika_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,9 @@ class DB : public std::enable_shared_from_this<DB>, public pstd::noncopyable {
void Init();
bool TryUpdateMasterOffset();
/*
* FlushDB & FlushSubDB use
* FlushDB used
*/
bool FlushDB();
bool FlushSubDB(const std::string& db_name);
bool FlushDBWithoutLock();
bool FlushSubDBWithoutLock(const std::string& db_name);
bool ChangeDb(const std::string& new_path);
pstd::Status GetBgSaveUUID(std::string* snapshot_uuid);
void PrepareRsync();
Expand Down
1 change: 1 addition & 0 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ void FlushallCmd::DoInitial() {
return;
}
}

void FlushallCmd::Do() {
std::lock_guard l_trw(g_pika_server->GetDBLock());
for (const auto& db_item : g_pika_server->GetDB()) {
Expand Down
40 changes: 1 addition & 39 deletions src/pika_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ DisplayCacheInfo DB::GetCacheInfo() {
}

bool DB::FlushDBWithoutLock() {
std::lock_guard l(bgsave_protector_);
if (bgsave_info_.bgsaving) {
return false;
}
Expand All @@ -225,34 +226,6 @@ bool DB::FlushDBWithoutLock() {
return true;
}

bool DB::FlushSubDBWithoutLock(const std::string& db_name) {
std::lock_guard l(bgsave_protector_);
if (bgsave_info_.bgsaving) {
return false;
}

LOG(INFO) << db_name_ << " Delete old " + db_name + " db...";
storage_.reset();

std::string dbpath = db_path_;
if (dbpath[dbpath.length() - 1] != '/') {
dbpath.append("/");
}

std::string sub_dbpath = dbpath + db_name;
std::string del_dbpath = dbpath + db_name + "_deleting";
pstd::RenameFile(sub_dbpath, del_dbpath);

storage_ = std::make_shared<storage::Storage>(g_pika_conf->db_instance_num(),
g_pika_conf->default_slot_num(), g_pika_conf->classic_mode());
rocksdb::Status s = storage_->Open(g_pika_server->storage_options(), db_path_);
assert(storage_);
assert(s.ok());
LOG(INFO) << db_name_ << " open new " + db_name + " db success";
g_pika_server->PurgeDir(del_dbpath);
return true;
}

void DB::DoBgSave(void* arg) {
std::unique_ptr<BgTaskArg> bg_task_arg(static_cast<BgTaskArg*>(arg));

Expand Down Expand Up @@ -575,11 +548,6 @@ void DB::ClearBgsave() {
bgsave_info_.Clear();
}

bool DB::FlushSubDB(const std::string& db_name) {
std::lock_guard rwl(dbs_rw_);
return FlushSubDBWithoutLock(db_name);
}

void DB::UpdateCacheInfo(CacheInfo& cache_info) {
std::unique_lock<std::shared_mutex> lock(cache_info_rwlock_);

Expand Down Expand Up @@ -628,9 +596,3 @@ void DB::ResetDisplayCacheInfo(int status) {
cache_info_.waitting_load_keys_num = 0;
cache_usage_ = 0;
}

bool DB::FlushDB() {
std::lock_guard rwl(dbs_rw_);
std::lock_guard l(bgsave_protector_);
return FlushDBWithoutLock();
}

0 comments on commit ac8e1dc

Please sign in to comment.