1 #ifndef _ABSTRACT_DB_H_
2 #define _ABSTRACT_DB_H_
11 #include "abstract_ordered_index.h"
12 #include "../str_arena.h"
15 * Abstract interface for a DB. This is to facilitate writing
16 * benchmarks for different systems, making each system present
23 * both get() and put() can throw abstract_abort_exception. If thrown,
24 * abort_txn() must be called (calling commit_txn() will result in undefined
25 * behavior). Also if thrown, subsequently calling get()/put() will also
26 * result in undefined behavior)
28 class abstract_abort_exception {};
30 // ctor should open db
33 // dtor should close db
34 virtual ~abstract_db() {}
37 * an approximate max batch size for updates in a transaction.
39 * A return value of -1 indicates no maximum
41 virtual ssize_t txn_max_batch_size() const { return -1; }
43 virtual bool index_has_stable_put_memory() const { return false; }
45 // XXX(stephentu): laziness
47 sizeof_txn_object(uint64_t txn_flags) const { NDB_UNIMPLEMENTED("sizeof_txn_object"); };
50 * XXX(stephentu): hack
52 virtual void do_txn_epoch_sync() const {}
55 * XXX(stephentu): hack
57 virtual void do_txn_finish() const {}
59 /** loader should be used as a performance hint, not for correctness */
60 virtual void thread_init(bool loader) {}
62 virtual void thread_end() {}
64 // [ntxns_persisted, ntxns_committed, avg latency]
65 virtual std::tuple<uint64_t, uint64_t, double>
66 get_ntxn_persisted() const { return std::make_tuple(0, 0, 0.0); }
68 virtual void reset_ntxn_persisted() { }
74 HINT_KV_GET_PUT, // KV workloads over a single key
75 HINT_KV_RMW, // get/put over a single key
76 HINT_KV_SCAN, // KV scan workloads (~100 keys)
82 HINT_TPCC_ORDER_STATUS,
83 HINT_TPCC_ORDER_STATUS_READ_ONLY,
84 HINT_TPCC_STOCK_LEVEL,
85 HINT_TPCC_STOCK_LEVEL_READ_ONLY,
89 * Initializes a new txn object the space pointed to by buf
91 * Flags is only for the ndb protocol for now
93 * [buf, buf + sizeof_txn_object(txn_flags)) is a valid ptr
95 virtual void *new_txn(
99 TxnProfileHint hint = HINT_DEFAULT) = 0;
101 typedef std::map<std::string, uint64_t> counter_map;
102 typedef std::map<std::string, counter_map> txn_counter_map;
105 * Reports things like read/write set sizes
108 get_txn_counters(void *txn) const
110 return counter_map();
114 * Returns true on successful commit.
116 * On failure, can either throw abstract_abort_exception, or
117 * return false- caller should be prepared to deal with both cases
119 virtual bool commit_txn(void *txn) = 0;
124 virtual void abort_txn(void *txn) = 0;
126 virtual void print_txn_debug(void *txn) const {}
128 virtual abstract_ordered_index *
129 open_index(const std::string &name,
130 size_t value_size_hint,
131 bool mostly_append = false) = 0;
134 close_index(abstract_ordered_index *idx) = 0;
137 #endif /* _ABSTRACT_DB_H_ */