X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Frecindex.c;h=e12fc19148b6adb08656c53a1574a97f546bf4df;hb=93d44a21d1aa585bb7f68d23a7590fc38ccb62a6;hp=64eea73eb8c48cf99d051b34eb38fde5eb032127;hpb=1bb217ab477284fd7fee47f19a6e8a780fa2bb50;p=idzebra-moved-to-github.git diff --git a/index/recindex.c b/index/recindex.c index 64eea73..e12fc19 100644 --- a/index/recindex.c +++ b/index/recindex.c @@ -1,4 +1,4 @@ -/* $Id: recindex.c,v 1.36 2004-08-06 12:28:22 adam Exp $ +/* $Id: recindex.c,v 1.39 2004-11-19 10:27:03 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -20,16 +20,17 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#define RIDX_CHUNK 128 /* * Format of first block - * next (4 bytes) - * ref_count (4 bytes) - * block (504 bytes) + * next (8 bytes) + * ref_count (2 bytes) + * block (500 bytes) * * Format of subsequent blocks - * next (4 bytes) - * block (508 bytes) + * next (8 bytes) + * block (502 bytes) * * Format of each record * sysno @@ -55,7 +56,7 @@ static void rec_write_head (Records p) r = bf_write (p->index_BFile, 0, 0, sizeof(p->head), &p->head); if (r) { - logf (LOG_FATAL|LOG_ERRNO, "write head of %s", p->index_fname); + yaz_log (YLOG_FATAL|YLOG_ERRNO, "write head of %s", p->index_fname); exit (1); } } @@ -76,11 +77,18 @@ static int read_indx (Records p, SYSNO sysno, void *buf, int itemsize, { int r; zint pos = (sysno-1)*itemsize; + int off = (int) (pos%RIDX_CHUNK); + int sz1 = RIDX_CHUNK - off; /* sz1 is size of buffer to read.. */ - r = bf_read (p->index_BFile, 1+pos/128, (int) (pos%128), itemsize, buf); + if (sz1 > itemsize) + sz1 = itemsize; /* no more than itemsize bytes */ + + r = bf_read (p->index_BFile, 1+pos/RIDX_CHUNK, off, sz1, buf); + if (r == 1 && sz1 < itemsize) /* boundary? - must read second part */ + r = bf_read (p->index_BFile, 2+pos/RIDX_CHUNK, 0, itemsize - sz1, buf + sz1); if (r != 1 && !ignoreError) { - logf (LOG_FATAL|LOG_ERRNO, "read in %s at pos %ld", + yaz_log (YLOG_FATAL|YLOG_ERRNO, "read in %s at pos %ld", p->index_fname, (long) pos); exit (1); } @@ -90,15 +98,22 @@ static int read_indx (Records p, SYSNO sysno, void *buf, int itemsize, static void write_indx (Records p, SYSNO sysno, void *buf, int itemsize) { zint pos = (sysno-1)*itemsize; + int off = (int) (pos%RIDX_CHUNK); + int sz1 = RIDX_CHUNK - off; /* sz1 is size of buffer to read.. */ + + if (sz1 > itemsize) + sz1 = itemsize; /* no more than itemsize bytes */ - bf_write (p->index_BFile, 1+pos/128, (int) (pos%128), itemsize, buf); + bf_write(p->index_BFile, 1+pos/RIDX_CHUNK, off, sz1, buf); + if (sz1 < itemsize) /* boundary? must write second part */ + bf_write(p->index_BFile, 2+pos/RIDX_CHUNK, 0, itemsize - sz1, buf + sz1); } static void rec_release_blocks (Records p, SYSNO sysno) { struct record_index_entry entry; zint freeblock; - char block_and_ref[sizeof(short) + sizeof(zint)]; + char block_and_ref[sizeof(zint) + sizeof(short)]; int dst_type; int first = 1; @@ -113,9 +128,10 @@ static void rec_release_blocks (Records p, SYSNO sysno) while (freeblock) { if (bf_read (p->data_BFile[dst_type], freeblock, 0, - sizeof(block_and_ref), block_and_ref) != 1) + first ? sizeof(block_and_ref) : sizeof(zint), + block_and_ref) != 1) { - logf (LOG_FATAL|LOG_ERRNO, "read in rec_del_single"); + yaz_log (YLOG_FATAL|YLOG_ERRNO, "read in rec_del_single"); exit (1); } if (first) @@ -129,7 +145,7 @@ static void rec_release_blocks (Records p, SYSNO sysno) if (bf_write (p->data_BFile[dst_type], freeblock, 0, sizeof(block_and_ref), block_and_ref)) { - logf (LOG_FATAL|LOG_ERRNO, "write in rec_del_single"); + yaz_log (YLOG_FATAL|YLOG_ERRNO, "write in rec_del_single"); exit (1); } return; @@ -140,7 +156,7 @@ static void rec_release_blocks (Records p, SYSNO sysno) if (bf_write (p->data_BFile[dst_type], freeblock, 0, sizeof(freeblock), &p->head.block_free[dst_type])) { - logf (LOG_FATAL|LOG_ERRNO, "write in rec_del_single"); + yaz_log (YLOG_FATAL|YLOG_ERRNO, "write in rec_del_single"); exit (1); } p->head.block_free[dst_type] = freeblock; @@ -184,7 +200,7 @@ static void rec_write_tmp_buf (Records p, int size, SYSNO *sysnos) block_free, 0, sizeof(*p->head.block_free), &p->head.block_free[dst_type]) != 1) { - logf (LOG_FATAL|LOG_ERRNO, "read in %s at free block " ZINT_FORMAT, + yaz_log (YLOG_FATAL|YLOG_ERRNO, "read in %s at free block " ZINT_FORMAT, p->data_fname[dst_type], block_free); exit (1); } @@ -231,10 +247,10 @@ Records rec_open (BFiles bfs, int rw, int compression_method) p->tmp_size = 1024; p->tmp_buf = (char *) xmalloc (p->tmp_size); p->index_fname = "reci"; - p->index_BFile = bf_open (bfs, p->index_fname, 128, rw); + p->index_BFile = bf_open (bfs, p->index_fname, RIDX_CHUNK, rw); if (p->index_BFile == NULL) { - logf (LOG_FATAL|LOG_ERRNO, "open %s", p->index_fname); + yaz_log (YLOG_FATAL|YLOG_ERRNO, "open %s", p->index_fname); exit (1); } r = bf_read (p->index_BFile, 0, 0, 0, p->tmp_buf); @@ -267,13 +283,13 @@ Records rec_open (BFiles bfs, int rw, int compression_method) memcpy (&p->head, p->tmp_buf, sizeof(p->head)); if (memcmp (p->head.magic, REC_HEAD_MAGIC, sizeof(p->head.magic))) { - logf (LOG_FATAL, "file %s has bad format", p->index_fname); + yaz_log (YLOG_FATAL, "file %s has bad format", p->index_fname); exit (1); } version = atoi (p->head.version); if (version != REC_VERSION) { - logf (LOG_FATAL, "file %s is version %d, but version" + yaz_log (YLOG_FATAL, "file %s is version %d, but version" " %d is required", p->index_fname, version, REC_VERSION); exit (1); } @@ -293,7 +309,7 @@ Records rec_open (BFiles bfs, int rw, int compression_method) p->head.block_size[i], rw))) { - logf (LOG_FATAL|LOG_ERRNO, "bf_open %s", p->data_fname[i]); + yaz_log (YLOG_FATAL|YLOG_ERRNO, "bf_open %s", p->data_fname[i]); exit (1); } } @@ -474,10 +490,10 @@ static void rec_write_multiple (Records p, int saveCount) &csize, out_buf, out_offset, 1, 0, 30); if (i != BZ_OK) { - logf (LOG_WARN, "bzBuffToBuffCompress error code=%d", i); + yaz_log (YLOG_WARN, "bzBuffToBuffCompress error code=%d", i); csize = 0; } - logf (LOG_LOG, "compress %4d %5d %5d", ref_count, out_offset, + yaz_log (YLOG_LOG, "compress %4d %5d %5d", ref_count, out_offset, csize); #endif break; @@ -672,17 +688,17 @@ static Record rec_get_int (Records p, SYSNO sysno) i = bzBuffToBuffDecompress #endif (bz_buf, &bz_size, in_buf, in_size, 0, 0); - logf (LOG_LOG, "decompress %5d %5d", in_size, bz_size); + yaz_log (YLOG_LOG, "decompress %5d %5d", in_size, bz_size); if (i == BZ_OK) break; - logf (LOG_LOG, "failed"); + yaz_log (YLOG_LOG, "failed"); xfree (bz_buf); bz_size *= 2; } in_buf = bz_buf; in_size = bz_size; #else - logf (LOG_FATAL, "cannot decompress record(s) in BZIP2 format"); + yaz_log (YLOG_FATAL, "cannot decompress record(s) in BZIP2 format"); exit (1); #endif break;