Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int main() {

### Creating and dropping column families
```cpp
db.CreateColumnFamily("my_column_family", (1024*1024)*64, TDB_DEFAULT_SKIP_LIST_MAX_LEVEL, TDB_DEFAULT_SKIP_LIST_PROBABILITY, true, TIDESDB_COMPRESSION_LZ4, true, TIDESDB_MEMTABLE_SKIPLIST);
db.CreateColumnFamily("my_column_family", (1024*1024)*64, TDB_DEFAULT_SKIP_LIST_MAX_LEVEL, TDB_DEFAULT_SKIP_LIST_PROBABILITY, true, TIDESDB_COMPRESSION_LZ4, true);
db.DropColumnFamily("my_column_family");
```

Expand Down Expand Up @@ -97,7 +97,7 @@ You can manually trigger a compaction.
db.CompactSSTables("my_column_family", 4); // Use 4 threads for compaction
```

Or you can start partial background merge compactions.
Or you can start incremental background merge compactions.
```cpp
db.StartBackgroundPartialMerges("my_column_family", std::chrono::seconds(60), 5); // Merge every 60 seconds if there are at least 5 SSTables
db.StartIncrementalMerges("my_column_family", std::chrono::seconds(60), 5); // Merge every 60 seconds if there are at least 5 SSTables
```
13 changes: 6 additions & 7 deletions test/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
std::string column_name = "my_db";
const int flush_threshold = (1024 * 1024) * 128;
const tidesdb_compression_algo_t compression_algo = TDB_COMPRESS_SNAPPY;
const float probability = TDB_USING_HT_PROBABILITY;
const int max_level = TDB_USING_HT_MAX_LEVEL;
const float probability = TDB_DEFAULT_SKIP_LIST_PROBABILITY;
const int max_level = TDB_DEFAULT_SKIP_LIST_MAX_LEVEL;
const bool bloom_filter = true;
const bool compressed = true;
const tidesdb_memtable_ds_t memtable_ds = TDB_MEMTABLE_HASH_TABLE;

TEST(TidesDB, Open_and_Close)
{
Expand All @@ -41,7 +40,7 @@ TEST(TidesDB, Create_and_Drop_Column_Family)
TidesDB::DB db;
EXPECT_EQ(db.Open("tmp"), 0);
EXPECT_EQ(db.CreateColumnFamily(column_name, flush_threshold, max_level, probability,
compressed, compression_algo, bloom_filter, memtable_ds),
compressed, compression_algo, bloom_filter),
0);
EXPECT_EQ(db.DropColumnFamily(column_name), 0);
EXPECT_EQ(db.Close(), 0);
Expand All @@ -53,7 +52,7 @@ TEST(TidesDB, Create_and_Column_Family_and_Put)
TidesDB::DB db;
EXPECT_EQ(db.Open("tmp"), 0);
EXPECT_EQ(db.CreateColumnFamily(column_name, flush_threshold, max_level, probability,
compressed, compression_algo, bloom_filter, memtable_ds),
compressed, compression_algo, bloom_filter),
0);
const std::vector<uint8_t> key = {'k', 'e', 'y'};
const std::vector<uint8_t> value = {'v', 'a', 'l', 'u', 'e'};
Expand All @@ -69,7 +68,7 @@ TEST(TidesDB, Put_and_Get)
std::vector<uint8_t> got_value;
EXPECT_EQ(db.Open("tmp"), 0);
EXPECT_EQ(db.CreateColumnFamily(column_name, flush_threshold, max_level, probability,
compressed, compression_algo, bloom_filter, memtable_ds),
compressed, compression_algo, bloom_filter),
0);

const std::vector<uint8_t> key = {'k', 'e', 'y'};
Expand All @@ -90,7 +89,7 @@ TEST(TidesDB, Put_and_Delete)

EXPECT_EQ(db.Open("tmp"), 0);
EXPECT_EQ(db.CreateColumnFamily(column_name, flush_threshold, max_level, probability,
compressed, compression_algo, true, memtable_ds),
compressed, compression_algo, true),
0);
const std::vector<uint8_t> key = {'k', 'e', 'y'};
const std::vector<uint8_t> value = {'v', 'a', 'l', 'u', 'e'};
Expand Down
35 changes: 25 additions & 10 deletions tidesdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ int DB::Close() const

int DB::CreateColumnFamily(const std::string &column_family_name, int flush_threshold,
int max_level, float probability, bool compressed,
tidesdb_compression_algo_t compress_algo, bool bloom_filter,
tidesdb_memtable_ds_t memtable_ds) const
tidesdb_compression_algo_t compress_algo, bool bloom_filter) const
{
tidesdb_err_t *err = tidesdb_create_column_family(
this->tdb, column_family_name.c_str(), flush_threshold, max_level, probability, compressed,
compress_algo, bloom_filter, memtable_ds);
tidesdb_err_t *err = tidesdb_create_column_family(this->tdb, column_family_name.c_str(),
flush_threshold, max_level, probability,
compressed, compress_algo, bloom_filter);
err_handler(err);
return 0;
}
Expand Down Expand Up @@ -116,17 +115,17 @@ int DB::CompactSSTables(const std::string &column_family_name, int max_threads)
return 0;
}

int DB::StartBackgroundPartialMerges(const std::string &column_family_name,
std::chrono::seconds seconds, int min_sstables) const
int DB::StartIncrementalMerges(const std::string &column_family_name, std::chrono::seconds seconds,
int min_sstables) const
{
auto duration = seconds.count();
if (duration > std::numeric_limits<int>::max() || duration < std::numeric_limits<int>::min())
{
return -1;
}

tidesdb_err_t *err = tidesdb_start_background_partial_merge(
this->tdb, column_family_name.c_str(), static_cast<int>(duration), min_sstables);
tidesdb_err_t *err = tidesdb_start_incremental_merge(this->tdb, column_family_name.c_str(),
static_cast<int>(duration), min_sstables);
err_handler(err);
return 0;
}
Expand All @@ -152,6 +151,22 @@ int Txn::Begin()
return 0;
}

int Txn::Get(const std::vector<uint8_t> *key, std::vector<uint8_t> *value) const
{
size_t key_size = key->size();
unsigned char *value_data = nullptr;
unsigned long value_size = 0;
tidesdb_err_t *err =
tidesdb_txn_get(this->txn, key->data(), key_size, &value_data, &value_size);
if (err == nullptr)
{
value->assign(value_data, value_data + value_size);
free(value_data);
}
err_handler(err);
return 0;
}

int Txn::Put(const std::vector<uint8_t> *key, const std::vector<uint8_t> *value,
std::chrono::seconds ttl) const
{
Expand Down Expand Up @@ -226,7 +241,7 @@ int Cursor::Prev() const
return 0;
}

int Cursor::Get(std::vector<uint8_t> &key, std::vector<uint8_t> &value)
int Cursor::Get(std::vector<uint8_t> &key, std::vector<uint8_t> &value)const
{
size_t key_size = key.size();
size_t value_size = value.size();
Expand Down
20 changes: 12 additions & 8 deletions tidesdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ class DB
[[nodiscard]] int CreateColumnFamily(const std::string &name, int flush_threshold,
int max_level, float probability, bool compressed,
tidesdb_compression_algo_t compress_algo,
bool bloom_filter,
tidesdb_memtable_ds_t memtable_ds) const;
bool bloom_filter) const;

/*
* DropColumnFamily
Expand Down Expand Up @@ -95,12 +94,11 @@ class DB
[[nodiscard]] int CompactSSTables(const std::string &column_family_name, int max_threads) const;

/*
* StartBackgroundPartialMerges
* starts background partial merges for a column family.
* StartIncrementalMerges
* starts background incremental merges for a column family.
*/
[[nodiscard]] int StartBackgroundPartialMerges(const std::string &column_family_name,
std::chrono::seconds seconds,
int min_sstables) const;
[[nodiscard]] int StartIncrementalMerges(const std::string &column_family_name,
std::chrono::seconds seconds, int min_sstables) const;

[[nodiscard]] tidesdb_t *GetTidesDB() const;

Expand Down Expand Up @@ -142,6 +140,12 @@ class Txn
* Get
* gets a value by key from a column family.
*/
int Get(const std::vector<uint8_t> *key, std::vector<uint8_t> *value) const;

/*
* Delete
* deletes a key-value pair from a column family.
*/
[[nodiscard]] int Delete(const std::vector<uint8_t> *key) const;

/*
Expand Down Expand Up @@ -197,7 +201,7 @@ class Cursor
* Get
* gets the current key-value pair in the column family cursor.
*/
[[nodiscard]] int Get(std::vector<uint8_t> &key, std::vector<uint8_t> &value);
[[nodiscard]] int Get(std::vector<uint8_t> &key, std::vector<uint8_t> &value)const;
};

}; // namespace TidesDB