This commit is contained in:
parent
b305b9c6f1
commit
9bb91682da
@ -44,6 +44,7 @@ private:
|
|||||||
std::unique_ptr<rocksdb::TransactionDB> db_{nullptr};
|
std::unique_ptr<rocksdb::TransactionDB> db_{nullptr};
|
||||||
rocksdb::ColumnFamilyHandle *directory_family_{};
|
rocksdb::ColumnFamilyHandle *directory_family_{};
|
||||||
rocksdb::ColumnFamilyHandle *file_family_{};
|
rocksdb::ColumnFamilyHandle *file_family_{};
|
||||||
|
rocksdb::ColumnFamilyHandle *path_family_{};
|
||||||
rocksdb::ColumnFamilyHandle *source_family_{};
|
rocksdb::ColumnFamilyHandle *source_family_{};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -66,50 +67,50 @@ private:
|
|||||||
rocksdb::Transaction *txn) -> rocksdb::Status;
|
rocksdb::Transaction *txn) -> rocksdb::Status;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
[[nodiscard]] auto add_directory(const std::string &api_path,
|
[[nodiscard]] auto
|
||||||
const std::string &source_path)
|
add_directory(const std::string &api_path,
|
||||||
-> api_error override;
|
const std::string &source_path) -> api_error override;
|
||||||
|
|
||||||
[[nodiscard]] auto add_or_update_file(const i_file_db::file_data &data)
|
[[nodiscard]] auto
|
||||||
-> api_error override;
|
add_or_update_file(const i_file_db::file_data &data) -> api_error override;
|
||||||
|
|
||||||
void clear() override;
|
void clear() override;
|
||||||
|
|
||||||
[[nodiscard]] auto count() const -> std::uint64_t override;
|
[[nodiscard]] auto count() const -> std::uint64_t override;
|
||||||
|
|
||||||
[[nodiscard]] auto get_api_path(const std::string &source_path,
|
[[nodiscard]] auto
|
||||||
std::string &api_path) const
|
get_api_path(const std::string &source_path,
|
||||||
-> api_error override;
|
std::string &api_path) const -> api_error override;
|
||||||
|
|
||||||
[[nodiscard]] auto get_directory_api_path(const std::string &source_path,
|
[[nodiscard]] auto
|
||||||
std::string &api_path) const
|
get_directory_api_path(const std::string &source_path,
|
||||||
-> api_error override;
|
std::string &api_path) const -> api_error override;
|
||||||
|
|
||||||
[[nodiscard]] auto get_directory_source_path(const std::string &api_path,
|
[[nodiscard]] auto get_directory_source_path(const std::string &api_path,
|
||||||
std::string &source_path) const
|
std::string &source_path) const
|
||||||
-> api_error override;
|
-> api_error override;
|
||||||
|
|
||||||
[[nodiscard]] auto get_file_api_path(const std::string &source_path,
|
[[nodiscard]] auto
|
||||||
std::string &api_path) const
|
get_file_api_path(const std::string &source_path,
|
||||||
-> api_error override;
|
std::string &api_path) const -> api_error override;
|
||||||
|
|
||||||
[[nodiscard]] auto get_file_data(const std::string &api_path,
|
[[nodiscard]] auto
|
||||||
i_file_db::file_data &data) const
|
get_file_data(const std::string &api_path,
|
||||||
-> api_error override;
|
i_file_db::file_data &data) const -> api_error override;
|
||||||
|
|
||||||
[[nodiscard]] auto get_file_source_path(const std::string &api_path,
|
[[nodiscard]] auto
|
||||||
std::string &source_path) const
|
get_file_source_path(const std::string &api_path,
|
||||||
-> api_error override;
|
std::string &source_path) const -> api_error override;
|
||||||
|
|
||||||
[[nodiscard]] auto get_item_list() const
|
[[nodiscard]] auto
|
||||||
-> std::vector<i_file_db::file_info> override;
|
get_item_list() const -> std::vector<i_file_db::file_info> override;
|
||||||
|
|
||||||
[[nodiscard]] auto get_source_path(const std::string &api_path,
|
[[nodiscard]] auto
|
||||||
std::string &source_path) const
|
get_source_path(const std::string &api_path,
|
||||||
-> api_error override;
|
std::string &source_path) const -> api_error override;
|
||||||
|
|
||||||
[[nodiscard]] auto remove_item(const std::string &api_path)
|
[[nodiscard]] auto
|
||||||
-> api_error override;
|
remove_item(const std::string &api_path) -> api_error override;
|
||||||
};
|
};
|
||||||
} // namespace repertory
|
} // namespace repertory
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ void rdb_file_db::create_or_open(bool clear) {
|
|||||||
families.emplace_back(rocksdb::kDefaultColumnFamilyName,
|
families.emplace_back(rocksdb::kDefaultColumnFamilyName,
|
||||||
rocksdb::ColumnFamilyOptions());
|
rocksdb::ColumnFamilyOptions());
|
||||||
families.emplace_back("file", rocksdb::ColumnFamilyOptions());
|
families.emplace_back("file", rocksdb::ColumnFamilyOptions());
|
||||||
|
families.emplace_back("path", rocksdb::ColumnFamilyOptions());
|
||||||
families.emplace_back("source", rocksdb::ColumnFamilyOptions());
|
families.emplace_back("source", rocksdb::ColumnFamilyOptions());
|
||||||
|
|
||||||
auto handles = std::vector<rocksdb::ColumnFamilyHandle *>();
|
auto handles = std::vector<rocksdb::ColumnFamilyHandle *>();
|
||||||
@ -52,6 +53,7 @@ void rdb_file_db::create_or_open(bool clear) {
|
|||||||
std::size_t idx{};
|
std::size_t idx{};
|
||||||
directory_family_ = handles.at(idx++);
|
directory_family_ = handles.at(idx++);
|
||||||
file_family_ = handles.at(idx++);
|
file_family_ = handles.at(idx++);
|
||||||
|
path_family_ = handles.at(idx++);
|
||||||
source_family_ = handles.at(idx++);
|
source_family_ = handles.at(idx++);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +82,11 @@ auto rdb_file_db::add_directory(const std::string &api_path,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res = txn->Put(path_family_, api_path, source_path);
|
||||||
|
if (not res.ok()) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
return txn->Put(source_family_, source_path, api_path);
|
return txn->Put(source_family_, source_path, api_path);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -114,6 +121,11 @@ auto rdb_file_db::add_or_update_file(const i_file_db::file_data &data)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res = txn->Put(path_family_, data.api_path, data.source_path);
|
||||||
|
if (not res.ok()) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
return txn->Put(source_family_, data.source_path, data.api_path);
|
return txn->Put(source_family_, data.source_path, data.api_path);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -147,9 +159,8 @@ auto rdb_file_db::get_api_path(const std::string &source_path,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
auto rdb_file_db::get_directory_api_path(const std::string &source_path,
|
auto rdb_file_db::get_directory_api_path(
|
||||||
std::string &api_path) const
|
const std::string &source_path, std::string &api_path) const -> api_error {
|
||||||
-> api_error {
|
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
auto result = perform_action(function_name, [&]() -> rocksdb::Status {
|
auto result = perform_action(function_name, [&]() -> rocksdb::Status {
|
||||||
@ -172,9 +183,8 @@ auto rdb_file_db::get_directory_api_path(const std::string &source_path,
|
|||||||
: result;
|
: result;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto rdb_file_db::get_directory_source_path(const std::string &api_path,
|
auto rdb_file_db::get_directory_source_path(
|
||||||
std::string &source_path) const
|
const std::string &api_path, std::string &source_path) const -> api_error {
|
||||||
-> api_error {
|
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
auto result = perform_action(function_name, [&]() -> rocksdb::Status {
|
auto result = perform_action(function_name, [&]() -> rocksdb::Status {
|
||||||
@ -235,9 +245,8 @@ auto rdb_file_db::get_file_data(const std::string &api_path,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto rdb_file_db::get_file_source_path(const std::string &api_path,
|
auto rdb_file_db::get_file_source_path(
|
||||||
std::string &source_path) const
|
const std::string &api_path, std::string &source_path) const -> api_error {
|
||||||
-> api_error {
|
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
auto result = perform_action(function_name, [&]() -> rocksdb::Status {
|
auto result = perform_action(function_name, [&]() -> rocksdb::Status {
|
||||||
@ -285,17 +294,12 @@ auto rdb_file_db::get_item_list() const -> std::vector<i_file_db::file_info> {
|
|||||||
|
|
||||||
auto rdb_file_db::get_source_path(const std::string &api_path,
|
auto rdb_file_db::get_source_path(const std::string &api_path,
|
||||||
std::string &source_path) const -> api_error {
|
std::string &source_path) const -> api_error {
|
||||||
auto iter = create_iterator(source_family_);
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
|
|
||||||
if (iter->value().ToString() != api_path) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
source_path = iter->key().ToString();
|
return perform_action(function_name, [&]() -> rocksdb::Status {
|
||||||
return api_error::success;
|
return db_->Get(rocksdb::ReadOptions{}, path_family_, api_path,
|
||||||
}
|
&source_path);
|
||||||
|
});
|
||||||
return api_error::item_not_found;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto rdb_file_db::perform_action(std::string_view function_name,
|
auto rdb_file_db::perform_action(std::string_view function_name,
|
||||||
@ -371,6 +375,11 @@ auto rdb_file_db::remove_item(const std::string &api_path,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res = txn->Delete(path_family_, api_path);
|
||||||
|
if (not res.ok()) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
res = txn->Delete(directory_family_, api_path);
|
res = txn->Delete(directory_family_, api_path);
|
||||||
if (not res.ok()) {
|
if (not res.ok()) {
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user