28 #include <yaz/xmalloc.h>
32 #define CF_OPTIMIZE_COMMIT 0
36 #if CF_OPTIMIZE_COMMIT
37 struct map_cache_entity {
46 struct map_cache_entity *map;
51 static struct map_cache *map_cache_init (
CFile cf)
53 int mem_max = 2000000;
54 struct map_cache *m_p;
56 m_p = xmalloc (
sizeof(*m_p));
59 m_p->buf = xmalloc (mem_max);
61 m_p->map = xmalloc (
sizeof(*m_p->map) * m_p->max);
65 static int map_cache_cmp_from (
const void *p1,
const void *p2)
67 return ((
struct map_cache_entity*) p1)->from -
68 ((
struct map_cache_entity*) p2)->from;
71 static int map_cache_cmp_to(
const void *p1,
const void *p2)
73 return ((
struct map_cache_entity*) p1)->to -
74 ((
struct map_cache_entity*) p2)->to;
77 static int map_cache_flush(
struct map_cache *m_p)
81 qsort (m_p->map, m_p->no,
sizeof(*m_p->map), map_cache_cmp_from);
82 assert (m_p->no < 2 || m_p->map[0].from < m_p->map[1].from);
83 for (i = 0; i<m_p->no; i++)
85 if (
mf_read(m_p->cf->block_mf, m_p->map[i].from, 0, 0,
86 m_p->buf + i * m_p->cf->head.block_size) != 1)
88 yaz_log (YLOG_FATAL,
"read commit block at position %d",
94 qsort (m_p->map, m_p->no,
sizeof(*m_p->map), map_cache_cmp_to);
95 assert (m_p->no < 2 || m_p->map[0].to < m_p->map[1].to);
96 for (i = 0; i<m_p->no; i++)
98 if (
mf_write(m_p->cf->rmf, m_p->map[i].to, 0, 0,
99 m_p->buf + m_p->map[i].from * m_p->cf->head.block_size))
106 static int map_cache_del(
struct map_cache *m_p)
108 int r = map_cache_flush(m_p);
115 static int map_cache_add(
struct map_cache *m_p,
int from,
int to)
119 m_p->map[i].from = from;
123 return map_cache_flush(m_p);
136 #if CF_OPTIMIZE_COMMIT
137 struct map_cache *m_p;
140 #if CF_OPTIMIZE_COMMIT
141 m_p = map_cache_init (cf);
150 yaz_log (YLOG_FATAL,
"read commit hash");
156 #if CF_OPTIMIZE_COMMIT
157 if (map_cache_add(m_p, p->
vno[i], p->
no[i]))
165 yaz_log (YLOG_FATAL,
"read commit block");
171 yaz_log (YLOG_FATAL,
"write commit block");
179 #if CF_OPTIMIZE_COMMIT
180 if (map_cache_del(m_p))
195 #if CF_OPTIMIZE_COMMIT
196 struct map_cache *m_p;
200 #if CF_OPTIMIZE_COMMIT
201 m_p = map_cache_init (cf);
211 yaz_log (YLOG_FATAL,
"read index block hno=" ZINT_FORMAT
221 #if CF_OPTIMIZE_COMMIT
222 if (map_cache_add(m_p, fp[i], vno))
248 #if CF_OPTIMIZE_COMMIT
249 if (map_cache_del(m_p))
252 yaz_log(
log_level,
"cf_commit_flat r=%d", r);
261 yaz_log(YLOG_FATAL,
"cf_commit: dirty cache");
271 yaz_log(YLOG_FATAL,
"cf_commit: bad state=%d", cf->
head.
state);
#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
static int cf_commit_flat(CFile cf)
static int cf_commit_hash(CFile cf)
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
CFile hash structure on disc.
All in-memory information per CFile.