meta db unit tests and fixes
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2024-12-04 18:40:50 -06:00
parent 65096f60b1
commit 3959067f22

View File

@ -115,7 +115,7 @@ auto rdb_meta_db::get_item_meta_json(const std::string &api_path,
REPERTORY_USES_FUNCTION_NAME();
try {
auto found{false};
json_data.clear();
{
std::string value;
@ -127,8 +127,7 @@ auto rdb_meta_db::get_item_meta_json(const std::string &api_path,
return res;
}
found = not value.empty();
if (found) {
if (not value.empty()) {
json_data = json::parse(value);
}
}
@ -142,8 +141,9 @@ auto rdb_meta_db::get_item_meta_json(const std::string &api_path,
if (res != api_error::success) {
return res;
}
if (not value.empty()) {
json_data[META_PINNED] = value;
found = found || not value.empty();
}
}
{
@ -154,11 +154,12 @@ auto rdb_meta_db::get_item_meta_json(const std::string &api_path,
if (res != api_error::success) {
return res;
}
if (not value.empty()) {
json_data[META_SIZE] = value;
found = found || not value.empty();
}
}
return found ? api_error::success : api_error::item_not_found;
return json_data.empty() ? api_error::item_not_found : api_error::success;
} catch (const std::exception &e) {
utils::error::raise_api_path_error(function_name, api_path, e,
"failed to get item meta");
@ -352,8 +353,8 @@ auto rdb_meta_db::set_item_meta(const std::string &api_path,
return update_item_meta(api_path, json_data);
}
auto rdb_meta_db::update_item_meta(const std::string &api_path, json json_data)
-> api_error {
auto rdb_meta_db::update_item_meta(const std::string &api_path,
json json_data) -> api_error {
REPERTORY_USES_FUNCTION_NAME();
try {
@ -379,6 +380,10 @@ auto rdb_meta_db::update_item_meta(const std::string &api_path, json json_data)
auto source_path = directory ? std::string("")
: json_data.at(META_SOURCE).get<std::string>();
json_data[META_PINNED] = utils::string::from_bool(pinned);
json_data[META_SIZE] = std::to_string(size);
json_data[META_SOURCE] = source_path;
if (not directory) {
std::string orig_source_path;
auto res = get_item_meta(api_path, META_SOURCE, orig_source_path);
@ -401,7 +406,6 @@ auto rdb_meta_db::update_item_meta(const std::string &api_path, json json_data)
json_data.erase(META_SIZE);
return perform_action(function_name, [&]() -> rocksdb::Status {
if (not directory) {
auto res = db_->Put(rocksdb::WriteOptions(), pinned_family_, api_path,
utils::string::from_bool(pinned));
if (not res.ok()) {
@ -421,7 +425,6 @@ auto rdb_meta_db::update_item_meta(const std::string &api_path, json json_data)
return res;
}
}
}
return db_->Put(rocksdb::WriteOptions(), default_family_, api_path,
json_data.dump());