benchmark silo added
[c11concurrency-benchmarks.git] / silo / benchmarks / kvdb_wrapper.h
1 #ifndef _KVDB_WRAPPER_H_
2 #define _KVDB_WRAPPER_H_
3
4 #include "abstract_db.h"
5 #include "../btree_choice.h"
6 #include "../rcu.h"
7
8 template <bool UseConcurrencyControl>
9 class kvdb_wrapper : public abstract_db {
10 public:
11
12   virtual ssize_t txn_max_batch_size() const OVERRIDE { return 100; }
13
14   virtual void do_txn_epoch_sync() const { }
15
16   virtual void do_txn_finish() const { }
17
18   virtual size_t
19   sizeof_txn_object(uint64_t txn_flags) const
20   {
21     return sizeof(scoped_rcu_region);
22   }
23
24   virtual void *
25   new_txn(uint64_t txn_flags, str_arena &arena, void *buf, TxnProfileHint hint)
26   {
27     return new (buf) scoped_rcu_region;
28   }
29
30   virtual bool
31   commit_txn(void *txn)
32   {
33     ((scoped_rcu_region *) txn)->~scoped_rcu_region();
34     return true;
35   }
36
37   virtual void abort_txn(void *txn) { ALWAYS_ASSERT(false); } // txn should never abort
38   virtual void print_txn_debug(void *txn) const { }
39
40   virtual abstract_ordered_index *
41   open_index(const std::string &name,
42              size_t value_size_hint,
43              bool mostly_append);
44
45   virtual void
46   close_index(abstract_ordered_index *idx)
47   {
48     delete idx;
49   }
50 };
51
52 template <bool UseConcurrencyControl>
53 class kvdb_ordered_index : public abstract_ordered_index {
54 public:
55   kvdb_ordered_index(const std::string &name)
56     : name(name) {}
57   virtual bool get(
58       void *txn,
59       const std::string &key,
60       std::string &value, size_t max_bytes_read);
61   virtual const char * put(
62       void *txn,
63       const std::string &key,
64       const std::string &value);
65   virtual const char *
66   insert(void *txn,
67          const std::string &key,
68          const std::string &value);
69   virtual void scan(
70       void *txn,
71       const std::string &start_key,
72       const std::string *end_key,
73       scan_callback &callback,
74       str_arena *arena);
75   virtual void rscan(
76       void *txn,
77       const std::string &start_key,
78       const std::string *end_key,
79       scan_callback &callback,
80       str_arena *arena);
81   virtual void remove(
82       void *txn,
83       const std::string &key);
84   virtual size_t size() const;
85   virtual std::map<std::string, uint64_t> clear();
86 private:
87   std::string name;
88   typedef
89     typename std::conditional<
90       UseConcurrencyControl,
91       concurrent_btree,
92       single_threaded_btree>::type
93     my_btree;
94   typedef typename my_btree::key_type key_type;
95   my_btree btr;
96 };
97
98 #endif /* _KVDB_WRAPPER_H_ */