Skip to content

Commit

Permalink
chore: expose StoreOption to c API
Browse files Browse the repository at this point in the history
Signed-off-by: Jian Zhang <[email protected]>
  • Loading branch information
zz-jason committed Aug 17, 2024
1 parent d69d7dc commit d098ac9
Show file tree
Hide file tree
Showing 51 changed files with 514 additions and 377 deletions.
12 changes: 6 additions & 6 deletions benchmarks/micro-benchmarks/InsertUpdateBench.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "leanstore-c/StoreOption.h"
#include "leanstore/LeanStore.hpp"
#include "leanstore/StoreOption.hpp"
#include "leanstore/btree/BasicKV.hpp"
#include "leanstore/btree/TransactionKV.hpp"
#include "leanstore/buffer-manager/BufferManager.hpp"
Expand All @@ -21,11 +21,11 @@ static void BenchUpdateInsert(benchmark::State& state) {
std::filesystem::path dirPath = "/tmp/InsertUpdateBench";
std::filesystem::remove_all(dirPath);
std::filesystem::create_directories(dirPath);
auto sLeanStore = std::make_unique<leanstore::LeanStore>(StoreOption{
.mCreateFromScratch = true,
.mStoreDir = "/tmp/InsertUpdateBench",
.mWorkerThreads = 4,
});

StoreOption* option = CreateStoreOption("/tmp/InsertUpdateBench");
option->mCreateFromScratch = true;
option->mWorkerThreads = 4;
auto sLeanStore = std::make_unique<leanstore::LeanStore>(option);

storage::btree::TransactionKV* btree;

Expand Down
30 changes: 16 additions & 14 deletions benchmarks/ycsb/YcsbLeanStore.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "Ycsb.hpp"
#include "leanstore-c/StoreOption.h"
#include "leanstore/KVInterface.hpp"
#include "leanstore/LeanStore.hpp"
#include "leanstore/StoreOption.hpp"
#include "leanstore/btree/BasicKV.hpp"
#include "leanstore/btree/TransactionKV.hpp"
#include "leanstore/concurrency/CRManager.hpp"
Expand Down Expand Up @@ -38,16 +38,18 @@ class YcsbLeanStore : public YcsbExecutor {
public:
YcsbLeanStore(bool benchTransactionKv, bool createFromScratch)
: mBenchTransactionKv(benchTransactionKv) {
auto res = LeanStore::Open(StoreOption{
.mCreateFromScratch = createFromScratch,
.mStoreDir = FLAGS_ycsb_data_dir + "/leanstore",
.mWorkerThreads = FLAGS_ycsb_threads,
.mBufferPoolSize = FLAGS_ycsb_mem_kb * 1024,
.mEnableMetrics = true,
.mMetricsPort = 8080,
});
auto dataDirStr = FLAGS_ycsb_data_dir + std::string("/leanstore");
StoreOption* option = CreateStoreOption(dataDirStr.c_str());
option->mCreateFromScratch = createFromScratch;
option->mWorkerThreads = FLAGS_ycsb_threads;
option->mBufferPoolSize = FLAGS_ycsb_mem_kb * 1024;
option->mEnableMetrics = true;
option->mMetricsPort = 8080;

auto res = LeanStore::Open(option);
if (!res) {
std::cerr << "Failed to open leanstore: " << res.error().ToString() << std::endl;
DestroyStoreOption(option);
exit(res.error().Code());
}

Expand Down Expand Up @@ -112,7 +114,7 @@ class YcsbLeanStore : public YcsbExecutor {
std::cout << summary << std::endl;
});

auto numWorkers = mStore->mStoreOption.mWorkerThreads;
auto numWorkers = mStore->mStoreOption->mWorkerThreads;
auto avg = FLAGS_ycsb_record_count / numWorkers;
auto rem = FLAGS_ycsb_record_count % numWorkers;
for (auto workerId = 0u, begin = 0u; workerId < numWorkers;) {
Expand Down Expand Up @@ -151,8 +153,8 @@ class YcsbLeanStore : public YcsbExecutor {
auto zipfRandom =
utils::ScrambledZipfGenerator(0, FLAGS_ycsb_record_count, FLAGS_ycsb_zipf_factor);
std::atomic<bool> keepRunning = true;
std::vector<std::atomic<uint64_t>> threadCommitted(mStore->mStoreOption.mWorkerThreads);
std::vector<std::atomic<uint64_t>> threadAborted(mStore->mStoreOption.mWorkerThreads);
std::vector<std::atomic<uint64_t>> threadCommitted(mStore->mStoreOption->mWorkerThreads);
std::vector<std::atomic<uint64_t>> threadAborted(mStore->mStoreOption->mWorkerThreads);
// init counters
for (auto& c : threadCommitted) {
c = 0;
Expand All @@ -161,7 +163,7 @@ class YcsbLeanStore : public YcsbExecutor {
a = 0;
}

for (uint64_t workerId = 0; workerId < mStore->mStoreOption.mWorkerThreads; workerId++) {
for (uint64_t workerId = 0; workerId < mStore->mStoreOption->mWorkerThreads; workerId++) {
mStore->ExecAsync(workerId, [&]() {
uint8_t key[FLAGS_ycsb_key_size];
std::string valRead;
Expand Down Expand Up @@ -236,7 +238,7 @@ class YcsbLeanStore : public YcsbExecutor {
a = 0;
}

printTpsSummary(1, FLAGS_ycsb_run_for_seconds, mStore->mStoreOption.mWorkerThreads,
printTpsSummary(1, FLAGS_ycsb_run_for_seconds, mStore->mStoreOption->mWorkerThreads,
threadCommitted, threadAborted);

// Shutdown threads
Expand Down
19 changes: 15 additions & 4 deletions examples/c/BasicKvExample.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
#include "leanstore-c/StoreOption.h"
#include "leanstore-c/leanstore-c.h"

#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "leanstore/leanstore-c.h"

int main() {
LeanStoreHandle* storeHandle =
CreateLeanStore(1, "/tmp/leanstore/examples/BasicKvExample", 2, 0, 1);
struct StoreOption* option = CreateStoreOption("/tmp/leanstore/examples/BasicKvExample");
option->mCreateFromScratch = 1;
option->mWorkerThreads = 2;
option->mEnableBulkInsert = 0;
option->mEnableEagerGc = 1;
LeanStoreHandle* storeHandle = CreateLeanStore(option);
BasicKvHandle* kvHandle = CreateBasicKV(storeHandle, 0, "testTree1");
if (kvHandle == NULL) {
DestroyStoreOption(option);
printf("create basic kv failed\n");
return -1;
}

// key-value pair 1
StringSlice keySlice;
Expand Down
18 changes: 10 additions & 8 deletions examples/cpp/BasicKvExample.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <leanstore-c/StoreOption.h>
#include <leanstore/LeanStore.hpp>
#include <leanstore/btree/BasicKV.hpp>
#include <leanstore/concurrency/Worker.hpp>
Expand All @@ -6,18 +7,19 @@
#include <memory>

using leanstore::LeanStore;
using leanstore::StoreOption;

int main() {
// create store option
StoreOption* option = CreateStoreOption("/tmp/leanstore/examples/BasicKvExample");
option->mCreateFromScratch = true;
option->mWorkerThreads = 2;
option->mEnableBulkInsert = false;
option->mEnableEagerGc = true;

// create store
auto res = LeanStore::Open(StoreOption{
.mCreateFromScratch = true,
.mStoreDir = "/tmp/leanstore/examples/BasicKvExample",
.mWorkerThreads = 2,
.mEnableBulkInsert = false,
.mEnableEagerGc = true,
});
auto res = LeanStore::Open(option);
if (!res) {
DestroyStoreOption(option);
std::cerr << "open store failed: " << res.error().ToString() << std::endl;
return 1;
}
Expand Down
Loading

0 comments on commit d098ac9

Please sign in to comment.