X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Frecindex.c;h=c11b136b038afb17752ca210b62e2cab47d48df6;hb=b9c1a6fcf5c4821d0190efdecbc14ea5d6c96aec;hp=95a4474932a92d65644da4c551cf780c6b61f53a;hpb=4478d785b7769691261005c98063b98a5a5971b3;p=idzebra-moved-to-github.git diff --git a/index/recindex.c b/index/recindex.c index 95a4474..c11b136 100644 --- a/index/recindex.c +++ b/index/recindex.c @@ -1,4 +1,4 @@ -/* $Id: recindex.c,v 1.51 2006-08-14 10:40:15 adam Exp $ +/* $Id: recindex.c,v 1.55 2006-11-22 11:13:17 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -61,13 +61,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define USUAL_RANGE 2000000000LL #endif -static SYSNO rec_sysno_to_ext(SYSNO sysno) +static zint rec_sysno_to_ext(zint sysno) { assert(sysno >= 0 && sysno <= USUAL_RANGE); return sysno + FAKE_OFFSET; } -SYSNO rec_sysno_to_int(SYSNO sysno) +zint rec_sysno_to_int(zint sysno) { assert(sysno >= FAKE_OFFSET && sysno <= FAKE_OFFSET + USUAL_RANGE); return sysno - FAKE_OFFSET; @@ -101,7 +101,7 @@ static void rec_tmp_expand(Records p, int size) } } -static int read_indx(Records p, SYSNO sysno, void *buf, int itemsize, +static int read_indx(Records p, zint sysno, void *buf, int itemsize, int ignoreError) { int r; @@ -124,7 +124,7 @@ static int read_indx(Records p, SYSNO sysno, void *buf, int itemsize, return r; } -static void write_indx(Records p, SYSNO sysno, void *buf, int itemsize) +static void write_indx(Records p, zint sysno, void *buf, int itemsize) { zint pos = (sysno-1)*itemsize; int off = CAST_ZINT_TO_INT(pos%RIDX_CHUNK); @@ -139,7 +139,7 @@ static void write_indx(Records p, SYSNO sysno, void *buf, int itemsize) (char*) buf + sz1); } -static ZEBRA_RES rec_release_blocks(Records p, SYSNO sysno) +static ZEBRA_RES rec_release_blocks(Records p, zint sysno) { struct record_index_entry entry; zint freeblock; @@ -202,6 +202,8 @@ static ZEBRA_RES rec_delete_single(Records p, Record rec) { struct record_index_entry entry; + /* all data in entry must be reset, since it's written verbatim */ + memset(&entry, '\0', sizeof(entry)); if (rec_release_blocks(p, rec_sysno_to_int(rec->sysno)) != ZEBRA_OK) return ZEBRA_FAIL; @@ -212,7 +214,7 @@ static ZEBRA_RES rec_delete_single(Records p, Record rec) return ZEBRA_OK; } -static ZEBRA_RES rec_write_tmp_buf(Records p, int size, SYSNO *sysnos) +static ZEBRA_RES rec_write_tmp_buf(Records p, int size, zint *sysnos) { struct record_index_entry entry; int no_written = 0; @@ -221,6 +223,9 @@ static ZEBRA_RES rec_write_tmp_buf(Records p, int size, SYSNO *sysnos) int dst_type = 0; int i; + /* all data in entry must be reset, since it's written verbatim */ + memset(&entry, '\0', sizeof(entry)); + for (i = 1; i= p->head.block_move[i]) dst_type = i; @@ -279,6 +284,7 @@ Records rec_open(BFiles bfs, int rw, int compression_method) ZEBRA_RES ret = ZEBRA_OK; p = (Records) xmalloc(sizeof(*p)); + memset(&p->head, '\0', sizeof(p->head)); p->compression_method = compression_method; p->rw = rw; p->tmp_size = 1024; @@ -352,6 +358,7 @@ Records rec_open(BFiles bfs, int rw, int compression_method) { yaz_log(YLOG_FATAL|YLOG_ERRNO, "bf_open %s", p->data_fname[i]); ret = ZEBRA_FAIL; + break; } } p->cache_max = 400; @@ -483,8 +490,8 @@ static ZEBRA_RES rec_write_multiple(Records p, int saveCount) int out_size = 1000; int out_offset = 0; char *out_buf = (char *) xmalloc(out_size); - SYSNO *sysnos = (SYSNO *) xmalloc(sizeof(*sysnos) * (p->cache_cur + 1)); - SYSNO *sysnop = sysnos; + zint *sysnos = (zint *) xmalloc(sizeof(*sysnos) * (p->cache_cur + 1)); + zint *sysnop = sysnos; ZEBRA_RES ret = ZEBRA_OK; for (i = 0; icache_cur - saveCount; i++) @@ -591,7 +598,7 @@ static ZEBRA_RES rec_cache_flush(Records p, int saveCount) for (i = 0; icache_cur - saveCount; i++) { struct record_cache_entry *e = p->record_cache + i; - rec_rm(&e->rec); + rec_free(&e->rec); } /* i still being used ... */ for (j = 0; jmutex); @@ -845,7 +852,7 @@ Record rec_get_root(Records p) static Record rec_new_int(Records p) { int i; - SYSNO sysno; + zint sysno; Record rec; assert(p); @@ -894,13 +901,13 @@ ZEBRA_RES rec_del(Records p, Record *recpp) (p->head.no_records)--; if ((recp = rec_cache_lookup(p, (*recpp)->sysno, recordFlagDelete))) { - rec_rm(recp); + rec_free(recp); *recp = *recpp; } else { ret = rec_cache_insert(p, *recpp, recordFlagDelete); - rec_rm(recpp); + rec_free(recpp); } zebra_mutex_unlock(&p->mutex); *recpp = NULL; @@ -915,20 +922,20 @@ ZEBRA_RES rec_put(Records p, Record *recpp) zebra_mutex_lock(&p->mutex); if ((recp = rec_cache_lookup(p, (*recpp)->sysno, recordFlagWrite))) { - rec_rm(recp); + rec_free(recp); *recp = *recpp; } else { ret = rec_cache_insert(p, *recpp, recordFlagWrite); - rec_rm(recpp); + rec_free(recpp); } zebra_mutex_unlock(&p->mutex); *recpp = NULL; return ret; } -void rec_rm(Record *recpp) +void rec_free(Record *recpp) { int i;