Skip to content

Commit

Permalink
add capacity param
Browse files Browse the repository at this point in the history
  • Loading branch information
Clueliss committed Sep 2, 2024
1 parent 91d1c38 commit 0a94076
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/dice/ffi/metall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ metall_manager *metall_open_read_only(char const *path) {
return open_impl<metall::open_read_only>(path);
}

metall_manager *metall_create(char const *path) {
metall_manager *metall_create(char const *path, size_t capacity) {
if (std::filesystem::exists(path)) {
// prevent accidental overwrite
errno = EEXIST;
return nullptr;
}

auto *manager = new metall_manager_t{metall::create_only, path};
auto *manager = new metall_manager_t{metall::create_only, path, capacity};
if (!manager->check_sanity()) {
delete manager;
errno = ENOTRECOVERABLE;
Expand Down
5 changes: 4 additions & 1 deletion src/dice/ffi/metall.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
#include <stddef.h>

#include <metall/logger_interface.h>
#include <metall/defs.hpp>

#ifdef __cplusplus
extern "C" {
#endif


typedef struct metall_manager metall_manager;

/**
Expand All @@ -31,11 +33,12 @@ metall_manager *metall_open_read_only(char const *path);
/**
* @brief Attempts to create a metall datastore at path
* @param path path at which to create a datastore
* @param capacity maximum capacity for metall manager, for default value use METALL_DEFAULT_CAPACITY
* @return true on success, false on failure. On failure, sets errno to one of the following values:
* - EEXIST if the given path already exists
* - ENOTRECOVERABLE if the datastore could not be created for some other reason
*/
metall_manager *metall_create(char const *path);
metall_manager *metall_create(char const *path, size_t capacity);

/**
* @brief Returns true if the metall manager was opened as read-only
Expand Down
4 changes: 2 additions & 2 deletions tests/tests_Sanity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TEST_SUITE("metall-ffi") {
std::string const snap_path = path + "-snap";

{
metall_manager *manager = metall_create(path.c_str());
metall_manager *manager = metall_create(path.c_str(), METALL_DEFAULT_CAPACITY);
if (manager == nullptr) {
FAIL("failed to create: ", strerror(errno));
}
Expand Down Expand Up @@ -96,7 +96,7 @@ TEST_SUITE("metall-ffi") {

TEST_CASE("prevent open same datastore twice") {
std::string const path = "/tmp/" + std::to_string(std::random_device{}());
metall_manager *manager = metall_create(path.c_str());
metall_manager *manager = metall_create(path.c_str(), METALL_DEFAULT_CAPACITY);
if (manager == nullptr) {
FAIL("failed to create datastore: ", strerror(errno));
}
Expand Down

0 comments on commit 0a94076

Please sign in to comment.