Params: faster atomic clearAll (#21973)

* faster clearAll

* use unlink

* fsync_dir if removed > 0

* remove macro ERR_NO_VALUE

* always fsync

* keep call to unlink

Co-authored-by: Willem Melching <willem.melching@gmail.com>
pull/22081/head
Dean Lee 2021-08-31 10:47:47 +08:00 committed by GitHub
parent d9baaf7eb9
commit 383ff35790
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -270,9 +270,8 @@ int Params::remove(const char *key) {
std::lock_guard<FileLock> lk(file_lock);
// Delete value.
std::string path = params_path + "/d/" + key;
int result = ::remove(path.c_str());
int result = unlink(path.c_str());
if (result != 0) {
result = ERR_NO_VALUE;
return result;
}
// fsync parent directory
@ -313,9 +312,18 @@ std::map<std::string, std::string> Params::readAll() {
}
void Params::clearAll(ParamKeyType key_type) {
FileLock file_lock(params_path + "/.lock", LOCK_EX);
std::lock_guard<FileLock> lk(file_lock);
std::string path;
for (auto &[key, type] : keys) {
if (type & key_type) {
remove(key);
path = params_path + "/d/" + key;
unlink(path.c_str());
}
}
// fsync parent directory
path = params_path + "/d";
fsync_dir(path.c_str());
}

View File

@ -4,8 +4,6 @@
#include <sstream>
#include <string>
#define ERR_NO_VALUE -33
enum ParamKeyType {
PERSISTENT = 0x02,
CLEAR_ON_MANAGER_START = 0x04,