From b6d310ad2e492a94a65f62bf461948a4c5afa8be Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 9 Sep 2005 14:22:12 +0000 Subject: [PATCH] Clear a few errors systematically --- index/kinput.c | 143 ++++++++++++++++++++++++++++++++++++++++-------------- index/zebraapi.c | 18 +++---- 2 files changed, 116 insertions(+), 45 deletions(-) diff --git a/index/kinput.c b/index/kinput.c index 3ed7512..cc53181 100644 --- a/index/kinput.c +++ b/index/kinput.c @@ -1,5 +1,5 @@ -/* $Id: kinput.c,v 1.60 2004-08-04 08:35:23 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 +/* $Id: kinput.c,v 1.59.2.1 2005-09-09 14:22:12 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps This file is part of the Zebra server. @@ -19,6 +19,8 @@ along with Zebra; see the file LICENSE.zebra. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + + #include #ifdef WIN32 @@ -47,12 +49,8 @@ struct key_file { size_t chunk; /* number of bytes allocated */ size_t buf_ptr; /* current position in buffer */ char *prev_name; /* last word read */ -#if IT_KEY_NEW - void *decode_handle; -#else int sysno; /* last sysno */ int seqno; /* last seqno */ -#endif off_t length; /* length of file */ /* handler invoked in each read */ void (*readHandler)(struct key_file *keyp, void *rinfo); @@ -126,9 +124,6 @@ void key_file_chunk_read (struct key_file *f) void key_file_destroy (struct key_file *f) { -#if IT_KEY_NEW - iscz1_stop(f->decode_handle); -#endif xfree (f->buf); xfree (f->prev_name); xfree (f); @@ -140,12 +135,8 @@ struct key_file *key_file_init (int no, int chunk, Res res) f = (struct key_file *) xmalloc (sizeof(*f)); f->res = res; -#if IT_KEY_NEW - f->decode_handle = iscz1_start(); -#else f->sysno = 0; f->seqno = 0; -#endif f->no = no; f->chunk = chunk; f->offset = 0; @@ -200,22 +191,15 @@ int key_file_decode (struct key_file *f) int key_file_read (struct key_file *f, char *key) { - int i, c; - char srcbuf[128]; -#if IT_KEY_NEW - const char *src = srcbuf; - char *dst; - int j; -#else + int i, d, c; struct it_key itkey; - int d; -#endif c = key_file_getc (f); if (c == 0) { strcpy (key, f->prev_name); i = 1+strlen (key); + } else if (c == EOF) return 0; @@ -226,20 +210,19 @@ int key_file_read (struct key_file *f, char *key) while ((key[i++] = key_file_getc (f))) ; strcpy (f->prev_name, key); -#if IT_KEY_NEW - iscz1_reset(f->decode_handle); -#endif + f->sysno = 0; + if (0) + { + int j; + char s[200]; + *s = '\0'; + for (j = 0; jdecode_handle, &dst, &src); - return i + sizeof(struct it_key); -#else d = key_file_decode (f); key[i++] = d & 1; d = d >> 1; @@ -251,10 +234,13 @@ int key_file_read (struct key_file *f, char *key) } d = key_file_decode (f); itkey.seqno = d + f->seqno; +#if 0 + yaz_log(LOG_LOG, "key sysno=%d seqno=%d cmd=%d", itkey.sysno, itkey.seqno, + key[i-1]); +#endif f->seqno = itkey.seqno; memcpy (key + i, &itkey, sizeof(struct it_key)); return i + sizeof (struct it_key); -#endif } struct heap_info { @@ -704,6 +690,87 @@ int heap_inpb (struct heap_info *hi) return 0; } +int heap_inpd (struct heap_info *hi) +{ + struct heap_cread_info hci; + ISAMD_I isamd_i = (ISAMD_I) xmalloc (sizeof(*isamd_i)); + + hci.key = (char *) xmalloc (KEY_SIZE); + hci.key_1 = (char *) xmalloc (KEY_SIZE); + hci.key_2 = (char *) xmalloc (KEY_SIZE); + hci.ret = -1; + hci.first_in_list = 1; + hci.hi = hi; + hci.more = heap_read_one (hi, hci.cur_name, hci.key); + + isamd_i->clientData = &hci; + isamd_i->read_item = heap_cread_item; + + while (hci.more) + { + char this_name[INP_NAME_MAX]; + char *dict_info; + char dictentry[ISAMD_MAX_DICT_LEN+1]; + char dictlen; + + strcpy (this_name, hci.cur_name); + + /* print_dict_item (hi->reg->zebra_maps, hci.cur_name); */ + /*!*/ /* FIXME: depend on isamd-debug */ + + assert (hci.cur_name[1]); + hi->no_diffs++; + if ((dict_info = dict_lookup (hi->reg->dict, hci.cur_name))) + { + dictlen=dict_info[0]; + memcpy (dictentry, dict_info+1, dictlen ); +#ifdef SKIPTHIS + logf(LOG_LOG,"dictentry before. len=%d: %d %d %d %d %d %d %d %d %d", + dictlen,dictentry[0], dictentry[1], dictentry[2], + dictentry[3], dictentry[4], dictentry[5], + dictentry[6], dictentry[7], dictentry[8]); /*!*/ +#endif + dictlen= isamd_append(hi->reg->isamd, dictentry, dictlen, isamd_i); + /* logf dictentry after */ + if (dictlen) + { + hi->no_updates++; + if ( (dictlen!=dict_info[0]) || + (0!=memcmp(dictentry, dict_info+1, dictlen)) ) + { + dict_insert(hi->reg->dict, this_name, + dictlen,dictentry); + } + } + else + { + hi->no_deletions++; + if (!dict_delete (hi->reg->dict, this_name)) + { + logf (LOG_FATAL, "dict_delete failed"); + abort(); + } + } + } + else + { + dictlen=0; + memset (dictentry, '\0', ISAMD_MAX_DICT_LEN); + dictlen= isamd_append(hi->reg->isamd, dictentry, dictlen, isamd_i); + /* logf dictentry first */ + hi->no_insertions++; + if (dictlen) + dict_insert(hi->reg->dict, this_name, + dictlen,dictentry); + } + } + xfree (isamd_i); + xfree (hci.key); + xfree (hci.key_1); + xfree (hci.key_2); + return 0; +} + int heap_inp (struct heap_info *hi) { char *info; @@ -915,6 +982,8 @@ void zebra_index_merge (ZebraHandle zh) heap_inpc (hi); if (zh->reg->isam) heap_inp (hi); + if (zh->reg->isamd) + heap_inpd (hi); if (zh->reg->isamb) heap_inpb (hi); @@ -941,3 +1010,5 @@ void zebra_index_merge (ZebraHandle zh) key_heap_destroy (hi, nkeys); } + + diff --git a/index/zebraapi.c b/index/zebraapi.c index 393f8b2..44a4aa0 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.120.2.9 2005-05-30 13:39:55 adam Exp $ +/* $Id: zebraapi.c,v 1.120.2.10 2005-09-09 14:22:12 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -744,7 +744,6 @@ int zebra_select_database (ZebraHandle zh, const char *basename) { ASSERTZH; yaz_log(LOG_API,"zebra_select_database %s",basename); - zh->errCode=0; return zebra_select_databases (zh, 1, &basename); } @@ -758,7 +757,7 @@ int zebra_select_databases (ZebraHandle zh, int num_bases, ASSERTZH; yaz_log(LOG_API,"zebra_select_databases n=%d [0]=%s", num_bases,basenames[0]); - zh->errCode=0; + zebra_clearError(zh); if (num_bases < 1) { @@ -832,7 +831,8 @@ int zebra_search_RPN (ZebraHandle zh, ODR o, { ASSERTZH; yaz_log(LOG_API,"zebra_search_rpn"); - zh->errCode=0; + + zebra_clearError(zh); zh->hits = 0; *hits = 0; @@ -859,7 +859,8 @@ int zebra_records_retrieve (ZebraHandle zh, ODR stream, int i, *pos_array, ret = 0; ASSERTZH; yaz_log(LOG_API,"zebra_records_retrieve n=%d",num_recs); - zh->errCode=0; + + zebra_clearError(zh); if (!zh->res) { @@ -868,8 +869,6 @@ int zebra_records_retrieve (ZebraHandle zh, ODR stream, return -1; } - zh->errCode = 0; - if (zebra_begin_read (zh)) return -1; @@ -1206,12 +1205,13 @@ static int delete_SU_handle(void *handle, int ord) return 0; } -int zebra_drop_database (ZebraHandle zh, const char *database) +int zebra_drop_database (ZebraHandle zh, const char *database) { int ret = 0; ASSERTZH; yaz_log(LOG_API,"zebra_drop_database"); - zh->errCode = 0; + + zebra_clearError(zh); if (zebra_select_database (zh, database)) return -1; -- 1.7.10.4