X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Frecindex.c;h=72e8259ce00f3ae3c4f97096a3857b8d89dc880e;hb=1e955e15c167cf701d87eb891acd70ed8cdad791;hp=0244da9c526c4796cfcc00ec339a5b9d1ab23100;hpb=f3425fb457792aae865096cf9acf5cb41798b1d1;p=idzebra-moved-to-github.git diff --git a/index/recindex.c b/index/recindex.c index 0244da9..72e8259 100644 --- a/index/recindex.c +++ b/index/recindex.c @@ -4,7 +4,26 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: recindex.c,v $ - * Revision 1.25 1999-07-06 12:28:04 adam + * Revision 1.31 2001-02-26 22:14:59 adam + * Updated for BZIP2 1.0.X. Configure script doesn't enable 64 bit LFS + * on broken glibc on Redhat 7.0. + * + * Revision 1.30 2000/07/13 10:14:20 heikki + * Removed compiler warnings when making zebra + * + * Revision 1.29 2000/04/05 09:49:35 adam + * On Unix, zebra/z'mbol uses automake. + * + * Revision 1.28 1999/12/08 22:44:45 adam + * Zebra/Z'mbol dependencies added. + * + * Revision 1.27 1999/10/29 10:02:33 adam + * Fixed decompression buffer overflow. + * + * Revision 1.26 1999/07/06 13:34:57 adam + * Fixed bug (introduced by previous commit). + * + * Revision 1.25 1999/07/06 12:28:04 adam * Updated record index structure. Format includes version ID. Compression * algorithm ID is stored for each record block. * @@ -387,6 +406,7 @@ Records rec_open (BFiles bfs, int rw, int compression_method) p->cache_cur = 0; p->record_cache = (struct record_cache_entry *) xmalloc (sizeof(*p->record_cache)*p->cache_max); + zebra_mutex_init (&p->mutex); return p; } @@ -419,6 +439,7 @@ static void rec_decode_unsigned(unsigned *np, unsigned char *buf, int *len) (*len)++; *np = n; } + static void rec_cache_flush_block1 (Records p, Record rec, Record last_rec, char **out_buf, int *out_size, int *out_offset) @@ -505,8 +526,8 @@ static void rec_write_multiple (Records p, int saveCount) default: break; } - rec_rm (&e->rec); } + *sysnop = -1; if (ref_count) { @@ -518,7 +539,12 @@ static void rec_write_multiple (Records p, int saveCount) #if HAVE_BZLIB_H csize = out_offset + (out_offset >> 6) + 620; rec_tmp_expand (p, csize); - i = bzBuffToBuffCompress (p->tmp_buf+sizeof(int)+sizeof(short)+ +#ifdef BZ_CONFIG_ERROR + i = BZ2_bzBuffToBuffCompress +#else + i = bzBuffToBuffCompress +#endif + (p->tmp_buf+sizeof(int)+sizeof(short)+ sizeof(char), &csize, out_buf, out_offset, 1, 0, 30); if (i != BZ_OK) @@ -562,6 +588,13 @@ static void rec_cache_flush (Records p, int saveCount) saveCount = 0; rec_write_multiple (p, saveCount); + + for (i = 0; icache_cur - saveCount; i++) + { + struct record_cache_entry *e = p->record_cache + i; + rec_rm (&e->rec); + } + /* i still being used ... */ for (j = 0; jrecord_cache+j, p->record_cache+i, sizeof(*p->record_cache)); @@ -618,6 +651,7 @@ void rec_close (Records *pp) assert (p); + zebra_mutex_destroy (&p->mutex); rec_cache_flush (p, 0); xfree (p->record_cache); @@ -638,17 +672,18 @@ void rec_close (Records *pp) *pp = NULL; } - -Record rec_get (Records p, int sysno) +static Record rec_get_int (Records p, int sysno) { - int i, in_size; + int i, in_size, r; Record rec, *recp; struct record_index_entry entry; int freeblock, dst_type; char *nptr, *cptr; char *in_buf = 0; char *bz_buf = 0; +#if HAVE_BZLIB_H int bz_size; +#endif char compression_method; assert (sysno > 0); @@ -657,7 +692,7 @@ Record rec_get (Records p, int sysno) if ((recp = rec_cache_lookup (p, sysno, recordFlagNop))) return rec_cp (*recp); - if (!read_indx (p, sysno, &entry, sizeof(entry), 1)) + if (read_indx (p, sysno, &entry, sizeof(entry), 1) < 1) return NULL; /* record is not there! */ if (!entry.size) @@ -669,11 +704,12 @@ Record rec_get (Records p, int sysno) assert (freeblock > 0); - rec = (Record) xmalloc (sizeof(*rec)); rec_tmp_expand (p, entry.size); cptr = p->tmp_buf; - bf_read (p->data_BFile[dst_type], freeblock, 0, 0, cptr); + r = bf_read (p->data_BFile[dst_type], freeblock, 0, 0, cptr); + if (r < 0) + return 0; memcpy (&freeblock, cptr, sizeof(freeblock)); while (freeblock) @@ -683,11 +719,14 @@ Record rec_get (Records p, int sysno) cptr += p->head.block_size[dst_type] - sizeof(freeblock); memcpy (&tmp, cptr, sizeof(tmp)); - bf_read (p->data_BFile[dst_type], freeblock, 0, 0, cptr); + r = bf_read (p->data_BFile[dst_type], freeblock, 0, 0, cptr); + if (r < 0) + return 0; memcpy (&freeblock, cptr, sizeof(freeblock)); memcpy (cptr, &tmp, sizeof(tmp)); } + rec = (Record) xmalloc (sizeof(*rec)); rec->sysno = sysno; memcpy (&compression_method, p->tmp_buf + sizeof(int) + sizeof(short), sizeof(compression_method)); @@ -697,14 +736,22 @@ Record rec_get (Records p, int sysno) { case REC_COMPRESS_BZIP2: #if HAVE_BZLIB_H - bz_size = entry.size * 30+100; - bz_buf = (char *) xmalloc (bz_size); - i = bzBuffToBuffDecompress (bz_buf, &bz_size, in_buf, in_size, 0, 0); - logf (LOG_LOG, "decompress %5d %5d", in_size, bz_size); - if (i != BZ_OK) + bz_size = entry.size * 20 + 100; + while (1) { - logf (LOG_FATAL, "bzBuffToBuffDecompress error code=%d", i); - exit (1); + bz_buf = (char *) xmalloc (bz_size); +#ifdef BZ_CONFIG_ERROR + i = BZ2_bzBuffToBuffDecompress +#else + i = bzBuffToBuffDecompress +#endif + (bz_buf, &bz_size, in_buf, in_size, 0, 0); + logf (LOG_LOG, "decompress %5d %5d", in_size, bz_size); + if (i == BZ_OK) + break; + logf (LOG_LOG, "failed"); + xfree (bz_buf); + bz_size *= 2; } in_buf = bz_buf; in_size = bz_size; @@ -767,7 +814,17 @@ Record rec_get (Records p, int sysno) return rec; } -Record rec_new (Records p) +Record rec_get (Records p, int sysno) +{ + Record rec; + zebra_mutex_lock (&p->mutex); + + rec = rec_get_int (p, sysno); + zebra_mutex_unlock (&p->mutex); + return rec; +} + +static Record rec_new_int (Records p) { int sysno, i; Record rec; @@ -784,6 +841,14 @@ Record rec_new (Records p) sysno = p->head.index_free; p->head.index_free = entry.next; } +#if ZMBOL +#else + if (sysno > 100000) + { + logf (LOG_FATAL, "100,000 record limit reached"); + exit (1); + } +#endif (p->head.no_records)++; rec->sysno = sysno; for (i = 0; i < REC_NO_INFO; i++) @@ -795,10 +860,21 @@ Record rec_new (Records p) return rec; } +Record rec_new (Records p) +{ + Record rec; + zebra_mutex_lock (&p->mutex); + + rec = rec_new_int (p); + zebra_mutex_unlock (&p->mutex); + return rec; +} + void rec_del (Records p, Record *recpp) { Record *recp; + zebra_mutex_lock (&p->mutex); (p->head.no_records)--; if ((recp = rec_cache_lookup (p, (*recpp)->sysno, recordFlagDelete))) { @@ -810,6 +886,7 @@ void rec_del (Records p, Record *recpp) rec_cache_insert (p, *recpp, recordFlagDelete); rec_rm (recpp); } + zebra_mutex_unlock (&p->mutex); *recpp = NULL; } @@ -817,6 +894,7 @@ void rec_put (Records p, Record *recpp) { Record *recp; + zebra_mutex_lock (&p->mutex); if ((recp = rec_cache_lookup (p, (*recpp)->sysno, recordFlagWrite))) { rec_rm (recp); @@ -827,6 +905,7 @@ void rec_put (Records p, Record *recpp) rec_cache_insert (p, *recpp, recordFlagWrite); rec_rm (recpp); } + zebra_mutex_unlock (&p->mutex); *recpp = NULL; }