1 #ifndef _NDB_WRAPPER_H_
2 #define _NDB_WRAPPER_H_
4 #include "abstract_db.h"
5 #include "../txn_btree.h"
9 abstract_db::TxnProfileHint hint;
13 // XXX: doesn't check to make sure you are passing in an ndbtx
15 template <template <typename> class Transaction, typename Traits>
17 typedef Transaction<Traits> type;
18 inline ALWAYS_INLINE type *
19 operator()(struct ndbtxn *p) const
21 return reinterpret_cast<type *>(&p->buf[0]);
25 STATIC_COUNTER_DECL(scopedperf::tsc_ctr, ndb_get_probe0, ndb_get_probe0_cg)
26 STATIC_COUNTER_DECL(scopedperf::tsc_ctr, ndb_put_probe0, ndb_put_probe0_cg)
27 STATIC_COUNTER_DECL(scopedperf::tsc_ctr, ndb_insert_probe0, ndb_insert_probe0_cg)
28 STATIC_COUNTER_DECL(scopedperf::tsc_ctr, ndb_scan_probe0, ndb_scan_probe0_cg)
29 STATIC_COUNTER_DECL(scopedperf::tsc_ctr, ndb_remove_probe0, ndb_remove_probe0_cg)
30 STATIC_COUNTER_DECL(scopedperf::tsc_ctr, ndb_dtor_probe0, ndb_dtor_probe0_cg)
33 template <template <typename> class Transaction>
34 class ndb_wrapper : public abstract_db {
36 typedef private_::ndbtxn ndbtxn;
37 template <typename Traits>
38 using cast = private_::cast_base<Transaction, Traits>;
43 const std::vector<std::string> &logfiles,
44 const std::vector<std::vector<unsigned>> &assignments_given,
49 virtual ssize_t txn_max_batch_size() const OVERRIDE { return 100; }
52 do_txn_epoch_sync() const
54 txn_epoch_sync<Transaction>::sync();
60 txn_epoch_sync<Transaction>::finish();
64 thread_init(bool loader)
66 txn_epoch_sync<Transaction>::thread_init(loader);
72 txn_epoch_sync<Transaction>::thread_end();
75 virtual std::tuple<uint64_t, uint64_t, double>
76 get_ntxn_persisted() const
78 return txn_epoch_sync<Transaction>::compute_ntxn_persisted();
82 reset_ntxn_persisted()
84 txn_epoch_sync<Transaction>::reset_ntxn_persisted();
88 sizeof_txn_object(uint64_t txn_flags) const;
90 virtual void *new_txn(
95 virtual bool commit_txn(void *txn);
96 virtual void abort_txn(void *txn);
97 virtual void print_txn_debug(void *txn) const;
98 virtual std::map<std::string, uint64_t> get_txn_counters(void *txn) const;
100 virtual abstract_ordered_index *
101 open_index(const std::string &name,
102 size_t value_size_hint,
106 close_index(abstract_ordered_index *idx);
110 template <template <typename> class Transaction>
111 class ndb_ordered_index : public abstract_ordered_index {
113 typedef private_::ndbtxn ndbtxn;
114 template <typename Traits>
115 using cast = private_::cast_base<Transaction, Traits>;
118 ndb_ordered_index(const std::string &name, size_t value_size_hint, bool mostly_append);
121 const std::string &key,
122 std::string &value, size_t max_bytes_read);
123 virtual const char * put(
125 const std::string &key,
126 const std::string &value);
127 virtual const char * put(
130 std::string &&value);
133 const std::string &key,
134 const std::string &value);
138 std::string &&value);
141 const std::string &start_key,
142 const std::string *end_key,
143 scan_callback &callback,
147 const std::string &start_key,
148 const std::string *end_key,
149 scan_callback &callback,
153 const std::string &key);
157 virtual size_t size() const;
158 virtual std::map<std::string, uint64_t> clear();
161 txn_btree<Transaction> btr;
164 #endif /* _NDB_WRAPPER_H_ */