27 #include <yaz/yaz-util.h>
28 #include <yaz/snprintf.h>
41 const char *tab = (
char*) cf->
array;
62 char *tab = (
char*) cf->
array;
83 int block_size,
int wflag,
int *firstp)
91 memset(cf,
'Z',
sizeof(*cf));
93 yaz_log(YLOG_DEBUG,
"cf: open %s %s", fname, wflag ?
"rdwr" :
"rd");
105 cf->
iobuf = (
char *) xmalloc(block_size);
106 memset(cf->
iobuf, 0, block_size);
116 yaz_snprintf(path,
sizeof(path),
"%s-b", fname);
122 yaz_snprintf(path,
sizeof(path),
"%s-i", fname);
145 cf->
array = (
zint *) xmalloc(hash_bytes);
171 cf->
array = (
zint *) xmalloc(hash_bytes);
220 for (i = 0; i != no_to_flush; i++)
279 yaz_log(YLOG_FATAL,
"read get_bucket");
333 if (hb->
ph.
no[i] == no)
336 *vno = hb->
ph.
vno[i];
354 yaz_log(YLOG_FATAL,
"Found hash bucket on other chain(1)");
358 if (hb->
ph.
no[i] == no)
360 yaz_log(YLOG_FATAL,
"Found hash bucket on other chain (2)");
370 if (hb->
ph.
no[i] == no)
372 *vno = hb->
ph.
vno[i];
397 yaz_log(YLOG_DEBUG,
"cf: Moving to flat shadow: %s", cf->
rmf->
name);
398 yaz_log(YLOG_DEBUG,
"cf: hits=%d miss=%d bucket_in_memory=" ZINT_FORMAT " total="
411 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"read bucket moveto flat");
472 if (hb->ph.this_bucket == *bucketpp)
474 bucketpp = &hb->ph.next_bucket;
484 if (hb->ph.this_bucket == *bucketpp)
486 yaz_log(YLOG_FATAL,
"Found hash bucket on other chain");
503 bucketpp = &hb->ph.next_bucket;
554 yaz_log(YLOG_FATAL,
"cf_lookup failed");
602 if (offset || nbytes)
606 memcpy(cf->
iobuf + offset, buf, nbytes);
619 yaz_log(YLOG_DEBUG,
"cf: close hits=%d miss=%d bucket_in_memory=" ZINT_FORMAT
static zint cf_new_flat(CFile cf, zint no)
CFile cf_open(MFile mf, MFile_area area, const char *fname, int block_size, int wflag, int *firstp)
static int cf_lookup(CFile cf, zint no, zint *vno)
static int cf_write_flat(CFile cf, zint no, zint vno)
static int cf_moveto_flat(CFile cf)
static int read_head(CFile cf)
int cf_read(CFile cf, zint no, int offset, int nbytes, void *buf)
reads block from commit area
static int cf_hash(CFile cf, zint no)
static zint cf_new_hash(CFile cf, zint no)
static struct CFile_hash_bucket * alloc_bucket(CFile cf, zint block_no, int hno)
static int write_head(CFile cf)
zint cf_new(CFile cf, zint no)
static struct CFile_hash_bucket * get_bucket(CFile cf, zint block_no, int hno)
static int cf_lookup_hash(CFile cf, zint no, zint *vno)
int cf_write(CFile cf, zint no, int offset, int nbytes, const void *buf)
writes block to commit area
static int flush_bucket(CFile cf, int no_to_flush)
static int cf_lookup_flat(CFile cf, zint no, zint *vno)
static void release_bucket(CFile cf, struct CFile_hash_bucket *p)
static struct CFile_hash_bucket * new_bucket(CFile cf, zint *block_nop, int hno)
struct CFile_struct * CFile
All in-memory information per CFile.
#define CFILE_STATE_HASH
state of CFile is a hash structure
#define CFILE_STATE_FLAT
state of CFile is a flat file file
#define HASH_BUCKET
number of blocks in hash bucket
int mf_write(MFile mf, zint no, int offset, int nbytes, const void *buf)
writes block to metafile
int mf_read(MFile mf, zint no, int offset, int nbytes, void *buf)
reads block from metafile
int mf_close(MFile mf)
closes metafile
MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag)
opens metafile
CFile hash structure info in memory.
struct CFile_hash_bucket * lru_next
struct CFile_ph_bucket ph
struct CFile_hash_bucket * h_next
struct CFile_hash_bucket * lru_prev
struct CFile_hash_bucket ** h_prev
All in-memory information per CFile.
struct CFile_hash_bucket ** parray
struct CFile_hash_bucket * bucket_lru_back
struct CFile_hash_bucket * bucket_lru_front
zint max_bucket_in_memory
int zebra_mutex_unlock(Zebra_mutex *p)
int zebra_mutex_init(Zebra_mutex *p)
int zebra_mutex_lock(Zebra_mutex *p)
int zebra_mutex_destroy(Zebra_mutex *p)