isomorfeus-ferret 0.17.2 → 0.17.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/isomorfeus_ferret_ext/benchmark.c +9 -20
- data/ext/isomorfeus_ferret_ext/benchmarks_all.h +1 -2
- data/ext/isomorfeus_ferret_ext/bm_hash.c +1 -2
- data/ext/isomorfeus_ferret_ext/brotli_dec_decode.c +4 -2
- data/ext/isomorfeus_ferret_ext/brotli_enc_encode.c +3 -2
- data/ext/isomorfeus_ferret_ext/frb_analysis.c +4 -5
- data/ext/isomorfeus_ferret_ext/frb_field_info.c +3 -4
- data/ext/isomorfeus_ferret_ext/frb_index.c +118 -125
- data/ext/isomorfeus_ferret_ext/frb_lazy_doc.c +14 -16
- data/ext/isomorfeus_ferret_ext/frb_search.c +31 -23
- data/ext/isomorfeus_ferret_ext/frb_store.c +27 -13
- data/ext/isomorfeus_ferret_ext/frb_utils.c +3 -6
- data/ext/isomorfeus_ferret_ext/frt_analysis.c +39 -46
- data/ext/isomorfeus_ferret_ext/frt_analysis.h +9 -9
- data/ext/isomorfeus_ferret_ext/frt_array.c +11 -22
- data/ext/isomorfeus_ferret_ext/frt_bitvector.h +3 -6
- data/ext/isomorfeus_ferret_ext/frt_doc_field.c +87 -0
- data/ext/isomorfeus_ferret_ext/frt_doc_field.h +26 -0
- data/ext/isomorfeus_ferret_ext/frt_document.c +4 -97
- data/ext/isomorfeus_ferret_ext/frt_document.h +2 -27
- data/ext/isomorfeus_ferret_ext/frt_except.c +8 -6
- data/ext/isomorfeus_ferret_ext/frt_except.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_field_index.c +13 -32
- data/ext/isomorfeus_ferret_ext/frt_field_index.h +0 -6
- data/ext/isomorfeus_ferret_ext/frt_field_info.c +69 -0
- data/ext/isomorfeus_ferret_ext/frt_field_info.h +49 -0
- data/ext/isomorfeus_ferret_ext/frt_field_infos.c +196 -0
- data/ext/isomorfeus_ferret_ext/frt_field_infos.h +35 -0
- data/ext/isomorfeus_ferret_ext/frt_global.c +10 -4
- data/ext/isomorfeus_ferret_ext/frt_global.h +11 -15
- data/ext/isomorfeus_ferret_ext/frt_hash.c +8 -8
- data/ext/isomorfeus_ferret_ext/frt_hash.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_hashset.c +20 -40
- data/ext/isomorfeus_ferret_ext/frt_hashset.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_helper.c +7 -15
- data/ext/isomorfeus_ferret_ext/frt_in_stream.c +35 -45
- data/ext/isomorfeus_ferret_ext/frt_in_stream.h +3 -2
- data/ext/isomorfeus_ferret_ext/frt_ind.c +20 -38
- data/ext/isomorfeus_ferret_ext/frt_index.c +292 -790
- data/ext/isomorfeus_ferret_ext/frt_index.h +1 -102
- data/ext/isomorfeus_ferret_ext/frt_lang.c +5 -10
- data/ext/isomorfeus_ferret_ext/frt_lazy_doc.c +3 -3
- data/ext/isomorfeus_ferret_ext/frt_lazy_doc.h +1 -1
- data/ext/isomorfeus_ferret_ext/frt_lazy_doc_field.c +18 -25
- data/ext/isomorfeus_ferret_ext/frt_lazy_doc_field.h +5 -5
- data/ext/isomorfeus_ferret_ext/frt_mdbx_store.c +102 -70
- data/ext/isomorfeus_ferret_ext/frt_mempool.c +8 -16
- data/ext/isomorfeus_ferret_ext/frt_multimapper.c +23 -46
- data/ext/isomorfeus_ferret_ext/frt_multimapper.h +4 -8
- data/ext/isomorfeus_ferret_ext/frt_out_stream.c +31 -43
- data/ext/isomorfeus_ferret_ext/frt_out_stream.h +2 -2
- data/ext/isomorfeus_ferret_ext/frt_posh.c +6 -819
- data/ext/isomorfeus_ferret_ext/frt_posh.h +0 -57
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.c +11 -22
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +85 -171
- data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +8 -16
- data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +1 -2
- data/ext/isomorfeus_ferret_ext/frt_q_parser.c +49 -98
- data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +52 -104
- data/ext/isomorfeus_ferret_ext/frt_q_range.c +6 -12
- data/ext/isomorfeus_ferret_ext/frt_q_span.c +113 -226
- data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +1 -2
- data/ext/isomorfeus_ferret_ext/frt_ram_store.c +134 -85
- data/ext/isomorfeus_ferret_ext/frt_search.c +82 -164
- data/ext/isomorfeus_ferret_ext/frt_similarity.c +11 -22
- data/ext/isomorfeus_ferret_ext/frt_similarity.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_store.c +13 -25
- data/ext/isomorfeus_ferret_ext/frt_store.h +86 -52
- data/ext/isomorfeus_ferret_ext/frt_term_vectors.c +8 -16
- data/ext/isomorfeus_ferret_ext/frt_win32.h +5 -10
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +12 -11
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +11 -13
- data/ext/isomorfeus_ferret_ext/lz4.c +422 -195
- data/ext/isomorfeus_ferret_ext/lz4.h +114 -46
- data/ext/isomorfeus_ferret_ext/lz4frame.c +421 -242
- data/ext/isomorfeus_ferret_ext/lz4frame.h +122 -53
- data/ext/isomorfeus_ferret_ext/lz4hc.c +127 -111
- data/ext/isomorfeus_ferret_ext/lz4hc.h +14 -14
- data/ext/isomorfeus_ferret_ext/lz4xxhash.h +1 -1
- data/ext/isomorfeus_ferret_ext/mdbx.c +3762 -2526
- data/ext/isomorfeus_ferret_ext/mdbx.h +115 -70
- data/ext/isomorfeus_ferret_ext/test.c +40 -87
- data/ext/isomorfeus_ferret_ext/test.h +3 -6
- data/ext/isomorfeus_ferret_ext/test_1710.c +11 -13
- data/ext/isomorfeus_ferret_ext/test_analysis.c +32 -64
- data/ext/isomorfeus_ferret_ext/test_array.c +6 -12
- data/ext/isomorfeus_ferret_ext/test_bitvector.c +12 -24
- data/ext/isomorfeus_ferret_ext/test_document.c +23 -33
- data/ext/isomorfeus_ferret_ext/test_except.c +10 -21
- data/ext/isomorfeus_ferret_ext/test_fields.c +62 -68
- data/ext/isomorfeus_ferret_ext/test_file_deleter.c +15 -23
- data/ext/isomorfeus_ferret_ext/test_filter.c +17 -27
- data/ext/isomorfeus_ferret_ext/test_global.c +14 -29
- data/ext/isomorfeus_ferret_ext/test_hash.c +19 -38
- data/ext/isomorfeus_ferret_ext/test_hashset.c +8 -16
- data/ext/isomorfeus_ferret_ext/test_helper.c +4 -8
- data/ext/isomorfeus_ferret_ext/test_highlighter.c +16 -28
- data/ext/isomorfeus_ferret_ext/test_index.c +277 -487
- data/ext/isomorfeus_ferret_ext/test_lang.c +7 -14
- data/ext/isomorfeus_ferret_ext/test_mdbx_store.c +2 -5
- data/ext/isomorfeus_ferret_ext/test_mempool.c +5 -10
- data/ext/isomorfeus_ferret_ext/test_multimapper.c +3 -6
- data/ext/isomorfeus_ferret_ext/test_priorityqueue.c +9 -18
- data/ext/isomorfeus_ferret_ext/test_q_const_score.c +4 -6
- data/ext/isomorfeus_ferret_ext/test_q_filtered.c +3 -4
- data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +9 -15
- data/ext/isomorfeus_ferret_ext/test_q_parser.c +8 -16
- data/ext/isomorfeus_ferret_ext/test_q_span.c +19 -35
- data/ext/isomorfeus_ferret_ext/test_ram_store.c +14 -13
- data/ext/isomorfeus_ferret_ext/test_search.c +60 -109
- data/ext/isomorfeus_ferret_ext/test_segments.c +8 -13
- data/ext/isomorfeus_ferret_ext/test_similarity.c +2 -4
- data/ext/isomorfeus_ferret_ext/test_sort.c +14 -24
- data/ext/isomorfeus_ferret_ext/test_store.c +96 -115
- data/ext/isomorfeus_ferret_ext/test_term.c +9 -15
- data/ext/isomorfeus_ferret_ext/test_term_vectors.c +9 -14
- data/ext/isomorfeus_ferret_ext/test_test.c +4 -8
- data/ext/isomorfeus_ferret_ext/test_threading.c +14 -20
- data/ext/isomorfeus_ferret_ext/testhelper.c +11 -21
- data/ext/isomorfeus_ferret_ext/testhelper.h +1 -1
- data/ext/isomorfeus_ferret_ext/tests_all.h +1 -2
- data/lib/isomorfeus/ferret/index/index.rb +1 -1
- data/lib/isomorfeus/ferret/version.rb +1 -1
- metadata +24 -4
@@ -10,8 +10,8 @@
|
|
10
10
|
|
11
11
|
extern void frt_micro_sleep(const int micro_seconds);
|
12
12
|
|
13
|
-
const char *dbi_name = "segmented_index";
|
14
13
|
const char *lock_s = "lock";
|
14
|
+
int keysize_max = 0;
|
15
15
|
|
16
16
|
// helper functions
|
17
17
|
|
@@ -76,12 +76,26 @@ static void mdbxs_abort_txn(FrtStore *store, MDBX_txn *txn, bool del_env_txn) {
|
|
76
76
|
// dbi
|
77
77
|
|
78
78
|
static void mdbxs_open_dbi(MDBX_txn *txn, const char *dbi_name, MDBX_dbi *dbi) {
|
79
|
-
int res = mdbx_dbi_open(txn, dbi_name, MDBX_DB_DEFAULTS
|
79
|
+
int res = mdbx_dbi_open(txn, dbi_name, MDBX_DB_DEFAULTS, dbi);
|
80
80
|
if (res != MDBX_SUCCESS) {
|
81
81
|
FRT_RAISE(FRT_IO_ERROR, "failed to open dbi '%s', error: %i\n", dbi_name, res);
|
82
82
|
}
|
83
83
|
}
|
84
84
|
|
85
|
+
static void mdbxs_create_dbi(MDBX_txn *txn, const char *dbi_name, MDBX_dbi *dbi) {
|
86
|
+
int res = mdbx_dbi_open(txn, dbi_name, MDBX_DB_DEFAULTS | MDBX_CREATE, dbi);
|
87
|
+
if (res != MDBX_SUCCESS) {
|
88
|
+
FRT_RAISE(FRT_IO_ERROR, "creating database '%s' failed, error: %i\n", dbi_name, res);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
static void mdbxs_drop_dbi(MDBX_txn *txn, const char *dbi_name, MDBX_dbi dbi) {
|
93
|
+
int res = mdbx_drop(txn, dbi, true);
|
94
|
+
if (res != MDBX_SUCCESS) {
|
95
|
+
FRT_RAISE(FRT_IO_ERROR, "dropping database '%s' failed, error: %i\n", dbi_name, res);
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
85
99
|
// cursor
|
86
100
|
|
87
101
|
static void mdbxs_open_cursor(MDBX_txn *txn, MDBX_dbi dbi, MDBX_cursor **cursor) {
|
@@ -108,7 +122,26 @@ static void mdbxs_put(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *val)
|
|
108
122
|
|
109
123
|
// store API
|
110
124
|
|
111
|
-
static void
|
125
|
+
static void mdbxs_create_folder(FrtStore *store, const char *folder_name) {
|
126
|
+
MDBX_txn *txn = NULL;
|
127
|
+
MDBX_dbi dbi;
|
128
|
+
|
129
|
+
bool del_env_txn = mdbxs_begin_txn(store, &txn);
|
130
|
+
mdbxs_create_dbi(txn, folder_name, &dbi);
|
131
|
+
mdbxs_commit_txn(store, txn, del_env_txn);
|
132
|
+
}
|
133
|
+
|
134
|
+
static void mdbxs_remove_folder(FrtStore *store, const char *folder_name) {
|
135
|
+
MDBX_txn *txn = NULL;
|
136
|
+
MDBX_dbi dbi;
|
137
|
+
|
138
|
+
bool del_env_txn = mdbxs_begin_txn(store, &txn);
|
139
|
+
mdbxs_open_dbi(txn, folder_name, &dbi);
|
140
|
+
mdbxs_drop_dbi(txn, folder_name, dbi);
|
141
|
+
mdbxs_commit_txn(store, txn, del_env_txn);
|
142
|
+
}
|
143
|
+
|
144
|
+
static void mdbxs_touch(FrtStore *store, const char *folder_name, const char *filename) {
|
112
145
|
int res = 0;
|
113
146
|
MDBX_txn *txn = NULL;
|
114
147
|
MDBX_dbi dbi;
|
@@ -120,7 +153,7 @@ static void mdbxs_touch(FrtStore *store, const char *filename) {
|
|
120
153
|
val.iov_len = 0;
|
121
154
|
|
122
155
|
bool del_env_txn = mdbxs_begin_txn(store, &txn);
|
123
|
-
mdbxs_open_dbi(txn,
|
156
|
+
mdbxs_open_dbi(txn, folder_name, &dbi);
|
124
157
|
res = mdbx_get(txn, dbi, &key, &val);
|
125
158
|
|
126
159
|
if (res == MDBX_NOTFOUND) {
|
@@ -136,7 +169,7 @@ static void mdbxs_touch(FrtStore *store, const char *filename) {
|
|
136
169
|
}
|
137
170
|
}
|
138
171
|
|
139
|
-
static int mdbxs_exists(FrtStore *store, const char *filename) {
|
172
|
+
static int mdbxs_exists(FrtStore *store, const char *folder_name, const char *filename) {
|
140
173
|
MDBX_txn *txn = NULL;
|
141
174
|
MDBX_dbi dbi;
|
142
175
|
|
@@ -147,7 +180,7 @@ static int mdbxs_exists(FrtStore *store, const char *filename) {
|
|
147
180
|
val.iov_len = 0;
|
148
181
|
|
149
182
|
bool del_env_txn = mdbxs_begin_ro_txn(store, &txn);
|
150
|
-
mdbxs_open_dbi(txn,
|
183
|
+
mdbxs_open_dbi(txn, folder_name, &dbi);
|
151
184
|
int res = mdbx_get(txn, dbi, &key, &val);
|
152
185
|
mdbxs_abort_txn(store, txn, del_env_txn);
|
153
186
|
|
@@ -155,7 +188,7 @@ static int mdbxs_exists(FrtStore *store, const char *filename) {
|
|
155
188
|
return false;
|
156
189
|
}
|
157
190
|
|
158
|
-
static int mdbxs_remove(FrtStore *store, const char *filename) {
|
191
|
+
static int mdbxs_remove(FrtStore *store, const char *folder_name, const char *filename) {
|
159
192
|
MDBX_txn *txn = NULL;
|
160
193
|
MDBX_dbi dbi;
|
161
194
|
|
@@ -164,14 +197,14 @@ static int mdbxs_remove(FrtStore *store, const char *filename) {
|
|
164
197
|
key.iov_len = strlen(filename);
|
165
198
|
|
166
199
|
bool del_env_txn = mdbxs_begin_txn(store, &txn);
|
167
|
-
mdbxs_open_dbi(txn,
|
200
|
+
mdbxs_open_dbi(txn, folder_name, &dbi);
|
168
201
|
mdbxs_del(txn, dbi, &key, NULL);
|
169
202
|
mdbxs_commit_txn(store, txn, del_env_txn);
|
170
203
|
|
171
204
|
return 0;
|
172
205
|
}
|
173
206
|
|
174
|
-
static void mdbxs_rename(FrtStore *store, const char *from, const char *to) {
|
207
|
+
static void mdbxs_rename(FrtStore *store, const char *folder_name, const char *from, const char *to) {
|
175
208
|
int res;
|
176
209
|
MDBX_txn *txn = NULL;
|
177
210
|
MDBX_dbi dbi;
|
@@ -183,7 +216,7 @@ static void mdbxs_rename(FrtStore *store, const char *from, const char *to) {
|
|
183
216
|
val.iov_len = 0;
|
184
217
|
|
185
218
|
bool del_env_txn = mdbxs_begin_txn(store, &txn);
|
186
|
-
mdbxs_open_dbi(txn,
|
219
|
+
mdbxs_open_dbi(txn, folder_name, &dbi);
|
187
220
|
res = mdbx_get(txn, dbi, &from_key, &val);
|
188
221
|
|
189
222
|
if (res == MDBX_SUCCESS) {
|
@@ -199,7 +232,7 @@ static void mdbxs_rename(FrtStore *store, const char *from, const char *to) {
|
|
199
232
|
}
|
200
233
|
}
|
201
234
|
|
202
|
-
static int mdbxs_count(FrtStore *store) {
|
235
|
+
static int mdbxs_count(FrtStore *store, const char *folder_name) {
|
203
236
|
MDBX_txn *txn = NULL;
|
204
237
|
MDBX_dbi dbi;
|
205
238
|
MDBX_stat stat;
|
@@ -207,7 +240,7 @@ static int mdbxs_count(FrtStore *store) {
|
|
207
240
|
int cnt = 0;
|
208
241
|
|
209
242
|
bool del_env_txn = mdbxs_begin_txn(store, &txn);
|
210
|
-
mdbxs_open_dbi(txn,
|
243
|
+
mdbxs_open_dbi(txn, folder_name, &dbi);
|
211
244
|
res = mdbx_dbi_stat(txn, dbi, &stat, sizeof(MDBX_stat));
|
212
245
|
cnt = stat.ms_entries;
|
213
246
|
mdbxs_abort_txn(store, txn, del_env_txn);
|
@@ -218,7 +251,7 @@ static int mdbxs_count(FrtStore *store) {
|
|
218
251
|
return cnt;
|
219
252
|
}
|
220
253
|
|
221
|
-
static void mdbxs_each(FrtStore *store, void (*func)(const char *fname, void *arg), void *arg) {
|
254
|
+
static void mdbxs_each(FrtStore *store, const char *folder_name, void (*func)(const char *fname, void *arg), void *arg) {
|
222
255
|
MDBX_txn *txn = NULL;
|
223
256
|
MDBX_dbi dbi;
|
224
257
|
MDBX_cursor *cursor = NULL;
|
@@ -230,7 +263,7 @@ static void mdbxs_each(FrtStore *store, void (*func)(const char *fname, void *ar
|
|
230
263
|
val.iov_len = 0;
|
231
264
|
|
232
265
|
bool del_env_txn = mdbxs_begin_txn(store, &txn);
|
233
|
-
mdbxs_open_dbi(txn,
|
266
|
+
mdbxs_open_dbi(txn, folder_name, &dbi);
|
234
267
|
mdbxs_open_cursor(txn, dbi, &cursor);
|
235
268
|
|
236
269
|
int op = MDBX_FIRST;
|
@@ -252,7 +285,7 @@ static void mdbxs_each(FrtStore *store, void (*func)(const char *fname, void *ar
|
|
252
285
|
mdbxs_commit_txn(store, txn, del_env_txn);
|
253
286
|
}
|
254
287
|
|
255
|
-
static void mdbxs_clear_locks(FrtStore *store) {
|
288
|
+
static void mdbxs_clear_locks(FrtStore *store, const char *folder_name) {
|
256
289
|
MDBX_txn *txn = NULL;
|
257
290
|
MDBX_dbi dbi;
|
258
291
|
MDBX_cursor *cursor = NULL;
|
@@ -264,7 +297,7 @@ static void mdbxs_clear_locks(FrtStore *store) {
|
|
264
297
|
val.iov_len = 0;
|
265
298
|
|
266
299
|
bool del_env_txn = mdbxs_begin_txn(store, &txn);
|
267
|
-
mdbxs_open_dbi(txn,
|
300
|
+
mdbxs_open_dbi(txn, folder_name, &dbi);
|
268
301
|
mdbxs_open_cursor(txn, dbi, &cursor);
|
269
302
|
|
270
303
|
int op = MDBX_FIRST;
|
@@ -303,7 +336,7 @@ static bool mdbxs_is_locked(FrtStore *store, MDBX_val *key, MDBX_txn *txn, MDBX_
|
|
303
336
|
return false;
|
304
337
|
}
|
305
338
|
|
306
|
-
static void mdbxs_clear(FrtStore *store) {
|
339
|
+
static void mdbxs_clear(FrtStore *store, const char *folder_name) {
|
307
340
|
MDBX_txn *txn = NULL;
|
308
341
|
MDBX_dbi dbi;
|
309
342
|
MDBX_cursor *cursor = NULL;
|
@@ -315,7 +348,7 @@ static void mdbxs_clear(FrtStore *store) {
|
|
315
348
|
val.iov_len = 0;
|
316
349
|
|
317
350
|
bool del_env_txn = mdbxs_begin_txn(store, &txn);
|
318
|
-
mdbxs_open_dbi(txn,
|
351
|
+
mdbxs_open_dbi(txn, folder_name, &dbi);
|
319
352
|
mdbxs_open_cursor(txn, dbi, &cursor);
|
320
353
|
|
321
354
|
int op = MDBX_FIRST;
|
@@ -333,7 +366,7 @@ static void mdbxs_clear(FrtStore *store) {
|
|
333
366
|
* Clear all files which belong to the index. Use mdbxs_clear to clear the
|
334
367
|
* directory regardless of the files origin.
|
335
368
|
*/
|
336
|
-
static void mdbxs_clear_all(FrtStore *store) {
|
369
|
+
static void mdbxs_clear_all(FrtStore *store, const char *folder_name) {
|
337
370
|
MDBX_txn *txn = NULL;
|
338
371
|
MDBX_dbi dbi;
|
339
372
|
MDBX_cursor *cursor = NULL;
|
@@ -345,7 +378,7 @@ static void mdbxs_clear_all(FrtStore *store) {
|
|
345
378
|
val.iov_len = 0;
|
346
379
|
|
347
380
|
bool del_env_txn = mdbxs_begin_txn(store, &txn);
|
348
|
-
mdbxs_open_dbi(txn,
|
381
|
+
mdbxs_open_dbi(txn, folder_name, &dbi);
|
349
382
|
mdbxs_open_cursor(txn, dbi, &cursor);
|
350
383
|
|
351
384
|
int op = MDBX_FIRST;
|
@@ -357,7 +390,7 @@ static void mdbxs_clear_all(FrtStore *store) {
|
|
357
390
|
mdbx_cursor_close(cursor);
|
358
391
|
mdbxs_commit_txn(store, txn, del_env_txn);
|
359
392
|
|
360
|
-
mdbxs_clear_locks(store);
|
393
|
+
mdbxs_clear_locks(store, folder_name);
|
361
394
|
}
|
362
395
|
|
363
396
|
/**
|
@@ -369,12 +402,12 @@ static void mdbxs_clear_all(FrtStore *store) {
|
|
369
402
|
static void mdbxs_destroy(FrtStore *store) {
|
370
403
|
FRT_TRY
|
371
404
|
if (store->dir.mdbx) {
|
372
|
-
mdbxs_clear_locks(store);
|
405
|
+
// mdbxs_clear_locks(store);
|
373
406
|
int res = mdbx_env_close(store->dir.mdbx->env);
|
374
407
|
if (res != MDBX_SUCCESS) {
|
375
408
|
fprintf(stderr, "closing env '%s' failed, error: %i\n", store->dir.mdbx->path, res);
|
376
409
|
}
|
377
|
-
free(store->dir.mdbx->path);
|
410
|
+
free((void *)store->dir.mdbx->path);
|
378
411
|
free(store->dir.mdbx);
|
379
412
|
store->dir.mdbx = NULL;
|
380
413
|
}
|
@@ -383,7 +416,7 @@ static void mdbxs_destroy(FrtStore *store) {
|
|
383
416
|
FRT_XENDTRY
|
384
417
|
}
|
385
418
|
|
386
|
-
static frt_off_t mdbxs_length(FrtStore *store, const char *filename) {
|
419
|
+
static frt_off_t mdbxs_length(FrtStore *store, const char *folder_name, const char *filename) {
|
387
420
|
frt_off_t len = 0;
|
388
421
|
MDBX_txn *txn = NULL;
|
389
422
|
MDBX_dbi dbi;
|
@@ -395,7 +428,7 @@ static frt_off_t mdbxs_length(FrtStore *store, const char *filename) {
|
|
395
428
|
val.iov_len = 0;
|
396
429
|
|
397
430
|
bool del_env_txn = mdbxs_begin_ro_txn(store, &txn);
|
398
|
-
mdbxs_open_dbi(txn,
|
431
|
+
mdbxs_open_dbi(txn, folder_name, &dbi);
|
399
432
|
int res = mdbx_get(txn, dbi, &key, &val);
|
400
433
|
if (res != MDBX_SUCCESS) {
|
401
434
|
mdbxs_abort_txn(store, txn, del_env_txn);
|
@@ -411,7 +444,7 @@ static void mdbxso_close_i(FrtOutStream *os) {
|
|
411
444
|
MDBX_dbi dbi;
|
412
445
|
|
413
446
|
bool del_env_txn = mdbxs_begin_txn(os->store, &txn);
|
414
|
-
mdbxs_open_dbi(txn,
|
447
|
+
mdbxs_open_dbi(txn, os->folder_name, &dbi);
|
415
448
|
|
416
449
|
FrtRAMFile *rf = os->file.rf;
|
417
450
|
|
@@ -457,22 +490,10 @@ static const struct FrtOutStreamMethods MDBXS_OUT_STREAM_METHODS = {
|
|
457
490
|
mdbxso_close_i
|
458
491
|
};
|
459
492
|
|
460
|
-
static FrtOutStream *mdbxs_new_output(FrtStore *store, const char *filename) {
|
461
|
-
MDBX_txn *txn = NULL;
|
462
|
-
MDBX_dbi dbi;
|
463
|
-
MDBX_val key, val;
|
464
|
-
key.iov_base = (char *)filename;
|
465
|
-
key.iov_len = strlen(filename);
|
466
|
-
val.iov_base = NULL;
|
467
|
-
val.iov_len = 0;
|
468
|
-
|
469
|
-
bool del_env_txn = mdbxs_begin_txn(store, &txn);
|
470
|
-
mdbxs_open_dbi(txn, dbi_name, &dbi);
|
471
|
-
mdbxs_put(txn, dbi, &key, &val);
|
472
|
-
mdbxs_commit_txn(store, txn, del_env_txn);
|
473
|
-
|
493
|
+
static FrtOutStream *mdbxs_new_output(FrtStore *store, const char *folder_name, const char *filename) {
|
474
494
|
FrtRAMFile *rf = rf_new(filename);
|
475
495
|
FrtOutStream *os = frt_os_new();
|
496
|
+
os->folder_name = frt_estrdup(folder_name);
|
476
497
|
os->pointer = 0;
|
477
498
|
os->file.rf = rf;
|
478
499
|
os->m = &MDBXS_OUT_STREAM_METHODS;
|
@@ -487,7 +508,7 @@ static const struct FrtInStreamMethods RAM_IN_STREAM_METHODS = {
|
|
487
508
|
rami_close_i
|
488
509
|
};
|
489
510
|
|
490
|
-
static FrtInStream *mdbxs_open_input(FrtStore *store, const char *filename) {
|
511
|
+
static FrtInStream *mdbxs_open_input(FrtStore *store, const char *folder_name, const char *filename) {
|
491
512
|
MDBX_txn *txn = NULL;
|
492
513
|
MDBX_dbi dbi;
|
493
514
|
MDBX_val key, val;
|
@@ -500,7 +521,7 @@ static FrtInStream *mdbxs_open_input(FrtStore *store, const char *filename) {
|
|
500
521
|
FrtInStream *is;
|
501
522
|
|
502
523
|
bool del_env_txn = mdbxs_begin_ro_txn(store, &txn);
|
503
|
-
mdbxs_open_dbi(txn,
|
524
|
+
mdbxs_open_dbi(txn, folder_name, &dbi);
|
504
525
|
if (mdbx_get(txn, dbi, &key, &val) != MDBX_SUCCESS) {
|
505
526
|
mdbxs_abort_txn(store, txn, del_env_txn);
|
506
527
|
FRT_RAISE(FRT_FILE_NOT_FOUND_ERROR, "tried to open '%s' but it doesn't exist", filename);
|
@@ -537,6 +558,7 @@ static FrtInStream *mdbxs_open_input(FrtStore *store, const char *filename) {
|
|
537
558
|
mdbxs_abort_txn(store, txn, del_env_txn);
|
538
559
|
|
539
560
|
is = frt_is_new();
|
561
|
+
is->folder_name = frt_estrdup(folder_name);
|
540
562
|
is->f->file.rf = rf;
|
541
563
|
is->f->ref_cnt = 1;
|
542
564
|
is->d.pointer = 0;
|
@@ -551,10 +573,10 @@ static int mdbxs_lock_obtain(FrtLock *lock) {
|
|
551
573
|
MDBX_txn *txn = NULL;
|
552
574
|
MDBX_dbi dbi;
|
553
575
|
bool del_env_txn = mdbxs_begin_txn(lock->store, &txn);
|
554
|
-
mdbxs_open_dbi(txn,
|
576
|
+
mdbxs_open_dbi(txn, lock->folder_name, &dbi);
|
555
577
|
|
556
578
|
MDBX_val key, val;
|
557
|
-
key.iov_base = lock->name;
|
579
|
+
key.iov_base = (void *)lock->name;
|
558
580
|
key.iov_len = strlen(lock->name);
|
559
581
|
int trys = LOCK_OBTAIN_TIMEOUT;
|
560
582
|
bool is_locked = mdbxs_is_locked(lock->store, &key, txn, dbi);
|
@@ -566,7 +588,7 @@ static int mdbxs_lock_obtain(FrtLock *lock) {
|
|
566
588
|
frt_micro_sleep(10000);
|
567
589
|
|
568
590
|
del_env_txn = mdbxs_begin_txn(lock->store, &txn);
|
569
|
-
mdbxs_open_dbi(txn,
|
591
|
+
mdbxs_open_dbi(txn, lock->folder_name, &dbi);
|
570
592
|
|
571
593
|
is_locked = mdbxs_is_locked(lock->store, &key, txn, dbi);
|
572
594
|
}
|
@@ -588,11 +610,11 @@ static int mdbxs_lock_is_locked(FrtLock *lock) {
|
|
588
610
|
MDBX_dbi dbi;
|
589
611
|
|
590
612
|
MDBX_val key;
|
591
|
-
key.iov_base = lock->name;
|
613
|
+
key.iov_base = (void *)lock->name;
|
592
614
|
key.iov_len = strlen(lock->name);
|
593
615
|
|
594
616
|
bool del_env_txn = mdbxs_begin_ro_txn(lock->store, &txn);
|
595
|
-
mdbxs_open_dbi(txn,
|
617
|
+
mdbxs_open_dbi(txn, lock->folder_name, &dbi);
|
596
618
|
res = mdbxs_is_locked(lock->store, &key, txn, dbi);
|
597
619
|
mdbxs_abort_txn(lock->store, txn, del_env_txn);
|
598
620
|
|
@@ -604,19 +626,20 @@ static void mdbxs_lock_release(FrtLock *lock) {
|
|
604
626
|
MDBX_dbi dbi;
|
605
627
|
|
606
628
|
MDBX_val key;
|
607
|
-
key.iov_base = lock->name;
|
629
|
+
key.iov_base = (void *)lock->name;
|
608
630
|
key.iov_len = strlen(lock->name);
|
609
631
|
|
610
632
|
bool del_env_txn = mdbxs_begin_txn(lock->store, &txn);
|
611
|
-
mdbxs_open_dbi(txn,
|
633
|
+
mdbxs_open_dbi(txn, lock->folder_name, &dbi);
|
612
634
|
mdbxs_del(txn, dbi, &key, NULL);
|
613
635
|
mdbxs_commit_txn(lock->store, txn, del_env_txn);
|
614
636
|
}
|
615
637
|
|
616
|
-
static FrtLock *mdbxs_open_lock_i(FrtStore *store, const char *lockname) {
|
638
|
+
static FrtLock *mdbxs_open_lock_i(FrtStore *store, const char *folder_name, const char *lockname) {
|
617
639
|
FrtLock *lock = FRT_ALLOC(FrtLock);
|
618
640
|
char lname[100];
|
619
641
|
snprintf(lname, 100, "%s%s.lck", FRT_LOCK_PREFIX, lockname);
|
642
|
+
lock->folder_name = frt_estrdup(folder_name);
|
620
643
|
lock->name = frt_estrdup(lname);
|
621
644
|
lock->store = store;
|
622
645
|
FRT_REF(store);
|
@@ -630,7 +653,7 @@ static FrtLock *mdbxs_open_lock_i(FrtStore *store, const char *lockname) {
|
|
630
653
|
static void mdbxs_close_lock_i(FrtLock *lock) {
|
631
654
|
mdbxs_lock_release(lock);
|
632
655
|
frt_store_close(lock->store);
|
633
|
-
free(lock->name);
|
656
|
+
free((void *)lock->name);
|
634
657
|
free(lock);
|
635
658
|
}
|
636
659
|
|
@@ -677,11 +700,12 @@ static FrtStore *mdbx_store_new(const char *pathname) {
|
|
677
700
|
|
678
701
|
MDBX_env *env = NULL;
|
679
702
|
int res;
|
703
|
+
|
680
704
|
res = mdbx_env_create(&env);
|
681
705
|
if (res != MDBX_SUCCESS) {
|
682
706
|
FRT_RAISE(FRT_IO_ERROR, "creating env '%s' failed, error: %i\n", pathname, res);
|
683
707
|
}
|
684
|
-
res = mdbx_env_set_maxdbs(env,
|
708
|
+
res = mdbx_env_set_maxdbs(env, 8);
|
685
709
|
if (res != MDBX_SUCCESS) {
|
686
710
|
mdbx_env_close(env);
|
687
711
|
FRT_RAISE(FRT_IO_ERROR, "setting maxdbs for '%s' failed, error: %i\n", pathname, res);
|
@@ -689,7 +713,7 @@ static FrtStore *mdbx_store_new(const char *pathname) {
|
|
689
713
|
res = mdbx_env_set_geometry(env, -1, -1, 40000000000, 4*1024*1024, 4*1024*1024, MDBX_MAX_PAGESIZE);
|
690
714
|
if (res != MDBX_SUCCESS) {
|
691
715
|
mdbx_env_close(env);
|
692
|
-
FRT_RAISE(FRT_IO_ERROR, "setting
|
716
|
+
FRT_RAISE(FRT_IO_ERROR, "setting geometry for '%s' failed, error: %i\n", pathname, res);
|
693
717
|
}
|
694
718
|
res = mdbx_env_open(env, pathname, MDBX_ENV_DEFAULTS, new_store->file_mode);
|
695
719
|
if (res != MDBX_SUCCESS) {
|
@@ -700,32 +724,40 @@ static FrtStore *mdbx_store_new(const char *pathname) {
|
|
700
724
|
FRT_RAISE(FRT_IO_ERROR, "opening env '%s' failed, error: %i\n", pathname, res);
|
701
725
|
}
|
702
726
|
}
|
727
|
+
|
703
728
|
MDBXInfo *mdbx = FRT_ALLOC(MDBXInfo);
|
704
729
|
mdbx->env = env;
|
705
730
|
mdbx->path = frt_estrdup(pathname);
|
706
|
-
|
707
|
-
|
708
|
-
new_store->
|
709
|
-
new_store->
|
710
|
-
new_store->
|
711
|
-
new_store->
|
712
|
-
new_store->
|
713
|
-
new_store->
|
714
|
-
new_store->
|
715
|
-
new_store->
|
716
|
-
new_store->
|
717
|
-
new_store->
|
718
|
-
new_store->
|
719
|
-
new_store->
|
720
|
-
new_store->
|
721
|
-
new_store->
|
722
|
-
new_store->
|
731
|
+
// mdbx->temp_store = frt_open_ram_store(NULL);
|
732
|
+
|
733
|
+
new_store->dir.mdbx = mdbx;
|
734
|
+
new_store->create_folder = &mdbxs_create_folder;
|
735
|
+
new_store->remove_folder = &mdbxs_remove_folder;
|
736
|
+
new_store->touch = &mdbxs_touch;
|
737
|
+
new_store->exists = &mdbxs_exists;
|
738
|
+
new_store->remove = &mdbxs_remove;
|
739
|
+
new_store->rename = &mdbxs_rename;
|
740
|
+
new_store->count = &mdbxs_count;
|
741
|
+
new_store->close_i = &mdbxs_close_i;
|
742
|
+
new_store->clear = &mdbxs_clear;
|
743
|
+
new_store->clear_all = &mdbxs_clear_all;
|
744
|
+
new_store->clear_locks = &mdbxs_clear_locks;
|
745
|
+
new_store->length = &mdbxs_length;
|
746
|
+
new_store->each = &mdbxs_each;
|
747
|
+
new_store->new_output = &mdbxs_new_output;
|
748
|
+
new_store->open_input = &mdbxs_open_input;
|
749
|
+
new_store->open_lock_i = &mdbxs_open_lock_i;
|
750
|
+
new_store->close_lock_i = &mdbxs_close_lock_i;
|
723
751
|
return new_store;
|
724
752
|
}
|
725
753
|
|
726
754
|
FrtStore *frt_open_mdbx_store(const char *pathname) {
|
727
755
|
FrtStore *store = NULL;
|
728
756
|
|
757
|
+
if (!keysize_max) {
|
758
|
+
keysize_max = mdbx_limits_keysize_max(mdbx_limits_pgsize_min(), MDBX_DB_DEFAULTS);
|
759
|
+
}
|
760
|
+
|
729
761
|
if (!mdbx_stores) {
|
730
762
|
mdbx_stores = frt_h_new_str(free, (frt_free_ft)mdbxs_destroy);
|
731
763
|
frt_register_for_cleanup(mdbx_stores, (frt_free_ft)frt_h_destroy);
|
@@ -2,8 +2,7 @@
|
|
2
2
|
#include "frt_mempool.h"
|
3
3
|
#include <string.h>
|
4
4
|
|
5
|
-
FrtMemoryPool *frt_mp_new_capa(int chuck_size, int init_buf_capa)
|
6
|
-
{
|
5
|
+
FrtMemoryPool *frt_mp_new_capa(int chuck_size, int init_buf_capa) {
|
7
6
|
FrtMemoryPool *mp = FRT_ALLOC(FrtMemoryPool);
|
8
7
|
mp->chunk_size = chuck_size;
|
9
8
|
mp->buf_capa = init_buf_capa;
|
@@ -20,8 +19,7 @@ FrtMemoryPool *frt_mp_new(void) {
|
|
20
19
|
return frt_mp_new_capa(FRT_MP_BUF_SIZE, FRT_MP_INIT_CAPA);
|
21
20
|
}
|
22
21
|
|
23
|
-
void *frt_mp_alloc(FrtMemoryPool *mp, int size)
|
24
|
-
{
|
22
|
+
void *frt_mp_alloc(FrtMemoryPool *mp, int size) {
|
25
23
|
char *p;
|
26
24
|
p = mp->curr_buffer + mp->pointer;
|
27
25
|
#if defined POSH_OS_SOLARIS || defined POSH_OS_SUNOS
|
@@ -45,38 +43,32 @@ void *frt_mp_alloc(FrtMemoryPool *mp, int size)
|
|
45
43
|
return p;
|
46
44
|
}
|
47
45
|
|
48
|
-
char *frt_mp_strdup(FrtMemoryPool *mp, const char *str)
|
49
|
-
{
|
46
|
+
char *frt_mp_strdup(FrtMemoryPool *mp, const char *str) {
|
50
47
|
int len = strlen(str) + 1;
|
51
48
|
return (char *)memcpy(frt_mp_alloc(mp, len), str, len);
|
52
49
|
}
|
53
50
|
|
54
|
-
char *frt_mp_strndup(FrtMemoryPool *mp, const char *str, int len)
|
55
|
-
{
|
51
|
+
char *frt_mp_strndup(FrtMemoryPool *mp, const char *str, int len) {
|
56
52
|
char *s = (char *)memcpy(frt_mp_alloc(mp, len + 1), str, len);
|
57
53
|
s[len] = '\0';
|
58
54
|
return s;
|
59
55
|
}
|
60
56
|
|
61
|
-
void *frt_mp_memdup(FrtMemoryPool *mp, const void *p, int len)
|
62
|
-
{
|
57
|
+
void *frt_mp_memdup(FrtMemoryPool *mp, const void *p, int len) {
|
63
58
|
return memcpy(frt_mp_alloc(mp, len), p, len);
|
64
59
|
}
|
65
60
|
|
66
|
-
int frt_mp_used(FrtMemoryPool *mp)
|
67
|
-
{
|
61
|
+
int frt_mp_used(FrtMemoryPool *mp) {
|
68
62
|
return mp->buf_pointer * mp->chunk_size + mp->pointer;
|
69
63
|
}
|
70
64
|
|
71
|
-
void frt_mp_reset(FrtMemoryPool *mp)
|
72
|
-
{
|
65
|
+
void frt_mp_reset(FrtMemoryPool *mp) {
|
73
66
|
mp->buf_pointer = 0;
|
74
67
|
mp->pointer = 0;
|
75
68
|
mp->curr_buffer = mp->buffers[0];
|
76
69
|
}
|
77
70
|
|
78
|
-
void frt_mp_destroy(FrtMemoryPool *mp)
|
79
|
-
{
|
71
|
+
void frt_mp_destroy(FrtMemoryPool *mp) {
|
80
72
|
int i;
|
81
73
|
for (i = 0; i < mp->buf_alloc; i++) {
|
82
74
|
free(mp->buffers[i]);
|