RocksDB implementations should be transactional #24
This commit is contained in:
parent
48ed06a255
commit
3a62c389ef
@ -490,50 +490,7 @@ auto rdb_meta_db::update_item_meta(const std::string &api_path, json json_data,
|
|||||||
json_data.erase(META_PINNED);
|
json_data.erase(META_PINNED);
|
||||||
json_data.erase(META_SIZE);
|
json_data.erase(META_SIZE);
|
||||||
|
|
||||||
const auto do_transaction =
|
const auto set_status = [&status](rocksdb::Status res) -> rocksdb::Status {
|
||||||
[&](rocksdb::Transaction *txn) -> rocksdb::Status {
|
|
||||||
if (should_del_source) {
|
|
||||||
auto res = txn->Delete(source_family_, orig_source_path);
|
|
||||||
if (status != nullptr) {
|
|
||||||
*status = res;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not res.ok()) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto res =
|
|
||||||
txn->Put(pinned_family_, api_path, utils::string::from_bool(pinned));
|
|
||||||
if (status != nullptr) {
|
|
||||||
*status = res;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not res.ok()) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = txn->Put(size_family_, api_path, std::to_string(size));
|
|
||||||
if (status != nullptr) {
|
|
||||||
*status = res;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not res.ok()) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not source_path.empty()) {
|
|
||||||
res = txn->Put(source_family_, source_path, api_path);
|
|
||||||
if (status != nullptr) {
|
|
||||||
*status = res;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not res.ok()) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
res = txn->Put(default_family_, api_path, json_data.dump());
|
|
||||||
if (status != nullptr) {
|
if (status != nullptr) {
|
||||||
*status = res;
|
*status = res;
|
||||||
}
|
}
|
||||||
@ -541,15 +498,41 @@ auto rdb_meta_db::update_item_meta(const std::string &api_path, json json_data,
|
|||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const auto do_transaction =
|
||||||
|
[&](rocksdb::Transaction *txn) -> rocksdb::Status {
|
||||||
|
if (should_del_source) {
|
||||||
|
auto res = set_status(txn->Delete(source_family_, orig_source_path));
|
||||||
|
if (not res.ok()) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto res = set_status(
|
||||||
|
txn->Put(pinned_family_, api_path, utils::string::from_bool(pinned)));
|
||||||
|
if (not res.ok()) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = set_status(txn->Put(size_family_, api_path, std::to_string(size)));
|
||||||
|
if (not res.ok()) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not source_path.empty()) {
|
||||||
|
res = set_status(txn->Put(source_family_, source_path, api_path));
|
||||||
|
if (not res.ok()) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return set_status(txn->Put(default_family_, api_path, json_data.dump()));
|
||||||
|
};
|
||||||
|
|
||||||
if (base_txn == nullptr) {
|
if (base_txn == nullptr) {
|
||||||
return perform_action(function_name, do_transaction);
|
return perform_action(function_name, do_transaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto res = do_transaction(base_txn);
|
auto res = set_status(do_transaction(base_txn));
|
||||||
if (status != nullptr) {
|
|
||||||
*status = res;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res.ok()) {
|
if (res.ok()) {
|
||||||
return api_error::success;
|
return api_error::success;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user