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
parent
d9baaf7eb9
commit
383ff35790
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#define ERR_NO_VALUE -33
|
||||
|
||||
enum ParamKeyType {
|
||||
PERSISTENT = 0x02,
|
||||
CLEAR_ON_MANAGER_START = 0x04,
|
||||
|
|
Loading…
Reference in New Issue