benchmark silo added
[c11concurrency-benchmarks.git] / silo / benchmarks / mysql_wrapper.h
1 #ifndef _MYSQL_WRAPPER_H_
2 #define _MYSQL_WRAPPER_H_
3
4 #include <string>
5 #include <mysql/mysql.h>
6
7 #include "abstract_db.h"
8 #include "../macros.h"
9
10 class mysql_wrapper : public abstract_db {
11   friend class mysql_ordered_index;
12 public:
13   mysql_wrapper(const std::string &dir, const std::string &db);
14   ~mysql_wrapper();
15
16   virtual void thread_init(bool loader);
17   virtual void thread_end();
18
19   virtual void *new_txn(
20       uint64_t txn_flags,
21       str_arena &arena,
22       void *buf,
23       TxnProfileHint hint);
24   virtual bool commit_txn(void *txn);
25   virtual void abort_txn(void *txn);
26
27   virtual abstract_ordered_index *
28   open_index(const std::string &name,
29              size_t value_size_hint,
30              bool mostly_append);
31
32   virtual void
33   close_index(abstract_ordered_index *idx);
34
35 private:
36   std::string db;
37   MYSQL *new_connection(const std::string &db);
38   static __thread MYSQL *tl_conn;
39 };
40
41 class mysql_ordered_index : public abstract_ordered_index {
42 public:
43   mysql_ordered_index(const std::string &name) : name(name) {}
44
45   virtual bool get(
46       void *txn,
47       const std::string &key,
48       std::string &value,
49       size_t max_bytes_read);
50
51   virtual const char * put(
52       void *txn,
53       const std::string &key,
54       const std::string &value);
55
56   virtual const char * insert(
57       void *txn,
58       const std::string &key,
59       const std::string &value);
60
61   virtual void scan(
62       void *txn,
63       const std::string &key,
64       const std::string *value,
65       scan_callback &callback,
66       str_arena *arena)
67   {
68     NDB_UNIMPLEMENTED("scan");
69   }
70
71   virtual void rscan(
72       void *txn,
73       const std::string &start_key,
74       const std::string *end_key,
75       scan_callback &callback,
76       str_arena *arena)
77   {
78     NDB_UNIMPLEMENTED("rscan");
79   }
80
81   virtual size_t
82   size() const
83   {
84     NDB_UNIMPLEMENTED("size");
85   }
86
87   virtual std::map<std::string, uint64_t>
88   clear()
89   {
90     NDB_UNIMPLEMENTED("clear");
91   }
92
93 private:
94   std::string name;
95 };
96
97 #endif /* _MYSQL_WRAPPER_H_ */