From 399876019df22a56614e9fda05552574939ccc0d Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 20 Feb 2002 23:07:54 +0000 Subject: [PATCH] Fixes for update --- index/Makefile.am | 5 +-- index/extract.c | 11 +++--- index/kinput.c | 97 ++++++++++++++--------------------------------------- index/zebraapi.c | 20 ++++++----- index/zinfo.c | 4 ++- test/api/t2.c | 5 ++- 6 files changed, 52 insertions(+), 90 deletions(-) diff --git a/index/Makefile.am b/index/Makefile.am index 2f5d6ad..31882b4 100644 --- a/index/Makefile.am +++ b/index/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.7 2002-02-20 17:30:01 adam Exp $ +## $Id: Makefile.am,v 1.8 2002-02-20 23:07:54 adam Exp $ noinst_PROGRAMS = apitest kdump @@ -39,6 +39,7 @@ LDADD = libzebra.a $(YAZLIB) $(TCL_LIB) libzebra.a: $(libzebra_a_OBJECTS) $(libzebra_a_DEPENDENCIES) -test ! -d atmp && mkdir atmp + -rm -f libzebra.a mkdir atmp; for i in $(libzebra_a_LIBADD); do cd atmp; ar x ../$$i; cd ..; done - ar qc libzebra.a $(libzebra_a_OBJECTS) libzebra.a atmp/*.o + ar cru libzebra.a $(libzebra_a_OBJECTS) libzebra.a atmp/*.o $(RANLIB) libzebra.a diff --git a/index/extract.c b/index/extract.c index a726916..b08d3bb 100644 --- a/index/extract.c +++ b/index/extract.c @@ -3,7 +3,7 @@ * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * - * $Id: extract.c,v 1.110 2002-02-20 17:30:01 adam Exp $ + * $Id: extract.c,v 1.111 2002-02-20 23:07:54 adam Exp $ */ #include #include @@ -945,7 +945,6 @@ int extract_rec_in_mem (ZebraHandle zh, const char *recordType, } /* match criteria */ - if (! *sysno) { /* new record */ @@ -1442,15 +1441,14 @@ static void extract_add_sort_string (RecWord *p, const char *string, { struct sortKey *sk; ZebraHandle zh = p->extractCtrl->handle; - struct sortKey *sortKeys = zh->sortKeys; - for (sk = sortKeys; sk; sk = sk->next) + for (sk = zh->sortKeys; sk; sk = sk->next) if (sk->attrSet == p->attrSet && sk->attrUse == p->attrUse) return; sk = (struct sortKey *) xmalloc (sizeof(*sk)); - sk->next = sortKeys; - sortKeys = sk; + sk->next = zh->sortKeys; + zh->sortKeys = sk; sk->string = (char *) xmalloc (length); sk->length = length; @@ -1597,6 +1595,7 @@ void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno, xfree (sk); sk = sk_next; } + yaz_log (LOG_LOG, "extract_flushSortKeys"); *skp = 0; } diff --git a/index/kinput.c b/index/kinput.c index b9d7f06..d9257db 100644 --- a/index/kinput.c +++ b/index/kinput.c @@ -3,7 +3,7 @@ * All rights reserved. * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto * - * $Id: kinput.c,v 1.45 2002-02-20 17:30:01 adam Exp $ + * $Id: kinput.c,v 1.46 2002-02-20 23:07:54 adam Exp $ * * Bugs * - Allocates a lot of memory for the merge process, but never releases it. @@ -117,6 +117,13 @@ void key_file_chunk_read (struct key_file *f) close (fd); } +void key_file_destroy (struct key_file *f) +{ + xfree (f->buf); + xfree (f->prev_name); + xfree (f); +} + struct key_file *key_file_init (int no, int chunk, Res res) { struct key_file *f; @@ -253,6 +260,19 @@ struct heap_info *key_heap_init (int nkeys, return hi; } +void key_heap_destroy (struct heap_info *hi, int nkeys) +{ + int i; + yaz_log (LOG_LOG, "key_heap_destroy"); + for (i = 0; i<=nkeys; i++) + xfree (hi->info.buf[i]); + + xfree (hi->info.buf); + xfree (hi->ptr); + xfree (hi->info.file); + xfree (hi); +} + static void key_heap_swap (struct heap_info *hi, int i1, int i2) { int swap; @@ -682,78 +702,11 @@ void zebra_index_merge (ZebraHandle zh) logf (LOG_LOG, "Deletions. . . .%7d", no_deletions); logf (LOG_LOG, "Insertions . . .%7d", no_insertions); zh->key_file_no = 0; -} -void key_input (ZebraHandle zh, int nkeys, int cache, Res res) - -{ - struct key_file **kf; - char rbuf[1024]; - int i, r; - struct heap_info *hi; - struct progressInfo progressInfo; - - if (nkeys < 0) - { - char fname[1024]; - nkeys = 0; - while (1) - { - getFnameTmp (res, fname, nkeys+1); - if (access (fname, R_OK) == -1) - break; - nkeys++; - } - if (!nkeys) - return ; - } - kf = (struct key_file **) xmalloc ((1+nkeys) * sizeof(*kf)); - progressInfo.totalBytes = 0; - progressInfo.totalOffset = 0; - time (&progressInfo.startTime); - time (&progressInfo.lastTime); - for (i = 1; i<=nkeys; i++) - { - kf[i] = key_file_init (i, 8192, res); - kf[i]->readHandler = progressFunc; - kf[i]->readInfo = &progressInfo; - progressInfo.totalBytes += kf[i]->length; - progressInfo.totalOffset += kf[i]->buf_size; - } - hi = key_heap_init (nkeys, key_qsort_compare); - hi->dict = zh->service->dict; - hi->isams = zh->service->isams; -#if ZMBOL - hi->isam = zh->service->isam; - hi->isamc = zh->service->isamc; - hi->isamd = zh->service->isamd; -#endif - + key_heap_destroy (hi, nkeys); for (i = 1; i<=nkeys; i++) - if ((r = key_file_read (kf[i], rbuf))) - key_heap_insert (hi, rbuf, r, kf[i]); - if (hi->isams) - heap_inps (hi); -#if ZMBOL - else if (hi->isamc) - heap_inpc (hi); - else if (hi->isam) - heap_inp (hi); - else if (hi->isamd) - heap_inpd (hi); -#endif - - for (i = 1; i<=nkeys; i++) - { - getFnameTmp (res, rbuf, i); - unlink (rbuf); - } - logf (LOG_LOG, "Iterations . . .%7d", no_iterations); - logf (LOG_LOG, "Distinct words .%7d", no_diffs); - logf (LOG_LOG, "Updates. . . . .%7d", no_updates); - logf (LOG_LOG, "Deletions. . . .%7d", no_deletions); - logf (LOG_LOG, "Insertions . . .%7d", no_insertions); - - /* xmalloc_trav("unfreed"); while hunting leaks */ + key_file_destroy (kf[i]); + xfree (kf); } + diff --git a/index/zebraapi.c b/index/zebraapi.c index bb0c06f..c2ae1d2 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2002, Index Data * All rights reserved. * - * $Id: zebraapi.c,v 1.45 2002-02-20 17:30:01 adam Exp $ + * $Id: zebraapi.c,v 1.46 2002-02-20 23:07:54 adam Exp $ */ #include @@ -34,9 +34,6 @@ static void zebra_chdir (ZebraService zh) static void zebra_flush_reg (ZebraHandle zh) { - if (zh->service->matchDict) - dict_close (zh->service->matchDict); - zh->service->matchDict = 0; zebraExplain_flush (zh->service->zei, 1, zh); extract_flushWriteKeys (zh); @@ -152,7 +149,6 @@ static int zebra_register_activate (ZebraHandle zh, int rw, int useshadow) zs->recTypes = recTypes_init (zs->dh); recTypes_default_handlers (zs->recTypes); - zs->records = NULL; zs->zebra_maps = zebra_maps_open (zs->res); zs->rank_classes = NULL; @@ -160,12 +156,14 @@ static int zebra_register_activate (ZebraHandle zh, int rw, int useshadow) zs->dict = 0; zs->sortIdx = 0; zs->isams = 0; + zs->matchDict = 0; #if ZMBOL zs->isam = 0; zs->isamc = 0; zs->isamd = 0; #endif zs->zei = 0; + zs->matchDict = 0; zebraRankInstall (zs, rank1_class); @@ -181,6 +179,10 @@ static int zebra_register_activate (ZebraHandle zh, int rw, int useshadow) logf (LOG_WARN, "rec_open"); return -1; } + if (rw) + { + zs->matchDict = dict_open (zs->bfs, GMATCH_DICT, 50, 1, 0); + } if (!(zs->dict = dict_open (zs->bfs, FNAME_DICT, 80, rw, 0))) { logf (LOG_WARN, "dict_open"); @@ -282,6 +284,8 @@ static int zebra_register_deactivate (ZebraHandle zh) { zebraExplain_close (zs->zei, 0); dict_close (zs->dict); + if (zs->matchDict) + dict_close (zs->matchDict); sortIdx_close (zs->sortIdx); if (zs->isams) isams_close (zs->isams); @@ -716,12 +720,14 @@ static int zebra_begin_read (ZebraHandle zh) char val; int seqno; - zebra_flush_reg (zh); (zh->trans_no)++; if (zh->trans_no != 1) + { + zebra_flush_reg (zh); return 0; + } zebra_get_state (&val, &seqno); if (val == 'd') @@ -832,8 +838,6 @@ void zebra_begin_trans (ZebraHandle zh) zebra_set_state ('d', seqno); zebra_register_activate (zh, 1, rval ? 1 : 0); - zh->service->matchDict = dict_open (zh->service->bfs, GMATCH_DICT, - 50, 1, 0); zh->seqno = seqno; } diff --git a/index/zinfo.c b/index/zinfo.c index d91b11e..4f5509b 100644 --- a/index/zinfo.c +++ b/index/zinfo.c @@ -3,7 +3,7 @@ * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * - * $Id: zinfo.c,v 1.23 2002-02-20 17:30:01 adam Exp $ + * $Id: zinfo.c,v 1.24 2002-02-20 23:07:54 adam Exp $ */ #include @@ -269,6 +269,8 @@ static Record createRecord (Records records, int *sysno) void zebraExplain_flush (ZebraExplainInfo zei, int writeFlag, void *handle) { + if (!zei) + return; zei->updateHandle = handle; if (writeFlag) { diff --git a/test/api/t2.c b/test/api/t2.c index dfe8fef..4e0d6bc 100644 --- a/test/api/t2.c +++ b/test/api/t2.c @@ -1,5 +1,5 @@ /* - * $Id: t2.c,v 1.1 2002-02-20 17:30:02 adam Exp $ + * $Id: t2.c,v 1.2 2002-02-20 23:07:54 adam Exp $ */ #include @@ -29,6 +29,9 @@ int main(int argc, char **argv) zebra_close (zh); zebra_stop (zs); + odr_destroy (odr_input); + odr_destroy (odr_output); + nmem_exit (); xmalloc_trav ("x"); exit (0); -- 1.7.10.4