1CURIA(3) Quick Database Manager CURIA(3)
2
3
4
6 Curia - the extended API of QDBM
7
8
10 #include <depot.h>
11 #include <curia.h>
12 #include <stdlib.h>
13
14 CURIA *cropen(const char *name, int omode, int bnum, int dnum);
15
16 int crclose(CURIA *curia);
17
18 int crput(CURIA *curia, const char *kbuf, int ksiz, const char *vbuf,
19 int vsiz, int dmode);
20
21 int crout(CURIA *curia, const char *kbuf, int ksiz);
22
23 char *crget(CURIA *curia, const char *kbuf, int ksiz, int start, int
24 max, int *sp);
25
26 int crgetwb(CURIA *curia, const char *kbuf, int ksiz, int start, int
27 max, char *vbuf);
28
29 int crvsiz(CURIA *curia, const char *kbuf, int ksiz);
30
31 int criterinit(CURIA *curia);
32
33 char *criternext(CURIA *curia, int *sp);
34
35 int crsetalign(CURIA *curia, int align);
36
37 int crsetfbpsiz(CURIA *curia, int size);
38
39 int crsync(CURIA *curia);
40
41 int croptimize(CURIA *curia, int bnum);
42
43 char *crname(CURIA *curia);
44
45 int crfsiz(CURIA *curia);
46
47 double crfsizd(CURIA *curia);
48
49 int crbnum(CURIA *curia);
50
51 int crbusenum(CURIA *curia);
52
53 int crrnum(CURIA *curia);
54
55 int crwritable(CURIA *curia);
56
57 int crfatalerror(CURIA *curia);
58
59 int crinode(CURIA *curia);
60
61 time_t crmtime(CURIA *curia);
62
63 int crremove(const char *name);
64
65 int crrepair(const char *name);
66
67 int crexportdb(CURIA *curia, const char *name);
68
69 int crimportdb(CURIA *curia, const char *name);
70
71 char *crsnaffle(const char *name, const char *kbuf, int ksiz, int *sp);
72
73 int crputlob(CURIA *curia, const char *kbuf, int ksiz, const char
74 *vbuf, int vsiz, int dmode);
75
76 int croutlob(CURIA *curia, const char *kbuf, int ksiz);
77
78 char *crgetlob(CURIA *curia, const char *kbuf, int ksiz, int start, int
79 max, int *sp);
80
81 int crgetlobfd(CURIA *curia, const char *kbuf, int ksiz);
82
83 int crvsizlob(CURIA *curia, const char *kbuf, int ksiz);
84
85 int crrnumlob(CURIA *curia);
86
87
89 Curia is the extended API of QDBM. It provides routines for managing
90 multiple database files in a directory. Restrictions of some file sys‐
91 tems that the size of each file is limited are escaped by dividing a
92 database file into two or more. If the database files deploy on multi‐
93 ple devices, the scalability is improved.
94
95 Although Depot creates a database with a file name, Curia creates a
96 database with a directory name. A database file named as `depot' is
97 placed in the specified directory. Although it keeps the attribute of
98 the database, it does not keep the entities of the records. Besides,
99 sub directories are created by the number of division of the database,
100 named with 4 digits. The database files are placed in the subdirecto‐
101 ries. The entities of the records are stored in the database file.
102 For example, in the case that a database directory named as `casket'
103 and the number of division is 3, `casket/depot', `casket/0001/depot',
104 `casket/0002/depot' and `casket/0003/depot' are created. No error
105 occurs even if the namesake directory exists when creating a database.
106 So, if sub directories exists and some devices are mounted on the sub
107 directories, the database files deploy on the multiple devices. It is
108 possible for the database files to deploy on multiple file servers
109 using NFS and so on.
110
111 Curia features managing large objects. Although usual records are
112 stored in some database files, records of large objects are stored in
113 individual files. Because the files of large objects are deployed in
114 different directories named with the hash values, the access speed is
115 part-way robust although it is slower than the speed of usual records.
116 Large and not often accessed data should be secluded as large objects.
117 By doing this, the access speed of usual records is improved. The
118 directory hierarchies of large objects are placed in the directory
119 named as `lob' in the sub directories of the database. Because the key
120 spaces of the usual records and the large objects are different, the
121 operations keep out of each other.
122
123 In order to use Curia, you should include `depot.h', `curia.h' and
124 `stdlib.h' in the source files. Usually, the following description
125 will be near the beginning of a source file.
126
127 #include <depot.h>
128 #include <curia.h>
129 #include <stdlib.h>
130
131 A pointer to `CURIA' is used as a database handle. It is like that
132 some file I/O routines of `stdio.h' use a pointer to `FILE'. A data‐
133 base handle is opened with the function `cropen' and closed with
134 `crclose'. You should not refer directly to any member of the handle.
135 If a fatal error occurs in a database, any access method via the handle
136 except `crclose' will not work and return error status. Although a
137 process is allowed to use multiple database handles at the same time,
138 handles of the same database directory should not be used.
139
140 Curia also assign the external variable `dpecode' with the error code.
141 The function `dperrmsg' is used in order to get the message of the
142 error code.
143
144 The function `cropen' is used in order to get a database handle.
145
146 CURIA *cropen(const char *name, int omode, int bnum, int dnum);
147 `name' specifies the name of a database directory. `omode'
148 specifies the connection mode: `CR_OWRITER' as a writer,
149 `CR_OREADER' as a reader. If the mode is `CR_OWRITER', the fol‐
150 lowing may be added by bitwise or: `CR_OCREAT', which means it
151 creates a new database if not exist, `CR_OTRUNC', which means it
152 creates a new database regardless if one exists. Both of
153 `CR_OREADER' and `CR_OWRITER' can be added to by bitwise or:
154 `CR_ONOLCK', which means it opens a database directory without
155 file locking, or `CR_OLCKNB', which means locking is performed
156 without blocking. `CR_OCREAT' can be added to by bitwise or:
157 `CR_OSPARSE', which means it creates database files as sparse
158 files. `bnum' specifies the number of elements of each bucket
159 array. If it is not more than 0, the default value is speci‐
160 fied. The size of each bucket array is determined on creating,
161 and can not be changed except for by optimization of the data‐
162 base. Suggested size of each bucket array is about from 0.5 to
163 4 times of the number of all records to store. `dnum' specifies
164 the number of division of the database. If it is not more than
165 0, the default value is specified. The number of division can
166 not be changed from the initial value. The max number of divi‐
167 sion is 512. The return value is the database handle or `NULL'
168 if it is not successful. While connecting as a writer, an
169 exclusive lock is invoked to the database directory. While con‐
170 necting as a reader, a shared lock is invoked to the database
171 directory. The thread blocks until the lock is achieved. If
172 `CR_ONOLCK' is used, the application is responsible for exclu‐
173 sion control.
174
175 The function `crclose' is used in order to close a database handle.
176
177 int crclose(CURIA *curia);
178 `curia' specifies a database handle. If successful, the return
179 value is true, else, it is false. Because the region of a
180 closed handle is released, it becomes impossible to use the han‐
181 dle. Updating a database is assured to be written when the han‐
182 dle is closed. If a writer opens a database but does not close
183 it appropriately, the database will be broken.
184
185 The function `crput' is used in order to store a record.
186
187 int crput(CURIA *curia, const char *kbuf, int ksiz, const char *vbuf,
188 int vsiz, int dmode);
189 `curia' specifies a database handle connected as a writer.
190 `kbuf' specifies the pointer to the region of a key. `ksiz'
191 specifies the size of the region of the key. If it is negative,
192 the size is assigned with `strlen(kbuf)'. `vbuf' specifies the
193 pointer to the region of a value. `vsiz' specifies the size of
194 the region of the value. If it is negative, the size is
195 assigned with `strlen(vbuf)'. `dmode' specifies behavior when
196 the key overlaps, by the following values: `CR_DOVER', which
197 means the specified value overwrites the existing one,
198 `CR_DKEEP', which means the existing value is kept, `CR_DCAT',
199 which means the specified value is concatenated at the end of
200 the existing value. If successful, the return value is true,
201 else, it is false.
202
203 The function `crout' is used in order to delete a record.
204
205 int crout(CURIA *curia, const char *kbuf, int ksiz);
206 `curia' specifies a database handle connected as a writer.
207 `kbuf' specifies the pointer to the region of a key. `ksiz'
208 specifies the size of the region of the key. If it is negative,
209 the size is assigned with `strlen(kbuf)'. If successful, the
210 return value is true, else, it is false. false is returned when
211 no record corresponds to the specified key.
212
213 The function `crget' is used in order to retrieve a record.
214
215 char *crget(CURIA *curia, const char *kbuf, int ksiz, int start, int
216 max, int *sp);
217 `curia' specifies a database handle. `kbuf' specifies the
218 pointer to the region of a key. `ksiz' specifies the size of
219 the region of the key. If it is negative, the size is assigned
220 with `strlen(kbuf)'. `start' specifies the offset address of
221 the beginning of the region of the value to be read. `max'
222 specifies the max size to be read. If it is negative, the size
223 to read is unlimited. `sp' specifies the pointer to a variable
224 to which the size of the region of the return value is assigned.
225 If it is `NULL', it is not used. If successful, the return
226 value is the pointer to the region of the value of the corre‐
227 sponding record, else, it is `NULL'. `NULL' is returned when no
228 record corresponds to the specified key or the size of the value
229 of the corresponding record is less than `start'. Because an
230 additional zero code is appended at the end of the region of the
231 return value, the return value can be treated as a character
232 string. Because the region of the return value is allocated
233 with the `malloc' call, it should be released with the `free'
234 call if it is no longer in use.
235
236 The function `crgetwb' is used in order to retrieve a record and write
237 the value into a buffer.
238
239 int crgetwb(CURIA *curia, const char *kbuf, int ksiz, int start, int
240 max, char *vbuf);
241 `curia' specifies a database handle. `kbuf' specifies the
242 pointer to the region of a key. `ksiz' specifies the size of
243 the region of the key. If it is negative, the size is assigned
244 with `strlen(kbuf)'. `start' specifies the offset address of
245 the beginning of the region of the value to be read. `max'
246 specifies the max size to be read. It shuld be equal to or less
247 than the size of the writing buffer. `vbuf' specifies the
248 pointer to a buffer into which the value of the corresponding
249 record is written. If successful, the return value is the size
250 of the written data, else, it is -1. -1 is returned when no
251 record corresponds to the specified key or the size of the value
252 of the corresponding record is less than `start'. Note that no
253 additional zero code is appended at the end of the region of the
254 writing buffer.
255
256 The function `crvsiz' is used in order to get the size of the value of
257 a record.
258
259 int crvsiz(CURIA *curia, const char *kbuf, int ksiz);
260 `curia' specifies a database handle. `kbuf' specifies the
261 pointer to the region of a key. `ksiz' specifies the size of
262 the region of the key. If it is negative, the size is assigned
263 with `strlen(kbuf)'. If successful, the return value is the
264 size of the value of the corresponding record, else, it is -1.
265 Because this function does not read the entity of a record, it
266 is faster than `crget'.
267
268 The function `criterinit' is used in order to initialize the iterator
269 of a database handle.
270
271 int criterinit(CURIA *curia);
272 `curia' specifies a database handle. If successful, the return
273 value is true, else, it is false. The iterator is used in order
274 to access the key of every record stored in a database.
275
276 The function `criternext' is used in order to get the next key of the
277 iterator.
278
279 char *criternext(CURIA *curia, int *sp);
280 `curia' specifies a database handle. `sp' specifies the pointer
281 to a variable to which the size of the region of the return
282 value is assigned. If it is `NULL', it is not used. If suc‐
283 cessful, the return value is the pointer to the region of the
284 next key, else, it is `NULL'. `NULL' is returned when no record
285 is to be get out of the iterator. Because an additional zero
286 code is appended at the end of the region of the return value,
287 the return value can be treated as a character string. Because
288 the region of the return value is allocated with the `malloc'
289 call, it should be released with the `free' call if it is no
290 longer in use. It is possible to access every record by itera‐
291 tion of calling this function. However, it is not assured if
292 updating the database is occurred while the iteration. Besides,
293 the order of this traversal access method is arbitrary, so it is
294 not assured that the order of storing matches the one of the
295 traversal access.
296
297 The function `crsetalign' is used in order to set alignment of a data‐
298 base handle.
299
300 int crsetalign(CURIA *curia, int align);
301 `curia' specifies a database handle connected as a writer.
302 `align' specifies the size of alignment. If successful, the
303 return value is true, else, it is false. If alignment is set to
304 a database, the efficiency of overwriting values is improved.
305 The size of alignment is suggested to be average size of the
306 values of the records to be stored. If alignment is positive,
307 padding whose size is multiple number of the alignment is
308 placed. If alignment is negative, as `vsiz' is the size of a
309 value, the size of padding is calculated with `(vsiz / pow(2,
310 abs(align) - 1))'. Because alignment setting is not saved in a
311 database, you should specify alignment every opening a database.
312
313 The function `crsetfbpsiz' is used in order to set the size of the free
314 block pool of a database handle.
315
316 int crsetfbpsiz(CURIA *curia, int size);
317 `curia' specifies a database handle connected as a writer.
318 `size' specifies the size of the free block pool of a database.
319 If successful, the return value is true, else, it is false. The
320 default size of the free block pool is 16. If the size is
321 greater, the space efficiency of overwriting values is improved
322 with the time efficiency sacrificed.
323
324 The function `crsync' is used in order to synchronize updating contents
325 with the files and the devices.
326
327 int crsync(CURIA *curia);
328 `curia' specifies a database handle connected as a writer. If
329 successful, the return value is true, else, it is false. This
330 function is useful when another process uses the connected data‐
331 base directory.
332
333 The function `croptimize' is used in order to optimize a database.
334
335 int croptimize(CURIA *curia, int bnum);
336 `curia' specifies a database handle connected as a writer.
337 `bnum' specifies the number of the elements of each bucket
338 array. If it is not more than 0, the default value is speci‐
339 fied. In an alternating succession of deleting and storing with
340 overwrite or concatenate, dispensable regions accumulate. This
341 function is useful to do away with them.
342
343 The function `crname' is used in order to get the name of a database.
344
345 char *crname(CURIA *curia);
346 `curia' specifies a database handle. If successful, the return
347 value is the pointer to the region of the name of the database,
348 else, it is `NULL'. Because the region of the return value is
349 allocated with the `malloc' call, it should be released with the
350 `free' call if it is no longer in use.
351
352 The function `crfsiz' is used in order to get the total size of data‐
353 base files.
354
355 int crfsiz(CURIA *curia);
356 `curia' specifies a database handle. If successful, the return
357 value is the total size of the database files, else, it is -1.
358 If the total size is more than 2GB, the return value overflows.
359
360 The function `crfsizd' is used in order to get the total size of data‐
361 base files as double-precision floating-point number.
362
363 double crfsizd(CURIA *curia);
364 `curia' specifies a database handle. If successful, the return
365 value is the total size of the database files, else, it is -1.0.
366
367 The function `crbnum' is used in order to get the total number of the
368 elements of each bucket array.
369
370 int crbnum(CURIA *curia);
371 `curia' specifies a database handle. If successful, the return
372 value is the total number of the elements of each bucket array,
373 else, it is -1.
374
375 The function `crbusenum' is used in order to get the total number of
376 the used elements of each bucket array.
377
378 int crbusenum(CURIA *curia);
379 `curia' specifies a database handle. If successful, the return
380 value is the total number of the used elements of each bucket
381 array, else, it is -1. This function is inefficient because it
382 accesses all elements of each bucket array.
383
384 The function `crrnum' is used in order to get the number of the records
385 stored in a database.
386
387 int crrnum(CURIA *curia);
388 `curia' specifies a database handle. If successful, the return
389 value is the number of the records stored in the database, else,
390 it is -1.
391
392 The function `crwritable' is used in order to check whether a database
393 handle is a writer or not.
394
395 int crwritable(CURIA *curia);
396 `curia' specifies a database handle. The return value is true
397 if the handle is a writer, false if not.
398
399 The function `crfatalerror' is used in order to check whether a data‐
400 base has a fatal error or not.
401
402 int crfatalerror(CURIA *curia);
403 `curia' specifies a database handle. The return value is true
404 if the database has a fatal error, false if not.
405
406 The function `crinode' is used in order to get the inode number of a
407 database directory.
408
409 int crinode(CURIA *curia);
410 `curia' specifies a database handle. The return value is the
411 inode number of the database directory.
412
413 The function `crmtime' is used in order to get the last modified time
414 of a database.
415
416 time_t crmtime(CURIA *curia);
417 `curia' specifies a database handle. The return value is the
418 last modified time of the database.
419
420 The function `crremove' is used in order to remove a database direc‐
421 tory.
422
423 int crremove(const char *name);
424 `name' specifies the name of a database directory. If success‐
425 ful, the return value is true, else, it is false.
426
427 The function `crrepair' is used in order to repair a broken database
428 directory.
429
430 int crrepair(const char *name);
431 `name' specifies the name of a database directory. If success‐
432 ful, the return value is true, else, it is false. There is no
433 guarantee that all records in a repaired database directory cor‐
434 respond to the original or expected state.
435
436 The function `crexportdb' is used in order to dump all records as
437 endian independent data.
438
439 int crexportdb(CURIA *curia, const char *name);
440 `curia' specifies a database handle. `name' specifies the name
441 of an output directory. If successful, the return value is
442 true, else, it is false. Note that large objects are ignored.
443
444 The function `crimportdb' is used in order to load all records from
445 endian independent data.
446
447 int crimportdb(CURIA *curia, const char *name);
448 `curia' specifies a database handle connected as a writer. The
449 database of the handle must be empty. `name' specifies the name
450 of an input directory. If successful, the return value is true,
451 else, it is false. Note that large objects are ignored.
452
453 The function `crsnaffle' is used in order to retrieve a record directly
454 from a database directory.
455
456 char *crsnaffle(const char *name, const char *kbuf, int ksiz, int *sp);
457 `name' specifies the name of a database directory. `kbuf' spec‐
458 ifies the pointer to the region of a key. `ksiz' specifies the
459 size of the region of the key. If it is negative, the size is
460 assigned with `strlen(kbuf)'. `sp' specifies the pointer to a
461 variable to which the size of the region of the return value is
462 assigned. If it is `NULL', it is not used. If successful, the
463 return value is the pointer to the region of the value of the
464 corresponding record, else, it is `NULL'. `NULL' is returned
465 when no record corresponds to the specified key. Because an
466 additional zero code is appended at the end of the region of the
467 return value, the return value can be treated as a character
468 string. Because the region of the return value is allocated
469 with the `malloc' call, it should be released with the `free'
470 call if it is no longer in use. Although this function can be
471 used even while the database directory is locked by another
472 process, it is not assured that recent updated is reflected.
473
474 The function `crputlob' is used in order to store a large object.
475
476 int crputlob(CURIA *curia, const char *kbuf, int ksiz, const char
477 *vbuf, int vsiz, int dmode);
478 `curia' specifies a database handle connected as a writer.
479 `kbuf' specifies the pointer to the region of a key. `ksiz'
480 specifies the size of the region of the key. If it is negative,
481 the size is assigned with `strlen(kbuf)'. `vbuf' specifies the
482 pointer to the region of a value. `vsiz' specifies the size of
483 the region of the value. If it is negative, the size is
484 assigned with `strlen(vbuf)'. `dmode' specifies behavior when
485 the key overlaps, by the following values: `CR_DOVER', which
486 means the specified value overwrites the existing one,
487 `CR_DKEEP', which means the existing value is kept, `CR_DCAT',
488 which means the specified value is concatenated at the end of
489 the existing value. If successful, the return value is true,
490 else, it is false.
491
492 The function `croutlob' is used in order to delete a large object.
493
494 int croutlob(CURIA *curia, const char *kbuf, int ksiz);
495 `curia' specifies a database handle connected as a writer.
496 `kbuf' specifies the pointer to the region of a key. `ksiz'
497 specifies the size of the region of the key. If it is negative,
498 the size is assigned with `strlen(kbuf)'. If successful, the
499 return value is true, else, it is false. false is returned when
500 no large object corresponds to the specified key.
501
502 The function `crgetlob' is used in order to retrieve a large object.
503
504 char *crgetlob(CURIA *curia, const char *kbuf, int ksiz, int start, int
505 max, int *sp);
506 `curia' specifies a database handle. `kbuf' specifies the
507 pointer to the region of a key. `ksiz' specifies the size of
508 the region of the key. If it is negative, the size is assigned
509 with `strlen(kbuf)'. `start' specifies the offset address of
510 the beginning of the region of the value to be read. `max'
511 specifies the max size to be read. If it is negative, the size
512 to read is unlimited. `sp' specifies the pointer to a variable
513 to which the size of the region of the return value is assigned.
514 If it is `NULL', it is not used. If successful, the return
515 value is the pointer to the region of the value of the corre‐
516 sponding large object, else, it is `NULL'. `NULL' is returned
517 when no large object corresponds to the specified key or the
518 size of the value of the corresponding large object is less than
519 `start'. Because an additional zero code is appended at the end
520 of the region of the return value, the return value can be
521 treated as a character string. Because the region of the return
522 value is allocated with the `malloc' call, it should be released
523 with the `free' call if it is no longer in use.
524
525 The function `crgetlobfd' is used in order to get the file descriptor
526 of a large object.
527
528 int crgetlobfd(CURIA *curia, const char *kbuf, int ksiz);
529 `curia' specifies a database handle. `kbuf' specifies the
530 pointer to the region of a key. `ksiz' specifies the size of
531 the region of the key. If it is negative, the size is assigned
532 with `strlen(kbuf)'. If successful, the return value is the
533 file descriptor of the corresponding large object, else, it is
534 -1. -1 is returned when no large object corresponds to the
535 specified key. The returned file descriptor is opened with the
536 `open' call. If the database handle was opened as a writer, the
537 descriptor is writable (O_RDWR), else, it is not writable
538 (O_RDONLY). The descriptor should be closed with the `close'
539 call if it is no longer in use.
540
541 The function `crvsizlob' is used in order to get the size of the value
542 of a large object.
543
544 int crvsizlob(CURIA *curia, const char *kbuf, int ksiz);
545 `curia' specifies a database handle. `kbuf' specifies the
546 pointer to the region of a key. `ksiz' specifies the size of
547 the region of the key. If it is negative, the size is assigned
548 with `strlen(kbuf)'. If successful, the return value is the
549 size of the value of the corresponding large object, else, it is
550 -1. Because this function does not read the entity of a large
551 object, it is faster than `crgetlob'.
552
553 The function `crrnumlob' is used in order to get the number of the
554 large objects stored in a database.
555
556 int crrnumlob(CURIA *curia);
557 `curia' specifies a database handle. If successful, the return
558 value is the number of the large objects stored in the database,
559 else, it is -1.
560
561 If QDBM was built with POSIX thread enabled, the global variable
562 `dpecode' is treated as thread specific data, and functions of Curia
563 are reentrant. In that case, they are thread-safe as long as a handle
564 is not accessed by threads at the same time, on the assumption that
565 `errno', `malloc', and so on are thread-safe.
566
567
569 qdbm(3), depot(3), relic(3), hovel(3), cabin(3), villa(3), odeum(3),
570 ndbm(3), gdbm(3)
571
572
573
574Man Page 2004-04-22 CURIA(3)