tokyomessenger 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +504 -0
- data/README.rdoc +224 -0
- data/Rakefile +72 -0
- data/benchmarks/balancer.rb +101 -0
- data/benchmarks/bulk_db.rb +92 -0
- data/benchmarks/bulk_table.rb +104 -0
- data/benchmarks/db.rb +131 -0
- data/benchmarks/table.rb +186 -0
- data/ext/a.h +496 -0
- data/ext/extconf.rb +27 -0
- data/ext/md5.c +381 -0
- data/ext/md5.h +101 -0
- data/ext/tc_myconf.c +493 -0
- data/ext/tc_myconf.h +543 -0
- data/ext/tcadb.c +4339 -0
- data/ext/tcadb.h +533 -0
- data/ext/tcbdb.c +4180 -0
- data/ext/tcbdb.h +1086 -0
- data/ext/tcfdb.c +2746 -0
- data/ext/tcfdb.h +842 -0
- data/ext/tchdb.c +5153 -0
- data/ext/tchdb.h +856 -0
- data/ext/tcrdb.c +2637 -0
- data/ext/tcrdb.h +785 -0
- data/ext/tctdb.c +6199 -0
- data/ext/tctdb.h +1070 -0
- data/ext/tcutil.c +10528 -0
- data/ext/tcutil.h +4166 -0
- data/ext/tokyo_messenger.c +147 -0
- data/ext/tokyo_messenger.h +49 -0
- data/ext/tokyo_messenger_db.c +227 -0
- data/ext/tokyo_messenger_db.h +8 -0
- data/ext/tokyo_messenger_module.c +453 -0
- data/ext/tokyo_messenger_module.h +10 -0
- data/ext/tokyo_messenger_query.c +226 -0
- data/ext/tokyo_messenger_query.h +9 -0
- data/ext/tokyo_messenger_table.c +319 -0
- data/ext/tokyo_messenger_table.h +8 -0
- data/ext/tt_myconf.c +169 -0
- data/ext/tt_myconf.h +408 -0
- data/ext/ttutil.c +1509 -0
- data/ext/ttutil.h +480 -0
- data/lib/tokyo_messenger/balancer.rb +188 -0
- data/spec/ext.lua +4 -0
- data/spec/plu_db.rb +538 -0
- data/spec/spec.rb +1 -0
- data/spec/spec_base.rb +17 -0
- data/spec/start_tyrants.sh +36 -0
- data/spec/stop_tyrants.sh +9 -0
- data/spec/tokyo_tyrant_balancer_db_spec.rb +160 -0
- data/spec/tokyo_tyrant_balancer_table_spec.rb +177 -0
- data/spec/tokyo_tyrant_query_spec.rb +159 -0
- data/spec/tokyo_tyrant_spec.rb +254 -0
- data/spec/tokyo_tyrant_table_spec.rb +301 -0
- metadata +117 -0
data/ext/tcadb.h
ADDED
@@ -0,0 +1,533 @@
|
|
1
|
+
/*************************************************************************************************
|
2
|
+
* The abstract database API of Tokyo Cabinet
|
3
|
+
* Copyright (C) 2006-2009 Mikio Hirabayashi
|
4
|
+
* This file is part of Tokyo Cabinet.
|
5
|
+
* Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
|
6
|
+
* the GNU Lesser General Public License as published by the Free Software Foundation; either
|
7
|
+
* version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope
|
8
|
+
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
10
|
+
* License for more details.
|
11
|
+
* You should have received a copy of the GNU Lesser General Public License along with Tokyo
|
12
|
+
* Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
13
|
+
* Boston, MA 02111-1307 USA.
|
14
|
+
*************************************************************************************************/
|
15
|
+
|
16
|
+
|
17
|
+
#ifndef _TCADB_H /* duplication check */
|
18
|
+
#define _TCADB_H
|
19
|
+
|
20
|
+
#include "tcutil.h"
|
21
|
+
#include "tchdb.h"
|
22
|
+
#include "tcbdb.h"
|
23
|
+
#include "tcfdb.h"
|
24
|
+
#include "tctdb.h"
|
25
|
+
|
26
|
+
/*************************************************************************************************
|
27
|
+
* API
|
28
|
+
*************************************************************************************************/
|
29
|
+
|
30
|
+
|
31
|
+
typedef struct { /* type of structure for an abstract database */
|
32
|
+
int omode; /* open mode */
|
33
|
+
TCMDB *mdb; /* on-memory hash database object */
|
34
|
+
TCNDB *ndb; /* on-memory tree database object */
|
35
|
+
TCHDB *hdb; /* hash database object */
|
36
|
+
TCBDB *bdb; /* B+ tree database object */
|
37
|
+
TCFDB *fdb; /* fixed-length databae object */
|
38
|
+
TCTDB *tdb; /* table database object */
|
39
|
+
int64_t capnum; /* capacity number of records */
|
40
|
+
int64_t capsiz; /* capacity size of using memory */
|
41
|
+
uint32_t capcnt; /* count for capacity check */
|
42
|
+
BDBCUR *cur; /* cursor of B+ tree */
|
43
|
+
void *skel; /* skeleton database */
|
44
|
+
} TCADB;
|
45
|
+
|
46
|
+
enum { /* enumeration for open modes */
|
47
|
+
ADBOVOID, /* not opened */
|
48
|
+
ADBOMDB, /* on-memory hash database */
|
49
|
+
ADBONDB, /* on-memory tree database */
|
50
|
+
ADBOHDB, /* hash database */
|
51
|
+
ADBOBDB, /* B+ tree database */
|
52
|
+
ADBOFDB, /* fixed-length database */
|
53
|
+
ADBOTDB, /* table database */
|
54
|
+
ADBOSKEL /* skeleton database */
|
55
|
+
};
|
56
|
+
|
57
|
+
|
58
|
+
/* Create an abstract database object.
|
59
|
+
The return value is the new abstract database object. */
|
60
|
+
TCADB *tcadbnew(void);
|
61
|
+
|
62
|
+
|
63
|
+
/* Delete an abstract database object.
|
64
|
+
`adb' specifies the abstract database object. */
|
65
|
+
void tcadbdel(TCADB *adb);
|
66
|
+
|
67
|
+
|
68
|
+
/* Open an abstract database.
|
69
|
+
`adb' specifies the abstract database object.
|
70
|
+
`name' specifies the name of the database. If it is "*", the database will be an on-memory
|
71
|
+
hash database. If it is "+", the database will be an on-memory tree database. If its suffix
|
72
|
+
is ".tch", the database will be a hash database. If its suffix is ".tcb", the database will
|
73
|
+
be a B+ tree database. If its suffix is ".tcf", the database will be a fixed-length database.
|
74
|
+
If its suffix is ".tct", the database will be a table database. Otherwise, this function
|
75
|
+
fails. Tuning parameters can trail the name, separated by "#". Each parameter is composed of
|
76
|
+
the name and the value, separated by "=". On-memory hash database supports "bnum", "capnum",
|
77
|
+
and "capsiz". On-memory tree database supports "capnum" and "capsiz". Hash database supports
|
78
|
+
"mode", "bnum", "apow", "fpow", "opts", "rcnum", "xmsiz", and "dfunit". B+ tree database
|
79
|
+
supports "mode", "lmemb", "nmemb", "bnum", "apow", "fpow", "opts", "lcnum", "ncnum", "xmsiz",
|
80
|
+
and "dfunit". Fixed-length database supports "mode", "width", and "limsiz". Table database
|
81
|
+
supports "mode", "bnum", "apow", "fpow", "opts", "rcnum", "lcnum", "ncnum", "xmsiz", "dfunit",
|
82
|
+
and "idx".
|
83
|
+
If successful, the return value is true, else, it is false.
|
84
|
+
The tuning parameter "capnum" specifies the capacity number of records. "capsiz" specifies
|
85
|
+
the capacity size of using memory. Records spilled the capacity are removed by the storing
|
86
|
+
order. "mode" can contain "w" of writer, "r" of reader, "c" of creating, "t" of truncating,
|
87
|
+
"e" of no locking, and "f" of non-blocking lock. The default mode is relevant to "wc".
|
88
|
+
"opts" can contains "l" of large option, "d" of Deflate option, "b" of BZIP2 option, and "t"
|
89
|
+
of TCBS option. "idx" specifies the column name of an index and its type separated by ":".
|
90
|
+
For example, "casket.tch#bnum=1000000#opts=ld" means that the name of the database file is
|
91
|
+
"casket.tch", and the bucket number is 1000000, and the options are large and Deflate. */
|
92
|
+
bool tcadbopen(TCADB *adb, const char *name);
|
93
|
+
|
94
|
+
|
95
|
+
/* Close an abstract database object.
|
96
|
+
`adb' specifies the abstract database object.
|
97
|
+
If successful, the return value is true, else, it is false.
|
98
|
+
Update of a database is assured to be written when the database is closed. If a writer opens
|
99
|
+
a database but does not close it appropriately, the database will be broken. */
|
100
|
+
bool tcadbclose(TCADB *adb);
|
101
|
+
|
102
|
+
|
103
|
+
/* Store a record into an abstract database object.
|
104
|
+
`adb' specifies the abstract database object.
|
105
|
+
`kbuf' specifies the pointer to the region of the key.
|
106
|
+
`ksiz' specifies the size of the region of the key.
|
107
|
+
`vbuf' specifies the pointer to the region of the value.
|
108
|
+
`vsiz' specifies the size of the region of the value.
|
109
|
+
If successful, the return value is true, else, it is false.
|
110
|
+
If a record with the same key exists in the database, it is overwritten. */
|
111
|
+
bool tcadbput(TCADB *adb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
|
112
|
+
|
113
|
+
|
114
|
+
/* Store a string record into an abstract object.
|
115
|
+
`adb' specifies the abstract database object.
|
116
|
+
`kstr' specifies the string of the key.
|
117
|
+
`vstr' specifies the string of the value.
|
118
|
+
If successful, the return value is true, else, it is false.
|
119
|
+
If a record with the same key exists in the database, it is overwritten. */
|
120
|
+
bool tcadbput2(TCADB *adb, const char *kstr, const char *vstr);
|
121
|
+
|
122
|
+
|
123
|
+
/* Store a new record into an abstract database object.
|
124
|
+
`adb' specifies the abstract database object.
|
125
|
+
`kbuf' specifies the pointer to the region of the key.
|
126
|
+
`ksiz' specifies the size of the region of the key.
|
127
|
+
`vbuf' specifies the pointer to the region of the value.
|
128
|
+
`vsiz' specifies the size of the region of the value.
|
129
|
+
If successful, the return value is true, else, it is false.
|
130
|
+
If a record with the same key exists in the database, this function has no effect. */
|
131
|
+
bool tcadbputkeep(TCADB *adb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
|
132
|
+
|
133
|
+
|
134
|
+
/* Store a new string record into an abstract database object.
|
135
|
+
`adb' specifies the abstract database object.
|
136
|
+
`kstr' specifies the string of the key.
|
137
|
+
`vstr' specifies the string of the value.
|
138
|
+
If successful, the return value is true, else, it is false.
|
139
|
+
If a record with the same key exists in the database, this function has no effect. */
|
140
|
+
bool tcadbputkeep2(TCADB *adb, const char *kstr, const char *vstr);
|
141
|
+
|
142
|
+
|
143
|
+
/* Concatenate a value at the end of the existing record in an abstract database object.
|
144
|
+
`adb' specifies the abstract database object.
|
145
|
+
`kbuf' specifies the pointer to the region of the key.
|
146
|
+
`ksiz' specifies the size of the region of the key.
|
147
|
+
`vbuf' specifies the pointer to the region of the value.
|
148
|
+
`vsiz' specifies the size of the region of the value.
|
149
|
+
If successful, the return value is true, else, it is false.
|
150
|
+
If there is no corresponding record, a new record is created. */
|
151
|
+
bool tcadbputcat(TCADB *adb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
|
152
|
+
|
153
|
+
|
154
|
+
/* Concatenate a string value at the end of the existing record in an abstract database object.
|
155
|
+
`adb' specifies the abstract database object.
|
156
|
+
`kstr' specifies the string of the key.
|
157
|
+
`vstr' specifies the string of the value.
|
158
|
+
If successful, the return value is true, else, it is false.
|
159
|
+
If there is no corresponding record, a new record is created. */
|
160
|
+
bool tcadbputcat2(TCADB *adb, const char *kstr, const char *vstr);
|
161
|
+
|
162
|
+
|
163
|
+
/* Remove a record of an abstract database object.
|
164
|
+
`adb' specifies the abstract database object.
|
165
|
+
`kbuf' specifies the pointer to the region of the key.
|
166
|
+
`ksiz' specifies the size of the region of the key.
|
167
|
+
If successful, the return value is true, else, it is false. */
|
168
|
+
bool tcadbout(TCADB *adb, const void *kbuf, int ksiz);
|
169
|
+
|
170
|
+
|
171
|
+
/* Remove a string record of an abstract database object.
|
172
|
+
`adb' specifies the abstract database object.
|
173
|
+
`kstr' specifies the string of the key.
|
174
|
+
If successful, the return value is true, else, it is false. */
|
175
|
+
bool tcadbout2(TCADB *adb, const char *kstr);
|
176
|
+
|
177
|
+
|
178
|
+
/* Retrieve a record in an abstract database object.
|
179
|
+
`adb' specifies the abstract database object.
|
180
|
+
`kbuf' specifies the pointer to the region of the key.
|
181
|
+
`ksiz' specifies the size of the region of the key.
|
182
|
+
`sp' specifies the pointer to the variable into which the size of the region of the return
|
183
|
+
value is assigned.
|
184
|
+
If successful, the return value is the pointer to the region of the value of the corresponding
|
185
|
+
record. `NULL' is returned if no record corresponds.
|
186
|
+
Because an additional zero code is appended at the end of the region of the return value,
|
187
|
+
the return value can be treated as a character string. Because the region of the return
|
188
|
+
value is allocated with the `malloc' call, it should be released with the `free' call when
|
189
|
+
it is no longer in use. */
|
190
|
+
void *tcadbget(TCADB *adb, const void *kbuf, int ksiz, int *sp);
|
191
|
+
|
192
|
+
|
193
|
+
/* Retrieve a string record in an abstract database object.
|
194
|
+
`adb' specifies the abstract database object.
|
195
|
+
`kstr' specifies the string of the key.
|
196
|
+
If successful, the return value is the string of the value of the corresponding record.
|
197
|
+
`NULL' is returned if no record corresponds.
|
198
|
+
Because the region of the return value is allocated with the `malloc' call, it should be
|
199
|
+
released with the `free' call when it is no longer in use. */
|
200
|
+
char *tcadbget2(TCADB *adb, const char *kstr);
|
201
|
+
|
202
|
+
|
203
|
+
/* Get the size of the value of a record in an abstract database object.
|
204
|
+
`adb' specifies the abstract database object.
|
205
|
+
`kbuf' specifies the pointer to the region of the key.
|
206
|
+
`ksiz' specifies the size of the region of the key.
|
207
|
+
If successful, the return value is the size of the value of the corresponding record, else,
|
208
|
+
it is -1. */
|
209
|
+
int tcadbvsiz(TCADB *adb, const void *kbuf, int ksiz);
|
210
|
+
|
211
|
+
|
212
|
+
/* Get the size of the value of a string record in an abstract database object.
|
213
|
+
`adb' specifies the abstract database object.
|
214
|
+
`kstr' specifies the string of the key.
|
215
|
+
If successful, the return value is the size of the value of the corresponding record, else,
|
216
|
+
it is -1. */
|
217
|
+
int tcadbvsiz2(TCADB *adb, const char *kstr);
|
218
|
+
|
219
|
+
|
220
|
+
/* Initialize the iterator of an abstract database object.
|
221
|
+
`adb' specifies the abstract database object.
|
222
|
+
If successful, the return value is true, else, it is false.
|
223
|
+
The iterator is used in order to access the key of every record stored in a database. */
|
224
|
+
bool tcadbiterinit(TCADB *adb);
|
225
|
+
|
226
|
+
|
227
|
+
/* Get the next key of the iterator of an abstract database object.
|
228
|
+
`adb' specifies the abstract database object.
|
229
|
+
`sp' specifies the pointer to the variable into which the size of the region of the return
|
230
|
+
value is assigned.
|
231
|
+
If successful, the return value is the pointer to the region of the next key, else, it is
|
232
|
+
`NULL'. `NULL' is returned when no record is to be get out of the iterator.
|
233
|
+
Because an additional zero code is appended at the end of the region of the return value, the
|
234
|
+
return value can be treated as a character string. Because the region of the return value is
|
235
|
+
allocated with the `malloc' call, it should be released with the `free' call when it is no
|
236
|
+
longer in use. It is possible to access every record by iteration of calling this function.
|
237
|
+
It is allowed to update or remove records whose keys are fetched while the iteration.
|
238
|
+
However, it is not assured if updating the database is occurred while the iteration. Besides,
|
239
|
+
the order of this traversal access method is arbitrary, so it is not assured that the order of
|
240
|
+
storing matches the one of the traversal access. */
|
241
|
+
void *tcadbiternext(TCADB *adb, int *sp);
|
242
|
+
|
243
|
+
|
244
|
+
/* Get the next key string of the iterator of an abstract database object.
|
245
|
+
`adb' specifies the abstract database object.
|
246
|
+
If successful, the return value is the string of the next key, else, it is `NULL'. `NULL' is
|
247
|
+
returned when no record is to be get out of the iterator.
|
248
|
+
Because the region of the return value is allocated with the `malloc' call, it should be
|
249
|
+
released with the `free' call when it is no longer in use. It is possible to access every
|
250
|
+
record by iteration of calling this function. However, it is not assured if updating the
|
251
|
+
database is occurred while the iteration. Besides, the order of this traversal access method
|
252
|
+
is arbitrary, so it is not assured that the order of storing matches the one of the traversal
|
253
|
+
access. */
|
254
|
+
char *tcadbiternext2(TCADB *adb);
|
255
|
+
|
256
|
+
|
257
|
+
/* Get forward matching keys in an abstract database object.
|
258
|
+
`adb' specifies the abstract database object.
|
259
|
+
`pbuf' specifies the pointer to the region of the prefix.
|
260
|
+
`psiz' specifies the size of the region of the prefix.
|
261
|
+
`max' specifies the maximum number of keys to be fetched. If it is negative, no limit is
|
262
|
+
specified.
|
263
|
+
The return value is a list object of the corresponding keys. This function does never fail.
|
264
|
+
It returns an empty list even if no key corresponds.
|
265
|
+
Because the object of the return value is created with the function `tclistnew', it should be
|
266
|
+
deleted with the function `tclistdel' when it is no longer in use. Note that this function
|
267
|
+
may be very slow because every key in the database is scanned. */
|
268
|
+
TCLIST *tcadbfwmkeys(TCADB *adb, const void *pbuf, int psiz, int max);
|
269
|
+
|
270
|
+
|
271
|
+
/* Get forward matching string keys in an abstract database object.
|
272
|
+
`adb' specifies the abstract database object.
|
273
|
+
`pstr' specifies the string of the prefix.
|
274
|
+
`max' specifies the maximum number of keys to be fetched. If it is negative, no limit is
|
275
|
+
specified.
|
276
|
+
The return value is a list object of the corresponding keys. This function does never fail.
|
277
|
+
It returns an empty list even if no key corresponds.
|
278
|
+
Because the object of the return value is created with the function `tclistnew', it should be
|
279
|
+
deleted with the function `tclistdel' when it is no longer in use. Note that this function
|
280
|
+
may be very slow because every key in the database is scanned. */
|
281
|
+
TCLIST *tcadbfwmkeys2(TCADB *adb, const char *pstr, int max);
|
282
|
+
|
283
|
+
|
284
|
+
/* Add an integer to a record in an abstract database object.
|
285
|
+
`adb' specifies the abstract database object.
|
286
|
+
`kbuf' specifies the pointer to the region of the key.
|
287
|
+
`ksiz' specifies the size of the region of the key.
|
288
|
+
`num' specifies the additional value.
|
289
|
+
If successful, the return value is the summation value, else, it is `INT_MIN'.
|
290
|
+
If the corresponding record exists, the value is treated as an integer and is added to. If no
|
291
|
+
record corresponds, a new record of the additional value is stored. */
|
292
|
+
int tcadbaddint(TCADB *adb, const void *kbuf, int ksiz, int num);
|
293
|
+
|
294
|
+
|
295
|
+
/* Add a real number to a record in an abstract database object.
|
296
|
+
`adb' specifies the abstract database object.
|
297
|
+
`kbuf' specifies the pointer to the region of the key.
|
298
|
+
`ksiz' specifies the size of the region of the key.
|
299
|
+
`num' specifies the additional value.
|
300
|
+
If successful, the return value is the summation value, else, it is Not-a-Number.
|
301
|
+
If the corresponding record exists, the value is treated as a real number and is added to. If
|
302
|
+
no record corresponds, a new record of the additional value is stored. */
|
303
|
+
double tcadbadddouble(TCADB *adb, const void *kbuf, int ksiz, double num);
|
304
|
+
|
305
|
+
|
306
|
+
/* Synchronize updated contents of an abstract database object with the file and the device.
|
307
|
+
`adb' specifies the abstract database object.
|
308
|
+
If successful, the return value is true, else, it is false. */
|
309
|
+
bool tcadbsync(TCADB *adb);
|
310
|
+
|
311
|
+
|
312
|
+
/* Optimize the storage of an abstract database object.
|
313
|
+
`adb' specifies the abstract database object.
|
314
|
+
`params' specifies the string of the tuning parameters, which works as with the tuning
|
315
|
+
of parameters the function `tcadbopen'. If it is `NULL', it is not used.
|
316
|
+
If successful, the return value is true, else, it is false.
|
317
|
+
This function is useful to reduce the size of the database storage with data fragmentation by
|
318
|
+
successive updating. */
|
319
|
+
bool tcadboptimize(TCADB *adb, const char *params);
|
320
|
+
|
321
|
+
|
322
|
+
/* Remove all records of an abstract database object.
|
323
|
+
`adb' specifies the abstract database object.
|
324
|
+
If successful, the return value is true, else, it is false. */
|
325
|
+
bool tcadbvanish(TCADB *adb);
|
326
|
+
|
327
|
+
|
328
|
+
/* Copy the database file of an abstract database object.
|
329
|
+
`adb' specifies the abstract database object.
|
330
|
+
`path' specifies the path of the destination file. If it begins with `@', the trailing
|
331
|
+
substring is executed as a command line.
|
332
|
+
If successful, the return value is true, else, it is false. False is returned if the executed
|
333
|
+
command returns non-zero code.
|
334
|
+
The database file is assured to be kept synchronized and not modified while the copying or
|
335
|
+
executing operation is in progress. So, this function is useful to create a backup file of
|
336
|
+
the database file. */
|
337
|
+
bool tcadbcopy(TCADB *adb, const char *path);
|
338
|
+
|
339
|
+
|
340
|
+
/* Begin the transaction of an abstract database object.
|
341
|
+
`adb' specifies the abstract database object.
|
342
|
+
If successful, the return value is true, else, it is false.
|
343
|
+
The database is locked by the thread while the transaction so that only one transaction can be
|
344
|
+
activated with a database object at the same time. Thus, the serializable isolation level is
|
345
|
+
assumed if every database operation is performed in the transaction. All updated regions are
|
346
|
+
kept track of by write ahead logging while the transaction. If the database is closed during
|
347
|
+
transaction, the transaction is aborted implicitly. */
|
348
|
+
bool tcadbtranbegin(TCADB *adb);
|
349
|
+
|
350
|
+
|
351
|
+
/* Commit the transaction of an abstract database object.
|
352
|
+
`adb' specifies the abstract database object.
|
353
|
+
If successful, the return value is true, else, it is false.
|
354
|
+
Update in the transaction is fixed when it is committed successfully. */
|
355
|
+
bool tcadbtrancommit(TCADB *adb);
|
356
|
+
|
357
|
+
|
358
|
+
/* Abort the transaction of an abstract database object.
|
359
|
+
`adb' specifies the abstract database object.
|
360
|
+
If successful, the return value is true, else, it is false.
|
361
|
+
Update in the transaction is discarded when it is aborted. The state of the database is
|
362
|
+
rollbacked to before transaction. */
|
363
|
+
bool tcadbtranabort(TCADB *adb);
|
364
|
+
|
365
|
+
|
366
|
+
/* Get the file path of an abstract database object.
|
367
|
+
`adb' specifies the abstract database object.
|
368
|
+
The return value is the path of the database file or `NULL' if the object does not connect to
|
369
|
+
any database. "*" stands for on-memory hash database. "+" stands for on-memory tree
|
370
|
+
database. */
|
371
|
+
const char *tcadbpath(TCADB *adb);
|
372
|
+
|
373
|
+
|
374
|
+
/* Get the number of records of an abstract database object.
|
375
|
+
`adb' specifies the abstract database object.
|
376
|
+
The return value is the number of records or 0 if the object does not connect to any database
|
377
|
+
instance. */
|
378
|
+
uint64_t tcadbrnum(TCADB *adb);
|
379
|
+
|
380
|
+
|
381
|
+
/* Get the size of the database of an abstract database object.
|
382
|
+
`adb' specifies the abstract database object.
|
383
|
+
The return value is the size of the database or 0 if the object does not connect to any
|
384
|
+
database instance. */
|
385
|
+
uint64_t tcadbsize(TCADB *adb);
|
386
|
+
|
387
|
+
|
388
|
+
/* Call a versatile function for miscellaneous operations of an abstract database object.
|
389
|
+
`adb' specifies the abstract database object.
|
390
|
+
`name' specifies the name of the function. All databases support "put", "out", "get",
|
391
|
+
"putlist", "outlist", "getlist", and "getpart". "put" is to store a record. It receives a
|
392
|
+
key and a value, and returns an empty list. "out" is to remove a record. It receives a key,
|
393
|
+
and returns an empty list. "get" is to retrieve a record. It receives a key, and returns a
|
394
|
+
list of the values. "putlist" is to store records. It receives keys and values one after the
|
395
|
+
other, and returns an empty list. "outlist" is to remove records. It receives keys, and
|
396
|
+
returns an empty list. "getlist" is to retrieve records. It receives keys, and returns keys
|
397
|
+
and values of corresponding records one after the other. "getpart" is to retrieve the partial
|
398
|
+
value of a record. It receives a key, the offset of the region, and the length of the region.
|
399
|
+
`args' specifies a list object containing arguments.
|
400
|
+
If successful, the return value is a list object of the result. `NULL' is returned on failure.
|
401
|
+
Because the object of the return value is created with the function `tclistnew', it
|
402
|
+
should be deleted with the function `tclistdel' when it is no longer in use. */
|
403
|
+
TCLIST *tcadbmisc(TCADB *adb, const char *name, const TCLIST *args);
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
/*************************************************************************************************
|
408
|
+
* features for experts
|
409
|
+
*************************************************************************************************/
|
410
|
+
|
411
|
+
|
412
|
+
typedef struct { /* type of structure for a extra database skeleton */
|
413
|
+
void *opq; /* opaque pointer */
|
414
|
+
void (*del)(void *); /* destructor */
|
415
|
+
bool (*open)(void *, const char *);
|
416
|
+
bool (*close)(void *);
|
417
|
+
bool (*put)(void *, const void *, int, const void *, int);
|
418
|
+
bool (*putkeep)(void *, const void *, int, const void *, int);
|
419
|
+
bool (*putcat)(void *, const void *, int, const void *, int);
|
420
|
+
bool (*out)(void *, const void *, int);
|
421
|
+
void *(*get)(void *, const void *, int, int *);
|
422
|
+
int (*vsiz)(void *, const void *, int);
|
423
|
+
bool (*iterinit)(void *);
|
424
|
+
void *(*iternext)(void *, int *);
|
425
|
+
TCLIST *(*fwmkeys)(void *, const void *, int, int);
|
426
|
+
int (*addint)(void *, const void *, int, int);
|
427
|
+
double (*adddouble)(void *, const void *, int, double);
|
428
|
+
bool (*sync)(void *);
|
429
|
+
bool (*optimize)(void *, const char *);
|
430
|
+
bool (*vanish)(void *);
|
431
|
+
bool (*copy)(void *, const char *);
|
432
|
+
bool (*tranbegin)(void *);
|
433
|
+
bool (*trancommit)(void *);
|
434
|
+
bool (*tranabort)(void *);
|
435
|
+
const char *(*path)(void *);
|
436
|
+
uint64_t (*rnum)(void *);
|
437
|
+
uint64_t (*size)(void *);
|
438
|
+
TCLIST *(*misc)(void *, const char *, const TCLIST *);
|
439
|
+
bool (*putproc)(void *, const void *, int, const void *, int, TCPDPROC, void *);
|
440
|
+
bool (*foreach)(void *, TCITER, void *);
|
441
|
+
} ADBSKEL;
|
442
|
+
|
443
|
+
/* type of the pointer to a mapping function.
|
444
|
+
`map' specifies the pointer to the destination manager.
|
445
|
+
`kbuf' specifies the pointer to the region of the key.
|
446
|
+
`ksiz' specifies the size of the region of the key.
|
447
|
+
`vbuf' specifies the pointer to the region of the value.
|
448
|
+
`vsiz' specifies the size of the region of the value.
|
449
|
+
`op' specifies the pointer to the optional opaque object.
|
450
|
+
The return value is true to continue iteration or false to stop iteration. */
|
451
|
+
typedef bool (*ADBMAPPROC)(void *map, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
|
452
|
+
void *op);
|
453
|
+
|
454
|
+
|
455
|
+
/* Set an extra database sleleton to an abstract database object.
|
456
|
+
`adb' specifies the abstract database object.
|
457
|
+
`skel' specifies the extra database skeleton.
|
458
|
+
If successful, the return value is true, else, it is false. */
|
459
|
+
bool tcadbsetskel(TCADB *adb, ADBSKEL *skel);
|
460
|
+
|
461
|
+
|
462
|
+
/* Set the multiple database skeleton to an abstract database object.
|
463
|
+
`adb' specifies the abstract database object.
|
464
|
+
`num' specifies the number of inner databases.
|
465
|
+
If successful, the return value is true, else, it is false. */
|
466
|
+
bool tcadbsetskelmulti(TCADB *adb, int num);
|
467
|
+
|
468
|
+
|
469
|
+
/* Get the open mode of an abstract database object.
|
470
|
+
`adb' specifies the abstract database object.
|
471
|
+
The return value is `ADBOVOID' for not opened database, `ADBOMDB' for on-memory hash database,
|
472
|
+
`ADBONDB' for on-memory tree database, `ADBOHDB' for hash database, `ADBOBDB' for B+ tree
|
473
|
+
database, `ADBOFDB' for fixed-length database, `ADBOTDB' for table database. */
|
474
|
+
int tcadbomode(TCADB *adb);
|
475
|
+
|
476
|
+
|
477
|
+
/* Get the concrete database object of an abstract database object.
|
478
|
+
`adb' specifies the abstract database object.
|
479
|
+
The return value is the concrete database object depend on the open mode or 0 if the object
|
480
|
+
does not connect to any database instance. */
|
481
|
+
void *tcadbreveal(TCADB *adb);
|
482
|
+
|
483
|
+
|
484
|
+
/* Store a record into an abstract database object with a duplication handler.
|
485
|
+
`adb' specifies the abstract database object.
|
486
|
+
`kbuf' specifies the pointer to the region of the key.
|
487
|
+
`ksiz' specifies the size of the region of the key.
|
488
|
+
`vbuf' specifies the pointer to the region of the value.
|
489
|
+
`vsiz' specifies the size of the region of the value.
|
490
|
+
`proc' specifies the pointer to the callback function to process duplication.
|
491
|
+
`op' specifies an arbitrary pointer to be given as a parameter of the callback function. If
|
492
|
+
it is not needed, `NULL' can be specified.
|
493
|
+
If successful, the return value is true, else, it is false.
|
494
|
+
This function does not work for the table database. */
|
495
|
+
bool tcadbputproc(TCADB *adb, const void *kbuf, int ksiz, const void *vbuf, int vsiz,
|
496
|
+
TCPDPROC proc, void *op);
|
497
|
+
|
498
|
+
|
499
|
+
/* Process each record atomically of an abstract database object.
|
500
|
+
`adb' specifies the abstract database object.
|
501
|
+
`iter' specifies the pointer to the iterator function called for each record.
|
502
|
+
`op' specifies an arbitrary pointer to be given as a parameter of the iterator function. If
|
503
|
+
it is not needed, `NULL' can be specified.
|
504
|
+
If successful, the return value is true, else, it is false. */
|
505
|
+
bool tcadbforeach(TCADB *adb, TCITER iter, void *op);
|
506
|
+
|
507
|
+
|
508
|
+
/* Map records of an abstract database object into another B+ tree database.
|
509
|
+
`adb' specifies the abstract database object.
|
510
|
+
`keys' specifies a list object of the keys of the target records. If it is `NULL', every
|
511
|
+
record is processed.
|
512
|
+
`bdb' specifies the B+ tree database object into which records emitted by the mapping function
|
513
|
+
are stored.
|
514
|
+
`proc' specifies the pointer to the mapping function called for each record.
|
515
|
+
`op' specifies specifies the pointer to the optional opaque object for the mapping function.
|
516
|
+
`csiz' specifies the size of the cache to sort emitted records. If it is negative, the
|
517
|
+
default size is specified. The default size is 268435456.
|
518
|
+
If successful, the return value is true, else, it is false. */
|
519
|
+
bool tcadbmapbdb(TCADB *adb, TCLIST *keys, TCBDB *bdb, ADBMAPPROC proc, void *op, int64_t csiz);
|
520
|
+
|
521
|
+
|
522
|
+
/* Emit records generated by the mapping function into the result map.
|
523
|
+
`kbuf' specifies the pointer to the region of the key.
|
524
|
+
`ksiz' specifies the size of the region of the key.
|
525
|
+
`vbuf' specifies the pointer to the region of the value.
|
526
|
+
`vsiz' specifies the size of the region of the value.
|
527
|
+
If successful, the return value is true, else, it is false. */
|
528
|
+
bool tcadbmapbdbemit(void *map, const char *kbuf, int ksiz, const char *vbuf, int vsiz);
|
529
|
+
|
530
|
+
#endif /* duplication check */
|
531
|
+
|
532
|
+
|
533
|
+
/* END OF FILE */
|