Skip to content

Commit

Permalink
Added RadosCatalogue unit tests and several fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolau-manubens committed Jun 25, 2024
1 parent fe324d1 commit 006bea5
Show file tree
Hide file tree
Showing 15 changed files with 1,402 additions and 169 deletions.
2 changes: 2 additions & 0 deletions src/fdb5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ if( HAVE_RADOSFDB )
rados/RadosIndexLocation.h
rados/RadosLazyFieldLocation.cc
rados/RadosLazyFieldLocation.h
rados/RadosEngine.cc
rados/RadosEngine.h
)
endif()

Expand Down
101 changes: 47 additions & 54 deletions src/fdb5/rados/RadosCatalogue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "fdb5/rados/RadosCatalogue.h"
// #include "fdb5/daos/DaosName.h"
// #include "fdb5/daos/DaosSession.h"
// #include "fdb5/daos/DaosIndex.h"
#include "fdb5/rados/RadosIndex.h"
// #include "fdb5/daos/DaosWipeVisitor.h"

// using namespace eckit;
Expand Down Expand Up @@ -109,60 +109,53 @@ WipeVisitor* RadosCatalogue::wipeVisitor(const Store& store, const metkit::mars:

std::vector<Index> RadosCatalogue::indexes(bool) const {

NOTIMP;
/// @note: sorted is not implemented as is not necessary in this backend.

/// @note: performed RPCs:
/// - db kv open (daos_kv_open)
/// - db kv list keys (daos_kv_list)

std::vector<fdb5::Index> res;

for (const auto& key : db_kv_->keys()) {

/// @todo: document these well. Single source these reserved values.
/// Ensure where appropriate that user-provided keys do not collide.
if (key == "schema" || key == "key") continue;

/// @note: performed RPCs:
/// - db kv get index location size (daos_kv_get without a buffer)
/// - db kv get index location (daos_kv_get)
std::vector<char> v;
auto m = db_kv_->getMemoryStream(v, key, "DB kv");

eckit::URI uri(std::string(v.begin(), v.end()));

/// @note: performed RPCs:
/// - index kv open (daos_kv_open)
/// - index kv get size (daos_kv_get without a buffer)
/// - index kv get key (daos_kv_get)
/// @note: the following three lines intend to check whether the index kv exists
/// or not. The DaosKeyValue constructor calls kv open, which always succeeds,
/// so it is not useful on its own to check whether the index KV existed or not.
/// Instead, presence of a "key" key in the KV is used to determine if the index
/// KV existed.
eckit::RadosKeyValue index_kv{uri};
std::optional<fdb5::Key> index_key;
try {
std::vector<char> data;
eckit::MemoryStream ms = index_kv.getMemoryStream(data, "key", "index KV");
index_key.emplace(ms);
} catch (eckit::RadosEntityNotFoundException& e) {
continue; /// @note: the index_kv may not exist after a failed wipe
/// @todo: the index_kv may exist even if it does not have the "key" key
}

res.push_back(Index(new fdb5::RadosIndex(index_key.value(), index_kv, false)));

}

// /// @note: sorted is not implemented as is not necessary in this backend.

// fdb5::DaosKeyValueName catalogue_kv_name{pool_, db_cont_, catalogue_kv_};
// fdb5::DaosSession s{};

// /// @note: performed RPCs:
// /// - db kv open (daos_kv_open)
// /// - db kv list keys (daos_kv_list)
// fdb5::DaosKeyValue catalogue_kv{s, catalogue_kv_name}; /// @note: throws if not exists

// std::vector<fdb5::Index> res;

// for (const auto& key : catalogue_kv.keys()) {

// /// @todo: document these well. Single source these reserved values.
// /// Ensure where appropriate that user-provided keys do not collide.
// if (key == "schema" || key == "key") continue;

// /// @note: performed RPCs:
// /// - db kv get index location size (daos_kv_get without a buffer)
// /// - db kv get index location (daos_kv_get)
// uint64_t size{catalogue_kv.size(key)};
// std::vector<char> v(size);
// catalogue_kv.get(key, v.data(), size);

// fdb5::DaosKeyValueName index_kv_name{eckit::URI(std::string(v.begin(), v.end()))};

// /// @note: performed RPCs:
// /// - index kv open (daos_kv_open)
// /// - index kv get size (daos_kv_get without a buffer)
// /// - index kv get key (daos_kv_get)
// /// @note: the following three lines intend to check whether the index kv exists
// /// or not. The DaosKeyValue constructor calls kv open, which always succeeds,
// /// so it is not useful on its own to check whether the index KV existed or not.
// /// Instead, presence of a "key" key in the KV is used to determine if the index
// /// KV existed.
// fdb5::DaosKeyValue index_kv{s, index_kv_name};
// std::optional<fdb5::Key> index_key;
// try {
// std::vector<char> data;
// eckit::MemoryStream ms = index_kv.getMemoryStream(data, "key", "index KV");
// index_key.emplace(ms);
// } catch (fdb5::DaosEntityNotFoundException& e) {
// continue; /// @note: the index_kv may not exist after a failed wipe
// /// @todo: the index_kv may exist even if it does not have the "key" key
// }

// res.push_back(Index(new fdb5::DaosIndex(index_key.value(), index_kv_name, false)));

// }

// return res;
return res;

}

Expand Down
10 changes: 9 additions & 1 deletion src/fdb5/rados/RadosCatalogueWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ RadosCatalogueWriter::RadosCatalogueWriter(const Key &key, const fdb5::Config& c

/// @note: performed RPCs:
/// - check if main kv contains db key (daos_kv_get without a buffer)
root_kv_->ensureCreated();
if (!root_kv_->has(db_name)) {

/// create catalogue kv
#ifndef fdb5_HAVE_RADOS_BACKENDS_SINGLE_POOL
db_kv_->nspace().pool().ensureCreated();
#endif
db_kv_->ensureCreated();

/// write schema under "schema"
Expand All @@ -68,7 +72,11 @@ RadosCatalogueWriter::RadosCatalogueWriter(const Key &key, const fdb5::Config& c
eckit::FileHandle in(config_.schemaPath());
std::vector<char> data;
data.resize(in.size());
in.read(&data[0], in.size());
{
eckit::AutoClose ac{in};
in.openForRead();
in.read(&data[0], in.size());
}
db_kv_->put("schema", &data[0], data.size());

/// write dbKey under "key"
Expand Down
21 changes: 14 additions & 7 deletions src/fdb5/rados/RadosCommon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ RadosCommon::RadosCommon(const fdb5::Config& config, const std::string& componen

#ifdef fdb5_HAVE_RADOS_BACKENDS_SINGLE_POOL

db_namespace_ = key.valuesToString();

readConfig(config, component, true);

db_namespace_ = nspace_prefix_ + "_" + key.valuesToString();

root_kv_.emplace(pool_, root_namespace_, "main_kv");
db_kv_.emplace(pool_, db_namespace_, "catalogue_kv");

#else

readConfig(config, component, true);

db_pool_ = prefix_ + "_" + key.valuesToString();
db_pool_ = pool_prefix_ + "_" + key.valuesToString();

root_kv_.emplace(root_pool_, namespace_, "main_kv");
db_kv_.emplace(db_pool_, namespace_, "catalogue_kv");
Expand Down Expand Up @@ -74,7 +74,7 @@ RadosCommon::RadosCommon(const fdb5::Config& config, const std::string& componen
const auto parts = eckit::Tokenizer("_").tokenize(db_pool_);
const auto n = parts.size();
ASSERT(n > 1);
prefix_ = parts[0];
pool_prefix_ = parts[0];

root_kv_.emplace(root_pool_, namespace_, "main_kv");
db_kv_.emplace(db_pool_, namespace_, "catalogue_kv");
Expand Down Expand Up @@ -110,28 +110,35 @@ void RadosCommon::readConfig(const fdb5::Config& config, const std::string& comp
pool_ = c.getString("pool", pool_);
if (c.has(component)) pool_ = c.getSubConfiguration(component).getString("pool", pool_);
}
root_namespace_ = c.getString("root_namespace", root_namespace_);
if (c.has(component)) root_namespace_ = c.getSubConfiguration(component).getString("root_namespace", root_namespace_);

if (readPool)
pool_ = eckit::Resource<std::string>("fdbRados" + first_cap + "Pool;$FDB_RADOS_" + all_caps + "_POOL", pool_);
root_namespace_ = eckit::Resource<std::string>("fdbRados" + first_cap + "RootNamespace;$FDB_RADOS_" + all_caps + "_ROOT_NAMESPACE", root_namespace_);

nspace_prefix_ = c.getString("namespace_prefix", nspace_prefix_);
if (c.has(component)) nspace_prefix_ = c.getSubConfiguration(component).getString("namespace_prefix", nspace_prefix_);
ASSERT_MSG(nspace_prefix_.find("_") == std::string::npos, "The configured namespace prefix must not contain underscores.");

#else

if (readNamespace) namespace_ = "default";
root_pool_ = "root";

if (readNamespace)
namespace_ = c.getString("namespace", namespace_);
if (c.has(component)) namespace_ = c.getSubConfiguration(component).getString("namespace", namespace_);
root_pool_ = c.getString("root_pool", root_pool_);
if (c.has(component)) root_pool_ = c.getSubConfiguration(component).getString("root_pool", root_pool_);

if (readNamespace)
namespace_ = eckit::Resource<std::string>("fdbRados" + first_cap + "Namespace;$FDB_RADOS_" + all_caps + "_NAMESPACE", namespace_);
root_pool_ = eckit::Resource<std::string>("fdbRados" + first_cap + "RootPool;$FDB_RADOS_" + all_caps + "_ROOT_POOL", root_pool_);

prefix_ = c.getString("pool_prefix", prefix_);
if (c.has(component)) prefix_ = c.getSubConfiguration(component).getString("pool_prefix", prefix_);
ASSERT_MSG(prefix_.find("_") == std::string::npos, "The configured pool prefix must not contain underscores.");
pool_prefix_ = c.getString("pool_prefix", pool_prefix_);
if (c.has(component)) pool_prefix_ = c.getSubConfiguration(component).getString("pool_prefix", pool_prefix_);
ASSERT_MSG(pool_prefix_.find("_") == std::string::npos, "The configured pool prefix must not contain underscores.");

#endif

Expand Down
6 changes: 4 additions & 2 deletions src/fdb5/rados/RadosCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ class RadosCommon {

eckit::Length maxObjectSize_;

#ifndef fdb5_HAVE_RADOS_BACKENDS_SINGLE_POOL
private: // members

std::string prefix_;
#ifdef fdb5_HAVE_RADOS_BACKENDS_SINGLE_POOL
std::string nspace_prefix_;
#else
std::string pool_prefix_;
#endif

};
Expand Down
Loading

0 comments on commit 006bea5

Please sign in to comment.