diff options
author | Aaron Seigo <aseigo@kde.org> | 2014-12-05 09:17:46 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2014-12-05 09:17:46 +0100 |
commit | 767312e2063f4e58af3de0f27aba52de49e14295 (patch) | |
tree | 8375b55e3496ece33f59de486f3354d731b6bc1e | |
parent | 2b4e5743cca6a59e6e1a32b03863bf5ec4a4c30f (diff) | |
download | sink-767312e2063f4e58af3de0f27aba52de49e14295.tar.gz sink-767312e2063f4e58af3de0f27aba52de49e14295.zip |
major reorg that puts Storage (previously Database) into common
there is now a top-level tests dir, and a compile time switch for
lmdb vs kyotocabinet
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | common/CMakeLists.txt | 12 | ||||
-rw-r--r-- | common/storage.h (renamed from store/database.h) | 6 | ||||
-rw-r--r-- | common/storage_kyoto.cpp (renamed from store/database.cpp) | 32 | ||||
-rw-r--r-- | common/storage_lmdb.cpp | 266 | ||||
-rw-r--r-- | dummyresource/facade.cpp | 10 | ||||
-rw-r--r-- | dummyresource/facade.h | 4 | ||||
-rw-r--r-- | store/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/CMakeLists.txt (renamed from store/test/CMakeLists.txt) | 11 | ||||
-rw-r--r-- | tests/calendar.fbs (renamed from store/test/calendar.fbs) | 0 | ||||
-rw-r--r-- | tests/storagebenchmark.cpp (renamed from store/test/storagebenchmark.cpp) | 32 |
11 files changed, 325 insertions, 55 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 392ca39..e8b6f23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -47,10 +47,10 @@ add_subdirectory(client) | |||
47 | # the resource | 47 | # the resource |
48 | add_subdirectory(resource) | 48 | add_subdirectory(resource) |
49 | 49 | ||
50 | # the store | ||
51 | add_subdirectory(store) | ||
52 | |||
53 | # a simple dummy resource implementation | 50 | # a simple dummy resource implementation |
54 | add_subdirectory(dummyresource) | 51 | add_subdirectory(dummyresource) |
55 | 52 | ||
53 | # some tests | ||
54 | add_subdirectory(tests) | ||
55 | |||
56 | feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) | 56 | feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) |
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index d409828..9b3f777 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt | |||
@@ -2,10 +2,20 @@ project(akonadinextcommon) | |||
2 | generate_flatbuffers(commands/handshake | 2 | generate_flatbuffers(commands/handshake |
3 | commands/revisionupdate) | 3 | commands/revisionupdate) |
4 | 4 | ||
5 | if (STORAGE_KYOTO) | ||
6 | set(storage_SRCS storage_kyoto.cpp) | ||
7 | set(storage_LIBS kyotocabinet) | ||
8 | else (STORAGE_KYOTO) | ||
9 | set(storage_SRCS storage_lmdb.cpp) | ||
10 | set(storage_LIBS lmdb) | ||
11 | endif (STORAGE_KYOTO) | ||
12 | |||
5 | set(command_SRCS | 13 | set(command_SRCS |
6 | commands.cpp | 14 | commands.cpp |
7 | console.cpp | 15 | console.cpp |
8 | ${CMAKE_CURRENT_BINARY_DIR}/commands/handshake_generated.h) | 16 | ${storage_SRCS}) |
9 | 17 | ||
10 | add_library(${PROJECT_NAME} ${command_SRCS}) | 18 | add_library(${PROJECT_NAME} ${command_SRCS}) |
19 | SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX) | ||
11 | qt5_use_modules(${PROJECT_NAME} Widgets) | 20 | qt5_use_modules(${PROJECT_NAME} Widgets) |
21 | target_link_libraries(${PROJECT_NAME} ${storage_LIBS}) | ||
diff --git a/store/database.h b/common/storage.h index e752ff5..f7dbd89 100644 --- a/store/database.h +++ b/common/storage.h | |||
@@ -3,12 +3,12 @@ | |||
3 | #include <string> | 3 | #include <string> |
4 | #include <QString> | 4 | #include <QString> |
5 | 5 | ||
6 | class Database { | 6 | class Storage { |
7 | public: | 7 | public: |
8 | enum TransactionType { ReadOnly, ReadWrite }; | 8 | enum TransactionType { ReadOnly, ReadWrite }; |
9 | 9 | ||
10 | Database(const QString &storageRoot, const QString &name); | 10 | Storage(const QString &storageRoot, const QString &name); |
11 | ~Database(); | 11 | ~Storage(); |
12 | bool isInTransaction() const; | 12 | bool isInTransaction() const; |
13 | bool startTransaction(TransactionType type = ReadWrite); | 13 | bool startTransaction(TransactionType type = ReadWrite); |
14 | bool commitTransaction(); | 14 | bool commitTransaction(); |
diff --git a/store/database.cpp b/common/storage_kyoto.cpp index 542667a..05942c2 100644 --- a/store/database.cpp +++ b/common/storage_kyoto.cpp | |||
@@ -1,4 +1,4 @@ | |||
1 | #include "database.h" | 1 | #include "storage.h" |
2 | 2 | ||
3 | #include <iostream> | 3 | #include <iostream> |
4 | 4 | ||
@@ -12,7 +12,7 @@ | |||
12 | 12 | ||
13 | #include <kchashdb.h> | 13 | #include <kchashdb.h> |
14 | 14 | ||
15 | class Database::Private | 15 | class Storage::Private |
16 | { | 16 | { |
17 | public: | 17 | public: |
18 | Private(const QString &storageRoot, const QString &name); | 18 | Private(const QString &storageRoot, const QString &name); |
@@ -23,7 +23,7 @@ public: | |||
23 | bool inTransaction; | 23 | bool inTransaction; |
24 | }; | 24 | }; |
25 | 25 | ||
26 | Database::Private::Private(const QString &storageRoot, const QString &name) | 26 | Storage::Private::Private(const QString &storageRoot, const QString &name) |
27 | : inTransaction(false) | 27 | : inTransaction(false) |
28 | { | 28 | { |
29 | QDir dir; | 29 | QDir dir; |
@@ -36,29 +36,29 @@ Database::Private::Private(const QString &storageRoot, const QString &name) | |||
36 | } | 36 | } |
37 | } | 37 | } |
38 | 38 | ||
39 | Database::Private::~Private() | 39 | Storage::Private::~Private() |
40 | { | 40 | { |
41 | if (dbOpen && inTransaction) { | 41 | if (dbOpen && inTransaction) { |
42 | db.end_transaction(false); | 42 | db.end_transaction(false); |
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 | ||
46 | Database::Database(const QString &storageRoot, const QString &name) | 46 | Storage::Storage(const QString &storageRoot, const QString &name) |
47 | : d(new Private(storageRoot, name)) | 47 | : d(new Private(storageRoot, name)) |
48 | { | 48 | { |
49 | } | 49 | } |
50 | 50 | ||
51 | Database::~Database() | 51 | Storage::~Storage() |
52 | { | 52 | { |
53 | delete d; | 53 | delete d; |
54 | } | 54 | } |
55 | 55 | ||
56 | bool Database::isInTransaction() const | 56 | bool Storage::isInTransaction() const |
57 | { | 57 | { |
58 | return d->inTransaction; | 58 | return d->inTransaction; |
59 | } | 59 | } |
60 | 60 | ||
61 | bool Database::startTransaction(TransactionType type) | 61 | bool Storage::startTransaction(TransactionType type) |
62 | { | 62 | { |
63 | if (!d->dbOpen) { | 63 | if (!d->dbOpen) { |
64 | return false; | 64 | return false; |
@@ -73,7 +73,7 @@ bool Database::startTransaction(TransactionType type) | |||
73 | return d->inTransaction; | 73 | return d->inTransaction; |
74 | } | 74 | } |
75 | 75 | ||
76 | bool Database::commitTransaction() | 76 | bool Storage::commitTransaction() |
77 | { | 77 | { |
78 | if (!d->dbOpen) { | 78 | if (!d->dbOpen) { |
79 | return false; | 79 | return false; |
@@ -88,7 +88,7 @@ bool Database::commitTransaction() | |||
88 | return success; | 88 | return success; |
89 | } | 89 | } |
90 | 90 | ||
91 | void Database::abortTransaction() | 91 | void Storage::abortTransaction() |
92 | { | 92 | { |
93 | if (!d->dbOpen || !d->inTransaction) { | 93 | if (!d->dbOpen || !d->inTransaction) { |
94 | return; | 94 | return; |
@@ -98,7 +98,7 @@ void Database::abortTransaction() | |||
98 | d->inTransaction = false; | 98 | d->inTransaction = false; |
99 | } | 99 | } |
100 | 100 | ||
101 | bool Database::write(const char *key, size_t keySize, const char *value, size_t valueSize) | 101 | bool Storage::write(const char *key, size_t keySize, const char *value, size_t valueSize) |
102 | { | 102 | { |
103 | if (!d->dbOpen) { | 103 | if (!d->dbOpen) { |
104 | return false; | 104 | return false; |
@@ -108,7 +108,7 @@ bool Database::write(const char *key, size_t keySize, const char *value, size_t | |||
108 | return success; | 108 | return success; |
109 | } | 109 | } |
110 | 110 | ||
111 | bool Database::write(const std::string &sKey, const std::string &sValue) | 111 | bool Storage::write(const std::string &sKey, const std::string &sValue) |
112 | { | 112 | { |
113 | if (!d->dbOpen) { | 113 | if (!d->dbOpen) { |
114 | return false; | 114 | return false; |
@@ -118,7 +118,7 @@ bool Database::write(const std::string &sKey, const std::string &sValue) | |||
118 | return success; | 118 | return success; |
119 | } | 119 | } |
120 | 120 | ||
121 | void Database::read(const std::string &sKey, const std::function<void(const std::string &value)> &resultHandler) | 121 | void Storage::read(const std::string &sKey, const std::function<void(const std::string &value)> &resultHandler) |
122 | { | 122 | { |
123 | if (!d->dbOpen) { | 123 | if (!d->dbOpen) { |
124 | return; | 124 | return; |
@@ -130,7 +130,7 @@ void Database::read(const std::string &sKey, const std::function<void(const std: | |||
130 | } | 130 | } |
131 | } | 131 | } |
132 | 132 | ||
133 | void Database::read(const std::string &sKey, const std::function<void(void *ptr, int size)> &resultHandler) | 133 | void Storage::read(const std::string &sKey, const std::function<void(void *ptr, int size)> &resultHandler) |
134 | { | 134 | { |
135 | if (!d->dbOpen) { | 135 | if (!d->dbOpen) { |
136 | return; | 136 | return; |
@@ -142,7 +142,7 @@ void Database::read(const std::string &sKey, const std::function<void(void *ptr, | |||
142 | delete[] valueBuffer; | 142 | delete[] valueBuffer; |
143 | } | 143 | } |
144 | 144 | ||
145 | qint64 Database::diskUsage() const | 145 | qint64 Storage::diskUsage() const |
146 | { | 146 | { |
147 | if (!d->dbOpen) { | 147 | if (!d->dbOpen) { |
148 | return 0; | 148 | return 0; |
@@ -152,7 +152,7 @@ qint64 Database::diskUsage() const | |||
152 | return info.size(); | 152 | return info.size(); |
153 | } | 153 | } |
154 | 154 | ||
155 | void Database::removeFromDisk() const | 155 | void Storage::removeFromDisk() const |
156 | { | 156 | { |
157 | if (!d->dbOpen) { | 157 | if (!d->dbOpen) { |
158 | return; | 158 | return; |
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp new file mode 100644 index 0000000..6c25448 --- /dev/null +++ b/common/storage_lmdb.cpp | |||
@@ -0,0 +1,266 @@ | |||
1 | #include "storage.h" | ||
2 | |||
3 | #include <iostream> | ||
4 | |||
5 | #include <QAtomicInt> | ||
6 | #include <QDebug> | ||
7 | #include <QDir> | ||
8 | #include <QReadWriteLock> | ||
9 | #include <QString> | ||
10 | #include <QTime> | ||
11 | |||
12 | #include <lmdb.h> | ||
13 | |||
14 | class Storage::Private | ||
15 | { | ||
16 | public: | ||
17 | Private(const QString &p); | ||
18 | ~Private(); | ||
19 | |||
20 | QString path; | ||
21 | MDB_dbi dbi; | ||
22 | MDB_env *env; | ||
23 | MDB_txn *transaction; | ||
24 | bool readTransaction; | ||
25 | bool firstOpen; | ||
26 | }; | ||
27 | |||
28 | Storage::Private::Private(const QString &p) | ||
29 | : path(p), | ||
30 | transaction(0), | ||
31 | readTransaction(false), | ||
32 | firstOpen(true) | ||
33 | { | ||
34 | QDir dir; | ||
35 | dir.mkdir(path); | ||
36 | |||
37 | //create file | ||
38 | if (mdb_env_create(&env)) { | ||
39 | // TODO: handle error | ||
40 | } else { | ||
41 | int rc = mdb_env_open(env, path.toStdString().data(), 0, 0664); | ||
42 | |||
43 | if (rc) { | ||
44 | std::cerr << "mdb_env_open: " << rc << " " << mdb_strerror(rc) << std::endl; | ||
45 | mdb_env_close(env); | ||
46 | env = 0; | ||
47 | } else { | ||
48 | const size_t dbSize = 10485760 * 100; //10MB * 100 | ||
49 | mdb_env_set_mapsize(env, dbSize); | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | |||
54 | Storage::Private::~Private() | ||
55 | { | ||
56 | if (transaction) { | ||
57 | mdb_txn_abort(transaction); | ||
58 | } | ||
59 | |||
60 | // it is still there and still unused, so we can shut it down | ||
61 | mdb_dbi_close(env, dbi); | ||
62 | mdb_env_close(env); | ||
63 | } | ||
64 | |||
65 | Storage::Storage(const QString &storageRoot, const QString &name) | ||
66 | : d(new Private(storageRoot + '/' + name)) | ||
67 | { | ||
68 | } | ||
69 | |||
70 | Storage::~Storage() | ||
71 | { | ||
72 | delete d; | ||
73 | } | ||
74 | |||
75 | bool Storage::isInTransaction() const | ||
76 | { | ||
77 | return d->transaction; | ||
78 | } | ||
79 | |||
80 | bool Storage::startTransaction(TransactionType type) | ||
81 | { | ||
82 | if (!d->env) { | ||
83 | return false; | ||
84 | } | ||
85 | |||
86 | bool requestedRead = type == ReadOnly; | ||
87 | if (d->transaction && (!d->readTransaction || requestedRead)) { | ||
88 | return true; | ||
89 | } | ||
90 | |||
91 | if (d->transaction) { | ||
92 | // we are about to turn a read transaction into a writable one | ||
93 | abortTransaction(); | ||
94 | } | ||
95 | |||
96 | if (d->firstOpen && requestedRead) { | ||
97 | //A write transaction is at least required the first time | ||
98 | mdb_txn_begin(d->env, nullptr, 0, &d->transaction); | ||
99 | //Open the database | ||
100 | //With this we could open multiple named databases if we wanted to | ||
101 | mdb_dbi_open(d->transaction, nullptr, 0, &d->dbi); | ||
102 | mdb_txn_abort(d->transaction); | ||
103 | } | ||
104 | |||
105 | int rc; | ||
106 | rc = mdb_txn_begin(d->env, NULL, requestedRead ? MDB_RDONLY : 0, &d->transaction); | ||
107 | if (!rc) { | ||
108 | rc = mdb_dbi_open(d->transaction, NULL, 0, &d->dbi); | ||
109 | } | ||
110 | |||
111 | d->firstOpen = false; | ||
112 | return !rc; | ||
113 | } | ||
114 | |||
115 | bool Storage::commitTransaction() | ||
116 | { | ||
117 | if (!d->env) { | ||
118 | return false; | ||
119 | } | ||
120 | |||
121 | if (!d->transaction) { | ||
122 | return false; | ||
123 | } | ||
124 | |||
125 | int rc; | ||
126 | rc = mdb_txn_commit(d->transaction); | ||
127 | d->transaction = 0; | ||
128 | |||
129 | if (rc) { | ||
130 | std::cerr << "mdb_txn_commit: " << rc << " " << mdb_strerror(rc) << std::endl; | ||
131 | } | ||
132 | |||
133 | return !rc; | ||
134 | } | ||
135 | |||
136 | void Storage::abortTransaction() | ||
137 | { | ||
138 | if (!d->env || !d->transaction) { | ||
139 | return; | ||
140 | } | ||
141 | |||
142 | mdb_txn_abort(d->transaction); | ||
143 | d->transaction = 0; | ||
144 | } | ||
145 | |||
146 | bool Storage::write(const std::string &sKey, const std::string &sValue) | ||
147 | { | ||
148 | if (!d->env) { | ||
149 | return false; | ||
150 | } | ||
151 | |||
152 | const bool implicitTransaction = !d->transaction || d->readTransaction; | ||
153 | if (implicitTransaction) { | ||
154 | // TODO: if this fails, still try the write below? | ||
155 | if (!startTransaction()) { | ||
156 | return false; | ||
157 | } | ||
158 | } | ||
159 | |||
160 | int rc; | ||
161 | MDB_val key, data; | ||
162 | key.mv_size = sKey.size(); | ||
163 | key.mv_data = (void*)sKey.data(); | ||
164 | data.mv_size = sValue.size(); | ||
165 | data.mv_data = (void*)sValue.data(); | ||
166 | rc = mdb_put(d->transaction, d->dbi, &key, &data, 0); | ||
167 | |||
168 | if (rc) { | ||
169 | std::cerr << "mdb_put: " << rc << " " << mdb_strerror(rc) << std::endl; | ||
170 | } | ||
171 | |||
172 | if (implicitTransaction) { | ||
173 | if (rc) { | ||
174 | abortTransaction(); | ||
175 | } else { | ||
176 | rc = commitTransaction(); | ||
177 | } | ||
178 | } | ||
179 | |||
180 | return !rc; | ||
181 | } | ||
182 | |||
183 | void Storage::read(const std::string &sKey, const std::function<void(const std::string &value)> &resultHandler) | ||
184 | { | ||
185 | read(sKey, | ||
186 | [&](void *ptr, int size) { | ||
187 | const std::string resultValue(static_cast<char*>(ptr), size); | ||
188 | resultHandler(resultValue); | ||
189 | }); | ||
190 | // std::cout << "key: " << resultKey << " data: " << resultValue << std::endl; | ||
191 | } | ||
192 | |||
193 | void Storage::read(const std::string &sKey, const std::function<void(void *ptr, int size)> &resultHandler) | ||
194 | { | ||
195 | if (!d->env) { | ||
196 | return; | ||
197 | } | ||
198 | |||
199 | int rc; | ||
200 | MDB_val key; | ||
201 | MDB_val data; | ||
202 | MDB_cursor *cursor; | ||
203 | |||
204 | key.mv_size = sKey.size(); | ||
205 | key.mv_data = (void*)sKey.data(); | ||
206 | |||
207 | const bool implicitTransaction = !d->transaction; | ||
208 | if (implicitTransaction) { | ||
209 | // TODO: if this fails, still try the write below? | ||
210 | if (!startTransaction(ReadOnly)) { | ||
211 | return; | ||
212 | } | ||
213 | } | ||
214 | |||
215 | rc = mdb_cursor_open(d->transaction, d->dbi, &cursor); | ||
216 | if (rc) { | ||
217 | std::cerr << "mdb_cursor_get: " << rc << " " << mdb_strerror(rc) << std::endl; | ||
218 | return; | ||
219 | } | ||
220 | |||
221 | if (sKey.empty()) { | ||
222 | std::cout << "Iterating over all values of store!" << std::endl; | ||
223 | rc = mdb_cursor_get(cursor, &key, &data, MDB_FIRST); | ||
224 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { | ||
225 | resultHandler(key.mv_data, data.mv_size); | ||
226 | } | ||
227 | |||
228 | //We never find the last value | ||
229 | if (rc == MDB_NOTFOUND) { | ||
230 | rc = 0; | ||
231 | } | ||
232 | } else { | ||
233 | if ((rc = mdb_cursor_get(cursor, &key, &data, MDB_SET)) == 0) { | ||
234 | resultHandler(data.mv_data, data.mv_size); | ||
235 | } else { | ||
236 | std::cout << "couldn't find value " << sKey << " " << std::endl; | ||
237 | } | ||
238 | } | ||
239 | |||
240 | if (rc) { | ||
241 | std::cerr << "mdb_cursor_get: " << rc << " " << mdb_strerror(rc) << std::endl; | ||
242 | } | ||
243 | |||
244 | mdb_cursor_close(cursor); | ||
245 | |||
246 | /** | ||
247 | we don't abort the transaction since we need it for reading the values | ||
248 | if (implicitTransaction) { | ||
249 | abortTransaction(); | ||
250 | } | ||
251 | */ | ||
252 | } | ||
253 | |||
254 | qint64 Storage::diskUsage() const | ||
255 | { | ||
256 | QFileInfo info(d->path, "data.mdb"); | ||
257 | return info.size(); | ||
258 | } | ||
259 | |||
260 | void Storage::removeFromDisk() const | ||
261 | { | ||
262 | QDir dir(d->path); | ||
263 | dir.remove("data.mdb"); | ||
264 | dir.remove("lock.mdb"); | ||
265 | } | ||
266 | |||
diff --git a/dummyresource/facade.cpp b/dummyresource/facade.cpp index 7e9881b..9758c1b 100644 --- a/dummyresource/facade.cpp +++ b/dummyresource/facade.cpp | |||
@@ -11,7 +11,7 @@ using namespace flatbuffers; | |||
11 | DummyResourceFacade::DummyResourceFacade() | 11 | DummyResourceFacade::DummyResourceFacade() |
12 | : Akonadi2::StoreFacade<Akonadi2::Domain::Event>(), | 12 | : Akonadi2::StoreFacade<Akonadi2::Domain::Event>(), |
13 | mResourceAccess(new ResourceAccess("dummyresource")), | 13 | mResourceAccess(new ResourceAccess("dummyresource")), |
14 | mDatabase(new Database(Akonadi2::Store::storageLocation(), "dummyresource")) | 14 | mStorage(new Storage(Akonadi2::Store::storageLocation(), "dummyresource")) |
15 | { | 15 | { |
16 | // connect(mResourceAccess.data(), &ResourceAccess::ready, this, onReadyChanged); | 16 | // connect(mResourceAccess.data(), &ResourceAccess::ready, this, onReadyChanged); |
17 | } | 17 | } |
@@ -69,20 +69,20 @@ public: | |||
69 | DummyEvent const *buffer; | 69 | DummyEvent const *buffer; |
70 | 70 | ||
71 | //Keep query alive so values remain valid | 71 | //Keep query alive so values remain valid |
72 | QSharedPointer<Database> db; | 72 | QSharedPointer<Storage> storage; |
73 | }; | 73 | }; |
74 | 74 | ||
75 | void DummyResourceFacade::load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::Domain::Event::Ptr &)> &resultCallback) | 75 | void DummyResourceFacade::load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::Domain::Event::Ptr &)> &resultCallback) |
76 | { | 76 | { |
77 | qDebug() << "load called"; | 77 | qDebug() << "load called"; |
78 | //TODO only read values matching the query | 78 | //TODO only read values matching the query |
79 | auto db = QSharedPointer<Database>::create(Akonadi2::Store::storageLocation(), "dummyresource"); | 79 | auto storage = QSharedPointer<Storage>::create(Akonadi2::Store::storageLocation(), "dummyresource"); |
80 | db->read("", [resultCallback, db](void *data, int size) { | 80 | storage->read("", [resultCallback, storage](void *data, int size) { |
81 | //TODO read second buffer as well | 81 | //TODO read second buffer as well |
82 | auto eventBuffer = GetDummyEvent(data); | 82 | auto eventBuffer = GetDummyEvent(data); |
83 | auto event = QSharedPointer<DummyEventAdaptor>::create("dummyresource", "key", 0); | 83 | auto event = QSharedPointer<DummyEventAdaptor>::create("dummyresource", "key", 0); |
84 | event->buffer = eventBuffer; | 84 | event->buffer = eventBuffer; |
85 | event->db = db; | 85 | event->storage = storage; |
86 | resultCallback(event); | 86 | resultCallback(event); |
87 | }); | 87 | }); |
88 | } | 88 | } |
diff --git a/dummyresource/facade.h b/dummyresource/facade.h index 7a516de..310ef77 100644 --- a/dummyresource/facade.h +++ b/dummyresource/facade.h | |||
@@ -1,7 +1,7 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #include "client/clientapi.h" | 3 | #include "client/clientapi.h" |
4 | #include "store/database.h" | 4 | #include "common/storage.h" |
5 | 5 | ||
6 | class ResourceAccess; | 6 | class ResourceAccess; |
7 | 7 | ||
@@ -18,5 +18,5 @@ public: | |||
18 | 18 | ||
19 | private: | 19 | private: |
20 | QSharedPointer<ResourceAccess> mResourceAccess; | 20 | QSharedPointer<ResourceAccess> mResourceAccess; |
21 | QSharedPointer<Database> mDatabase; | 21 | QSharedPointer<Storage> mStorage; |
22 | }; | 22 | }; |
diff --git a/store/CMakeLists.txt b/store/CMakeLists.txt deleted file mode 100644 index 552439e..0000000 --- a/store/CMakeLists.txt +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | add_subdirectory(test) | ||
diff --git a/store/test/CMakeLists.txt b/tests/CMakeLists.txt index 1b9dc9e..23776a1 100644 --- a/store/test/CMakeLists.txt +++ b/tests/CMakeLists.txt | |||
@@ -1,20 +1,15 @@ | |||
1 | set(CMAKE_AUTOMOC ON) | 1 | set(CMAKE_AUTOMOC ON) |
2 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) | 2 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
3 | 3 | ||
4 | set(store_path "../") | ||
5 | set(store_SRCS | ||
6 | ${store_path}/database.cpp | ||
7 | ) | ||
8 | |||
9 | generate_flatbuffers(calendar) | 4 | generate_flatbuffers(calendar) |
10 | 5 | ||
11 | macro(manual_tests) | 6 | macro(manual_tests) |
12 | foreach(_testname ${ARGN}) | 7 | foreach(_testname ${ARGN}) |
13 | add_executable(${_testname} ${_testname}.cpp ${store_SRCS}) | 8 | add_executable(${_testname} ${_testname}.cpp) |
14 | qt5_use_modules(${_testname} Core Test) | 9 | qt5_use_modules(${_testname} Core Test) |
15 | target_link_libraries(${_testname} kyotocabinet) | 10 | target_link_libraries(${_testname} akonadinextcommon) |
16 | endforeach(_testname) | 11 | endforeach(_testname) |
17 | endmacro(auto_tests) | 12 | endmacro(manual_tests) |
18 | 13 | ||
19 | manual_tests ( | 14 | manual_tests ( |
20 | storagebenchmark | 15 | storagebenchmark |
diff --git a/store/test/calendar.fbs b/tests/calendar.fbs index 203ee43..203ee43 100644 --- a/store/test/calendar.fbs +++ b/tests/calendar.fbs | |||
diff --git a/store/test/storagebenchmark.cpp b/tests/storagebenchmark.cpp index d42dea8..15da9da 100644 --- a/store/test/storagebenchmark.cpp +++ b/tests/storagebenchmark.cpp | |||
@@ -10,7 +10,7 @@ | |||
10 | #include <QString> | 10 | #include <QString> |
11 | #include <QTime> | 11 | #include <QTime> |
12 | 12 | ||
13 | #include "store/database.h" | 13 | #include "common/storage.h" |
14 | 14 | ||
15 | using namespace Calendar; | 15 | using namespace Calendar; |
16 | using namespace flatbuffers; | 16 | using namespace flatbuffers; |
@@ -72,9 +72,9 @@ private Q_SLOTS: | |||
72 | QFETCH(bool, useDb); | 72 | QFETCH(bool, useDb); |
73 | QFETCH(int, count); | 73 | QFETCH(int, count); |
74 | 74 | ||
75 | Database *db = 0; | 75 | Storage *store = 0; |
76 | if (useDb) { | 76 | if (useDb) { |
77 | db = new Database(testDataPath, dbName); | 77 | store = new Storage(testDataPath, dbName); |
78 | } | 78 | } |
79 | 79 | ||
80 | std::ofstream myfile; | 80 | std::ofstream myfile; |
@@ -87,22 +87,22 @@ private Q_SLOTS: | |||
87 | { | 87 | { |
88 | auto event = createEvent(); | 88 | auto event = createEvent(); |
89 | for (int i = 0; i < count; i++) { | 89 | for (int i = 0; i < count; i++) { |
90 | if (db) { | 90 | if (store) { |
91 | if (i % 10000 == 0) { | 91 | if (i % 10000 == 0) { |
92 | if (i > 0) { | 92 | if (i > 0) { |
93 | db->commitTransaction(); | 93 | store->commitTransaction(); |
94 | } | 94 | } |
95 | db->startTransaction(); | 95 | store->startTransaction(); |
96 | } | 96 | } |
97 | 97 | ||
98 | db->write(keyPrefix + std::to_string(i), event); | 98 | store->write(keyPrefix + std::to_string(i), event); |
99 | } else { | 99 | } else { |
100 | myfile << event; | 100 | myfile << event; |
101 | } | 101 | } |
102 | } | 102 | } |
103 | 103 | ||
104 | if (db) { | 104 | if (store) { |
105 | db->commitTransaction(); | 105 | store->commitTransaction(); |
106 | } else { | 106 | } else { |
107 | myfile.close(); | 107 | myfile.close(); |
108 | } | 108 | } |
@@ -112,20 +112,20 @@ private Q_SLOTS: | |||
112 | 112 | ||
113 | { | 113 | { |
114 | for (int i = 0; i < count; i++) { | 114 | for (int i = 0; i < count; i++) { |
115 | if (db) { | 115 | if (store) { |
116 | db->read(keyPrefix + std::to_string(i), [](std::string value){}); | 116 | store->read(keyPrefix + std::to_string(i), [](std::string value){}); |
117 | } | 117 | } |
118 | } | 118 | } |
119 | } | 119 | } |
120 | const int readDuration = time.restart(); | 120 | const int readDuration = time.restart(); |
121 | 121 | ||
122 | if (db) { | 122 | if (store) { |
123 | qDebug() << "Reading took[ms]: " << readDuration; | 123 | qDebug() << "Reading took[ms]: " << readDuration; |
124 | } else { | 124 | } else { |
125 | qDebug() << "File reading is not implemented."; | 125 | qDebug() << "File reading is not implemented."; |
126 | } | 126 | } |
127 | 127 | ||
128 | delete db; | 128 | delete store; |
129 | } | 129 | } |
130 | 130 | ||
131 | void testBufferCreation() | 131 | void testBufferCreation() |
@@ -144,9 +144,9 @@ private Q_SLOTS: | |||
144 | 144 | ||
145 | void testSizes() | 145 | void testSizes() |
146 | { | 146 | { |
147 | Database db(testDataPath, dbName); | 147 | Storage store(testDataPath, dbName); |
148 | qDebug() << "Database size [kb]: " << db.diskUsage()/1024; | 148 | qDebug() << "Database size [kb]: " << store.diskUsage()/1024; |
149 | db.removeFromDisk(); | 149 | store.removeFromDisk(); |
150 | 150 | ||
151 | QFileInfo fileInfo(filePath); | 151 | QFileInfo fileInfo(filePath); |
152 | qDebug() << "File size [kb]: " << fileInfo.size()/1024; | 152 | qDebug() << "File size [kb]: " << fileInfo.size()/1024; |