Skip to content
Open
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
23 changes: 11 additions & 12 deletions include/leanstore/btree/basic_kv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,31 @@ class LeanStore;

namespace leanstore {

class BasicKV : public KVInterface, public BTreeGeneric {
class BasicKV : public BTreeGeneric {
public:
BasicKV() {
tree_type_ = BTreeType::kBasicKV;
}

OpCode Lookup(Slice key, ValCallback val_callback) override;
OpCode Lookup(Slice key, ValCallback val_callback);

OpCode Insert(Slice key, Slice val) override;
OpCode Insert(Slice key, Slice val);

OpCode UpdatePartial(Slice key, MutValCallback update_call_back,
UpdateDesc& update_desc) override;
OpCode UpdatePartial(Slice key, MutValCallback update_call_back, UpdateDesc& update_desc);

OpCode Remove(Slice key) override;
OpCode Remove(Slice key);

OpCode ScanAsc(Slice start_key, ScanCallback callback) override;
OpCode ScanAsc(Slice start_key, ScanCallback callback);

OpCode ScanDesc(Slice start_key, ScanCallback callback) override;
OpCode ScanDesc(Slice start_key, ScanCallback callback);

OpCode PrefixLookup(Slice, PrefixLookupCallback callback) override;
OpCode PrefixLookup(Slice, PrefixLookupCallback callback);

OpCode PrefixLookupForPrev(Slice key, PrefixLookupCallback callback) override;
OpCode PrefixLookupForPrev(Slice key, PrefixLookupCallback callback);

OpCode RangeRemove(Slice start_key, Slice end_key, bool page_used) override;
OpCode RangeRemove(Slice start_key, Slice end_key, bool page_used);

uint64_t CountEntries() override;
uint64_t CountEntries();

bool IsRangeEmpty(Slice start_key, Slice end_key);

Expand Down
26 changes: 0 additions & 26 deletions include/leanstore/kv_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,30 +141,4 @@ using MutValCallback = std::function<void(MutableSlice val)>;
using ScanCallback = std::function<bool(Slice key, Slice val)>;
using PrefixLookupCallback = std::function<void(Slice key, Slice val)>;

class KVInterface {
public:
virtual OpCode Insert(Slice key, Slice val) = 0;

/// Update old value with a same sized new value.
/// NOTE: The value is updated via user provided callback.
virtual OpCode UpdatePartial(Slice key, MutValCallback update_call_back,
UpdateDesc& update_desc) = 0;

virtual OpCode Remove(Slice key) = 0;

virtual OpCode RangeRemove(Slice start_key, Slice end_key, bool page_wise) = 0;

virtual OpCode ScanAsc(Slice start_key, ScanCallback callback) = 0;

virtual OpCode ScanDesc(Slice start_key, ScanCallback callback) = 0;

virtual OpCode Lookup(Slice key, ValCallback val_callback) = 0;

virtual OpCode PrefixLookup(Slice, PrefixLookupCallback) = 0;

virtual OpCode PrefixLookupForPrev(Slice, PrefixLookupCallback) = 0;

virtual uint64_t CountEntries() = 0;
};

} // namespace leanstore
15 changes: 10 additions & 5 deletions include/leanstore/table/table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@

#include <memory>
#include <string>
#include <variant>

namespace leanstore {

class LeanStore;
class BTreeGeneric;
class BasicKV;
class TransactionKV;

using KVVariant = std::variant<BasicKV*, TransactionKV*>;

class TableCursor {
public:
TableCursor(KVInterface* kv_interface, const TableDefinition& def);
TableCursor(KVVariant kv, const TableDefinition& def);
~TableCursor();

bool SeekToFirst();
Expand All @@ -32,7 +37,7 @@ class TableCursor {
private:
bool Assign(Slice key, Slice val);

KVInterface* kv_interface_;
KVVariant kv_;
std::string current_key_;
std::string current_value_;
bool is_valid_ = false;
Expand All @@ -58,15 +63,15 @@ class Table {

std::unique_ptr<TableCursor> NewCursor();

Table(TableDefinition definition, KVInterface* kv_interface)
Table(TableDefinition definition, KVVariant kv)
: definition_(std::move(definition)),
kv_interface_(kv_interface),
kv_(kv),
codec_(definition_) {
}

private:
TableDefinition definition_;
KVInterface* kv_interface_;
KVVariant kv_;
TableCodec codec_;
};

Expand Down
14 changes: 6 additions & 8 deletions include/leanstore/tx/transaction_kv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "leanstore/buffer/guarded_buffer_frame.hpp"
#include "leanstore/c/types.h"
#include "leanstore/c/wal_record.h"
#include "leanstore/kv_interface.hpp"
#include "leanstore/tx/chained_tuple.hpp"
#include "leanstore/tx/tuple.hpp"
#include "leanstore/tx/tx_manager.hpp"
Expand Down Expand Up @@ -40,18 +39,17 @@ class TransactionKV : public BasicKV {
tree_type_ = BTreeType::kTransactionKV;
}

OpCode Lookup(Slice key, ValCallback val_callback) override;
OpCode Lookup(Slice key, ValCallback val_callback);

OpCode ScanAsc(Slice start_key, ScanCallback) override;
OpCode ScanAsc(Slice start_key, ScanCallback);

OpCode ScanDesc(Slice start_key, ScanCallback) override;
OpCode ScanDesc(Slice start_key, ScanCallback);

OpCode Insert(Slice key, Slice val) override;
OpCode Insert(Slice key, Slice val);

OpCode UpdatePartial(Slice key, MutValCallback update_call_back,
UpdateDesc& update_desc) override;
OpCode UpdatePartial(Slice key, MutValCallback update_call_back, UpdateDesc& update_desc);

OpCode Remove(Slice key) override;
OpCode Remove(Slice key);

void Init(LeanStore* store, lean_treeid_t tree_id, lean_btree_config config, BasicKV* graveyard);

Expand Down
8 changes: 7 additions & 1 deletion src/lean_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,13 @@ Result<BasicKV*> LeanStore::CreateBasicKv(const std::string& name, lean_btree_co
}

void LeanStore::GetBasicKV(const std::string& name, BasicKV** btree) {
*btree = dynamic_cast<BasicKV*>(tree_registry_->GetTree(name));
auto* tree = tree_registry_->GetTree(name);
auto* generic = dynamic_cast<BTreeGeneric*>(tree);
if (generic == nullptr || generic->tree_type_ != BTreeType::kBasicKV) {
*btree = nullptr;
return;
}
*btree = static_cast<BasicKV*>(generic);
}

void LeanStore::DropBasicKV(const std::string& name) {
Expand Down
Loading