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(); REPERTORY_USES_FUNCTION_NAME();
try { try {
auto found{false}; json_data.clear();
{ {
std::string value; std::string value;
@ -127,8 +127,7 @@ auto rdb_meta_db::get_item_meta_json(const std::string &api_path,
return res; return res;
} }
found = not value.empty(); if (not value.empty()) {
if (found) {
json_data = json::parse(value); 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) { if (res != api_error::success) {
return res; return res;
} }
json_data[META_PINNED] = value; if (not value.empty()) {
found = found || not value.empty(); json_data[META_PINNED] = value;
}
} }
{ {
@ -154,11 +154,12 @@ auto rdb_meta_db::get_item_meta_json(const std::string &api_path,
if (res != api_error::success) { if (res != api_error::success) {
return res; return res;
} }
json_data[META_SIZE] = value; if (not value.empty()) {
found = found || not value.empty(); json_data[META_SIZE] = value;
}
} }
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) { } catch (const std::exception &e) {
utils::error::raise_api_path_error(function_name, api_path, e, utils::error::raise_api_path_error(function_name, api_path, e,
"failed to get item meta"); "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); return update_item_meta(api_path, json_data);
} }
auto rdb_meta_db::update_item_meta(const std::string &api_path, json json_data) auto rdb_meta_db::update_item_meta(const std::string &api_path,
-> api_error { json json_data) -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { 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("") auto source_path = directory ? std::string("")
: json_data.at(META_SOURCE).get<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) { if (not directory) {
std::string orig_source_path; std::string orig_source_path;
auto res = get_item_meta(api_path, META_SOURCE, orig_source_path); auto res = get_item_meta(api_path, META_SOURCE, orig_source_path);
@ -401,26 +406,24 @@ auto rdb_meta_db::update_item_meta(const std::string &api_path, json json_data)
json_data.erase(META_SIZE); json_data.erase(META_SIZE);
return perform_action(function_name, [&]() -> rocksdb::Status { return perform_action(function_name, [&]() -> rocksdb::Status {
if (not directory) { auto res = db_->Put(rocksdb::WriteOptions(), pinned_family_, api_path,
auto res = db_->Put(rocksdb::WriteOptions(), pinned_family_, api_path, utils::string::from_bool(pinned));
utils::string::from_bool(pinned)); if (not res.ok()) {
return res;
}
res = db_->Put(rocksdb::WriteOptions(), size_family_, api_path,
std::to_string(size));
if (not res.ok()) {
return res;
}
if (not source_path.empty()) {
res = db_->Put(rocksdb::WriteOptions(), source_family_, source_path,
api_path);
if (not res.ok()) { if (not res.ok()) {
return res; return res;
} }
res = db_->Put(rocksdb::WriteOptions(), size_family_, api_path,
std::to_string(size));
if (not res.ok()) {
return res;
}
if (not source_path.empty()) {
res = db_->Put(rocksdb::WriteOptions(), source_family_, source_path,
api_path);
if (not res.ok()) {
return res;
}
}
} }
return db_->Put(rocksdb::WriteOptions(), default_family_, api_path, return db_->Put(rocksdb::WriteOptions(), default_family_, api_path,