IDZEBRA
2.1.3
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <yaz/xmalloc.h>
#include <idzebra/util.h>
#include <idzebra/bfile.h>
#include "mfile.h"
#include "cfile.h"
Go to the source code of this file.
Data Structures | |
struct | BFile_struct |
struct | BFiles_struct |
Macros | |
#define | HEADER_SIZE 256 |
Functions | |
BFiles | bfs_create (const char *spec, const char *base) |
creates a Block files collection More... | |
void | bfs_destroy (BFiles bfs) |
destroys a block files handle More... | |
static FILE * | open_cache (BFiles bfs, const char *flags) |
static void | unlink_cache (BFiles bfs) |
ZEBRA_RES | bf_cache (BFiles bfs, const char *spec) |
enables or disables shadow for block files More... | |
int | bf_close2 (BFile bf) |
closes a Block file More... | |
void | bf_close (BFile bf) |
closes a Block file (may call exit) More... | |
BFile | bf_xopen (BFiles bfs, const char *name, int block_size, int wrflag, const char *magic, int *read_version, const char **more_info) |
opens and returns an extended Block file handle More... | |
int | bf_xclose (BFile bf, int version, const char *more_info) |
closes an extended Block file handle.. More... | |
BFile | bf_open (BFiles bfs, const char *name, int block_size, int wflag) |
opens and returns a Block file handle More... | |
int | bf_read (BFile bf, zint no, int offset, int nbytes, void *buf) |
read from block file (may call exit) More... | |
int | bf_read2 (BFile bf, zint no, int offset, int nbytes, void *buf) |
read from block file More... | |
int | bf_write (BFile bf, zint no, int offset, int nbytes, const void *buf) |
writes block of bytes to file (may call exit) More... | |
int | bf_write2 (BFile bf, zint no, int offset, int nbytes, const void *buf) |
writes block of bytes to file More... | |
int | bf_commitExists (BFiles bfs) |
Check if there is content in shadow area (to be committed). More... | |
void | bf_reset (BFiles bfs) |
Removes register and shadow completely. More... | |
int | bf_commitExec (BFiles bfs) |
Executes commit operation. More... | |
void | bf_commitClean (BFiles bfs, const char *spec) |
Cleans shadow files (remove them) More... | |
int | bf_alloc (BFile bf, int no, zint *blocks) |
Allocates one or more blocks in an extended block file. More... | |
int | bf_free (BFile bf, int no, const zint *blocks) |
Releases one or more blocks in an extended block file. More... | |
int | bfs_register_directory_stat (BFiles bfs, int no, const char **directory, double *used_bytes, double *max_bytes) |
int | bfs_shadow_directory_stat (BFiles bfs, int no, const char **directory, double *used_bytes, double *max_bytes) |
#define HEADER_SIZE 256 |
Definition at line 160 of file bfile.c.
Referenced by bf_xopen().
Allocates one or more blocks in an extended block file.
bf | extended block file |
no | number of blocks to allocate |
blocks | output array of size no with block offsets |
Definition at line 452 of file bfile.c.
References BFile_struct::alloc_buf, bf_read(), BFile_struct::free_list, BFile_struct::header_dirty, BFile_struct::last_block, zebra_zint_decode(), and ZINT_FORMAT.
enables or disables shadow for block files
bfs | block files |
spec | such as "shadow:100M /other:200M"; or NULL to disable |
ZEBRA_OK | successful. spec is OK |
ZEBRA_FAIL | failure. |
Definition at line 105 of file bfile.c.
References BFiles_struct::base, BFiles_struct::cache_fname, BFiles_struct::commit_area, MFile_area_struct::dirs, mf_init(), mf_dir::name, ZEBRA_FAIL, and ZEBRA_OK.
Referenced by bf_commitClean(), tst(), zebra_commit_ex(), zebra_init(), and zebra_register_open().
void bf_close | ( | BFile | bf | ) |
closes a Block file (may call exit)
bf | block file |
Definition at line 151 of file bfile.c.
References bf_close2(), and zebra_exit().
Referenced by bf_open(), bf_xopen(), dict_bf_close(), isamb_close(), isamc_close(), isams_close(), rec_close(), recindex_close(), tst(), zebra_sort_close(), and zebra_sort_type().
int bf_close2 | ( | BFile | bf | ) |
closes a Block file
bf | block file |
0 | success |
-1 | failure |
Definition at line 131 of file bfile.c.
References BFile_struct::alloc_buf, BFile_struct::cf, cf_close(), BFile_struct::magic, BFile_struct::mf, mf_close(), BFile_struct::rdwr_lock, and zebra_lock_rdwr_destroy().
Referenced by bf_close(), and bf_xclose().
void bf_commitClean | ( | BFiles | bfs, |
const char * | spec | ||
) |
Cleans shadow files (remove them)
bfs | block files |
spec | shadow specification |
Definition at line 435 of file bfile.c.
References bf_cache(), BFiles_struct::commit_area, mf_reset(), and unlink_cache().
Referenced by zebra_commit_ex(), and zebra_end_transaction().
int bf_commitExec | ( | BFiles | bfs | ) |
Executes commit operation.
bfs | block files |
Definition at line 391 of file bfile.c.
References BFile_struct::block_size, BFile_struct::cf, cf_close(), cf_commit(), cf_open(), BFiles_struct::commit_area, inf, BFile_struct::mf, mf_close(), mf_open(), open_cache(), and BFiles_struct::register_area.
Referenced by zebra_commit_ex().
int bf_commitExists | ( | BFiles | bfs | ) |
Check if there is content in shadow area (to be committed).
bfs | block files |
1 | there is content in shadow area |
0 | no content in shadow area |
Definition at line 369 of file bfile.c.
References inf, and open_cache().
Referenced by zebra_commit_ex().
Releases one or more blocks in an extended block file.
bf | extended block file |
no | numer of blocks to release |
blocks | input array with block offsets (IDs) to release |
Definition at line 480 of file bfile.c.
References BFile_struct::alloc_buf, bf_write(), BFile_struct::free_list, BFile_struct::header_dirty, and zebra_zint_encode().
opens and returns a Block file handle
bfs | block files |
name | filename |
block_size | block size in bytes |
wflag | 1=opened for read&write, 0=read only |
0 | success |
-1 | failure (can never happen as the code is now) |
Definition at line 261 of file bfile.c.
References BFile_struct::alloc_buf, bf_close(), BFile_struct::block_size, BFiles_struct::cache_fname, BFile_struct::cf, cf_open(), BFiles_struct::commit_area, BFile_struct::header_dirty, BFile_struct::magic, BFile_struct::mf, mf_open(), open_cache(), outf, BFile_struct::rdwr_lock, BFiles_struct::register_area, and zebra_lock_rdwr_init().
Referenced by bf_xopen(), dict_bf_open(), isamb_open2(), isamc_open(), isams_open(), rec_open(), recindex_open(), tst(), and zebra_sort_type().
read from block file (may call exit)
bf | block file handle |
no | block no (first block is 0, second is 1..) |
offset | offset within block to be read |
nbytes | number of bytes to read (0 for whole block) |
buf | raw bytes with content (at least nbytes of size) |
1 | whole block could be read |
0 | whole block could not be read |
Definition at line 319 of file bfile.c.
References bf_read2(), and zebra_exit().
Referenced by alloc_block(), bf_alloc(), bf_xopen(), cache_block(), dict_bf_readp(), isamb_open2(), isamc_open(), isamc_read_block(), isamc_write_dblock(), isams_open(), isams_pp_open(), isams_read_item(), new_block(), open_block(), rec_get_int(), rec_prstat(), rec_release_blocks(), rec_write_tmp_buf(), recindex_read_head(), recindex_read_indx(), tst(), zebra_sort_read(), and zebra_sort_type().
read from block file
bf | block file handle |
no | block no (first block is 0, second is 1..) |
offset | offset within block to be read |
nbytes | number of bytes to read (0 for whole block) |
buf | raw bytes with content (at least nbytes of size) |
1 | whole block could be read |
0 | whole block could not be read |
-1 | error |
Definition at line 330 of file bfile.c.
References BFile_struct::cf, cf_read(), BFile_struct::mf, mf_read(), BFile_struct::rdwr_lock, zebra_lock_rdwr_rlock(), and zebra_lock_rdwr_runlock().
Referenced by bf_read().
void bf_reset | ( | BFiles | bfs | ) |
Removes register and shadow completely.
bfs | block files |
Definition at line 382 of file bfile.c.
References BFiles_struct::commit_area, mf_reset(), BFiles_struct::register_area, and unlink_cache().
Referenced by main(), tst(), tst1(), tst2(), tst3(), and zebra_init().
writes block of bytes to file (may call exit)
bf | block file handle |
no | block no |
offset | within block |
nbytes | number of bytes to write |
buf | buffer to write |
0 | success (block could be written) |
This function can not return a failure. System calls exit(1) if write failed.
Definition at line 346 of file bfile.c.
References bf_write2(), and zebra_exit().
Referenced by bf_free(), bf_xclose(), cache_block(), close_block(), dict_bf_flush_blocks(), flush_blocks(), isamb_close(), isamc_close(), isamc_merge(), isamc_write_block(), isamc_write_dblock(), isams_close(), isams_merge(), rec_release_blocks(), rec_write_tmp_buf(), recindex_write_head(), recindex_write_indx(), release_block(), tst(), zebra_sort_add(), and zebra_sort_delete().
writes block of bytes to file
bf | block file handle |
no | block no |
offset | within block |
nbytes | number of bytes to write |
buf | buffer to write |
0 | success (block written) |
-1 | error |
This function can not return a failure. System calls exit(1) if write failed.
Definition at line 357 of file bfile.c.
References BFile_struct::cf, cf_write(), BFile_struct::mf, mf_write(), BFile_struct::rdwr_lock, zebra_lock_rdwr_wlock(), and zebra_lock_rdwr_wunlock().
Referenced by bf_write().
int bf_xclose | ( | BFile | bf, |
int | version, | ||
const char * | more_info | ||
) |
closes an extended Block file handle..
bf | extended block file opened with bf_xopen |
version | version to be put in a file |
more_info | more information to be stored in file (header) |
0 | success |
-1 | failure (can never happen as the code is now) |
Definition at line 239 of file bfile.c.
References BFile_struct::alloc_buf, bf_close2(), bf_write(), BFile_struct::block_size, BFile_struct::free_list, BFile_struct::header_dirty, BFile_struct::last_block, BFile_struct::magic, and ZINT_FORMAT.
BFile bf_xopen | ( | BFiles | bfs, |
const char * | name, | ||
int | block_size, | ||
int | wflag, | ||
const char * | magic, | ||
int * | read_version, | ||
const char ** | more_info | ||
) |
opens and returns an extended Block file handle
bfs | block files |
name | filename |
block_size | block size in bytes |
wflag | 1=opened for read&write, 0=read only |
magic | magic string to be used for file |
read_version | holds after completion of bf_xopen the version |
more_info | holds more_info as read from file (header) |
Definition at line 162 of file bfile.c.
References BFile_struct::alloc_buf, BFile_struct::alloc_buf_size, bf_close(), bf_open(), bf_read(), BFile_struct::block_size, BFile_struct::free_list, BFile_struct::header_dirty, HEADER_SIZE, BFile_struct::last_block, BFile_struct::magic, BFile_struct::root_block, and ZINT_FORMAT.
BFiles bfs_create | ( | const char * | spec, |
const char * | base | ||
) |
creates a Block files collection
spec | register specification , e.g. "d1:100M d2:1G" |
base | base directory for register spec (if that is relative path) |
Definition at line 63 of file bfile.c.
References BFiles_struct::base, bfs_destroy(), BFiles_struct::cache_fname, BFiles_struct::commit_area, mf_init(), and BFiles_struct::register_area.
Referenced by main(), tst(), zebra_commit_ex(), zebra_compact(), zebra_end_transaction(), zebra_init(), and zebra_register_open().
void bfs_destroy | ( | BFiles | bfiles | ) |
destroys a block files handle
bfiles | block files handle |
The files in the block files collection are not deleted. Only the handle is freed.
Definition at line 80 of file bfile.c.
References BFiles_struct::base, BFiles_struct::cache_fname, BFiles_struct::commit_area, mf_destroy(), and BFiles_struct::register_area.
Referenced by bfs_create(), main(), tst(), zebra_commit_ex(), zebra_compact(), zebra_end_transaction(), zebra_init(), zebra_register_close(), and zebra_register_open().
int bfs_register_directory_stat | ( | BFiles | bfs, |
int | no, | ||
const char ** | directory, | ||
double * | used_bytes, | ||
double * | max_bytes | ||
) |
Definition at line 497 of file bfile.c.
References mf_area_directory_stat(), and BFiles_struct::register_area.
Referenced by show_bfs_stats().
int bfs_shadow_directory_stat | ( | BFiles | bfs, |
int | no, | ||
const char ** | directory, | ||
double * | used_bytes, | ||
double * | max_bytes | ||
) |
Definition at line 505 of file bfile.c.
References BFiles_struct::commit_area, and mf_area_directory_stat().
Referenced by show_bfs_stats().
|
static |
Definition at line 91 of file bfile.c.
References BFiles_struct::cache_fname.
Referenced by bf_commitExec(), bf_commitExists(), and bf_open().
|
static |
Definition at line 99 of file bfile.c.
References BFiles_struct::cache_fname.
Referenced by bf_commitClean(), and bf_reset().