meta db unit tests and fixes
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				BlockStorage/repertory/pipeline/head This commit looks good
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	BlockStorage/repertory/pipeline/head This commit looks good
				
			This commit is contained in:
		| @@ -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; | ||||
|       } | ||||
|       json_data[META_PINNED] = value; | ||||
|       found = found || not value.empty(); | ||||
|       if (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) { | ||||
|         return res; | ||||
|       } | ||||
|       json_data[META_SIZE] = value; | ||||
|       found = found || not value.empty(); | ||||
|       if (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) { | ||||
|     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,26 +406,24 @@ 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)); | ||||
|       auto res = db_->Put(rocksdb::WriteOptions(), pinned_family_, api_path, | ||||
|                           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()) { | ||||
|           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, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user