Skip to content

Commit 1d11314

Browse files
authored
chore: expose StoreOption to c API (#115)
Signed-off-by: Jian Zhang <[email protected]>
1 parent d69d7dc commit 1d11314

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+514
-377
lines changed

benchmarks/micro-benchmarks/InsertUpdateBench.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
#include "leanstore-c/StoreOption.h"
12
#include "leanstore/LeanStore.hpp"
2-
#include "leanstore/StoreOption.hpp"
33
#include "leanstore/btree/BasicKV.hpp"
44
#include "leanstore/btree/TransactionKV.hpp"
55
#include "leanstore/buffer-manager/BufferManager.hpp"
@@ -21,11 +21,11 @@ static void BenchUpdateInsert(benchmark::State& state) {
2121
std::filesystem::path dirPath = "/tmp/InsertUpdateBench";
2222
std::filesystem::remove_all(dirPath);
2323
std::filesystem::create_directories(dirPath);
24-
auto sLeanStore = std::make_unique<leanstore::LeanStore>(StoreOption{
25-
.mCreateFromScratch = true,
26-
.mStoreDir = "/tmp/InsertUpdateBench",
27-
.mWorkerThreads = 4,
28-
});
24+
25+
StoreOption* option = CreateStoreOption("/tmp/InsertUpdateBench");
26+
option->mCreateFromScratch = true;
27+
option->mWorkerThreads = 4;
28+
auto sLeanStore = std::make_unique<leanstore::LeanStore>(option);
2929

3030
storage::btree::TransactionKV* btree;
3131

benchmarks/ycsb/YcsbLeanStore.hpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "Ycsb.hpp"
2+
#include "leanstore-c/StoreOption.h"
23
#include "leanstore/KVInterface.hpp"
34
#include "leanstore/LeanStore.hpp"
4-
#include "leanstore/StoreOption.hpp"
55
#include "leanstore/btree/BasicKV.hpp"
66
#include "leanstore/btree/TransactionKV.hpp"
77
#include "leanstore/concurrency/CRManager.hpp"
@@ -38,16 +38,18 @@ class YcsbLeanStore : public YcsbExecutor {
3838
public:
3939
YcsbLeanStore(bool benchTransactionKv, bool createFromScratch)
4040
: mBenchTransactionKv(benchTransactionKv) {
41-
auto res = LeanStore::Open(StoreOption{
42-
.mCreateFromScratch = createFromScratch,
43-
.mStoreDir = FLAGS_ycsb_data_dir + "/leanstore",
44-
.mWorkerThreads = FLAGS_ycsb_threads,
45-
.mBufferPoolSize = FLAGS_ycsb_mem_kb * 1024,
46-
.mEnableMetrics = true,
47-
.mMetricsPort = 8080,
48-
});
41+
auto dataDirStr = FLAGS_ycsb_data_dir + std::string("/leanstore");
42+
StoreOption* option = CreateStoreOption(dataDirStr.c_str());
43+
option->mCreateFromScratch = createFromScratch;
44+
option->mWorkerThreads = FLAGS_ycsb_threads;
45+
option->mBufferPoolSize = FLAGS_ycsb_mem_kb * 1024;
46+
option->mEnableMetrics = true;
47+
option->mMetricsPort = 8080;
48+
49+
auto res = LeanStore::Open(option);
4950
if (!res) {
5051
std::cerr << "Failed to open leanstore: " << res.error().ToString() << std::endl;
52+
DestroyStoreOption(option);
5153
exit(res.error().Code());
5254
}
5355

@@ -112,7 +114,7 @@ class YcsbLeanStore : public YcsbExecutor {
112114
std::cout << summary << std::endl;
113115
});
114116

115-
auto numWorkers = mStore->mStoreOption.mWorkerThreads;
117+
auto numWorkers = mStore->mStoreOption->mWorkerThreads;
116118
auto avg = FLAGS_ycsb_record_count / numWorkers;
117119
auto rem = FLAGS_ycsb_record_count % numWorkers;
118120
for (auto workerId = 0u, begin = 0u; workerId < numWorkers;) {
@@ -151,8 +153,8 @@ class YcsbLeanStore : public YcsbExecutor {
151153
auto zipfRandom =
152154
utils::ScrambledZipfGenerator(0, FLAGS_ycsb_record_count, FLAGS_ycsb_zipf_factor);
153155
std::atomic<bool> keepRunning = true;
154-
std::vector<std::atomic<uint64_t>> threadCommitted(mStore->mStoreOption.mWorkerThreads);
155-
std::vector<std::atomic<uint64_t>> threadAborted(mStore->mStoreOption.mWorkerThreads);
156+
std::vector<std::atomic<uint64_t>> threadCommitted(mStore->mStoreOption->mWorkerThreads);
157+
std::vector<std::atomic<uint64_t>> threadAborted(mStore->mStoreOption->mWorkerThreads);
156158
// init counters
157159
for (auto& c : threadCommitted) {
158160
c = 0;
@@ -161,7 +163,7 @@ class YcsbLeanStore : public YcsbExecutor {
161163
a = 0;
162164
}
163165

164-
for (uint64_t workerId = 0; workerId < mStore->mStoreOption.mWorkerThreads; workerId++) {
166+
for (uint64_t workerId = 0; workerId < mStore->mStoreOption->mWorkerThreads; workerId++) {
165167
mStore->ExecAsync(workerId, [&]() {
166168
uint8_t key[FLAGS_ycsb_key_size];
167169
std::string valRead;
@@ -236,7 +238,7 @@ class YcsbLeanStore : public YcsbExecutor {
236238
a = 0;
237239
}
238240

239-
printTpsSummary(1, FLAGS_ycsb_run_for_seconds, mStore->mStoreOption.mWorkerThreads,
241+
printTpsSummary(1, FLAGS_ycsb_run_for_seconds, mStore->mStoreOption->mWorkerThreads,
240242
threadCommitted, threadAborted);
241243

242244
// Shutdown threads

examples/c/BasicKvExample.c

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1+
#include "leanstore-c/StoreOption.h"
2+
#include "leanstore-c/leanstore-c.h"
3+
4+
#include <stddef.h>
15
#include <stdio.h>
26
#include <stdlib.h>
37
#include <string.h>
48

5-
#include "leanstore/leanstore-c.h"
6-
79
int main() {
8-
LeanStoreHandle* storeHandle =
9-
CreateLeanStore(1, "/tmp/leanstore/examples/BasicKvExample", 2, 0, 1);
10+
struct StoreOption* option = CreateStoreOption("/tmp/leanstore/examples/BasicKvExample");
11+
option->mCreateFromScratch = 1;
12+
option->mWorkerThreads = 2;
13+
option->mEnableBulkInsert = 0;
14+
option->mEnableEagerGc = 1;
15+
LeanStoreHandle* storeHandle = CreateLeanStore(option);
1016
BasicKvHandle* kvHandle = CreateBasicKV(storeHandle, 0, "testTree1");
17+
if (kvHandle == NULL) {
18+
DestroyStoreOption(option);
19+
printf("create basic kv failed\n");
20+
return -1;
21+
}
1122

1223
// key-value pair 1
1324
StringSlice keySlice;

examples/cpp/BasicKvExample.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <leanstore-c/StoreOption.h>
12
#include <leanstore/LeanStore.hpp>
23
#include <leanstore/btree/BasicKV.hpp>
34
#include <leanstore/concurrency/Worker.hpp>
@@ -6,18 +7,19 @@
67
#include <memory>
78

89
using leanstore::LeanStore;
9-
using leanstore::StoreOption;
1010

1111
int main() {
12+
// create store option
13+
StoreOption* option = CreateStoreOption("/tmp/leanstore/examples/BasicKvExample");
14+
option->mCreateFromScratch = true;
15+
option->mWorkerThreads = 2;
16+
option->mEnableBulkInsert = false;
17+
option->mEnableEagerGc = true;
18+
1219
// create store
13-
auto res = LeanStore::Open(StoreOption{
14-
.mCreateFromScratch = true,
15-
.mStoreDir = "/tmp/leanstore/examples/BasicKvExample",
16-
.mWorkerThreads = 2,
17-
.mEnableBulkInsert = false,
18-
.mEnableEagerGc = true,
19-
});
20+
auto res = LeanStore::Open(option);
2021
if (!res) {
22+
DestroyStoreOption(option);
2123
std::cerr << "open store failed: " << res.error().ToString() << std::endl;
2224
return 1;
2325
}

0 commit comments

Comments
 (0)