isomorfeus-ferret 0.14.4 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +56 -6
- data/ext/isomorfeus_ferret_ext/extconf.rb +19 -1
- data/ext/isomorfeus_ferret_ext/frb_analysis.c +0 -4
- data/ext/isomorfeus_ferret_ext/frb_index.c +170 -52
- data/ext/isomorfeus_ferret_ext/frb_lazy_doc.c +4 -0
- data/ext/isomorfeus_ferret_ext/frb_qparser.c +1 -6
- data/ext/isomorfeus_ferret_ext/frb_search.c +1 -6
- data/ext/isomorfeus_ferret_ext/frb_store.c +246 -61
- data/ext/isomorfeus_ferret_ext/frb_utils.c +0 -4
- data/ext/isomorfeus_ferret_ext/frt_compound_io.c +5 -5
- data/ext/isomorfeus_ferret_ext/frt_except.c +11 -11
- data/ext/isomorfeus_ferret_ext/frt_hash.c +32 -70
- data/ext/isomorfeus_ferret_ext/frt_ind.c +20 -20
- data/ext/isomorfeus_ferret_ext/frt_ind.h +1 -1
- data/ext/isomorfeus_ferret_ext/frt_index.c +84 -90
- data/ext/isomorfeus_ferret_ext/frt_index.h +11 -11
- data/ext/isomorfeus_ferret_ext/frt_mdbx_store.c +749 -0
- data/ext/isomorfeus_ferret_ext/frt_q_parser.c +4 -4
- data/ext/isomorfeus_ferret_ext/frt_ram_store.c +9 -9
- data/ext/isomorfeus_ferret_ext/frt_search.c +0 -3
- data/ext/isomorfeus_ferret_ext/frt_search.h +1 -1
- data/ext/isomorfeus_ferret_ext/frt_sort.c +2 -2
- data/ext/isomorfeus_ferret_ext/frt_store.c +6 -8
- data/ext/isomorfeus_ferret_ext/frt_store.h +37 -24
- data/ext/isomorfeus_ferret_ext/frt_threading.h +0 -16
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +2 -11
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +1 -1
- data/ext/isomorfeus_ferret_ext/mdbx.c +33675 -0
- data/ext/isomorfeus_ferret_ext/mdbx.h +5495 -0
- data/ext/isomorfeus_ferret_ext/test.c +9 -9
- data/ext/isomorfeus_ferret_ext/test_index.c +3 -3
- data/ext/isomorfeus_ferret_ext/{test_fs_store.c → test_mdbx_store.c} +4 -10
- data/ext/isomorfeus_ferret_ext/test_ram_store.c +1 -1
- data/ext/isomorfeus_ferret_ext/test_segments.c +1 -1
- data/ext/isomorfeus_ferret_ext/test_sort.c +2 -2
- data/ext/isomorfeus_ferret_ext/test_store.c +4 -8
- data/ext/isomorfeus_ferret_ext/test_threading.c +4 -4
- data/ext/isomorfeus_ferret_ext/tests_all.h +2 -3
- data/lib/isomorfeus/ferret/index/index.rb +8 -9
- data/lib/isomorfeus/ferret/version.rb +1 -1
- metadata +9 -7
- data/ext/isomorfeus_ferret_ext/frt_fs_store.c +0 -505
@@ -9,7 +9,7 @@ VALUE cLock;
|
|
9
9
|
VALUE cLockError;
|
10
10
|
VALUE cDirectory;
|
11
11
|
VALUE cRAMDirectory;
|
12
|
-
VALUE
|
12
|
+
VALUE cMDBXDirectory;
|
13
13
|
|
14
14
|
/****************************************************************************
|
15
15
|
* Lock Methods
|
@@ -78,6 +78,9 @@ const rb_data_type_t frb_lock_t = {
|
|
78
78
|
* Lock::LockError otherwise.
|
79
79
|
*/
|
80
80
|
static VALUE frb_lock_obtain(int argc, VALUE *argv, VALUE self) {
|
81
|
+
int ex_code = 0;
|
82
|
+
const char *msg = NULL;
|
83
|
+
|
81
84
|
VALUE rtimeout;
|
82
85
|
int timeout = 1;
|
83
86
|
FrtLock *lock;
|
@@ -90,17 +93,28 @@ static VALUE frb_lock_obtain(int argc, VALUE *argv, VALUE self) {
|
|
90
93
|
timeout = FIX2INT(rtimeout);
|
91
94
|
}
|
92
95
|
end_t = time(NULL) + timeout;
|
93
|
-
|
94
|
-
got_lock = true;
|
95
|
-
}
|
96
|
-
while (!got_lock && !got_timeout) {
|
97
|
-
frt_micro_sleep(10000);
|
96
|
+
FRT_TRY
|
98
97
|
if (lock->obtain(lock)) {
|
99
98
|
got_lock = true;
|
100
|
-
} else if (time(NULL) >= end_t) {
|
101
|
-
got_timeout = true;
|
102
99
|
}
|
100
|
+
while (!got_lock && !got_timeout) {
|
101
|
+
frt_micro_sleep(10000);
|
102
|
+
if (lock->obtain(lock)) {
|
103
|
+
got_lock = true;
|
104
|
+
} else if (time(NULL) >= end_t) {
|
105
|
+
got_timeout = true;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
FRT_XCATCHALL
|
109
|
+
ex_code = xcontext.excode;
|
110
|
+
msg = xcontext.msg;
|
111
|
+
FRT_HANDLED();
|
112
|
+
FRT_XENDTRY
|
113
|
+
|
114
|
+
if (ex_code && msg) {
|
115
|
+
frb_raise(ex_code, msg);
|
103
116
|
}
|
117
|
+
|
104
118
|
if (!got_lock) {
|
105
119
|
rb_raise(cLockError, "could not obtain lock: #%s", lock->name);
|
106
120
|
}
|
@@ -122,6 +136,8 @@ static VALUE frb_lock_obtain(int argc, VALUE *argv, VALUE self) {
|
|
122
136
|
* Lock::LockError otherwise.
|
123
137
|
*/
|
124
138
|
static VALUE frb_lock_while_locked(int argc, VALUE *argv, VALUE self) {
|
139
|
+
int ex_code = 0;
|
140
|
+
const char *msg = NULL;
|
125
141
|
VALUE rtimeout;
|
126
142
|
int timeout = 1;
|
127
143
|
FrtLock *lock;
|
@@ -134,22 +150,45 @@ static VALUE frb_lock_while_locked(int argc, VALUE *argv, VALUE self) {
|
|
134
150
|
timeout = FIX2INT(rtimeout);
|
135
151
|
}
|
136
152
|
end_t = time(NULL) + timeout;
|
137
|
-
|
138
|
-
got_lock = true;
|
139
|
-
}
|
140
|
-
while (!got_lock && !got_timeout) {
|
141
|
-
frt_micro_sleep(10000);
|
153
|
+
FRT_TRY
|
142
154
|
if (lock->obtain(lock)) {
|
143
155
|
got_lock = true;
|
144
|
-
} else if (time(NULL) >= end_t) {
|
145
|
-
got_timeout = true;
|
146
156
|
}
|
157
|
+
while (!got_lock && !got_timeout) {
|
158
|
+
frt_micro_sleep(10000);
|
159
|
+
if (lock->obtain(lock)) {
|
160
|
+
got_lock = true;
|
161
|
+
} else if (time(NULL) >= end_t) {
|
162
|
+
got_timeout = true;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
FRT_XCATCHALL
|
166
|
+
ex_code = xcontext.excode;
|
167
|
+
msg = xcontext.msg;
|
168
|
+
FRT_HANDLED();
|
169
|
+
FRT_XENDTRY
|
170
|
+
|
171
|
+
if (ex_code && msg) {
|
172
|
+
frb_raise(ex_code, msg);
|
147
173
|
}
|
174
|
+
|
148
175
|
if (!got_lock) {
|
149
176
|
rb_raise(cLockError, "could not obtain lock: #%s", lock->name);
|
150
177
|
}
|
178
|
+
|
151
179
|
rb_yield(Qnil);
|
152
|
-
|
180
|
+
|
181
|
+
FRT_TRY
|
182
|
+
lock->release(lock);
|
183
|
+
FRT_XCATCHALL
|
184
|
+
ex_code = xcontext.excode;
|
185
|
+
msg = xcontext.msg;
|
186
|
+
FRT_HANDLED();
|
187
|
+
FRT_XENDTRY
|
188
|
+
|
189
|
+
if (ex_code && msg) {
|
190
|
+
frb_raise(ex_code, msg);
|
191
|
+
}
|
153
192
|
return Qtrue;
|
154
193
|
}
|
155
194
|
|
@@ -160,9 +199,24 @@ static VALUE frb_lock_while_locked(int argc, VALUE *argv, VALUE self) {
|
|
160
199
|
* Returns true if the lock has been obtained.
|
161
200
|
*/
|
162
201
|
static VALUE frb_lock_is_locked(VALUE self) {
|
202
|
+
int ex_code = 0;
|
203
|
+
const char *msg = NULL;
|
163
204
|
FrtLock *lock;
|
205
|
+
bool res;
|
164
206
|
GET_LOCK(lock, self);
|
165
|
-
|
207
|
+
FRT_TRY
|
208
|
+
res = lock->is_locked(lock);
|
209
|
+
FRT_XCATCHALL
|
210
|
+
ex_code = xcontext.excode;
|
211
|
+
msg = xcontext.msg;
|
212
|
+
FRT_HANDLED();
|
213
|
+
FRT_XENDTRY
|
214
|
+
|
215
|
+
if (ex_code && msg) {
|
216
|
+
frb_raise(ex_code, msg);
|
217
|
+
}
|
218
|
+
|
219
|
+
return res ? Qtrue : Qfalse;
|
166
220
|
}
|
167
221
|
|
168
222
|
/*
|
@@ -173,9 +227,22 @@ static VALUE frb_lock_is_locked(VALUE self) {
|
|
173
227
|
* the lock.
|
174
228
|
*/
|
175
229
|
static VALUE frb_lock_release(VALUE self) {
|
230
|
+
int ex_code = 0;
|
231
|
+
const char *msg = NULL;
|
232
|
+
|
176
233
|
FrtLock *lock;
|
177
234
|
GET_LOCK(lock, self);
|
178
|
-
|
235
|
+
FRT_TRY
|
236
|
+
lock->release(lock);
|
237
|
+
FRT_XCATCHALL
|
238
|
+
ex_code = xcontext.excode;
|
239
|
+
msg = xcontext.msg;
|
240
|
+
FRT_HANDLED();
|
241
|
+
FRT_XENDTRY
|
242
|
+
|
243
|
+
if (ex_code && msg) {
|
244
|
+
frb_raise(ex_code, msg);
|
245
|
+
}
|
179
246
|
return self;
|
180
247
|
}
|
181
248
|
|
@@ -245,9 +312,25 @@ static VALUE frb_dir_close(VALUE self) {
|
|
245
312
|
* Return true if a file with the name +file_name+ exists in the directory.
|
246
313
|
*/
|
247
314
|
static VALUE frb_dir_exists(VALUE self, VALUE rfname) {
|
315
|
+
int ex_code = 0;
|
316
|
+
const char *msg = NULL;
|
248
317
|
FrtStore *store = DATA_PTR(self);
|
249
318
|
StringValue(rfname);
|
250
|
-
|
319
|
+
bool res;
|
320
|
+
|
321
|
+
FRT_TRY
|
322
|
+
res = store->exists(store, rs2s(rfname));
|
323
|
+
FRT_XCATCHALL
|
324
|
+
ex_code = xcontext.excode;
|
325
|
+
msg = xcontext.msg;
|
326
|
+
FRT_HANDLED();
|
327
|
+
FRT_XENDTRY
|
328
|
+
|
329
|
+
if (ex_code && msg) {
|
330
|
+
frb_raise(ex_code, msg);
|
331
|
+
}
|
332
|
+
|
333
|
+
return res ? Qtrue : Qfalse;
|
251
334
|
}
|
252
335
|
|
253
336
|
/*
|
@@ -257,9 +340,23 @@ static VALUE frb_dir_exists(VALUE self, VALUE rfname) {
|
|
257
340
|
* Create an empty file in the directory with the name +file_name+.
|
258
341
|
*/
|
259
342
|
static VALUE frb_dir_touch(VALUE self, VALUE rfname) {
|
343
|
+
int ex_code = 0;
|
344
|
+
const char *msg = NULL;
|
260
345
|
FrtStore *store = DATA_PTR(self);
|
261
346
|
StringValue(rfname);
|
262
|
-
|
347
|
+
|
348
|
+
FRT_TRY
|
349
|
+
store->touch(store, rs2s(rfname));
|
350
|
+
FRT_XCATCHALL
|
351
|
+
ex_code = xcontext.excode;
|
352
|
+
msg = xcontext.msg;
|
353
|
+
FRT_HANDLED();
|
354
|
+
FRT_XENDTRY
|
355
|
+
|
356
|
+
if (ex_code && msg) {
|
357
|
+
frb_raise(ex_code, msg);
|
358
|
+
}
|
359
|
+
|
263
360
|
return Qnil;
|
264
361
|
}
|
265
362
|
|
@@ -270,9 +367,24 @@ static VALUE frb_dir_touch(VALUE self, VALUE rfname) {
|
|
270
367
|
* Remove file +file_name+ from the directory. Returns true if successful.
|
271
368
|
*/
|
272
369
|
static VALUE frb_dir_delete(VALUE self, VALUE rfname) {
|
370
|
+
int ex_code = 0;
|
371
|
+
const char *msg = NULL;
|
273
372
|
FrtStore *store = DATA_PTR(self);
|
274
373
|
StringValue(rfname);
|
275
|
-
|
374
|
+
bool res;
|
375
|
+
FRT_TRY
|
376
|
+
res = (store->remove(store, rs2s(rfname)) == 0);
|
377
|
+
FRT_XCATCHALL
|
378
|
+
ex_code = xcontext.excode;
|
379
|
+
msg = xcontext.msg;
|
380
|
+
FRT_HANDLED();
|
381
|
+
FRT_XENDTRY
|
382
|
+
|
383
|
+
if (ex_code && msg) {
|
384
|
+
frb_raise(ex_code, msg);
|
385
|
+
}
|
386
|
+
|
387
|
+
return res ? Qtrue : Qfalse;
|
276
388
|
}
|
277
389
|
|
278
390
|
/*
|
@@ -282,8 +394,23 @@ static VALUE frb_dir_delete(VALUE self, VALUE rfname) {
|
|
282
394
|
* Return a count of the number of files in the directory.
|
283
395
|
*/
|
284
396
|
static VALUE frb_dir_file_count(VALUE self) {
|
397
|
+
int ex_code = 0;
|
398
|
+
const char *msg = NULL;
|
285
399
|
FrtStore *store = DATA_PTR(self);
|
286
|
-
|
400
|
+
int cnt = 0;
|
401
|
+
FRT_TRY
|
402
|
+
cnt = INT2FIX(store->count(store));
|
403
|
+
FRT_XCATCHALL
|
404
|
+
ex_code = xcontext.excode;
|
405
|
+
msg = xcontext.msg;
|
406
|
+
FRT_HANDLED();
|
407
|
+
FRT_XENDTRY
|
408
|
+
|
409
|
+
if (ex_code && msg) {
|
410
|
+
frb_raise(ex_code, msg);
|
411
|
+
}
|
412
|
+
|
413
|
+
return cnt;
|
287
414
|
}
|
288
415
|
|
289
416
|
/*
|
@@ -293,8 +420,22 @@ static VALUE frb_dir_file_count(VALUE self) {
|
|
293
420
|
* Delete all files in the directory. It gives you a clean slate.
|
294
421
|
*/
|
295
422
|
static VALUE frb_dir_refresh(VALUE self) {
|
423
|
+
int ex_code = 0;
|
424
|
+
const char *msg = NULL;
|
296
425
|
FrtStore *store = DATA_PTR(self);
|
297
|
-
|
426
|
+
|
427
|
+
FRT_TRY
|
428
|
+
store->clear_all(store);
|
429
|
+
FRT_XCATCHALL
|
430
|
+
ex_code = xcontext.excode;
|
431
|
+
msg = xcontext.msg;
|
432
|
+
FRT_HANDLED();
|
433
|
+
FRT_XENDTRY
|
434
|
+
|
435
|
+
if (ex_code && msg) {
|
436
|
+
frb_raise(ex_code, msg);
|
437
|
+
}
|
438
|
+
|
298
439
|
return self;
|
299
440
|
}
|
300
441
|
|
@@ -306,10 +447,24 @@ static VALUE frb_dir_refresh(VALUE self) {
|
|
306
447
|
* doesn't exist or there is some other type of IOError.
|
307
448
|
*/
|
308
449
|
static VALUE frb_dir_rename(VALUE self, VALUE rfrom, VALUE rto) {
|
450
|
+
int ex_code = 0;
|
451
|
+
const char *msg = NULL;
|
452
|
+
|
309
453
|
FrtStore *store = DATA_PTR(self);
|
310
454
|
StringValue(rfrom);
|
311
455
|
StringValue(rto);
|
312
|
-
|
456
|
+
FRT_TRY
|
457
|
+
store->rename(store, rs2s(rfrom), rs2s(rto));
|
458
|
+
FRT_XCATCHALL
|
459
|
+
ex_code = xcontext.excode;
|
460
|
+
msg = xcontext.msg;
|
461
|
+
FRT_HANDLED();
|
462
|
+
FRT_XENDTRY
|
463
|
+
|
464
|
+
if (ex_code && msg) {
|
465
|
+
frb_raise(ex_code, msg);
|
466
|
+
}
|
467
|
+
|
313
468
|
return self;
|
314
469
|
}
|
315
470
|
|
@@ -323,11 +478,25 @@ static VALUE frb_dir_rename(VALUE self, VALUE rfrom, VALUE rto) {
|
|
323
478
|
* reserved for lock files
|
324
479
|
*/
|
325
480
|
static VALUE frb_dir_make_lock(VALUE self, VALUE rlock_name) {
|
481
|
+
int ex_code = 0;
|
482
|
+
const char *msg = NULL;
|
483
|
+
|
326
484
|
VALUE rlock;
|
327
485
|
FrtLock *lock;
|
328
486
|
FrtStore *store = DATA_PTR(self);
|
329
487
|
StringValue(rlock_name);
|
330
|
-
|
488
|
+
FRT_TRY
|
489
|
+
lock = frt_open_lock(store, rs2s(rlock_name));
|
490
|
+
FRT_XCATCHALL
|
491
|
+
ex_code = xcontext.excode;
|
492
|
+
msg = xcontext.msg;
|
493
|
+
FRT_HANDLED();
|
494
|
+
FRT_XENDTRY
|
495
|
+
|
496
|
+
if (ex_code && msg) {
|
497
|
+
frb_raise(ex_code, msg);
|
498
|
+
}
|
499
|
+
|
331
500
|
rlock = TypedData_Wrap_Struct(cLock, &frb_lock_t, lock);
|
332
501
|
lock->rlock = rlock;
|
333
502
|
return rlock;
|
@@ -345,7 +514,7 @@ static VALUE frb_dir_make_lock(VALUE self, VALUE rlock_name) {
|
|
345
514
|
*
|
346
515
|
* Create a new RAMDirectory.
|
347
516
|
*
|
348
|
-
* You can optionally load another Directory (usually a
|
517
|
+
* You can optionally load another Directory (usually a MDBXDirectory) into
|
349
518
|
* memory. This may be useful to speed up search performance but usually the
|
350
519
|
* speedup won't be worth the trouble. Be sure to benchmark.
|
351
520
|
*
|
@@ -372,17 +541,17 @@ static VALUE frb_ramdir_init(int argc, VALUE *argv, VALUE self) {
|
|
372
541
|
|
373
542
|
/****************************************************************************
|
374
543
|
*
|
375
|
-
*
|
544
|
+
* MDBXDirectory Methods
|
376
545
|
*
|
377
546
|
****************************************************************************/
|
378
547
|
|
379
548
|
/*
|
380
549
|
* call-seq:
|
381
|
-
*
|
550
|
+
* MDBXDirectory.new(/path/to/env/, create = false)
|
382
551
|
*
|
383
|
-
* Create a new
|
552
|
+
* Create a new MDBXDirectory at +/path/to/env/+ which must be a valid path
|
384
553
|
* on your file system. If it doesn't exist it will be created. You can also
|
385
|
-
* specify the +create+ parameter. If +create+ is true the
|
554
|
+
* specify the +create+ parameter. If +create+ is true the MDBXDirectory will
|
386
555
|
* be refreshed as new. That is to say, any existing files in the directory
|
387
556
|
* will be deleted. The default value for +create+ is false.
|
388
557
|
*
|
@@ -390,31 +559,50 @@ static VALUE frb_ramdir_init(int argc, VALUE *argv, VALUE self) {
|
|
390
559
|
* create:: set to true if you want any existing files in the directory to be
|
391
560
|
* deleted
|
392
561
|
*/
|
393
|
-
static VALUE
|
394
|
-
VALUE self, rpath, rcreate;
|
562
|
+
static VALUE frb_mdbxdir_new(int argc, VALUE *argv, VALUE klass) {
|
563
|
+
VALUE self, rpath, mdbx_rpath, rcreate;
|
395
564
|
FrtStore *store;
|
396
565
|
bool create;
|
397
566
|
|
567
|
+
int ex_code = 0;
|
568
|
+
const char *msg = NULL;
|
569
|
+
|
398
570
|
rb_scan_args(argc, argv, "11", &rpath, &rcreate);
|
399
571
|
StringValue(rpath);
|
572
|
+
|
400
573
|
create = RTEST(rcreate);
|
401
574
|
if (create) {
|
402
575
|
frb_create_dir(rpath);
|
403
|
-
}
|
404
|
-
if (!rb_funcall(rb_cFile, id_is_directory, 1, rpath)) {
|
405
|
-
rb_raise(cFileNotFoundError, "No directory <%s> found. Use :create => true to create one.", rs2s(rpath));
|
406
|
-
}
|
407
|
-
store = frt_open_fs_store(rs2s(rpath));
|
408
|
-
if (create) store->clear_all(store);
|
409
|
-
self = store->rstore;
|
410
|
-
if (self == Qnil || DATA_PTR(self) == NULL) {
|
411
|
-
self = TypedData_Wrap_Struct(klass, &frb_store_t, store);
|
412
|
-
store->rstore = self;
|
413
|
-
rb_ivar_set(self, id_ref_cnt, INT2FIX(0));
|
414
576
|
} else {
|
415
|
-
|
416
|
-
|
577
|
+
mdbx_rpath = rb_str_dup(rpath);
|
578
|
+
rb_str_cat_cstr(mdbx_rpath, "/mdbx.dat");
|
579
|
+
if (!rb_funcall(rb_cFile, id_exist, 1, mdbx_rpath)) {
|
580
|
+
rb_raise(cFileNotFoundError, "No database at <%s> found. Use :create => true to create one.", rs2s(rpath));
|
581
|
+
}
|
417
582
|
}
|
583
|
+
|
584
|
+
FRT_TRY
|
585
|
+
store = frt_open_mdbx_store(rs2s(rpath));
|
586
|
+
if (create) store->clear_all(store);
|
587
|
+
self = store->rstore;
|
588
|
+
if (self == Qnil || DATA_PTR(self) == NULL) {
|
589
|
+
self = TypedData_Wrap_Struct(klass, &frb_store_t, store);
|
590
|
+
store->rstore = self;
|
591
|
+
rb_ivar_set(self, id_ref_cnt, INT2FIX(0));
|
592
|
+
} else {
|
593
|
+
int ref_cnt = FIX2INT(rb_ivar_get(self, id_ref_cnt)) + 1;
|
594
|
+
rb_ivar_set(self, id_ref_cnt, INT2FIX(ref_cnt));
|
595
|
+
}
|
596
|
+
FRT_XCATCHALL
|
597
|
+
ex_code = xcontext.excode;
|
598
|
+
msg = xcontext.msg;
|
599
|
+
FRT_HANDLED();
|
600
|
+
FRT_XENDTRY
|
601
|
+
|
602
|
+
if (ex_code && msg) {
|
603
|
+
frb_raise(ex_code, msg);
|
604
|
+
}
|
605
|
+
|
418
606
|
return self;
|
419
607
|
}
|
420
608
|
|
@@ -431,7 +619,7 @@ static VALUE frb_fsdir_new(int argc, VALUE *argv, VALUE klass) {
|
|
431
619
|
* Ruby's IO API is not used so that we can use different storage
|
432
620
|
* mechanisms to store the index. Some examples are;
|
433
621
|
*
|
434
|
-
* *
|
622
|
+
* * MDBX system based storage (currently implemented as MDBXDirectory)
|
435
623
|
* * RAM based storage (currently implemented as RAMDirectory)
|
436
624
|
* * Database based storage
|
437
625
|
*
|
@@ -447,6 +635,7 @@ void Init_Directory(void) {
|
|
447
635
|
rb_define_const(cDirectory, "LOCK_PREFIX", rb_str_new2(FRT_LOCK_PREFIX));
|
448
636
|
rb_define_method(cDirectory, "close", frb_dir_close, 0);
|
449
637
|
rb_define_method(cDirectory, "exists?", frb_dir_exists, 1);
|
638
|
+
rb_define_method(cDirectory, "exist?", frb_dir_exists, 1);
|
450
639
|
rb_define_method(cDirectory, "touch", frb_dir_touch, 1);
|
451
640
|
rb_define_method(cDirectory, "delete", frb_dir_delete, 1);
|
452
641
|
rb_define_method(cDirectory, "file_count", frb_dir_file_count, 0);
|
@@ -492,7 +681,7 @@ void Init_Lock(void) {
|
|
492
681
|
* Document-class: Ferret::Store::RAMDirectory
|
493
682
|
*
|
494
683
|
* Memory resident Directory implementation. You should use a RAMDirectory
|
495
|
-
* during testing but otherwise you should stick with
|
684
|
+
* during testing but otherwise you should stick with MDBXDirectory. While
|
496
685
|
* loading an index into memory may slightly speed things up, on most
|
497
686
|
* operating systems there won't be much difference so it wouldn't be worth
|
498
687
|
* your trouble.
|
@@ -504,24 +693,20 @@ void Init_RAMDirectory(void) {
|
|
504
693
|
}
|
505
694
|
|
506
695
|
/*
|
507
|
-
* Document-class: Ferret::Store::
|
696
|
+
* Document-class: Ferret::Store::MDBXDirectory
|
508
697
|
*
|
509
|
-
*
|
510
|
-
* single
|
511
|
-
* touch this
|
512
|
-
*
|
698
|
+
* MDBX resident Directory implementation. The MDBXDirectory will use a
|
699
|
+
* single MDBX database to store all of it's files. You should not otherwise
|
700
|
+
* touch this ddatabase. Modifying the database will corrupt the index.
|
701
|
+
* The one exception to this rule is you may need to delete stale
|
513
702
|
* lock files which have a ".lck" extension.
|
514
703
|
*/
|
515
|
-
void
|
516
|
-
|
517
|
-
rb_define_alloc_func(
|
518
|
-
rb_define_singleton_method(
|
704
|
+
void Init_MDBXDirectory(void) {
|
705
|
+
cMDBXDirectory = rb_define_class_under(mStore, "MDBXDirectory", cDirectory);
|
706
|
+
rb_define_alloc_func(cMDBXDirectory, frb_store_alloc);
|
707
|
+
rb_define_singleton_method(cMDBXDirectory, "new", frb_mdbxdir_new, -1);
|
519
708
|
}
|
520
709
|
|
521
|
-
/* rdoc hack
|
522
|
-
extern VALUE mFerret = rb_define_module("Ferret");
|
523
|
-
*/
|
524
|
-
|
525
710
|
/*
|
526
711
|
* Document-module: Ferret::Store
|
527
712
|
*
|
@@ -538,5 +723,5 @@ void Init_Store(void) {
|
|
538
723
|
Init_Directory();
|
539
724
|
Init_Lock();
|
540
725
|
Init_RAMDirectory();
|
541
|
-
|
726
|
+
Init_MDBXDirectory();
|
542
727
|
}
|
@@ -1051,10 +1051,6 @@ static void Init_PriorityQueue(void) {
|
|
1051
1051
|
rb_define_method(cPriorityQueue, "adjust", frb_pq_adjust, 0);
|
1052
1052
|
}
|
1053
1053
|
|
1054
|
-
/* rdoc hack
|
1055
|
-
extern VALUE mFerret = rb_define_module("Ferret");
|
1056
|
-
*/
|
1057
|
-
|
1058
1054
|
/*
|
1059
1055
|
* Document-module: Ferret::Utils
|
1060
1056
|
*
|
@@ -142,21 +142,21 @@ static FrtInStream *cmpd_open_input(FrtStore *store, const char *file_name) {
|
|
142
142
|
FrtCompoundStore *cmpd = store->dir.cmpd;
|
143
143
|
FrtInStream *is;
|
144
144
|
|
145
|
-
|
145
|
+
pthread_mutex_lock(&store->mutex);
|
146
146
|
if (cmpd->stream == NULL) {
|
147
|
-
|
147
|
+
pthread_mutex_unlock(&store->mutex);
|
148
148
|
FRT_RAISE(FRT_IO_ERROR, "Can't open compound file input stream. Parent "
|
149
149
|
"stream is closed.");
|
150
150
|
}
|
151
151
|
|
152
152
|
entry = (FileEntry *)frt_h_get(cmpd->entries, file_name);
|
153
153
|
if (entry == NULL) {
|
154
|
-
|
155
|
-
FRT_RAISE(FRT_IO_ERROR, "File %s does not exist: ", file_name);
|
154
|
+
pthread_mutex_unlock(&store->mutex);
|
155
|
+
FRT_RAISE(FRT_IO_ERROR, "File '%s' does not exist: ", file_name);
|
156
156
|
}
|
157
157
|
|
158
158
|
is = cmpd_create_input(cmpd->stream, entry->offset, entry->length);
|
159
|
-
|
159
|
+
pthread_mutex_unlock(&store->mutex);
|
160
160
|
|
161
161
|
return is;
|
162
162
|
}
|
@@ -29,19 +29,19 @@ char frt_xmsg_buffer[FRT_XMSG_BUFFER_SIZE];
|
|
29
29
|
char frt_xmsg_buffer_final[FRT_XMSG_BUFFER_FINAL_SIZE];
|
30
30
|
|
31
31
|
static frt_thread_key_t exception_stack_key;
|
32
|
-
static
|
32
|
+
static pthread_once_t exception_stack_key_once = PTHREAD_ONCE_INIT;
|
33
33
|
|
34
34
|
static void exception_stack_alloc(void) {
|
35
|
-
|
36
|
-
|
35
|
+
frb_thread_key_create(&exception_stack_key, NULL);
|
36
|
+
frb_thread_setspecific(exception_stack_key, NULL);
|
37
37
|
}
|
38
38
|
|
39
39
|
void frt_xpush_context(frt_xcontext_t *context) {
|
40
40
|
frt_xcontext_t *top_context;
|
41
|
-
|
42
|
-
top_context = (frt_xcontext_t *)
|
41
|
+
pthread_once(&exception_stack_key_once, *exception_stack_alloc);
|
42
|
+
top_context = (frt_xcontext_t *)frb_thread_getspecific(exception_stack_key);
|
43
43
|
context->next = top_context;
|
44
|
-
|
44
|
+
frb_thread_setspecific(exception_stack_key, context);
|
45
45
|
context->handled = true;
|
46
46
|
context->in_finally = false;
|
47
47
|
}
|
@@ -55,8 +55,8 @@ static void frt_xraise_context(frt_xcontext_t *context, volatile int excode, con
|
|
55
55
|
|
56
56
|
void frt_xraise(int excode, const char *const msg) {
|
57
57
|
frt_xcontext_t *top_context;
|
58
|
-
|
59
|
-
top_context = (frt_xcontext_t *)
|
58
|
+
pthread_once(&exception_stack_key_once, *exception_stack_alloc);
|
59
|
+
top_context = (frt_xcontext_t *)frb_thread_getspecific(exception_stack_key);
|
60
60
|
|
61
61
|
if (!top_context) {
|
62
62
|
FRT_XEXIT(ERROR_TYPES[excode], msg);
|
@@ -73,10 +73,10 @@ void frt_xraise(int excode, const char *const msg) {
|
|
73
73
|
|
74
74
|
void frt_xpop_context(void) {
|
75
75
|
frt_xcontext_t *top_cxt, *context;
|
76
|
-
|
77
|
-
top_cxt = (frt_xcontext_t *)
|
76
|
+
pthread_once(&exception_stack_key_once, *exception_stack_alloc);
|
77
|
+
top_cxt = (frt_xcontext_t *)frb_thread_getspecific(exception_stack_key);
|
78
78
|
context = top_cxt->next;
|
79
|
-
|
79
|
+
frb_thread_setspecific(exception_stack_key, context);
|
80
80
|
if (!top_cxt->handled) {
|
81
81
|
if (context) {
|
82
82
|
frt_xraise_context(context, top_cxt->excode, top_cxt->msg);
|