From 2b1851bd5565e3d21f9cf9a37661a584c063b75f Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 4 Apr 2002 14:14:13 +0000 Subject: [PATCH] Multiple registers (alpha early) --- bfile/bfile.c | 60 +++-- bfile/mfile.c | 19 +- buildconf.sh | 10 +- dict/dicttest.c | 9 +- include/bfile.h | 7 +- include/direntz.h | 7 +- include/mfile.h | 4 +- include/res.h | 47 +--- index/apitest.c | 36 ++- index/attribute.c | 13 +- index/extract.c | 288 +++++++++++----------- index/index.h | 267 +++++++++++++++++++-- index/invstat.c | 31 ++- index/kdump.c | 9 +- index/kinput.c | 29 ++- index/lockutil.c | 3 +- index/main.c | 18 +- index/rank1.c | 15 +- index/retrieve.c | 26 +- index/trav.c | 18 +- index/trunc.c | 45 ++-- index/zebraapi.c | 651 ++++++++++++++++++++++++++++++++++---------------- index/zebraapi.h | 58 ++++- index/zinfo.c | 20 +- index/zrpn.c | 100 ++++---- index/zserver.c | 51 ++-- index/zserver.h | 240 +------------------ index/zsets.c | 51 ++-- rset/rsisamc.c | 6 +- test/api/Makefile.am | 2 +- util/dirent.c | 18 +- util/res.c | 115 ++------- 32 files changed, 1239 insertions(+), 1034 deletions(-) diff --git a/bfile/bfile.c b/bfile/bfile.c index ce6972d..2d92341 100644 --- a/bfile/bfile.c +++ b/bfile/bfile.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: bfile.c,v $ - * Revision 1.32 2000-03-15 15:00:30 adam + * Revision 1.33 2002-04-04 14:14:13 adam + * Multiple registers (alpha early) + * + * Revision 1.32 2000/03/15 15:00:30 adam * First work on threaded version. * * Revision 1.31 1999/12/08 15:03:11 adam @@ -119,15 +122,19 @@ struct BFiles_struct { MFile_area commit_area; MFile_area_struct *register_area; - char *lockDir; + char *base; + char *cache_fname; }; -BFiles bfs_create (const char *spec) +BFiles bfs_create (const char *spec, const char *base) { BFiles bfs = (BFiles) xmalloc (sizeof(*bfs)); bfs->commit_area = NULL; - bfs->register_area = mf_init("register", spec); - bfs->lockDir = NULL; + bfs->base = 0; + bfs->cache_fname = 0; + if (base) + bfs->base = xstrdup (base); + bfs->register_area = mf_init("register", spec, base); if (!bfs->register_area) { bfs_destroy(bfs); @@ -138,7 +145,8 @@ BFiles bfs_create (const char *spec) void bfs_destroy (BFiles bfs) { - xfree (bfs->lockDir); + xfree (bfs->cache_fname); + xfree (bfs->base); mf_destroy (bfs->commit_area); mf_destroy (bfs->register_area); xfree (bfs); @@ -146,45 +154,32 @@ void bfs_destroy (BFiles bfs) static FILE *open_cache (BFiles bfs, const char *flags) { - char cacheFilename[1024]; FILE *file; - sprintf (cacheFilename, "%scache", - bfs->lockDir ? bfs->lockDir : ""); - file = fopen (cacheFilename, flags); + file = fopen (bfs->cache_fname, flags); return file; } static void unlink_cache (BFiles bfs) { - char cacheFilename[1024]; - - sprintf (cacheFilename, "%scache", - bfs->lockDir ? bfs->lockDir : ""); - unlink (cacheFilename); -} - -void bf_lockDir (BFiles bfs, const char *lockDir) -{ - size_t len; - - xfree (bfs->lockDir); - if (lockDir == NULL) - lockDir = ""; - len = strlen(lockDir); - bfs->lockDir = (char *) xmalloc (len+2); - strcpy (bfs->lockDir, lockDir); - - if (len > 0 && bfs->lockDir[len-1] != '/') - strcpy (bfs->lockDir + len, "/"); + unlink (bfs->cache_fname); } void bf_cache (BFiles bfs, const char *spec) { if (spec) { + yaz_log (LOG_LOG, "enabling cache spec=%s", spec); if (!bfs->commit_area) - bfs->commit_area = mf_init ("shadow", spec); + bfs->commit_area = mf_init ("shadow", spec, bfs->base); + if (bfs->commit_area) + { + bfs->cache_fname = xmalloc (strlen(bfs->commit_area->dirs->name)+ + 8); + strcpy (bfs->cache_fname, bfs->commit_area->dirs->name); + strcat (bfs->cache_fname, "/cache"); + yaz_log (LOG_LOG, "cache_fname = %s", bfs->cache_fname); + } } else bfs->commit_area = NULL; @@ -218,8 +213,7 @@ BFile bf_open (BFiles bfs, const char *name, int block_size, int wflag) outf = open_cache (bfs, "ab"); if (!outf) { - logf (LOG_FATAL|LOG_ERRNO, "open %scache", - bfs->lockDir ? bfs->lockDir : ""); + logf (LOG_FATAL|LOG_ERRNO, "open %s", bfs->cache_fname); exit (1); } fprintf (outf, "%s %d\n", name, block_size); diff --git a/bfile/mfile.c b/bfile/mfile.c index 4fce68e..794d529 100644 --- a/bfile/mfile.c +++ b/bfile/mfile.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: mfile.c,v $ - * Revision 1.41 2000-11-29 14:24:01 adam + * Revision 1.42 2002-04-04 14:14:13 adam + * Multiple registers (alpha early) + * + * Revision 1.41 2000/11/29 14:24:01 adam * Script configure uses yaz pthreads options. Added locking for * zebra_register_{lock,unlock}. * @@ -159,7 +162,7 @@ #include #include -static int scan_areadef(MFile_area ma, const char *name, const char *ad) +static int scan_areadef(MFile_area ma, const char *ad, const char *base) { /* * If no definition is given, use current directory, unlimited. @@ -168,7 +171,7 @@ static int scan_areadef(MFile_area ma, const char *name, const char *ad) mf_dir **dp = &ma->dirs, *dir = *dp; if (!ad) - ad = ".:-1b"; + ad = ".:-1b"; for (;;) { const char *ad0 = ad; @@ -179,6 +182,12 @@ static int scan_areadef(MFile_area ma, const char *name, const char *ad) ad++; if (!*ad) break; + if (!zebra_is_abspath(ad) && base) + { + strcpy (dirname, base); + i = strlen(dirname); + dirname[i++] = '/'; + } while (*ad) { if (*ad == ':' && strchr ("+-0123456789", ad[1])) @@ -283,7 +292,7 @@ static int cmp_part_file(const void *p1, const void *p2) * Create a new area, cotaining metafiles in directories. * Find the part-files in each directory, and inventory the existing metafiles. */ -MFile_area mf_init(const char *name, const char *spec) +MFile_area mf_init(const char *name, const char *spec, const char *base) { MFile_area ma = (MFile_area) xmalloc(sizeof(*ma)); mf_dir *dirp; @@ -298,7 +307,7 @@ MFile_area mf_init(const char *name, const char *spec) strcpy(ma->name, name); ma->mfiles = 0; ma->dirs = 0; - if (scan_areadef(ma, name, spec) < 0) + if (scan_areadef(ma, spec, base) < 0) { logf (LOG_WARN, "Failed to access description of '%s'", name); return 0; diff --git a/buildconf.sh b/buildconf.sh index 60dd200..4823d77 100755 --- a/buildconf.sh +++ b/buildconf.sh @@ -1,16 +1,16 @@ #!/bin/sh -# $Id: buildconf.sh,v 1.5 2001-02-28 09:01:41 adam Exp $ +# $Id: buildconf.sh,v 1.6 2002-04-04 14:14:13 adam Exp $ dir=`aclocal --print-ac-dir` if [ -f $dir/yaz.m4 ]; then - aclocal || exit 1 + aclocal else - aclocal -I . || exit 1 + aclocal -I . fi test -d isamc || mkdir isamc test -d isamb || mkdir isamb test -d isam || mkdir isam -automake -a >/dev/null 2>&1 || exit 2 -autoconf || exit 3 +automake -a >/dev/null 2>&1 +autoconf if [ -f config.cache ]; then rm config.cache fi diff --git a/dict/dicttest.c b/dict/dicttest.c index 57f1119..da56a75 100644 --- a/dict/dicttest.c +++ b/dict/dicttest.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dicttest.c,v $ - * Revision 1.25 2000-12-05 09:59:10 adam + * Revision 1.26 2002-04-04 14:14:13 adam + * Multiple registers (alpha early) + * + * Revision 1.25 2000/12/05 09:59:10 adam * Work on dict_delete_subtree. * * Revision 1.24 2000/09/05 14:04:05 adam @@ -228,13 +231,13 @@ int main (int argc, char **argv) logf (LOG_FATAL, "no config and/or dictionary specified"); exit (1); } - my_resource = res_open (config); + my_resource = res_open (config, 0); if (!my_resource) { logf (LOG_FATAL, "cannot open resource `%s'", config); exit (1); } - bfs = bfs_create (res_get(my_resource, "register")); + bfs = bfs_create (res_get(my_resource, "register"), 0); if (!bfs) { logf (LOG_FATAL, "bfs_create fail"); diff --git a/include/bfile.h b/include/bfile.h index d3c9380..018a8d6 100644 --- a/include/bfile.h +++ b/include/bfile.h @@ -3,7 +3,7 @@ * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * - * $Id: bfile.h,v 1.19 2000-03-15 15:00:30 adam Exp $ + * $Id: bfile.h,v 1.20 2002-04-04 14:14:13 adam Exp $ */ #ifndef BFILE_H @@ -19,7 +19,7 @@ extern "C" { typedef struct BFiles_struct *BFiles; -BFiles bfs_create (const char *spec); +BFiles bfs_create (const char *spec, const char *base); void bfs_destroy (BFiles bfiles); typedef struct BFile_struct @@ -57,9 +57,6 @@ int bf_write (BFile bf, int no, int offset, int nbytes, const void *buf); /* bf_cache: enables bfile cache if spec is not NULL */ void bf_cache (BFiles bfs, const char *spec); -/* bf_lockDir: specifies locking directory for the cache system */ -void bf_lockDir (BFiles bfs, const char *lockDir); - /* bf_commitExists: returns 1 if commit is pending; 0 otherwise */ int bf_commitExists (BFiles bfs); diff --git a/include/direntz.h b/include/direntz.h index 52770ec..7e8ba5b 100644 --- a/include/direntz.h +++ b/include/direntz.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: direntz.h,v $ - * Revision 1.4 1999-05-26 07:49:13 adam + * Revision 1.5 2002-04-04 14:14:13 adam + * Multiple registers (alpha early) + * + * Revision 1.4 1999/05/26 07:49:13 adam * C++ compilation. * * Revision 1.3 1999/02/02 14:50:33 adam @@ -47,3 +50,5 @@ void closedir (DIR *dd); /* include UNIX version */ #include #endif + +int zebra_is_abspath (const char *p); diff --git a/include/mfile.h b/include/mfile.h index 865914c..81fd99e 100644 --- a/include/mfile.h +++ b/include/mfile.h @@ -3,7 +3,7 @@ * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * - * $Id: mfile.h,v 1.16 2001-01-14 13:41:06 adam Exp $ + * $Id: mfile.h,v 1.17 2002-04-04 14:14:13 adam Exp $ */ #ifndef MFILE_H @@ -83,7 +83,7 @@ typedef struct MFile_area_struct /* * Open an area, cotaining metafiles in directories. */ -MFile_area mf_init(const char *name, const char *spec); +MFile_area mf_init(const char *name, const char *spec, const char *base); /* * Release an area. diff --git a/include/res.h b/include/res.h index 1ebbc71..fce25f9 100644 --- a/include/res.h +++ b/include/res.h @@ -1,38 +1,9 @@ /* - * Copyright (C) 1994-1999, Index Data + * Copyright (C) 1994-2002, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * - * $Log: res.h,v $ - * Revision 1.10 1999-02-02 14:50:36 adam - * Updated WIN32 code specific sections. Changed header. - * - * Revision 1.9 1997/11/18 10:04:03 adam - * Function res_trav returns number of 'hits'. - * - * Revision 1.8 1997/09/17 12:19:10 adam - * Zebra version corresponds to YAZ version 1.4. - * Changed Zebra server so that it doesn't depend on global common_resource. - * - * Revision 1.7 1997/09/05 15:30:02 adam - * Changed prototype for chr_map_input - added const. - * Added support for C++, headers uses extern "C" for public definitions. - * - * Revision 1.6 1996/10/29 13:44:12 adam - * Added res_get_match. - * - * Revision 1.5 1994/09/16 14:37:46 quinn - * added res_get_def - * - * Revision 1.4 1994/09/06 13:02:29 quinn - * Removed const from res_get - * - * Revision 1.3 1994/08/18 09:43:04 adam - * Added res_trav. Major changes of prototypes. - * - * Revision 1.2 1994/08/18 08:22:26 adam - * Res.h modified. xmalloc now declares xstrdup. - * + * $Id: res.h,v 1.11 2002-04-04 14:14:13 adam Exp $ */ #ifndef RES_H @@ -42,19 +13,9 @@ extern "C" { #endif -struct res_entry { - char *name; - char *value; - struct res_entry *next; -}; - -typedef struct res_struct { - struct res_entry *first, *last; - char *name; - int init; -} *Res; +typedef struct res_struct *Res; -Res res_open (const char *name); +Res res_open (const char *name, Res res_def); void res_close (Res r); char *res_get (Res r, const char *name); char *res_get_def (Res r, const char *name, char *def); diff --git a/index/apitest.c b/index/apitest.c index c9eac7f..9bfe1af 100644 --- a/index/apitest.c +++ b/index/apitest.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2000, Index Data * All rights reserved. * - * $Header: /home/cvsroot/idis/index/Attic/apitest.c,v 1.10 2000-09-06 08:59:36 adam Exp $ + * $Header: /home/cvsroot/idis/index/Attic/apitest.c,v 1.11 2002-04-04 14:14:13 adam Exp $ */ #include @@ -113,7 +113,7 @@ int main (int argc, char **argv) ZebraHandle zh; /* the database we specify in our example */ - char *base = "Default"; + const char *base = "Default"; int argno; nmem_init (); @@ -136,6 +136,7 @@ int main (int argc, char **argv) printf ("zebras_open failed\n"); exit (1); } + zebra_select_databases (zh, 1, &base); /* Each argument to main will be a query */ for (argno = 1; argno < argc; argno++) { @@ -144,8 +145,8 @@ int main (int argc, char **argv) char setname[64]; int errCode; int i; - const char *errString; - char *errAdd; + int hits; + char *errString; ZebraRetrievalRecord *records; int noOfRecordsToFetch; @@ -179,28 +180,26 @@ int main (int argc, char **argv) sprintf (setname, "%d", argno); /* fire up the search */ - zebra_search_rpn (zh, odr_input, odr_output, query, 1, &base, setname); + zebra_search_rpn (zh, odr_input, odr_output, query, setname, &hits); /* status ... */ - errCode = zebra_errCode (zh); - errString = zebra_errString (zh); - errAdd = zebra_errAdd (zh); + zebra_result (zh, &errCode, &errString); /* error? */ if (errCode) { - printf ("Zebra Search Error %d %s %s\n", - errCode, errString, errAdd ? errAdd : ""); + printf ("Zebra Search Error %d %s\n", + errCode, errString); continue; } /* ok ... */ - printf ("Zebra Search gave %d hits\n", zebra_hits (zh)); + printf ("Zebra Search gave %d hits\n", hits); /* Deterimine number of records to fetch ... */ - if (zebra_hits(zh) > 10) + if (hits > 10) noOfRecordsToFetch = 10; else - noOfRecordsToFetch = zebra_hits(zh); + noOfRecordsToFetch = hits; /* reset our memory - we've finished dealing with search */ odr_reset (odr_input); @@ -217,15 +216,14 @@ int main (int argc, char **argv) noOfRecordsToFetch, records); /* status ... */ - errCode = zebra_errCode (zh); - errString = zebra_errString (zh); - errAdd = zebra_errAdd (zh); - + + zebra_result (zh, &errCode, &errString); + /* error ? */ if (errCode) { - printf ("Zebra Search Error %d %s %s\n", - errCode, errString, errAdd ? errAdd : ""); + printf ("Zebra Search Error %d %s\n", + errCode, errString); } else { diff --git a/index/attribute.c b/index/attribute.c index e3aedba..efdb9ad 100644 --- a/index/attribute.c +++ b/index/attribute.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: attribute.c,v $ - * Revision 1.12 2000-03-15 15:00:30 adam + * Revision 1.13 2002-04-04 14:14:13 adam + * Multiple registers (alpha early) + * + * Revision 1.12 2000/03/15 15:00:30 adam * First work on threaded version. * * Revision 1.11 1999/11/30 13:48:03 adam @@ -51,7 +54,7 @@ #include #include #include -#include "zserver.h" +#include "index.h" static data1_att *getatt(data1_attset *p, int att) { @@ -74,10 +77,10 @@ int att_getentbyatt(ZebraHandle zi, attent *res, oid_value set, int att) data1_att *r; data1_attset *p; - if (!(p = data1_attset_search_id (zi->service->dh, set))) + if (!(p = data1_attset_search_id (zi->reg->dh, set))) { - zebraExplain_loadAttsets (zi->service->dh, zi->service->res); - p = data1_attset_search_id (zi->service->dh, set); + zebraExplain_loadAttsets (zi->reg->dh, zi->res); + p = data1_attset_search_id (zi->reg->dh, set); } if (!p) return -2; diff --git a/index/extract.c b/index/extract.c index 713a90e..2f4bf84 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.113 2002-03-15 20:20:55 adam Exp $ + * $Id: extract.c,v 1.114 2002-04-04 14:14:13 adam Exp $ */ #include #include @@ -14,12 +14,8 @@ #endif #include -#include -#include -#include #include "index.h" -#include "zserver.h" -#include "zinfo.h" +#include #if _FILE_OFFSET_BITS == 64 #define PRINTF_OFF_T "%Ld" @@ -27,14 +23,6 @@ #define PRINTF_OFF_T "%ld" #endif -#ifndef ZEBRASDR -#define ZEBRASDR 0 -#endif - -#if ZEBRASDR -#include "zebrasdr.h" -#endif - static int records_inserted = 0; static int records_updated = 0; static int records_deleted = 0; @@ -82,7 +70,7 @@ static const char **searchRecordKey (ZebraHandle zh, ws[i] = NULL; #if SU_SCHEME - chS = zebraExplain_lookupSU (zh->service->zei, attrSetS, attrUseS); + chS = zebraExplain_lookupSU (zh->reg->zei, attrSetS, attrUseS); if (chS < 0) return ws; #endif @@ -232,7 +220,7 @@ static void file_end (void *handle, off_t offset) p->file_moffset = offset; } -static char *fileMatchStr (ZebraHandle zh, +static char *fileMatchStr (ZebraHandle zh, struct recKeys *reckeys, struct recordGroup *rGroup, const char *fname, const char *spec) { @@ -271,11 +259,11 @@ static char *fileMatchStr (ZebraHandle zh, attname_str[i] = '\0'; } - if ((attset = data1_get_attset (zh->service->dh, attset_str))) + if ((attset = data1_get_attset (zh->reg->dh, attset_str))) { data1_att *att; attSet = attset->reference; - att = data1_getattbyname(zh->service->dh, attset, attname_str); + att = data1_getattbyname(zh->reg->dh, attset, attname_str); if (att) attUse = att->value; else @@ -422,11 +410,11 @@ static int recordExtract (ZebraHandle zh, /* we are going to read from a file, so prepare the extraction */ int i; - zh->keys.buf_used = 0; - zh->keys.prevAttrUse = -1; - zh->keys.prevAttrSet = -1; - zh->keys.prevSeqNo = 0; - zh->sortKeys = 0; + zh->reg->keys.buf_used = 0; + zh->reg->keys.prevAttrUse = -1; + zh->reg->keys.prevAttrSet = -1; + zh->reg->keys.prevSeqNo = 0; + zh->reg->sortKeys = 0; recordOffset = fi->file_moffset; extractCtrl.offset = fi->file_moffset; @@ -439,16 +427,16 @@ static int recordExtract (ZebraHandle zh, extractCtrl.init = extract_init; extractCtrl.tokenAdd = extract_token_add; extractCtrl.schemaAdd = extract_schema_add; - extractCtrl.dh = zh->service->dh; + extractCtrl.dh = zh->reg->dh; extractCtrl.handle = zh; for (i = 0; i<256; i++) { - if (zebra_maps_is_positioned(zh->service->zebra_maps, i)) + if (zebra_maps_is_positioned(zh->reg->zebra_maps, i)) extractCtrl.seqno[i] = 1; else extractCtrl.seqno[i] = 0; } - extractCtrl.zebra_maps = zh->service->zebra_maps; + extractCtrl.zebra_maps = zh->reg->zebra_maps; extractCtrl.flagShowRecords = !rGroup->flagRw; if (!rGroup->flagRw) @@ -476,7 +464,7 @@ static int recordExtract (ZebraHandle zh, } return 0; } - if (zh->keys.buf_used == 0) + if (zh->reg->keys.buf_used == 0) { /* the extraction process returned no information - the record is probably empty - unless flagShowRecords is in use */ @@ -500,11 +488,11 @@ static int recordExtract (ZebraHandle zh, { char *rinfo; - matchStr = fileMatchStr (zh, &zh->keys, rGroup, fname, + matchStr = fileMatchStr (zh, &zh->reg->keys, rGroup, fname, rGroup->recordId); if (matchStr) { - rinfo = dict_lookup (zh->service->matchDict, matchStr); + rinfo = dict_lookup (zh->reg->matchDict, matchStr); if (rinfo) memcpy (sysno, rinfo+1, sizeof(*sysno)); } @@ -529,18 +517,18 @@ static int recordExtract (ZebraHandle zh, if (records_processed < rGroup->fileVerboseLimit) logf (LOG_LOG, "add %s %s " PRINTF_OFF_T, rGroup->recordType, fname, recordOffset); - rec = rec_new (zh->service->records); + rec = rec_new (zh->reg->records); *sysno = rec->sysno; - recordAttr = rec_init_attr (zh->service->zei, rec); + recordAttr = rec_init_attr (zh->reg->zei, rec); if (matchStr) { - dict_insert (zh->service->matchDict, matchStr, sizeof(*sysno), sysno); + dict_insert (zh->reg->matchDict, matchStr, sizeof(*sysno), sysno); } - extract_flushRecordKeys (zh, *sysno, 1, &zh->keys); - extract_flushSortKeys (zh, *sysno, 1, &zh->sortKeys); + extract_flushRecordKeys (zh, *sysno, 1, &zh->reg->keys); + extract_flushSortKeys (zh, *sysno, 1, &zh->reg->sortKeys); records_inserted++; } @@ -549,24 +537,24 @@ static int recordExtract (ZebraHandle zh, /* record already exists */ struct recKeys delkeys; - rec = rec_get (zh->service->records, *sysno); + rec = rec_get (zh->reg->records, *sysno); assert (rec); - recordAttr = rec_init_attr (zh->service->zei, rec); + recordAttr = rec_init_attr (zh->reg->zei, rec); if (recordAttr->runNumber == - zebraExplain_runNumberIncrement (zh->service->zei, 0)) + zebraExplain_runNumberIncrement (zh->reg->zei, 0)) { logf (LOG_LOG, "skipped %s %s " PRINTF_OFF_T, rGroup->recordType, fname, recordOffset); - extract_flushSortKeys (zh, *sysno, -1, &zh->sortKeys); + extract_flushSortKeys (zh, *sysno, -1, &zh->reg->sortKeys); rec_rm (&rec); logRecord (0); return 1; } delkeys.buf_used = rec->size[recInfo_delKeys]; delkeys.buf = rec->info[recInfo_delKeys]; - extract_flushSortKeys (zh, *sysno, 0, &zh->sortKeys); + extract_flushSortKeys (zh, *sysno, 0, &zh->reg->sortKeys); extract_flushRecordKeys (zh, *sysno, 0, &delkeys); if (deleteFlag) { @@ -584,8 +572,8 @@ static int recordExtract (ZebraHandle zh, rGroup->recordType, fname, recordOffset); records_deleted++; if (matchStr) - dict_delete (zh->service->matchDict, matchStr); - rec_del (zh->service->records, &rec); + dict_delete (zh->reg->matchDict, matchStr); + rec_del (zh->reg->records, &rec); } rec_rm (&rec); logRecord (0); @@ -605,7 +593,7 @@ static int recordExtract (ZebraHandle zh, if (records_processed < rGroup->fileVerboseLimit) logf (LOG_LOG, "update %s %s " PRINTF_OFF_T, rGroup->recordType, fname, recordOffset); - extract_flushRecordKeys (zh, *sysno, 1, &zh->keys); + extract_flushRecordKeys (zh, *sysno, 1, &zh->reg->keys); records_updated++; } } @@ -622,13 +610,13 @@ static int recordExtract (ZebraHandle zh, /* update delete keys */ xfree (rec->info[recInfo_delKeys]); - if (zh->keys.buf_used > 0 && rGroup->flagStoreKeys == 1) + if (zh->reg->keys.buf_used > 0 && rGroup->flagStoreKeys == 1) { #if 1 - rec->size[recInfo_delKeys] = zh->keys.buf_used; - rec->info[recInfo_delKeys] = zh->keys.buf; - zh->keys.buf = NULL; - zh->keys.buf_max = 0; + rec->size[recInfo_delKeys] = zh->reg->keys.buf_used; + rec->info[recInfo_delKeys] = zh->reg->keys.buf; + zh->reg->keys.buf = NULL; + zh->reg->keys.buf_max = 0; #else rec->info[recInfo_delKeys] = xmalloc (reckeys.buf_used); rec->size[recInfo_delKeys] = reckeys.buf_used; @@ -643,16 +631,16 @@ static int recordExtract (ZebraHandle zh, } /* save file size of original record */ - zebraExplain_recordBytesIncrement (zh->service->zei, + zebraExplain_recordBytesIncrement (zh->reg->zei, - recordAttr->recordSize); recordAttr->recordSize = fi->file_moffset - recordOffset; if (!recordAttr->recordSize) recordAttr->recordSize = fi->file_max - recordOffset; - zebraExplain_recordBytesIncrement (zh->service->zei, + zebraExplain_recordBytesIncrement (zh->reg->zei, recordAttr->recordSize); /* set run-number for this record */ - recordAttr->runNumber = zebraExplain_runNumberIncrement (zh->service->zei, + recordAttr->runNumber = zebraExplain_runNumberIncrement (zh->reg->zei, 0); /* update store data */ @@ -690,7 +678,7 @@ static int recordExtract (ZebraHandle zh, recordAttr->recordOffset = recordOffset; /* commit this record */ - rec_put (zh->service->records, &rec); + rec_put (zh->reg->records, &rec); logRecord (0); return 1; } @@ -732,10 +720,10 @@ int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, if (!rGroup->recordType) { sprintf (ext_res, "%srecordType.%s", gprefix, ext); - if (!(rGroup->recordType = res_get (zh->service->res, ext_res))) + if (!(rGroup->recordType = res_get (zh->res, ext_res))) { sprintf (ext_res, "%srecordType", gprefix); - rGroup->recordType = res_get (zh->service->res, ext_res); + rGroup->recordType = res_get (zh->res, ext_res); } } if (!rGroup->recordType) @@ -747,7 +735,7 @@ int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, if (!*rGroup->recordType) return 0; if (!(recType = - recType_byName (zh->service->recTypes, rGroup->recordType, subType, + recType_byName (zh->reg->recTypes, rGroup->recordType, subType, &clientData))) { logf (LOG_WARN, "No such record type: %s", rGroup->recordType); @@ -758,17 +746,17 @@ int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, if (!rGroup->recordId) { sprintf (ext_res, "%srecordId.%s", gprefix, ext); - rGroup->recordId = res_get (zh->service->res, ext_res); + rGroup->recordId = res_get (zh->res, ext_res); } /* determine database name */ if (!rGroup->databaseName) { sprintf (ext_res, "%sdatabase.%s", gprefix, ext); - if (!(rGroup->databaseName = res_get (zh->service->res, ext_res))) + if (!(rGroup->databaseName = res_get (zh->res, ext_res))) { sprintf (ext_res, "%sdatabase", gprefix); - rGroup->databaseName = res_get (zh->service->res, ext_res); + rGroup->databaseName = res_get (zh->res, ext_res); } } if (!rGroup->databaseName) @@ -778,12 +766,12 @@ int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, sprintf (ext_res, "%sexplainDatabase", gprefix); rGroup->explainDatabase = - atoi (res_get_def (zh->service->res, ext_res, "0")); + atoi (res_get_def (zh->res, ext_res, "0")); /* announce database */ - if (zebraExplain_curDatabase (zh->service->zei, rGroup->databaseName)) + if (zebraExplain_curDatabase (zh->reg->zei, rGroup->databaseName)) { - if (zebraExplain_newDatabase (zh->service->zei, rGroup->databaseName, + if (zebraExplain_newDatabase (zh->reg->zei, rGroup->databaseName, rGroup->explainDatabase)) return 0; } @@ -792,10 +780,10 @@ int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, { const char *sval; sprintf (ext_res, "%sstoreData.%s", gprefix, ext); - if (!(sval = res_get (zh->service->res, ext_res))) + if (!(sval = res_get (zh->res, ext_res))) { sprintf (ext_res, "%sstoreData", gprefix); - sval = res_get (zh->service->res, ext_res); + sval = res_get (zh->res, ext_res); } if (sval) rGroup->flagStoreData = atoi (sval); @@ -808,14 +796,14 @@ int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, const char *sval; sprintf (ext_res, "%sstoreKeys.%s", gprefix, ext); - sval = res_get (zh->service->res, ext_res); + sval = res_get (zh->res, ext_res); if (!sval) { sprintf (ext_res, "%sstoreKeys", gprefix); - sval = res_get (zh->service->res, ext_res); + sval = res_get (zh->res, ext_res); } if (!sval) - sval = res_get (zh->service->res, "storeKeys"); + sval = res_get (zh->res, "storeKeys"); if (sval) rGroup->flagStoreKeys = atoi (sval); } @@ -880,36 +868,36 @@ int extract_rec_in_mem (ZebraHandle zh, const char *recordType, extractCtrl.fh = &fc; /* announce database */ - if (zebraExplain_curDatabase (zh->service->zei, databaseName)) + if (zebraExplain_curDatabase (zh->reg->zei, databaseName)) { - if (zebraExplain_newDatabase (zh->service->zei, databaseName, 0)) + if (zebraExplain_newDatabase (zh->reg->zei, databaseName, 0)) return 0; } if (!(recType = - recType_byName (zh->service->recTypes, recordType, subType, + recType_byName (zh->reg->recTypes, recordType, subType, &clientData))) { logf (LOG_WARN, "No such record type: %s", recordType); return 0; } - zh->keys.buf_used = 0; - zh->keys.prevAttrUse = -1; - zh->keys.prevAttrSet = -1; - zh->keys.prevSeqNo = 0; - zh->sortKeys = 0; + zh->reg->keys.buf_used = 0; + zh->reg->keys.prevAttrUse = -1; + zh->reg->keys.prevAttrSet = -1; + zh->reg->keys.prevSeqNo = 0; + zh->reg->sortKeys = 0; extractCtrl.subType = subType; extractCtrl.init = extract_init; extractCtrl.tokenAdd = extract_token_add; extractCtrl.schemaAdd = extract_schema_add; - extractCtrl.dh = zh->service->dh; + extractCtrl.dh = zh->reg->dh; extractCtrl.handle = zh; - extractCtrl.zebra_maps = zh->service->zebra_maps; + extractCtrl.zebra_maps = zh->reg->zebra_maps; extractCtrl.flagShowRecords = 0; for (i = 0; i<256; i++) { - if (zebra_maps_is_positioned(zh->service->zebra_maps, i)) + if (zebra_maps_is_positioned(zh->reg->zebra_maps, i)) extractCtrl.seqno[i] = 1; else extractCtrl.seqno[i] = 0; @@ -934,7 +922,7 @@ int extract_rec_in_mem (ZebraHandle zh, const char *recordType, #endif return 0; } - if (zh->keys.buf_used == 0) + if (zh->reg->keys.buf_used == 0) { /* the extraction process returned no information - the record is probably empty - unless flagShowRecords is in use */ @@ -958,32 +946,32 @@ int extract_rec_in_mem (ZebraHandle zh, const char *recordType, } logf (LOG_LOG, "add %s %s %ld", recordType, fname, (long) recordOffset); - rec = rec_new (zh->service->records); + rec = rec_new (zh->reg->records); *sysno = rec->sysno; - recordAttr = rec_init_attr (zh->service->zei, rec); + recordAttr = rec_init_attr (zh->reg->zei, rec); if (matchStr) { - dict_insert (zh->service->matchDict, matchStr, + dict_insert (zh->reg->matchDict, matchStr, sizeof(*sysno), sysno); } - extract_flushRecordKeys (zh, *sysno, 1, &zh->keys); - extract_flushSortKeys (zh, *sysno, 1, &zh->sortKeys); + extract_flushRecordKeys (zh, *sysno, 1, &zh->reg->keys); + extract_flushSortKeys (zh, *sysno, 1, &zh->reg->sortKeys); } else { /* record already exists */ struct recKeys delkeys; - rec = rec_get (zh->service->records, *sysno); + rec = rec_get (zh->reg->records, *sysno); assert (rec); - recordAttr = rec_init_attr (zh->service->zei, rec); + recordAttr = rec_init_attr (zh->reg->zei, rec); if (recordAttr->runNumber == - zebraExplain_runNumberIncrement (zh->service->zei, 0)) + zebraExplain_runNumberIncrement (zh->reg->zei, 0)) { logf (LOG_LOG, "skipped %s %s %ld", recordType, fname, (long) recordOffset); @@ -992,7 +980,7 @@ int extract_rec_in_mem (ZebraHandle zh, const char *recordType, } delkeys.buf_used = rec->size[recInfo_delKeys]; delkeys.buf = rec->info[recInfo_delKeys]; - extract_flushSortKeys (zh, *sysno, 0, &zh->sortKeys); + extract_flushSortKeys (zh, *sysno, 0, &zh->reg->sortKeys); extract_flushRecordKeys (zh, *sysno, 0, &delkeys); if (delete_flag) { @@ -1011,7 +999,7 @@ int extract_rec_in_mem (ZebraHandle zh, const char *recordType, if (matchStr) dict_delete (matchDict, matchStr); #endif - rec_del (zh->service->records, &rec); + rec_del (zh->reg->records, &rec); } rec_rm (&rec); return 1; @@ -1029,7 +1017,7 @@ int extract_rec_in_mem (ZebraHandle zh, const char *recordType, { logf (LOG_LOG, "update %s %s %ld", recordType, fname, (long) recordOffset); - extract_flushRecordKeys (zh, *sysno, 1, &zh->keys); + extract_flushRecordKeys (zh, *sysno, 1, &zh->reg->keys); } } } @@ -1045,12 +1033,12 @@ int extract_rec_in_mem (ZebraHandle zh, const char *recordType, /* update delete keys */ xfree (rec->info[recInfo_delKeys]); - if (zh->keys.buf_used > 0 && store_keys == 1) + if (zh->reg->keys.buf_used > 0 && store_keys == 1) { - rec->size[recInfo_delKeys] = zh->keys.buf_used; - rec->info[recInfo_delKeys] = zh->keys.buf; - zh->keys.buf = NULL; - zh->keys.buf_max = 0; + rec->size[recInfo_delKeys] = zh->reg->keys.buf_used; + rec->info[recInfo_delKeys] = zh->reg->keys.buf; + zh->reg->keys.buf = NULL; + zh->reg->keys.buf_max = 0; } else { @@ -1059,7 +1047,7 @@ int extract_rec_in_mem (ZebraHandle zh, const char *recordType, } /* save file size of original record */ - zebraExplain_recordBytesIncrement (zh->service->zei, + zebraExplain_recordBytesIncrement (zh->reg->zei, - recordAttr->recordSize); #if 0 recordAttr->recordSize = fi->file_moffset - recordOffset; @@ -1068,12 +1056,12 @@ int extract_rec_in_mem (ZebraHandle zh, const char *recordType, #else recordAttr->recordSize = buf_size; #endif - zebraExplain_recordBytesIncrement (zh->service->zei, + zebraExplain_recordBytesIncrement (zh->reg->zei, recordAttr->recordSize); /* set run-number for this record */ recordAttr->runNumber = - zebraExplain_runNumberIncrement (zh->service->zei, 0); + zebraExplain_runNumberIncrement (zh->reg->zei, 0); /* update store data */ xfree (rec->info[recInfo_storeData]); @@ -1114,7 +1102,7 @@ int extract_rec_in_mem (ZebraHandle zh, const char *recordType, recordAttr->recordOffset = recordOffset; /* commit this record */ - rec_put (zh->service->records, &rec); + rec_put (zh->reg->records, &rec); return 0; } @@ -1125,28 +1113,28 @@ int explain_extract (void *handle, Record rec, data1_node *n) struct recExtractCtrl extractCtrl; int i; - if (zebraExplain_curDatabase (zh->service->zei, + if (zebraExplain_curDatabase (zh->reg->zei, rec->info[recInfo_databaseName])) { abort(); - if (zebraExplain_newDatabase (zh->service->zei, + if (zebraExplain_newDatabase (zh->reg->zei, rec->info[recInfo_databaseName], 0)) abort (); } - zh->keys.buf_used = 0; - zh->keys.prevAttrUse = -1; - zh->keys.prevAttrSet = -1; - zh->keys.prevSeqNo = 0; - zh->sortKeys = 0; + zh->reg->keys.buf_used = 0; + zh->reg->keys.prevAttrUse = -1; + zh->reg->keys.prevAttrSet = -1; + zh->reg->keys.prevSeqNo = 0; + zh->reg->sortKeys = 0; extractCtrl.init = extract_init; extractCtrl.tokenAdd = extract_token_add; extractCtrl.schemaAdd = extract_schema_add; - extractCtrl.dh = zh->service->dh; + extractCtrl.dh = zh->reg->dh; for (i = 0; i<256; i++) extractCtrl.seqno[i] = 0; - extractCtrl.zebra_maps = zh->service->zebra_maps; + extractCtrl.zebra_maps = zh->reg->zebra_maps; extractCtrl.flagShowRecords = 0; extractCtrl.handle = handle; @@ -1162,14 +1150,14 @@ int explain_extract (void *handle, Record rec, data1_node *n) extract_flushSortKeys (zh, rec->sysno, 0, &sortKeys); extract_flushRecordKeys (zh, rec->sysno, 0, &delkeys); } - extract_flushRecordKeys (zh, rec->sysno, 1, &zh->keys); - extract_flushSortKeys (zh, rec->sysno, 1, &zh->sortKeys); + extract_flushRecordKeys (zh, rec->sysno, 1, &zh->reg->keys); + extract_flushSortKeys (zh, rec->sysno, 1, &zh->reg->sortKeys); xfree (rec->info[recInfo_delKeys]); - rec->size[recInfo_delKeys] = zh->keys.buf_used; - rec->info[recInfo_delKeys] = zh->keys.buf; - zh->keys.buf = NULL; - zh->keys.buf_max = 0; + rec->size[recInfo_delKeys] = zh->reg->keys.buf_used; + rec->info[recInfo_delKeys] = zh->reg->keys.buf; + zh->reg->keys.buf = NULL; + zh->reg->keys.buf_max = 0; return 0; } @@ -1184,16 +1172,16 @@ void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno, int seqno = 0; int off = 0; int ch = 0; - ZebraExplainInfo zei = zh->service->zei; + ZebraExplainInfo zei = zh->reg->zei; - if (!zh->key_buf) + if (!zh->reg->key_buf) { int mem = 8*1024*1024; - zh->key_buf = (char**) xmalloc (mem); - zh->ptr_top = mem/sizeof(char*); - zh->ptr_i = 0; - zh->key_buf_used = 0; - zh->key_file_no = 0; + zh->reg->key_buf = (char**) xmalloc (mem); + zh->reg->ptr_top = mem/sizeof(char*); + zh->reg->ptr_i = 0; + zh->reg->key_buf_used = 0; + zh->reg->key_file_no = 0; } zebraExplain_recordCountIncrement (zei, cmd ? 1 : -1); while (off < reckeys->buf_used) @@ -1222,11 +1210,12 @@ void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno, src += sizeof(attrUse); } #endif - if (zh->key_buf_used + 1024 > (zh->ptr_top-zh->ptr_i)*sizeof(char*)) + if (zh->reg->key_buf_used + 1024 > + (zh->reg->ptr_top -zh->reg->ptr_i)*sizeof(char*)) extract_flushWriteKeys (zh); - ++(zh->ptr_i); - (zh->key_buf)[zh->ptr_top - zh->ptr_i] = - (char*)zh->key_buf + zh->key_buf_used; + ++(zh->reg->ptr_i); + (zh->reg->key_buf)[zh->reg->ptr_top - zh->reg->ptr_i] = + (char*)zh->reg->key_buf + zh->reg->key_buf_used; #if SU_SCHEME #else ch = zebraExplain_lookupSU (zei, attrSet, attrUse); @@ -1234,14 +1223,15 @@ void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno, ch = zebraExplain_addSU (zei, attrSet, attrUse); #endif assert (ch > 0); - zh->key_buf_used += - key_SU_encode (ch,((char*)zh->key_buf) + zh->key_buf_used); + zh->reg->key_buf_used += + key_SU_encode (ch,((char*)zh->reg->key_buf) + + zh->reg->key_buf_used); while (*src) - ((char*)zh->key_buf) [(zh->key_buf_used)++] = *src++; + ((char*)zh->reg->key_buf) [(zh->reg->key_buf_used)++] = *src++; src++; - ((char*)(zh->key_buf))[(zh->key_buf_used)++] = '\0'; - ((char*)(zh->key_buf))[(zh->key_buf_used)++] = cmd; + ((char*)(zh->reg->key_buf))[(zh->reg->key_buf_used)++] = '\0'; + ((char*)(zh->reg->key_buf))[(zh->reg->key_buf_used)++] = cmd; if (lead & 60) seqno += ((lead>>2) & 15)-1; @@ -1252,8 +1242,8 @@ void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno, } key.seqno = seqno; key.sysno = sysno; - memcpy ((char*)zh->key_buf + zh->key_buf_used, &key, sizeof(key)); - (zh->key_buf_used) += sizeof(key); + memcpy ((char*)zh->reg->key_buf + zh->reg->key_buf_used, &key, sizeof(key)); + (zh->reg->key_buf_used) += sizeof(key); off = src - reckeys->buf; } assert (off == reckeys->buf_used); @@ -1265,34 +1255,34 @@ void extract_flushWriteKeys (ZebraHandle zh) char out_fname[200]; char *prevcp, *cp; struct encode_info encode_info; - int ptr_i = zh->ptr_i; + int ptr_i = zh->reg->ptr_i; #if SORT_EXTRA int i; #endif - if (!zh->key_buf || ptr_i <= 0) + if (!zh->reg->key_buf || ptr_i <= 0) return; - (zh->key_file_no)++; - logf (LOG_LOG, "sorting section %d", (zh->key_file_no)); + (zh->reg->key_file_no)++; + logf (LOG_LOG, "sorting section %d", (zh->reg->key_file_no)); #if !SORT_EXTRA - qsort (zh->key_buf + zh->ptr_top - ptr_i, ptr_i, sizeof(char*), + qsort (zh->reg->key_buf + zh->reg->ptr_top - ptr_i, ptr_i, sizeof(char*), key_qsort_compare); - extract_get_fname_tmp (zh, out_fname, zh->key_file_no); + extract_get_fname_tmp (zh, out_fname, zh->reg->key_file_no); if (!(outf = fopen (out_fname, "wb"))) { logf (LOG_FATAL|LOG_ERRNO, "fopen %s", out_fname); exit (1); } - logf (LOG_LOG, "writing section %d", zh->key_file_no); - prevcp = cp = (zh->key_buf)[zh->ptr_top - ptr_i]; + logf (LOG_LOG, "writing section %d", zh->reg->key_file_no); + prevcp = cp = (zh->reg->key_buf)[zh->reg->ptr_top - ptr_i]; encode_key_init (&encode_info); encode_key_write (cp, &encode_info, outf); while (--ptr_i > 0) { - cp = (zh->key_buf)[zh->ptr_top - ptr_i]; + cp = (zh->reg->key_buf)[zh->reg->ptr_top - ptr_i]; if (strcmp (cp, prevcp)) { encode_key_init (&encode_info); @@ -1343,9 +1333,9 @@ void extract_flushWriteKeys (ZebraHandle zh) logf (LOG_FATAL|LOG_ERRNO, "fclose %s", out_fname); exit (1); } - logf (LOG_LOG, "finished section %d", zh->key_file_no); - zh->ptr_i = 0; - zh->key_buf_used = 0; + logf (LOG_LOG, "finished section %d", zh->reg->key_file_no); + zh->reg->ptr_i = 0; + zh->reg->key_buf_used = 0; } void extract_add_index_string (RecWord *p, const char *string, @@ -1358,8 +1348,8 @@ void extract_add_index_string (RecWord *p, const char *string, int diff = 0; int *pseqno = &p->seqnos[p->reg_type]; ZebraHandle zh = p->extractCtrl->handle; - ZebraExplainInfo zei = zh->service->zei; - struct recKeys *keys = &zh->keys; + ZebraExplainInfo zei = zh->reg->zei; + struct recKeys *keys = &zh->reg->keys; if (keys->buf_used+1024 > keys->buf_max) { @@ -1441,13 +1431,13 @@ static void extract_add_sort_string (RecWord *p, const char *string, struct sortKey *sk; ZebraHandle zh = p->extractCtrl->handle; - for (sk = zh->sortKeys; sk; sk = sk->next) + for (sk = zh->reg->sortKeys; sk; sk = sk->next) if (sk->attrSet == p->attrSet && sk->attrUse == p->attrUse) return; sk = (struct sortKey *) xmalloc (sizeof(*sk)); - sk->next = zh->sortKeys; - zh->sortKeys = sk; + sk->next = zh->reg->sortKeys; + zh->reg->sortKeys = sk; sk->string = (char *) xmalloc (length); sk->length = length; @@ -1575,14 +1565,14 @@ void extract_token_add (RecWord *p) void extract_schema_add (struct recExtractCtrl *p, Odr_oid *oid) { ZebraHandle zh = (ZebraHandle) (p->handle); - zebraExplain_addSchema (zh->service->zei, oid); + zebraExplain_addSchema (zh->reg->zei, oid); } void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno, int cmd, struct sortKey **skp) { struct sortKey *sk = *skp; - SortIdx sortIdx = zh->service->sortIdx; + SortIdx sortIdx = zh->reg->sortIdx; sortIdx_sysno (sortIdx, sysno); while (sk) diff --git a/index/index.h b/index/index.h index 7a78de2..21969e8 100644 --- a/index/index.h +++ b/index/index.h @@ -2,7 +2,7 @@ * Copyright (C) 1995-2002, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto - * $Id: index.h,v 1.74 2002-03-21 10:25:42 adam Exp $ + * $Id: index.h,v 1.75 2002-04-04 14:14:13 adam Exp $ */ #ifndef INDEX_H @@ -12,6 +12,11 @@ #include #include #include +#include + +#if HAVE_SYS_TIMES_H +#include +#endif #include #include @@ -25,7 +30,11 @@ #endif #include #include +#include "recindex.h" #include "zebraapi.h" +#include "zinfo.h" +#include +#include YAZ_BEGIN_CDECL @@ -57,20 +66,6 @@ struct dirs_entry { time_t mtime; }; -struct recordGroup { - char *groupName; - char *databaseName; - char *path; - char *recordId; - char *recordType; - int flagStoreData; - int flagStoreKeys; - int flagRw; - int fileVerboseLimit; - int databaseNamePath; - int explainDatabase; -}; - void getFnameTmp (Res res, char *fname, int no); struct dirs_info *dirs_open (Dict dict, const char *rep, int rw); @@ -130,8 +125,6 @@ int index_char_cvt (int c); int index_word_prefix (char *string, int attset_ordinal, int local_attribute, const char *databaseName); -int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, - const struct recordGroup *rGroup, int deleteFlag); void zebraIndexLockMsg (ZebraHandle zh, const char *str); void zebraIndexUnlock (ZebraHandle zh); @@ -175,6 +168,246 @@ void encode_key_init (struct encode_info *i); char *encode_key_int (int d, char *bp); void encode_key_write (char *k, struct encode_info *i, FILE *outf); +typedef struct { + char *term; + char *db; + int sysno; + int score; +} *ZebraPosSet; + +typedef struct zebra_set *ZebraSet; + +typedef struct zebra_rank_class { + struct rank_control *control; + int init_flag; + void *class_handle; + struct zebra_rank_class *next; +} *ZebraRankClass; + +struct recKeys { + int buf_used; + int buf_max; + char *buf; + char prevAttrSet; + short prevAttrUse; + int prevSeqNo; +}; + +struct sortKey { + char *string; + int length; + int attrSet; + int attrUse; + struct sortKey *next; +}; + +struct zebra_register { + char *name; + + ISAMS isams; +#if ZMBOL + ISAM isam; + ISAMC isamc; + ISAMD isamd; +#endif + Dict dict; + Dict matchDict; + SortIdx sortIdx; + int registerState; /* 0 (no commit pages), 1 (use commit pages) */ + time_t registerChange; + BFiles bfs; + Records records; + ZebraExplainInfo zei; + + char *server_path_prefix; + data1_handle dh; + ZebraMaps zebra_maps; + ZebraRankClass rank_classes; + RecTypes recTypes; + int seqno; + int last_val; + int stop_flag; + int active; /* 0=shutdown, 1=enabled and inactive, 2=activated */ + + + + struct recKeys keys; + struct sortKey *sortKeys; + + char **key_buf; + size_t ptr_top; + size_t ptr_i; + size_t key_buf_used; + int key_file_no; +}; + +struct zebra_service { + int stop_flag; + Res global_res; + char *configName; + struct zebra_session *sessions; + struct zebra_register *regs; + Zebra_mutex_cond session_lock; + Passwd_db passwd_db; + char *path_root; +}; + + +struct zebra_session { + struct zebra_session *next; + struct zebra_service *service; + struct zebra_register *reg; + + char *admin_databaseName; + + char **basenames; + int num_basenames; + char *reg_name; + char *path_reg; + + ZebraLockHandle lock_normal; + ZebraLockHandle lock_shadow; + + int trans_no; + int destroyed; + ZebraSet sets; + Res res; + int errCode; + int hits; + char *errString; +#if HAVE_SYS_TIMES_H + struct tms tms1; + struct tms tms2; +#endif + struct recordGroup rGroup; +}; + +struct rank_control { + char *name; + void *(*create)(struct zebra_register *reg); + void (*destroy)(struct zebra_register *reg, void *class_handle); + void *(*begin)(struct zebra_register *reg, void *class_handle, RSET rset); + void (*end)(struct zebra_register *reg, void *set_handle); + int (*calc)(void *set_handle, int sysno); + void (*add)(void *set_handle, int seqno, int term_index); +}; + +struct term_set_entry { + char *term; + struct term_set_entry *next; +}; + +struct term_set_list { + struct term_set_entry *first; + struct term_set_entry *last; +}; + +RSET rpn_search (ZebraHandle zh, NMEM mem, + Z_RPNQuery *rpn, int num_bases, char **basenames, + const char *setname, ZebraSet sset); + + +void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, + oid_value attributeset, + int num_bases, char **basenames, + int *position, int *num_entries, ZebraScanEntry **list, + int *is_partial); + +RSET rset_trunc (ZebraHandle zh, ISAMS_P *isam_p, int no, + const char *term, int length_term, const char *flags); + +void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type, + const char *db, int set, + int use, const char *term); +ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov); +ZebraSet resultSetGet (ZebraHandle zh, const char *name); +ZebraSet resultSetAddRPN (ZebraHandle zh, ODR stream, ODR decode, + Z_RPNQuery *rpn, int num_bases, + char **basenames, const char *setname); +RSET resultSetRef (ZebraHandle zh, Z_ResultSetId *resultSetId); +void resultSetDestroy (ZebraHandle zh, int num_names, char **names, + int *statuses); + + +ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name, + int num, int *positions); +void zebraPosSetDestroy (ZebraHandle zh, ZebraPosSet records, int num); + +void resultSetSort (ZebraHandle zh, NMEM nmem, + int num_input_setnames, const char **input_setnames, + const char *output_setname, + Z_SortKeySpecList *sort_sequence, int *sort_status); +void resultSetSortSingle (ZebraHandle zh, NMEM nmem, + ZebraSet sset, RSET rset, + Z_SortKeySpecList *sort_sequence, int *sort_status); +void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset); +void resultSetInvalidate (ZebraHandle zh); + +int zebra_server_lock_init (ZebraService zh); +int zebra_server_lock_destroy (ZebraService zh); +int zebra_server_lock (ZebraService zh, int lockCommit); +void zebra_server_unlock (ZebraService zh, int commitPhase); +int zebra_server_lock_get_state (ZebraService zh, time_t *timep); + +typedef struct attent +{ + int attset_ordinal; + data1_local_attribute *local_attributes; +} attent; + +void zebraRankInstall (struct zebra_register *reg, struct rank_control *ctrl); +ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name); +void zebraRankDestroy (struct zebra_register *reg); + +int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att); + +extern struct rank_control *rank1_class; + +int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream, + oid_value input_format, Z_RecordComposition *comp, + oid_value *output_format, char **rec_bufp, + int *rec_lenp, char **basenamep); + +void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no); +void zebra_index_merge (ZebraHandle zh); + + +int extract_rec_in_mem (ZebraHandle zh, const char *recordType, + const char *buf, size_t buf_size, + const char *databaseName, int delete_flag, + int test_mode, int *sysno, + int store_keys, int store_data, + const char *match_criteria); + +void extract_flushWriteKeys (ZebraHandle zh); + +struct zebra_fetch_control { + off_t offset_end; + off_t record_offset; + off_t record_int_pos; + const char *record_int_buf; + int record_int_len; + int fd; +}; + +int zebra_record_ext_read (void *fh, char *buf, size_t count); +off_t zebra_record_ext_seek (void *fh, off_t offset); +off_t zebra_record_ext_tell (void *fh); +off_t zebra_record_int_seek (void *fh, off_t offset); +off_t zebra_record_int_tell (void *fh); +int zebra_record_int_read (void *fh, char *buf, size_t count); +void zebra_record_int_end (void *fh, off_t offset); + +void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno, + int cmd, struct recKeys *reckeys); +void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno, + int cmd, struct sortKey **skp); +void extract_schema_add (struct recExtractCtrl *p, Odr_oid *oid); +void extract_token_add (RecWord *p); +int explain_extract (void *handle, Record rec, data1_node *n); + +int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, + const struct recordGroup *rGroup, int deleteFlag); YAZ_END_CDECL diff --git a/index/invstat.c b/index/invstat.c index 5a23007..ba98053 100644 --- a/index/invstat.c +++ b/index/invstat.c @@ -10,11 +10,9 @@ #include #include "index.h" -#include "recindex.h" #if ZMBOL #include "../isamc/isamd-p.h" #endif -#include "zserver.h" struct inv_stat_info { ISAMS isams; @@ -131,7 +129,8 @@ static int inv_stat_handle (char *name, const char *info, int pos, void inv_prstat (ZebraHandle zh) { - BFiles bfs = zh->service->bfs; + Res res = zh->res; + BFiles bfs; Dict dict; ISAMS isams = NULL; #if ZMBOL @@ -148,6 +147,11 @@ void inv_prstat (ZebraHandle zh) int after = 1000000000; struct inv_stat_info stat_info; char term_dict[2*IT_MAX_WORD+2]; + + if (!res || !zh->reg) + return; + + bfs = zh->reg->bfs; term_dict[0] = 1; term_dict[1] = 0; @@ -158,11 +162,11 @@ void inv_prstat (ZebraHandle zh) logf (LOG_FATAL, "dict_open fail"); exit (1); } - if (res_get_match (zh->service->res, "isam", "s", ISAM_DEFAULT)) + if (res_get_match (res, "isam", "s", ISAM_DEFAULT)) { struct ISAMS_M_s isams_m; isams = isams_open (bfs, FNAME_ISAMS, 0, - key_isams_m(zh->service->res, &isams_m)); + key_isams_m(res, &isams_m)); if (!isams) { logf (LOG_FATAL, "isams_open fail"); @@ -170,32 +174,32 @@ void inv_prstat (ZebraHandle zh) } } #if ZMBOL - else if (res_get_match (zh->service->res, "isam", "i", ISAM_DEFAULT)) + else if (res_get_match (res, "isam", "i", ISAM_DEFAULT)) { isam = is_open (bfs, FNAME_ISAM, key_compare, 0, - sizeof(struct it_key), zh->service->res); + sizeof(struct it_key), res); if (!isam) { logf (LOG_FATAL, "is_open fail"); exit (1); } } - else if (res_get_match (zh->service->res, "isam", "d", ISAM_DEFAULT)) + else if (res_get_match (res, "isam", "d", ISAM_DEFAULT)) { struct ISAMD_M_s isamd_m; isamd = isamd_open (bfs, FNAME_ISAMD, 0, - key_isamd_m(zh->service->res,&isamd_m)); + key_isamd_m(res,&isamd_m)); if (!isamd) { logf (LOG_FATAL, "isamd_open fail"); exit (1); } } - else if (res_get_match (zh->service->res, "isam", "c", ISAM_DEFAULT)) + else if (res_get_match (res, "isam", "c", ISAM_DEFAULT)) { struct ISAMC_M_s isamc_m; isamc = isc_open (bfs, FNAME_ISAMC, 0, - key_isamc_m (zh->service->res, &isamc_m)); + key_isamc_m (res, &isamc_m)); if (!isamc) { logf (LOG_FATAL, "isc_open fail"); @@ -325,7 +329,10 @@ void inv_prstat (ZebraHandle zh) /* * * $Log: invstat.c,v $ - * Revision 1.22 2002-02-20 17:30:01 adam + * Revision 1.23 2002-04-04 14:14:13 adam + * Multiple registers (alpha early) + * + * Revision 1.22 2002/02/20 17:30:01 adam * Work on new API. Locking system re-implemented * * Revision 1.21 2000/07/13 10:14:20 heikki diff --git a/index/kdump.c b/index/kdump.c index a3d3901..0e2fc2d 100644 --- a/index/kdump.c +++ b/index/kdump.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: kdump.c,v $ - * Revision 1.19 2000-12-05 10:01:44 adam + * Revision 1.20 2002-04-04 14:14:13 adam + * Multiple registers (alpha early) + * + * Revision 1.19 2000/12/05 10:01:44 adam * Fixed bug regarding user-defined attribute sets. * * Revision 1.18 1999/09/07 07:19:21 adam @@ -170,7 +173,7 @@ int main (int argc, char **argv) } else if (ret == 'c') { - if (!(res = res_open (arg))) + if (!(res = res_open (arg, 0))) { logf(LOG_FATAL, "Failed to open resource file %s", arg); exit (1); @@ -188,7 +191,7 @@ int main (int argc, char **argv) exit (1); } if (!res) - res = res_open ("zebra.cfg"); + res = res_open ("zebra.cfg", 0); zm = zebra_maps_open (res); if (!(inf = fopen (key_fname, "r"))) { diff --git a/index/kinput.c b/index/kinput.c index d9257db..b6eaca2 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.46 2002-02-20 23:07:54 adam Exp $ + * $Id: kinput.c,v 1.47 2002-04-04 14:14:13 adam Exp $ * * Bugs * - Allocates a lot of memory for the merge process, but never releases it. @@ -23,7 +23,6 @@ #include #include "index.h" -#include "zserver.h" #define KEY_SIZE (1+sizeof(struct it_key)) #define INP_NAME_MAX 768 @@ -65,7 +64,7 @@ void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no) { const char *pre; - pre = res_get_def (zh->service->res, "keyTmpDir", "."); + pre = res_get_def (zh->res, "keyTmpDir", "."); sprintf (fname, "%s/key%d.tmp", pre, no); } @@ -639,7 +638,7 @@ void zebra_index_merge (ZebraHandle zh) int i, r; struct heap_info *hi; struct progressInfo progressInfo; - int nkeys = zh->key_file_no; + int nkeys = zh->reg->key_file_no; if (nkeys < 0) { @@ -662,32 +661,32 @@ void zebra_index_merge (ZebraHandle zh) time (&progressInfo.lastTime); for (i = 1; i<=nkeys; i++) { - kf[i] = key_file_init (i, 8192, zh->service->res); + kf[i] = key_file_init (i, 8192, zh->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; + hi->dict = zh->reg->dict; + hi->isams = zh->reg->isams; #if ZMBOL - hi->isam = zh->service->isam; - hi->isamc = zh->service->isamc; - hi->isamd = zh->service->isamd; + hi->isam = zh->reg->isam; + hi->isamc = zh->reg->isamc; + hi->isamd = zh->reg->isamd; #endif for (i = 1; i<=nkeys; i++) if ((r = key_file_read (kf[i], rbuf))) key_heap_insert (hi, rbuf, r, kf[i]); - if (zh->service->isams) + if (zh->reg->isams) heap_inps (hi); #if ZMBOL - else if (zh->service->isamc) + else if (zh->reg->isamc) heap_inpc (hi); - else if (zh->service->isam) + else if (zh->reg->isam) heap_inp (hi); - else if (zh->service->isamd) + else if (zh->reg->isamd) heap_inpd (hi); #endif @@ -701,7 +700,7 @@ void zebra_index_merge (ZebraHandle zh) logf (LOG_LOG, "Updates. . . . .%7d", no_updates); logf (LOG_LOG, "Deletions. . . .%7d", no_deletions); logf (LOG_LOG, "Insertions . . .%7d", no_insertions); - zh->key_file_no = 0; + zh->reg->key_file_no = 0; key_heap_destroy (hi, nkeys); for (i = 1; i<=nkeys; i++) diff --git a/index/lockutil.c b/index/lockutil.c index db8c148..cbfbb97 100644 --- a/index/lockutil.c +++ b/index/lockutil.c @@ -3,7 +3,7 @@ * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * - * $Id: lockutil.c,v 1.14 2002-03-21 10:25:42 adam Exp $ + * $Id: lockutil.c,v 1.15 2002-04-04 14:14:13 adam Exp $ */ #include #include @@ -61,7 +61,6 @@ char *zebra_mk_fname (const char *dir, const char *name) ZebraLockHandle zebra_lock_create (const char *dir, const char *name, int excl_flag) { - int dlen = dir ? strlen(dir) : 0; char *fname = zebra_mk_fname(dir, name); ZebraLockHandle h = (ZebraLockHandle) xmalloc (sizeof(*h)); diff --git a/index/main.c b/index/main.c index 3508f2a..1b91efc 100644 --- a/index/main.c +++ b/index/main.c @@ -2,7 +2,7 @@ * Copyright (C) 1994-2002, Index Data * All rights reserved. * - * $Id: main.c,v 1.82 2002-02-20 17:30:01 adam Exp $ + * $Id: main.c,v 1.83 2002-04-04 14:14:13 adam Exp $ */ #include #include @@ -15,9 +15,6 @@ #include #include "zebraapi.h" -#include "zserver.h" -#include "index.h" -#include "recindex.h" char *prog; @@ -98,10 +95,15 @@ int main (int argc, char **argv) logf (LOG_LOG, "zebra version %s %s", ZEBRAVER, ZEBRADATE); #endif - zs = zebra_start (configName ? configName : FNAME_CONFIG); + zs = zebra_start (configName ? configName : "zebra.cfg"); zh = zebra_open (zs); } + if (rGroupDef.databaseName) + zebra_select_database (zh, rGroupDef.databaseName); + else + zebra_select_database (zh, "Default"); + if (!strcmp (arg, "update")) cmd = 'u'; else if (!strcmp (arg, "update1")) @@ -140,10 +142,10 @@ int main (int argc, char **argv) } else { - memcpy (&zh->rGroup, &rGroupDef, sizeof(rGroupDef)); + rGroupDef.path = arg; + zebra_set_group (zh, &rGroupDef); zebra_begin_trans (zh); - zh->rGroup.path = arg; switch (cmd) { case 'u': @@ -153,7 +155,7 @@ int main (int argc, char **argv) zebra_repository_delete (zh); break; case 's': - logf (LOG_LOG, "dumping %s", zh->rGroup.path); + logf (LOG_LOG, "dumping %s", rGroupDef.path); zebra_repository_show (zh); nsections = 0; break; diff --git a/index/rank1.c b/index/rank1.c index 29fcb58..89f8455 100644 --- a/index/rank1.c +++ b/index/rank1.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: rank1.c,v $ - * Revision 1.7 2001-11-14 22:06:27 adam + * Revision 1.8 2002-04-04 14:14:13 adam + * Multiple registers (alpha early) + * + * Revision 1.7 2001/11/14 22:06:27 adam * Rank-weight may be controlled via query. * * Revision 1.6 2000/03/15 15:00:30 adam @@ -36,7 +39,7 @@ #include #endif -#include "zserver.h" +#include "index.h" struct rank_class_info { int dummy; @@ -69,7 +72,7 @@ static int log2_int (unsigned g) * create: Creates/Initialises this rank handler. This routine is * called exactly once. The routine returns the class_handle. */ -static void *create (ZebraService zh) +static void *create (struct zebra_register *reg) { struct rank_class_info *ci = (struct rank_class_info *) xmalloc (sizeof(*ci)); @@ -83,7 +86,7 @@ static void *create (ZebraService zh) * when the handler is no longer needed - i.e. when the server * dies. The class_handle was previously returned by create. */ -static void destroy (ZebraService zh, void *class_handle) +static void destroy (struct zebra_register *reg, void *class_handle) { struct rank_class_info *ci = (struct rank_class_info *) class_handle; @@ -97,7 +100,7 @@ static void destroy (ZebraService zh, void *class_handle) * each result set. The returned handle is a "set handle" and * will be used in each of the handlers below. */ -static void *begin (ZebraHandle zh, void *class_handle, RSET rset) +static void *begin (struct zebra_register *reg, void *class_handle, RSET rset) { struct rank_set_info *si = (struct rank_set_info *) xmalloc (sizeof(*si)); int i; @@ -132,7 +135,7 @@ static void *begin (ZebraHandle zh, void *class_handle, RSET rset) * end: Terminates ranking process. Called after a result set * has been ranked. */ -static void end (ZebraHandle zh, void *set_handle) +static void end (struct zebra_register *reg, void *set_handle) { struct rank_set_info *si = (struct rank_set_info *) set_handle; logf (LOG_DEBUG, "rank-1 end"); diff --git a/index/retrieve.c b/index/retrieve.c index d824a1a..9b8baae 100644 --- a/index/retrieve.c +++ b/index/retrieve.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: retrieve.c,v $ - * Revision 1.14 2001-01-22 11:41:41 adam + * Revision 1.15 2002-04-04 14:14:13 adam + * Multiple registers (alpha early) + * + * Revision 1.14 2001/01/22 11:41:41 adam * Added support for raw retrieval (element set name "R"). * * Revision 1.13 2000/03/20 19:08:36 adam @@ -61,16 +64,7 @@ #include #endif -#include -#include "zserver.h" - -#ifndef ZEBRASDR -#define ZEBRASDR 0 -#endif - -#if ZEBRASDR -#include "zebrasdr.h" -#endif +#include "index.h" int zebra_record_ext_read (void *fh, char *buf, size_t count) { @@ -134,14 +128,14 @@ int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream, RecordAttr *recordAttr; void *clientData; - rec = rec_get (zh->service->records, sysno); + rec = rec_get (zh->reg->records, sysno); if (!rec) { logf (LOG_DEBUG, "rec_get fail on sysno=%d", sysno); *basenamep = 0; return 14; } - recordAttr = rec_init_attr (zh->service->zei, rec); + recordAttr = rec_init_attr (zh->reg->zei, rec); file_type = rec->info[recInfo_fileType]; fname = rec->info[recInfo_filename]; @@ -155,7 +149,7 @@ int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream, if (!strcmp (comp->u.simple->u.generic, "R")) file_type = "text"; } - if (!(rt = recType_byName (zh->service->recTypes, + if (!(rt = recType_byName (zh->reg->recTypes, file_type, subType, &clientData))) { logf (LOG_WARN, "Retrieve: Cannot handle type %s", file_type); @@ -199,8 +193,8 @@ int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream, retrieveCtrl.input_format = retrieveCtrl.output_format = input_format; retrieveCtrl.comp = comp; retrieveCtrl.diagnostic = 0; - retrieveCtrl.dh = zh->service->dh; - retrieveCtrl.res = zh->service->res; + retrieveCtrl.dh = zh->reg->dh; + retrieveCtrl.res = zh->res; (*rt->retrieve)(clientData, &retrieveCtrl); *output_format = retrieveCtrl.output_format; *rec_bufp = (char *) retrieveCtrl.rec_buf; diff --git a/index/trav.c b/index/trav.c index b855ead..3cd2001 100644 --- a/index/trav.c +++ b/index/trav.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: trav.c,v $ - * Revision 1.37 2002-02-20 17:30:01 adam + * Revision 1.38 2002-04-04 14:14:13 adam + * Multiple registers (alpha early) + * + * Revision 1.37 2002/02/20 17:30:01 adam * Work on new API. Locking system re-implemented * * Revision 1.36 1999/05/15 14:36:38 adam @@ -154,7 +157,6 @@ #include #include "index.h" -#include "zserver.h" static int repComp (const char *a, const char *b, size_t len) { @@ -377,7 +379,7 @@ static void fileUpdateR (ZebraHandle zh, dir_free (&e_src); } -static void groupRes (ZebraService zs, struct recordGroup *rGroup) +static void groupRes (ZebraHandle zh, struct recordGroup *rGroup) { char resStr[256]; char gPrefix[256]; @@ -388,10 +390,10 @@ static void groupRes (ZebraService zs, struct recordGroup *rGroup) sprintf (gPrefix, "%s.", rGroup->groupName); sprintf (resStr, "%srecordId", gPrefix); - rGroup->recordId = res_get (zs->res, resStr); + rGroup->recordId = res_get (zh->res, resStr); sprintf (resStr, "%sdatabasePath", gPrefix); rGroup->databaseNamePath = - atoi (res_get_def (zs->res, resStr, "0")); + atoi (res_get_def (zh->res, resStr, "0")); } void repositoryShow (ZebraHandle zh) @@ -404,7 +406,7 @@ void repositoryShow (ZebraHandle zh) Dict dict; struct dirs_info *di; - if (!(dict = dict_open (zh->service->bfs, FMATCH_DICT, 50, 0, 0))) + if (!(dict = dict_open (zh->reg->bfs, FMATCH_DICT, 50, 0, 0))) { logf (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT); return; @@ -518,12 +520,12 @@ static void repositoryExtractG (ZebraHandle zh, void repositoryUpdate (ZebraHandle zh) { struct recordGroup *rGroup = &zh->rGroup; - groupRes (zh->service, rGroup); + groupRes (zh, rGroup); assert (rGroup->path); if (rGroup->recordId && !strcmp (rGroup->recordId, "file")) { Dict dict; - if (!(dict = dict_open (zh->service->bfs, FMATCH_DICT, 50, + if (!(dict = dict_open (zh->reg->bfs, FMATCH_DICT, 50, rGroup->flagRw, 0))) { logf (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT); diff --git a/index/trunc.c b/index/trunc.c index 954302c..1638684 100644 --- a/index/trunc.c +++ b/index/trunc.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: trunc.c,v $ - * Revision 1.20 2002-03-20 20:24:29 adam + * Revision 1.21 2002-04-04 14:14:13 adam + * Multiple registers (alpha early) + * + * Revision 1.20 2002/03/20 20:24:29 adam * Hits per term. Returned in SearchResult-1 * * Revision 1.19 2001/01/16 16:56:15 heikki @@ -76,7 +79,7 @@ #define NEW_TRUNC 1 -#include "zserver.h" +#include "index.h" #include #include #include @@ -195,7 +198,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, parms.cmp = key_compare_it; parms.key_size = sizeof(struct it_key); - parms.temp_path = res_get (zi->service->res, "setTmpDir"); + parms.temp_path = res_get (zi->res, "setTmpDir"); parms.rset_term = rset_term_create (term, length, flags); result = rset_create (rset_kind_temp, &parms); result_rsfd = rset_open (result, RSETF_WRITE); @@ -263,7 +266,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, heap_close (ti); } #if ZMBOL - else if (zi->service->isam) + else if (zi->reg->isam) { ISPT *ispt; int i; @@ -275,7 +278,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, key_compare_it); for (i = to-from; --i >= 0; ) { - ispt[i] = is_position (zi->service->isam, isam_p[from+i]); + ispt[i] = is_position (zi->reg->isam, isam_p[from+i]); if (is_readkey (ispt[i], ti->tmpbuf)) heap_insert (ti, ti->tmpbuf, i); else @@ -315,7 +318,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, heap_close (ti); xfree (ispt); } - else if (zi->service->isamc) + else if (zi->reg->isamc) { ISAMC_PP *ispt; int i; @@ -327,7 +330,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, key_compare_it); for (i = to-from; --i >= 0; ) { - ispt[i] = isc_pp_open (zi->service->isamc, isam_p[from+i]); + ispt[i] = isc_pp_open (zi->reg->isamc, isam_p[from+i]); if (isc_pp_read (ispt[i], ti->tmpbuf)) heap_insert (ti, ti->tmpbuf, i); else @@ -368,7 +371,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, xfree (ispt); } - else if (zi->service->isamd) + else if (zi->reg->isamd) { ISAMD_PP *ispt; int i; @@ -380,7 +383,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, key_compare_it); for (i = to-from; --i >= 0; ) { - ispt[i] = isamd_pp_open (zi->service->isamd, isam_p[from+i]); + ispt[i] = isamd_pp_open (zi->reg->isamd, isam_p[from+i]); if (isamd_pp_read (ispt[i], ti->tmpbuf)) heap_insert (ti, ti->tmpbuf, i); else @@ -422,7 +425,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, } #endif - else if (zi->service->isams) + else if (zi->reg->isams) { ISAMS_PP *ispt; int i; @@ -434,7 +437,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, key_compare_it); for (i = to-from; --i >= 0; ) { - ispt[i] = isams_pp_open (zi->service->isams, isam_p[from+i]); + ispt[i] = isams_pp_open (zi->reg->isams, isam_p[from+i]); if (isams_pp_read (ispt[i], ti->tmpbuf)) heap_insert (ti, ti->tmpbuf, i); else @@ -526,34 +529,34 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, parms.rset_term = rset_term_create (term, length, flags); return rset_create (rset_kind_null, &parms); } - if (zi->service->isams) + if (zi->reg->isams) { if (no == 1) { rset_isams_parms parms; parms.pos = *isam_p; - parms.is = zi->service->isams; + parms.is = zi->reg->isams; parms.rset_term = rset_term_create (term, length, flags); return rset_create (rset_kind_isams, &parms); } qsort (isam_p, no, sizeof(*isam_p), isams_trunc_cmp); } #if ZMBOL - else if (zi->service->isam) + else if (zi->reg->isam) { if (no == 1) { rset_isam_parms parms; parms.pos = *isam_p; - parms.is = zi->service->isam; + parms.is = zi->reg->isam; parms.rset_term = rset_term_create (term, length, flags); return rset_create (rset_kind_isam, &parms); } qsort (isam_p, no, sizeof(*isam_p), isam_trunc_cmp); } - else if (zi->service->isamc) + else if (zi->reg->isamc) { if (no == 1) { @@ -562,7 +565,7 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, parms.key_size = sizeof(struct it_key); parms.cmp = key_compare_it; parms.pos = *isam_p; - parms.is = zi->service->isamc; + parms.is = zi->reg->isamc; parms.rset_term = rset_term_create (term, length, flags); return rset_create (rset_kind_isamc, &parms); } @@ -573,7 +576,7 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, parms.key_size = sizeof(struct it_key); parms.cmp = key_compare_it; - parms.isc = zi->service->isamc; + parms.isc = zi->reg->isamc; parms.isam_positions = isam_p; parms.no_isam_positions = no; parms.no_save_positions = 100000; @@ -583,14 +586,14 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, #endif qsort (isam_p, no, sizeof(*isam_p), isamc_trunc_cmp); } - else if (zi->service->isamd) + else if (zi->reg->isamd) { if (no == 1) { rset_isamd_parms parms; parms.pos = *isam_p; - parms.is = zi->service->isamd; + parms.is = zi->reg->isamd; parms.rset_term = rset_term_create (term, length, flags); return rset_create (rset_kind_isamd, &parms); } @@ -602,7 +605,7 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, parms.key_size = sizeof(struct it_key); parms.cmp = key_compare_it; parms.isc = 0; - parms.isamd=zi->service->isamd; + parms.isamd=zi->reg->isamd; parms.isam_positions = isam_p; parms.no_isam_positions = no; parms.no_save_positions = 100000; diff --git a/index/zebraapi.c b/index/zebraapi.c index 6e2e3a8..a84c4c1 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.50 2002-03-27 07:53:13 adam Exp $ + * $Id: zebraapi.c,v 1.51 2002-04-04 14:14:13 adam Exp $ */ #include @@ -16,12 +16,15 @@ #endif #include -#include "zserver.h" +#include "index.h" #include +static Res zebra_open_res (ZebraHandle zh); +static void zebra_close_res (ZebraHandle zh); + static void zebra_chdir (ZebraService zh) { - const char *dir = res_get (zh->res, "chdir"); + const char *dir = res_get (zh->global_res, "chdir"); if (!dir) return; logf (LOG_DEBUG, "chdir %s", dir); @@ -32,17 +35,22 @@ static void zebra_chdir (ZebraService zh) #endif } + static void zebra_flush_reg (ZebraHandle zh) { - zebraExplain_flush (zh->service->zei, 1, zh); + zebraExplain_flush (zh->reg->zei, 1, zh); extract_flushWriteKeys (zh); zebra_index_merge (zh); } -static int zebra_register_activate (ZebraHandle zh, int rw, int useshadow); -static int zebra_register_deactivate (ZebraHandle zh); +static struct zebra_register *zebra_register_open (ZebraService zs, + const char *name, + int rw, int useshadow, + Res res, + const char *reg_path); +static void zebra_register_close (ZebraService zs, struct zebra_register *reg); static int zebra_begin_read (ZebraHandle zh); static void zebra_end_read (ZebraHandle zh); @@ -52,31 +60,30 @@ ZebraHandle zebra_open (ZebraService zs) ZebraHandle zh; assert (zs); - if (zs->stop_flag) - return 0; zh = (ZebraHandle) xmalloc (sizeof(*zh)); yaz_log (LOG_LOG, "zebra_open zs=%p returns %p", zs, zh); zh->service = zs; + zh->reg = 0; /* no register attached yet */ zh->sets = 0; zh->destroyed = 0; zh->errCode = 0; zh->errString = 0; + zh->res = 0; + + zh->reg_name = xstrdup (""); + zh->path_reg = 0; + zh->num_basenames = 0; + zh->basenames = 0; zh->trans_no = 0; - zh->lock_normal = zebra_lock_create (res_get(zs->res, "lockDir"), - "norm.LCK", 0); - zh->lock_shadow = zebra_lock_create (res_get(zs->res, "lockDir"), - "shadow.LCK", 0); + zh->lock_normal = 0; + zh->lock_shadow = 0; - zh->key_buf = 0; zh->admin_databaseName = 0; - zh->keys.buf_max = 0; - zh->keys.buf = 0; - zebra_mutex_cond_lock (&zs->session_lock); zh->next = zs->sessions; @@ -87,7 +94,6 @@ ZebraHandle zebra_open (ZebraService zs) return zh; } - ZebraService zebra_start (const char *configName) { ZebraService zh = xmalloc (sizeof(*zh)); @@ -96,24 +102,19 @@ ZebraService zebra_start (const char *configName) zh->configName = xstrdup(configName); zh->sessions = 0; - zh->stop_flag = 0; - zh->active = 1; - zh->registerState = -1; - zh->registerChange = 0; - - zh->seqno = 0; - zh->last_val = 0; - - if (!(zh->res = res_open (zh->configName))) + if (!(zh->global_res = res_open (zh->configName, 0))) { logf (LOG_WARN, "Failed to read resources `%s'", zh->configName); -// return zh; + } + else + { + logf (LOG_LOG, "Read resources `%s'", zh->configName); } zebra_chdir (zh); zebra_mutex_cond_init (&zh->session_lock); - if (!res_get (zh->res, "passwd")) + if (!res_get (zh->global_res, "passwd")) zh->passwd_db = NULL; else { @@ -121,143 +122,156 @@ ZebraService zebra_start (const char *configName) if (!zh->passwd_db) logf (LOG_WARN|LOG_ERRNO, "passwd_db_open failed"); else - passwd_db_file (zh->passwd_db, res_get (zh->res, "passwd")); + passwd_db_file (zh->passwd_db, res_get (zh->global_res, "passwd")); } - + zh->path_root = res_get (zh->global_res, "root"); return zh; } -static int zebra_register_activate (ZebraHandle zh, int rw, int useshadow) +static +struct zebra_register *zebra_register_open (ZebraService zs, const char *name, + int rw, int useshadow, Res res, + const char *reg_path) { - ZebraService zs = zh->service; + struct zebra_register *reg; int record_compression = REC_COMPRESS_NONE; char *recordCompression = 0; - yaz_log (LOG_LOG, "zebra_open_register_activate rw = %d useshadow=%d", - rw, useshadow); + reg = xmalloc (sizeof(*reg)); - zs->dh = data1_create (); - if (!zs->dh) - return -1; - zs->bfs = bfs_create (res_get (zs->res, "register")); - if (!zs->bfs) + assert (name); + reg->name = xstrdup (name); + + reg->seqno = 0; + reg->last_val = 0; + + assert (res); + + yaz_log (LOG_LOG, "zebra_register_open rw = %d useshadow=%d p=%p", + rw, useshadow, reg); + + reg->dh = data1_create (); + if (!reg->dh) + return 0; + reg->bfs = bfs_create (res_get (res, "register"), reg_path); + if (!reg->bfs) { - data1_destroy(zs->dh); - return -1; + data1_destroy(reg->dh); + return 0; } - bf_lockDir (zs->bfs, res_get (zs->res, "lockDir")); if (useshadow) - bf_cache (zs->bfs, res_get (zs->res, "shadow")); - data1_set_tabpath (zs->dh, res_get(zs->res, "profilePath")); - zs->recTypes = recTypes_init (zs->dh); - recTypes_default_handlers (zs->recTypes); - - zs->zebra_maps = zebra_maps_open (zs->res); - zs->rank_classes = NULL; - - zs->records = 0; - zs->dict = 0; - zs->sortIdx = 0; - zs->isams = 0; - zs->matchDict = 0; + bf_cache (reg->bfs, res_get (res, "shadow")); + data1_set_tabpath (reg->dh, res_get(res, "profilePath")); + reg->recTypes = recTypes_init (reg->dh); + recTypes_default_handlers (reg->recTypes); + + reg->zebra_maps = zebra_maps_open (res); + reg->rank_classes = NULL; + + reg->key_buf = 0; + + reg->keys.buf_max = 0; + reg->keys.buf = 0; + + reg->records = 0; + reg->dict = 0; + reg->sortIdx = 0; + reg->isams = 0; + reg->matchDict = 0; #if ZMBOL - zs->isam = 0; - zs->isamc = 0; - zs->isamd = 0; + reg->isam = 0; + reg->isamc = 0; + reg->isamd = 0; #endif - zs->zei = 0; - zs->matchDict = 0; + reg->zei = 0; + reg->matchDict = 0; - zebraRankInstall (zs, rank1_class); + zebraRankInstall (reg, rank1_class); - recordCompression = res_get_def (zh->service->res, - "recordCompression", "none"); + recordCompression = res_get_def (res, "recordCompression", "none"); if (!strcmp (recordCompression, "none")) record_compression = REC_COMPRESS_NONE; if (!strcmp (recordCompression, "bzip2")) record_compression = REC_COMPRESS_BZIP2; - if (!(zs->records = rec_open (zs->bfs, rw, record_compression))) + if (!(reg->records = rec_open (reg->bfs, rw, record_compression))) { logf (LOG_WARN, "rec_open"); - return -1; + return 0; } if (rw) { - zs->matchDict = dict_open (zs->bfs, GMATCH_DICT, 20, 1, 0); + reg->matchDict = dict_open (reg->bfs, GMATCH_DICT, 20, 1, 0); } - if (!(zs->dict = dict_open (zs->bfs, FNAME_DICT, 40, rw, 0))) + if (!(reg->dict = dict_open (reg->bfs, FNAME_DICT, 40, rw, 0))) { logf (LOG_WARN, "dict_open"); - return -1; + return 0; } - if (!(zs->sortIdx = sortIdx_open (zs->bfs, rw))) + if (!(reg->sortIdx = sortIdx_open (reg->bfs, rw))) { logf (LOG_WARN, "sortIdx_open"); - return -1; + return 0; } - if (res_get_match (zs->res, "isam", "s", ISAM_DEFAULT)) + if (res_get_match (res, "isam", "s", ISAM_DEFAULT)) { struct ISAMS_M_s isams_m; - if (!(zs->isams = isams_open (zs->bfs, FNAME_ISAMS, rw, - key_isams_m(zs->res, &isams_m)))) + if (!(reg->isams = isams_open (reg->bfs, FNAME_ISAMS, rw, + key_isams_m(res, &isams_m)))) { logf (LOG_WARN, "isams_open"); - return -1; + return 0; } } #if ZMBOL - else if (res_get_match (zs->res, "isam", "i", ISAM_DEFAULT)) + else if (res_get_match (res, "isam", "i", ISAM_DEFAULT)) { - if (!(zs->isam = is_open (zs->bfs, FNAME_ISAM, key_compare, rw, - sizeof (struct it_key), zs->res))) + if (!(reg->isam = is_open (reg->bfs, FNAME_ISAM, key_compare, rw, + sizeof (struct it_key), res))) { logf (LOG_WARN, "is_open"); - return -1; + return 0; } } - else if (res_get_match (zs->res, "isam", "c", ISAM_DEFAULT)) + else if (res_get_match (res, "isam", "c", ISAM_DEFAULT)) { struct ISAMC_M_s isamc_m; - if (!(zs->isamc = isc_open (zs->bfs, FNAME_ISAMC, - rw, key_isamc_m(zs->res, &isamc_m)))) + if (!(reg->isamc = isc_open (reg->bfs, FNAME_ISAMC, + rw, key_isamc_m(res, &isamc_m)))) { logf (LOG_WARN, "isc_open"); - return -1; + return 0; } } - else if (res_get_match (zs->res, "isam", "d", ISAM_DEFAULT)) + else if (res_get_match (res, "isam", "d", ISAM_DEFAULT)) { struct ISAMD_M_s isamd_m; - if (!(zs->isamd = isamd_open (zs->bfs, FNAME_ISAMD, - rw, key_isamd_m(zs->res, &isamd_m)))) + if (!(reg->isamd = isamd_open (reg->bfs, FNAME_ISAMD, + rw, key_isamd_m(res, &isamd_m)))) { logf (LOG_WARN, "isamd_open"); - return -1; + return 0; } } #endif - zs->zei = zebraExplain_open (zs->records, zs->dh, - zs->res, rw, zh, - explain_extract); - if (!zs->zei) + reg->zei = zebraExplain_open (reg->records, reg->dh, + res, rw, reg, + explain_extract); + if (!reg->zei) { logf (LOG_WARN, "Cannot obtain EXPLAIN information"); - return -1; + return 0; } - zs->active = 2; - yaz_log (LOG_LOG, "zebra_register_activate ok"); - return 0; + reg->active = 2; + yaz_log (LOG_LOG, "zebra_register_open ok p=%p", reg); + return reg; } void zebra_admin_shutdown (ZebraHandle zh) { zebra_mutex_cond_lock (&zh->service->session_lock); zh->service->stop_flag = 1; - if (!zh->service->sessions) - zebra_register_deactivate(zh); - zh->service->active = 0; zebra_mutex_cond_unlock (&zh->service->session_lock); } @@ -266,54 +280,44 @@ void zebra_admin_start (ZebraHandle zh) ZebraService zs = zh->service; zh->errCode = 0; zebra_mutex_cond_lock (&zs->session_lock); - if (!zs->stop_flag) - zh->service->active = 1; zebra_mutex_cond_unlock (&zs->session_lock); } -static int zebra_register_deactivate (ZebraHandle zh) +static void zebra_register_close (ZebraService zs, struct zebra_register *reg) { - ZebraService zs = zh->service; - zs->stop_flag = 0; - if (zs->active <= 1) - { - yaz_log(LOG_LOG, "zebra_register_deactivate (ignored since active=%d)", - zs->active); - return 0; - } - yaz_log(LOG_LOG, "zebra_register_deactivate"); + yaz_log(LOG_LOG, "zebra_register_close p=%p", reg); + reg->stop_flag = 0; zebra_chdir (zs); - if (zs->records) - { - 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); + if (reg->records) + { + zebraExplain_close (reg->zei, 0); + dict_close (reg->dict); + if (reg->matchDict) + dict_close (reg->matchDict); + sortIdx_close (reg->sortIdx); + if (reg->isams) + isams_close (reg->isams); #if ZMBOL - if (zs->isam) - is_close (zs->isam); - if (zs->isamc) - isc_close (zs->isamc); - if (zs->isamd) - isamd_close (zs->isamd); + if (reg->isam) + is_close (reg->isam); + if (reg->isamc) + isc_close (reg->isamc); + if (reg->isamd) + isamd_close (reg->isamd); #endif - rec_close (&zs->records); + rec_close (®->records); } - resultSetInvalidate (zh); - recTypes_destroy (zs->recTypes); - zebra_maps_close (zs->zebra_maps); - zebraRankDestroy (zs); - bfs_destroy (zs->bfs); - data1_destroy (zs->dh); + recTypes_destroy (reg->recTypes); + zebra_maps_close (reg->zebra_maps); + zebraRankDestroy (reg); + bfs_destroy (reg->bfs); + data1_destroy (reg->dh); - if (zs->passwd_db) - passwd_db_close (zs->passwd_db); - zs->active = 1; - return 0; + xfree (reg->key_buf); + xfree (reg->name); + xfree (reg); + yaz_log (LOG_LOG, "zebra_register_close 2"); } void zebra_stop(ZebraService zs) @@ -325,7 +329,6 @@ void zebra_stop(ZebraService zs) zebra_mutex_cond_lock (&zs->session_lock); while (zs->sessions) { - zebra_register_deactivate(zs->sessions); zebra_close (zs->sessions); } @@ -333,8 +336,12 @@ void zebra_stop(ZebraService zs) zebra_mutex_cond_destroy (&zs->session_lock); - res_close (zs->res); + if (zs->passwd_db) + passwd_db_close (zs->passwd_db); + + res_close (zs->global_res); xfree (zs->configName); + xfree (zs->path_root); xfree (zs); } @@ -352,12 +359,11 @@ void zebra_close (ZebraHandle zh) return ; resultSetDestroy (zh, -1, 0, 0); - if (zh->key_buf) - { - xfree (zh->key_buf); - zh->key_buf = 0; - } - + + if (zh->reg) + zebra_register_close (zh->service, zh->reg); + zebra_close_res (zh); + xfree (zh->admin_databaseName); zebra_mutex_cond_lock (&zs->session_lock); zebra_lock_destroy (zh->lock_normal); @@ -376,8 +382,9 @@ void zebra_close (ZebraHandle zh) // if (!zs->sessions && zs->stop_flag) // zebra_register_deactivate(zs); zebra_mutex_cond_unlock (&zs->session_lock); + xfree (zh->reg_name); xfree (zh); -} + yaz_log (LOG_LOG, "zebra_close zh=%p end", zh);} struct map_baseinfo { ZebraHandle zh; @@ -388,7 +395,100 @@ struct map_baseinfo { char **new_basenames; int new_num_max; }; - + +static Res zebra_open_res (ZebraHandle zh) +{ + Res res = 0; + char fname[512]; + if (*zh->reg_name == 0) + { + res = zh->service->global_res; + yaz_log (LOG_LOG, "local res = global res"); + } + else if (zh->path_reg) + { + sprintf (fname, "%.200s/zebra.cfg", zh->path_reg); + yaz_log (LOG_LOG, "res_open(%s)", fname); + res = res_open (fname, zh->service->global_res); + if (!res) + return 0; + } + else + return 0; /* no path for register - fail! */ + return res; +} + +static void zebra_close_res (ZebraHandle zh) +{ + if (zh->res != zh->service->global_res) + res_close (zh->res); + zh->res = 0; +} + +static int zebra_select_register (ZebraHandle zh, const char *new_reg) +{ + if (zh->res && strcmp (zh->reg_name, new_reg) == 0) + return 0; + if (!zh->res) + { + assert (zh->reg == 0); + assert (*zh->reg_name == 0); + } + else + { + if (zh->reg) + { + resultSetInvalidate (zh); + zebra_register_close (zh->service, zh->reg); + zh->reg = 0; + } + zebra_close_res(zh); + } + xfree (zh->reg_name); + zh->reg_name = xstrdup (new_reg); + + xfree (zh->path_reg); + zh->path_reg = 0; + if (zh->service->path_root) + { + zh->path_reg = xmalloc (strlen(zh->service->path_root) + + strlen(zh->reg_name) + 3); + strcpy (zh->path_reg, zh->service->path_root); + if (*zh->reg_name) + { + strcat (zh->path_reg, "/"); + strcat (zh->path_reg, zh->reg_name); + } + } + zh->res = zebra_open_res (zh); + + if (zh->lock_normal) + zebra_lock_destroy (zh->lock_normal); + zh->lock_normal = 0; + + if (zh->lock_shadow) + zebra_lock_destroy (zh->lock_shadow); + zh->lock_shadow = 0; + + if (zh->res) + { + char fname[512]; + const char *lock_area =res_get (zh->res, "lockDir"); + + if (!lock_area && zh->path_reg) + res_put (zh->res, "lockDir", zh->path_reg); + sprintf (fname, "norm.%s.LCK", zh->reg_name); + zh->lock_normal = + zebra_lock_create (res_get(zh->res, "lockDir"), fname, 0); + + sprintf (fname, "shadow.%s.LCK", zh->reg_name); + zh->lock_shadow = + zebra_lock_create (res_get(zh->res, "lockDir"), fname, 0); + + } + return 1; +} + void map_basenames_func (void *vp, const char *name, const char *value) { struct map_baseinfo *p = (struct map_baseinfo *) vp; @@ -433,7 +533,7 @@ void map_basenames (ZebraHandle zh, ODR stream, odr_malloc (stream, sizeof(*info.new_basenames) * info.new_num_max); info.mem = stream->mem; - res_trav (zh->service->res, "mapdb", &info, map_basenames_func); + res_trav (zh->service->global_res, "mapdb", &info, map_basenames_func); for (i = 0; inum_bases; i++) if (p->basenames[i] && p->new_num_bases < p->new_num_max) @@ -447,23 +547,98 @@ void map_basenames (ZebraHandle zh, ODR stream, logf (LOG_LOG, "base %s", (*basenames)[i]); } -void zebra_search_rpn (ZebraHandle zh, ODR stream, ODR decode, - Z_RPNQuery *query, int num_bases, char **basenames, - const char *setname) +int zebra_select_database (ZebraHandle zh, const char *basename) +{ + return zebra_select_databases (zh, 1, &basename); +} + +int zebra_select_databases (ZebraHandle zh, int num_bases, + const char **basenames) +{ + int i; + const char *cp; + size_t len = 0; + char *new_reg = 0; + + if (num_bases < 1) + { + zh->errCode = 23; + return -1; + } + for (i = 0; i < zh->num_basenames; i++) + xfree (zh->basenames[i]); + xfree (zh->basenames); + + zh->num_basenames = num_bases; + zh->basenames = xmalloc (zh->num_basenames * sizeof(*zh->basenames)); + for (i = 0; i < zh->num_basenames; i++) + zh->basenames[i] = xstrdup (basenames[i]); + + cp = strrchr(basenames[0], '/'); + if (cp) + { + len = cp - basenames[0]; + new_reg = xmalloc (len + 1); + memcpy (new_reg, basenames[0], len); + new_reg[len] = '\0'; + } + else + new_reg = xstrdup (""); + for (i = 1; ierrCode = 23; + return -1; + } + if (len != cp - basenames[i] || + memcmp (basenames[i], new_reg, len)) + { + zh->errCode = 23; + return -1; + } + } + else + { + if (cp1) + { + zh->errCode = 23; + return -1; + } + } + } + zebra_select_register (zh, new_reg); + xfree (new_reg); + if (!zh->res) + { + zh->errCode = 109; + return -1; + } + return 0; +} + +void zebra_search_rpn (ZebraHandle zh, ODR decode, ODR stream, + Z_RPNQuery *query, const char *setname, int *hits) { zh->hits = 0; + *hits = 0; + if (zebra_begin_read (zh)) return; - map_basenames (zh, stream, &num_bases, &basenames); - resultSetAddRPN (zh, stream, decode, query, num_bases, basenames, setname); + resultSetAddRPN (zh, decode, stream, query, + zh->num_basenames, zh->basenames, setname); zebra_end_read (zh); logf(LOG_APP,"SEARCH:%d:",zh->hits); + *hits = zh->hits; } - - void zebra_records_retrieve (ZebraHandle zh, ODR stream, const char *setname, Z_RecordComposition *comp, oid_value input_format, int num_recs, @@ -472,6 +647,13 @@ void zebra_records_retrieve (ZebraHandle zh, ODR stream, ZebraPosSet poset; int i, *pos_array; + if (!zh->res) + { + zh->errCode = 30; + zh->errString = odr_strdup (stream, setname); + return; + } + if (zebra_begin_read (zh)) return; @@ -513,7 +695,7 @@ void zebra_records_retrieve (ZebraHandle zh, ODR stream, sprintf (num_str, "%d", pos_array[i]); zh->errCode = 13; - zh->errString = nmem_strdup (stream->mem, num_str); + zh->errString = odr_strdup (stream, num_str); break; } } @@ -525,7 +707,6 @@ void zebra_records_retrieve (ZebraHandle zh, ODR stream, void zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, oid_value attributeset, - int num_bases, char **basenames, int *position, int *num_entries, ZebraScanEntry **entries, int *is_partial) { @@ -535,9 +716,8 @@ void zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, *num_entries = 0; return; } - map_basenames (zh, stream, &num_bases, &basenames); rpn_scan (zh, stream, zapt, attributeset, - num_bases, basenames, position, + zh->num_basenames, zh->basenames, position, num_entries, entries, is_partial); zebra_end_read (zh); } @@ -593,14 +773,10 @@ char *zebra_errAdd (ZebraHandle zh) return zh->errString; } -int zebra_hits (ZebraHandle zh) +int zebra_auth (ZebraHandle zh, const char *user, const char *pass) { - return zh->hits; -} - -int zebra_auth (ZebraService zh, const char *user, const char *pass) -{ - if (!zh->passwd_db || !passwd_db_auth (zh->passwd_db, user, pass)) + ZebraService zs = zh->service; + if (!zs->passwd_db || !passwd_db_auth (zs->passwd_db, user, pass)) { logf(LOG_APP,"AUTHOK:%s", user?user:"ANONYMOUS"); return 0; @@ -626,8 +802,6 @@ void zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment) { int sysno; int i; - if (zh->service->active < 2) - return; for (i = 0; inum_segmentRecords; i++) { Z_NamePlusRecord *npr = segment->segmentRecords[i]; @@ -668,7 +842,7 @@ void zebra_admin_create (ZebraHandle zh, const char *database) zs = zh->service; /* announce database */ - if (zebraExplain_newDatabase (zh->service->zei, database, 0 + if (zebraExplain_newDatabase (zh->reg->zei, database, 0 /* explainDatabase */)) { zh->errCode = 224; @@ -682,9 +856,9 @@ int zebra_string_norm (ZebraHandle zh, unsigned reg_id, char *output_str, int output_len) { WRBUF wrbuf; - if (!zh->service->zebra_maps) + if (!zh->reg->zebra_maps) return -1; - wrbuf = zebra_replace(zh->service->zebra_maps, reg_id, "", + wrbuf = zebra_replace(zh->reg->zebra_maps, reg_id, "", input_str, input_len); if (!wrbuf) return -2; @@ -699,10 +873,16 @@ int zebra_string_norm (ZebraHandle zh, unsigned reg_id, void zebra_set_state (ZebraHandle zh, int val, int seqno) { - char *fname = zebra_mk_fname (res_get(zh->service->res, "lockDir"), - "state.LCK"); + char state_fname[256]; + char *fname; long p = getpid(); - FILE *f = fopen (fname, "w"); + FILE *f; + + sprintf (state_fname, "state.%s.LCK", zh->reg_name); + fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname); + f = fopen (fname, "w"); + + yaz_log (LOG_LOG, "%c %d %ld", val, seqno, p); fprintf (f, "%c %d %ld\n", val, seqno, p); fclose (f); xfree (fname); @@ -710,10 +890,13 @@ void zebra_set_state (ZebraHandle zh, int val, int seqno) void zebra_get_state (ZebraHandle zh, char *val, int *seqno) { - char *fname = zebra_mk_fname (res_get(zh->service->res, "lockDir"), - "state.LCK"); - FILE *f = fopen (fname, "r"); + char state_fname[256]; + char *fname; + FILE *f; + sprintf (state_fname, "state.%s.LCK", zh->reg_name); + fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname); + f = fopen (fname, "r"); *val = 'o'; *seqno = 0; @@ -731,6 +914,7 @@ static int zebra_begin_read (ZebraHandle zh) char val; int seqno; + assert (zh->res); (zh->trans_no)++; @@ -739,18 +923,28 @@ static int zebra_begin_read (ZebraHandle zh) zebra_flush_reg (zh); return 0; } - + if (!zh->res) + { + (zh->trans_no)--; + zh->errCode = 109; + return -1; + } zebra_get_state (zh, &val, &seqno); if (val == 'd') val = 'o'; - if (seqno != zh->service->seqno) + + if (!zh->reg) + dirty = 1; + else if (seqno != zh->reg->seqno) { - yaz_log (LOG_LOG, "reopen seqno cur/old %d/%d", seqno, zh->service->seqno); + yaz_log (LOG_LOG, "reopen seqno cur/old %d/%d", + seqno, zh->reg->seqno); dirty = 1; } - else if (zh->service->last_val != val) + else if (zh->reg->last_val != val) { - yaz_log (LOG_LOG, "reopen last cur/old %d/%d", val, zh->service->last_val); + yaz_log (LOG_LOG, "reopen last cur/old %d/%d", + val, zh->reg->last_val); dirty = 1; } if (!dirty) @@ -761,12 +955,19 @@ static int zebra_begin_read (ZebraHandle zh) else zebra_lock_r (zh->lock_normal); - zh->service->last_val = val; - zh->service->seqno = seqno; - - zebra_register_deactivate (zh); + if (zh->reg) + zebra_register_close (zh->service, zh->reg); + zh->reg = zebra_register_open (zh->service, zh->reg_name, + 0, val == 'c' ? 1 : 0, + zh->res, zh->path_reg); + if (!zh->reg) + { + zh->errCode = 109; + return -1; + } + zh->reg->last_val = val; + zh->reg->seqno = seqno; - zebra_register_activate (zh, 0, val == 'c' ? 1 : 0); return 0; } @@ -788,19 +989,21 @@ void zebra_begin_trans (ZebraHandle zh) char val = '?'; const char *rval; + assert (zh->res); + (zh->trans_no++); if (zh->trans_no != 1) { return; } - + yaz_log (LOG_LOG, "zebra_begin_trans"); #if HAVE_SYS_TIMES_H times (&zh->tms1); #endif - + /* lock */ - rval = res_get (zh->service->res, "shadow"); + rval = res_get (zh->res, "shadow"); for (pass = 0; pass < 2; pass++) { @@ -828,7 +1031,8 @@ void zebra_begin_trans (ZebraHandle zh) { if (rval) { - BFiles bfs = bfs_create (res_get (zh->service->res, "shadow")); + BFiles bfs = bfs_create (res_get (zh->res, "shadow"), + zh->path_reg); yaz_log (LOG_LOG, "previous transaction didn't reach commit"); bf_commitClean (bfs, rval); bfs_destroy (bfs); @@ -848,8 +1052,11 @@ void zebra_begin_trans (ZebraHandle zh) } zebra_set_state (zh, 'd', seqno); - zebra_register_activate (zh, 1, rval ? 1 : 0); - zh->service->seqno = seqno; + zh->reg = zebra_register_open (zh->service, zh->reg_name, + 1, rval ? 1 : 0, zh->res, + zh->path_reg); + + zh->reg->seqno = seqno; } void zebra_end_trans (ZebraHandle zh) @@ -863,16 +1070,18 @@ void zebra_end_trans (ZebraHandle zh) return; yaz_log (LOG_LOG, "zebra_end_trans"); - rval = res_get (zh->service->res, "shadow"); + rval = res_get (zh->res, "shadow"); zebra_flush_reg (zh); - zebra_register_deactivate (zh); + zebra_register_close (zh->service, zh->reg); + zh->reg = 0; zebra_get_state (zh, &val, &seqno); if (val != 'd') { - BFiles bfs = bfs_create (res_get (zh->service->res, "shadow")); + BFiles bfs = bfs_create (rval, zh->path_reg); + yaz_log (LOG_LOG, "deleting shadow stuff val=%c", val); bf_commitClean (bfs, rval); bfs_destroy (bfs); } @@ -911,24 +1120,30 @@ void zebra_repository_show (ZebraHandle zh) repositoryShow (zh); } -void zebra_commit (ZebraHandle zh) +int zebra_commit (ZebraHandle zh) { int seqno; char val; - const char *rval = res_get (zh->service->res, "shadow"); + const char *rval; BFiles bfs; + if (!zh->res) + { + zh->errCode = 109; + return -1; + } + rval = res_get (zh->res, "shadow"); if (!rval) { logf (LOG_WARN, "Cannot perform commit"); logf (LOG_WARN, "No shadow area defined"); - return; + return 0; } zebra_lock_w (zh->lock_normal); zebra_lock_r (zh->lock_shadow); - bfs = bfs_create (res_get (zh->service->res, "register")); + bfs = bfs_create (res_get (zh->res, "register"), zh->path_reg); zebra_get_state (zh, &val, &seqno); @@ -939,6 +1154,7 @@ void zebra_commit (ZebraHandle zh) zebra_set_state (zh, 'c', seqno); logf (LOG_LOG, "commit start"); + sleep (2); bf_commitExec (bfs); #ifndef WIN32 sync (); @@ -956,27 +1172,44 @@ void zebra_commit (ZebraHandle zh) zebra_unlock (zh->lock_shadow); zebra_unlock (zh->lock_normal); + return 0; } -void zebra_init (ZebraHandle zh) +int zebra_init (ZebraHandle zh) { - const char *rval = res_get (zh->service->res, "shadow"); + const char *rval; BFiles bfs = 0; - bfs = bfs_create (res_get (zh->service->res, "register")); + if (!zh->res) + { + zh->errCode = 109; + return -1; + } + rval = res_get (zh->res, "shadow"); + + bfs = bfs_create (res_get (zh->service->global_res, "register"), + zh->path_reg); if (rval && *rval) bf_cache (bfs, rval); bf_reset (bfs); bfs_destroy (bfs); zebra_set_state (zh, 'o', 0); + return 0; } -void zebra_compact (ZebraHandle zh) +int zebra_compact (ZebraHandle zh) { - BFiles bfs = bfs_create (res_get (zh->service->res, "register")); + BFiles bfs; + if (!zh->res) + { + zh->errCode = 109; + return -1; + } + bfs = bfs_create (res_get (zh->res, "register"), zh->path_reg); inv_compact (bfs); bfs_destroy (bfs); + return 0; } int zebra_record_insert (ZebraHandle zh, const char *buf, int len) @@ -995,3 +1228,15 @@ int zebra_record_insert (ZebraHandle zh, const char *buf, int len) zebra_end_trans (zh); return sysno; } + +void zebra_set_group (ZebraHandle zh, struct recordGroup *rg) +{ + memcpy (&zh->rGroup, rg, sizeof(*rg)); +} + +void zebra_result (ZebraHandle zh, int *code, char **addinfo) +{ + *code = zh->errCode; + *addinfo = zh->errString; +} + diff --git a/index/zebraapi.h b/index/zebraapi.h index 8fe0dad..0bc5099 100644 --- a/index/zebraapi.h +++ b/index/zebraapi.h @@ -3,7 +3,7 @@ * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * - * $Id: zebraapi.h,v 1.13 2002-02-20 17:30:01 adam Exp $ + * $Id: zebraapi.h,v 1.14 2002-04-04 14:14:13 adam Exp $ */ #ifndef ZEBRAAPI_H @@ -12,9 +12,24 @@ #include #include #include +#include YAZ_BEGIN_CDECL +struct recordGroup { + char *groupName; + char *databaseName; + char *path; + char *recordId; + char *recordType; + int flagStoreData; + int flagStoreKeys; + int flagRw; + int fileVerboseLimit; + int databaseNamePath; + int explainDatabase; +}; + /* Retrieval Record Descriptor */ typedef struct { int errCode; /* non-zero if error when fetching this */ @@ -40,8 +55,8 @@ YAZ_EXPORT ZebraHandle zebra_open (ZebraService zs); /* Search using RPN-Query */ YAZ_EXPORT void zebra_search_rpn (ZebraHandle zh, ODR input, ODR output, - Z_RPNQuery *query, int num_bases, char **basenames, - const char *setname); + Z_RPNQuery *query, + const char *setname, int *hits); /* Retrieve record(s) */ YAZ_EXPORT void zebra_records_retrieve (ZebraHandle zh, ODR stream, @@ -53,7 +68,6 @@ YAZ_EXPORT void zebra_records_retrieve (ZebraHandle zh, ODR stream, YAZ_EXPORT void zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, oid_value attributeset, - int num_bases, char **basenames, int *position, int *num_entries, ZebraScanEntry **list, int *is_partial); @@ -74,11 +88,8 @@ YAZ_EXPORT const char *zebra_errString (ZebraHandle zh); /* extra information associated with error */ YAZ_EXPORT char *zebra_errAdd (ZebraHandle zh); -/* number of hits (after search) */ -YAZ_EXPORT int zebra_hits (ZebraHandle zh); - /* do authentication */ -YAZ_EXPORT int zebra_auth (ZebraService zh, const char *user, const char *pass); +YAZ_EXPORT int zebra_auth (ZebraHandle zh, const char *user, const char *pass); /* Character normalisation on specific register . This routine is subject to change - do not use. */ @@ -106,14 +117,39 @@ void zebra_admin_import_end (ZebraHandle zh); void zebra_begin_trans (ZebraHandle zh); void zebra_end_trans (ZebraHandle zh); -void zebra_commit (ZebraHandle zh); +int zebra_commit (ZebraHandle zh); -void zebra_init (ZebraHandle zh); -void zebra_compact (ZebraHandle zh); +int zebra_init (ZebraHandle zh); +int zebra_compact (ZebraHandle zh); void zebra_repository_update (ZebraHandle zh); void zebra_repository_delete (ZebraHandle zh); void zebra_repository_show (ZebraHandle zh); int zebra_record_insert (ZebraHandle zh, const char *buf, int len); +YAZ_EXPORT void zebra_set_group (ZebraHandle zh, struct recordGroup *rg); + +YAZ_EXPORT void zebra_result (ZebraHandle zh, int *code, char **addinfo); + +YAZ_EXPORT const char *zebra_resultSetTerms (ZebraHandle zh, + const char *setname, + int no, int *count, int *no_max); + +YAZ_EXPORT void zebra_sort (ZebraHandle zh, ODR stream, + int num_input_setnames, + const char **input_setnames, + const char *output_setname, + Z_SortKeySpecList *sort_sequence, + int *sort_status); + + +YAZ_EXPORT +int zebra_select_databases (ZebraHandle zh, int num_bases, + const char **basenames); + +YAZ_EXPORT +int zebra_select_database (ZebraHandle zh, const char *basename); + + + YAZ_END_CDECL #endif diff --git a/index/zinfo.c b/index/zinfo.c index 4f5509b..7a2f3bc 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.24 2002-02-20 23:07:54 adam Exp $ + * $Id: zinfo.c,v 1.25 2002-04-04 14:14:13 adam Exp $ */ #include @@ -702,6 +702,12 @@ static void zebraExplain_readDatabase (ZebraExplainInfo zei, int zebraExplain_curDatabase (ZebraExplainInfo zei, const char *database) { struct zebDatabaseInfoB *zdi; + const char *database_n = strrchr (database, '/'); + + if (database_n) + database_n++; + else + database_n = database; assert (zei); if (zei->curDatabaseInfo && @@ -709,7 +715,7 @@ int zebraExplain_curDatabase (ZebraExplainInfo zei, const char *database) return 0; for (zdi = zei->databaseInfo; zdi; zdi=zdi->next) { - if (!strcmp (zdi->databaseName, database)) + if (!strcmp (zdi->databaseName, database_n)) break; } if (!zdi) @@ -786,6 +792,12 @@ int zebraExplain_newDatabase (ZebraExplainInfo zei, const char *database, { struct zebDatabaseInfoB *zdi; data1_node *node_dbinfo, *node_adinfo; + const char *database_n = strrchr (database, '/'); + + if (database_n) + database_n++; + else + database_n = database; #if ZINFO_DEBUG logf (LOG_LOG, "zebraExplain_newDatabase: %s", database); @@ -793,7 +805,7 @@ int zebraExplain_newDatabase (ZebraExplainInfo zei, const char *database, assert (zei); for (zdi = zei->databaseInfo; zdi; zdi=zdi->next) { - if (!strcmp (zdi->databaseName, database)) + if (!strcmp (zdi->databaseName, database_n)) break; } if (zdi) @@ -806,7 +818,7 @@ int zebraExplain_newDatabase (ZebraExplainInfo zei, const char *database, zdi->recordCount = 0; zdi->recordBytes = 0; zdi->readFlag = 0; - zdi->databaseName = nmem_strdup (zei->nmem, database); + zdi->databaseName = nmem_strdup (zei->nmem, database_n); zebraExplain_mergeAccessInfo (zei, 0, &zdi->accessInfo); diff --git a/index/zrpn.c b/index/zrpn.c index 6bc4537..2a14aee 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -3,7 +3,7 @@ * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * - * $Id: zrpn.c,v 1.111 2002-03-21 10:25:42 adam Exp $ + * $Id: zrpn.c,v 1.112 2002-04-04 14:14:13 adam Exp $ */ #include #include @@ -14,7 +14,7 @@ #endif #include -#include "zserver.h" +#include "index.h" #include #include @@ -32,12 +32,12 @@ static const char **rpn_char_map_handler (void *vp, const char **from, int len) return zebra_maps_input (p->zm, p->reg_type, from, len); } -static void rpn_char_map_prepare (ZebraHandle zh, int reg_type, +static void rpn_char_map_prepare (struct zebra_register *reg, int reg_type, struct rpn_char_map_info *map_info) { - map_info->zm = zh->service->zebra_maps; + map_info->zm = reg->zebra_maps; map_info->reg_type = reg_type; - dict_grep_cmap (zh->service->dict, map_info, rpn_char_map_handler); + dict_grep_cmap (reg->dict, map_info, rpn_char_map_handler); } typedef struct { @@ -152,7 +152,7 @@ static void term_untrans (ZebraHandle zh, int reg_type, { while (*src) { - const char *cp = zebra_maps_output (zh->service->zebra_maps, + const char *cp = zebra_maps_output (zh->reg->zebra_maps, reg_type, &src); if (!cp) *dst++ = *src++; @@ -209,7 +209,7 @@ static void add_isam_p (const char *name, const char *info, term_untrans (p->zh, p->reg_type, term_tmp, name+len+1); logf (LOG_LOG, "grep: %d %c %s", su_code, name[len], term_tmp); - zebraExplain_lookup_ord (p->zh->service->zei, + zebraExplain_lookup_ord (p->zh->reg->zei, su_code, &db, &set, &use); logf (LOG_LOG, "grep: set=%d use=%d db=%s", set, use, db); @@ -656,7 +656,7 @@ static int string_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, switch (relation_value) { case 1: - if (!term_100 (zh->service->zebra_maps, reg_type, + if (!term_100 (zh->reg->zebra_maps, reg_type, term_sub, term_component, space_split, term_dst)) return 0; @@ -686,7 +686,7 @@ static int string_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, *term_tmp = '\0'; break; case 2: - if (!term_100 (zh->service->zebra_maps, reg_type, + if (!term_100 (zh->reg->zebra_maps, reg_type, term_sub, term_component, space_split, term_dst)) return 0; @@ -717,7 +717,7 @@ static int string_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, *term_tmp = '\0'; break; case 5: - if (!term_100 (zh->service->zebra_maps, reg_type, + if (!term_100 (zh->reg->zebra_maps, reg_type, term_sub, term_component, space_split, term_dst)) return 0; logf (LOG_DEBUG, "Relation >"); @@ -749,7 +749,7 @@ static int string_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, *term_tmp = '\0'; break; case 4: - if (!term_100 (zh->service->zebra_maps, reg_type, term_sub, + if (!term_100 (zh->reg->zebra_maps, reg_type, term_sub, term_component, space_split, term_dst)) return 0; logf (LOG_DEBUG, "Relation >="); @@ -786,7 +786,7 @@ static int string_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, case 3: default: logf (LOG_DEBUG, "Relation ="); - if (!term_100 (zh->service->zebra_maps, reg_type, term_sub, + if (!term_100 (zh->reg->zebra_maps, reg_type, term_sub, term_component, space_split, term_dst)) return 0; strcat (term_tmp, "("); @@ -815,7 +815,7 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, struct rpn_char_map_info rcmi; int space_split = complete_flag ? 0 : 1; - rpn_char_map_prepare (zh, reg_type, &rcmi); + rpn_char_map_prepare (zh->reg, reg_type, &rcmi); attr_init (&use, zapt, 1); use_value = attr_find (&use, &curAttributeSet); logf (LOG_DEBUG, "string_term, use value %d", use_value); @@ -859,7 +859,7 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, } return -1; } - if (zebraExplain_curDatabase (zh->service->zei, basenames[base_no])) + if (zebraExplain_curDatabase (zh->reg->zei, basenames[base_no])) { zh->errCode = 109; /* Database unavailable */ zh->errString = basenames[base_no]; @@ -872,7 +872,7 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, char ord_buf[32]; int i, ord_len; - ord = zebraExplain_lookupSU (zh->service->zei, attp.attset_ordinal, + ord = zebraExplain_lookupSU (zh->reg->zei, attp.attset_ordinal, local_attr->local); if (ord < 0) continue; @@ -911,59 +911,59 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, reg_type, space_split, term_dst)) return 0; logf (LOG_DEBUG, "dict_lookup_grep: %s", term_dict+prefix_len); - r = dict_lookup_grep (zh->service->dict, term_dict, 0, + r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info, &max_pos, 0, grep_handle); if (r) logf (LOG_WARN, "dict_lookup_grep fail, rel=gt: %d", r); break; case 1: /* right truncation */ term_dict[j++] = '('; - if (!term_100 (zh->service->zebra_maps, reg_type, + if (!term_100 (zh->reg->zebra_maps, reg_type, &termp, term_dict + j, space_split, term_dst)) return 0; strcat (term_dict, ".*)"); - dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info, + dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info, &max_pos, 0, grep_handle); break; case 2: /* keft truncation */ term_dict[j++] = '('; term_dict[j++] = '.'; term_dict[j++] = '*'; - if (!term_100 (zh->service->zebra_maps, reg_type, + if (!term_100 (zh->reg->zebra_maps, reg_type, &termp, term_dict + j, space_split, term_dst)) return 0; strcat (term_dict, ")"); - dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info, + dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info, &max_pos, 0, grep_handle); break; case 3: /* left&right truncation */ term_dict[j++] = '('; term_dict[j++] = '.'; term_dict[j++] = '*'; - if (!term_100 (zh->service->zebra_maps, reg_type, + if (!term_100 (zh->reg->zebra_maps, reg_type, &termp, term_dict + j, space_split, term_dst)) return 0; strcat (term_dict, ".*)"); - dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info, + dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info, &max_pos, 0, grep_handle); break; zh->errCode = 120; return -1; case 101: /* process # in term */ term_dict[j++] = '('; - if (!term_101 (zh->service->zebra_maps, reg_type, + if (!term_101 (zh->reg->zebra_maps, reg_type, &termp, term_dict + j, space_split, term_dst)) return 0; strcat (term_dict, ")"); - r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info, + r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info, &max_pos, 0, grep_handle); if (r) logf (LOG_WARN, "dict_lookup_grep err, trunc=#: %d", r); break; case 102: /* Regexp-1 */ term_dict[j++] = '('; - if (!term_102 (zh->service->zebra_maps, reg_type, + if (!term_102 (zh->reg->zebra_maps, reg_type, &termp, term_dict + j, space_split, term_dst)) return 0; strcat (term_dict, ")"); logf (LOG_DEBUG, "Regexp-1 tolerance=%d", r); - r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info, + r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info, &max_pos, 0, grep_handle); if (r) logf (LOG_WARN, "dict_lookup_grep err, trunc=regular: %d", @@ -972,12 +972,12 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, case 103: /* Regexp-2 */ r = 1; term_dict[j++] = '('; - if (!term_103 (zh->service->zebra_maps, reg_type, + if (!term_103 (zh->reg->zebra_maps, reg_type, &termp, term_dict + j, &r, space_split, term_dst)) return 0; strcat (term_dict, ")"); logf (LOG_DEBUG, "Regexp-2 tolerance=%d", r); - r = dict_lookup_grep (zh->service->dict, term_dict, r, grep_info, + r = dict_lookup_grep (zh->reg->dict, term_dict, r, grep_info, &max_pos, 2, grep_handle); if (r) logf (LOG_WARN, "dict_lookup_grep err, trunc=eregular: %d", @@ -985,33 +985,33 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, break; case 104: /* process # and ! in term */ term_dict[j++] = '('; - if (!term_104 (zh->service->zebra_maps, reg_type, + if (!term_104 (zh->reg->zebra_maps, reg_type, &termp, term_dict + j, space_split, term_dst)) return 0; strcat (term_dict, ")"); - r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info, + r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info, &max_pos, 0, grep_handle); if (r) logf (LOG_WARN, "dict_lookup_grep err, trunc=#/!: %d", r); break; case 105: /* process * and ! in term */ term_dict[j++] = '('; - if (!term_105 (zh->service->zebra_maps, reg_type, + if (!term_105 (zh->reg->zebra_maps, reg_type, &termp, term_dict + j, space_split, term_dst, 1)) return 0; strcat (term_dict, ")"); - r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info, + r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info, &max_pos, 0, grep_handle); if (r) logf (LOG_WARN, "dict_lookup_grep err, trunc=*/!: %d", r); break; case 106: /* process * and ! in term */ term_dict[j++] = '('; - if (!term_105 (zh->service->zebra_maps, reg_type, + if (!term_105 (zh->reg->zebra_maps, reg_type, &termp, term_dict + j, space_split, term_dst, 0)) return 0; strcat (term_dict, ")"); - r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info, + r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info, &max_pos, 0, grep_handle); if (r) logf (LOG_WARN, "dict_lookup_grep err, trunc=*/!: %d", r); @@ -1050,7 +1050,7 @@ static void trans_scan_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, while ((len = (cp_end - cp)) > 0) { - map = zebra_maps_input (zh->service->zebra_maps, reg_type, &cp, len); + map = zebra_maps_input (zh->reg->zebra_maps, reg_type, &cp, len); if (**map == *CHR_SPACE) space_map = *map; else @@ -1138,7 +1138,7 @@ static RSET rpn_prox (ZebraHandle zh, RSET *rset, int rset_no, parms.rset_term->nn = min_nn; parms.cmp = key_compare_it; parms.key_size = sizeof (struct it_key); - parms.temp_path = res_get (zh->service->res, "setTmpDir"); + parms.temp_path = res_get (zh->res, "setTmpDir"); result = rset_create (rset_kind_temp, &parms); rsfd_result = rset_open (result, RSETF_WRITE); @@ -1197,7 +1197,7 @@ static RSET rpn_prox (ZebraHandle zh, RSET *rset, int rset_no, parms.rset_term->nn = min_nn; parms.cmp = key_compare_it; parms.key_size = sizeof (struct it_key); - parms.temp_path = res_get (zh->service->res, "setTmpDir"); + parms.temp_path = res_get (zh->res, "setTmpDir"); result = rset_create (rset_kind_temp, &parms); rsfd_result = rset_open (result, RSETF_WRITE); @@ -1321,7 +1321,7 @@ char *normalize_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, break; } if (ex_list) - wrbuf = zebra_replace(zh->service->zebra_maps, reg_id, ex_list, + wrbuf = zebra_replace(zh->reg->zebra_maps, reg_id, ex_list, termz, strlen(termz)); if (!wrbuf) return nmem_strdup(stream, termz); @@ -1576,7 +1576,7 @@ static int numeric_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, logf (LOG_DEBUG, "numeric relation value=%d", relation_value); - if (!term_100 (zh->service->zebra_maps, reg_type, term_sub, term_tmp, 1, + if (!term_100 (zh->reg->zebra_maps, reg_type, term_sub, term_tmp, 1, term_dst)) return 0; term_value = atoi (term_tmp); @@ -1604,7 +1604,7 @@ static int numeric_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, sprintf (term_tmp, "(0*%d)", term_value); } logf (LOG_DEBUG, "dict_lookup_grep: %s", term_tmp); - r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info, max_pos, + r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info, max_pos, 0, grep_handle); if (r) logf (LOG_WARN, "dict_lookup_grep fail, rel=gt: %d", r); @@ -1627,7 +1627,7 @@ static int numeric_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, const char *termp; struct rpn_char_map_info rcmi; - rpn_char_map_prepare (zh, reg_type, &rcmi); + rpn_char_map_prepare (zh->reg, reg_type, &rcmi); attr_init (&use, zapt, 1); use_value = attr_find (&use, &curAttributeSet); logf (LOG_DEBUG, "numeric_term, use value %d", use_value); @@ -1652,7 +1652,7 @@ static int numeric_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, zh->errCode = 121; return -1; } - if (zebraExplain_curDatabase (zh->service->zei, basenames[base_no])) + if (zebraExplain_curDatabase (zh->reg->zei, basenames[base_no])) { zh->errCode = 109; /* Database unavailable */ zh->errString = basenames[base_no]; @@ -1665,7 +1665,7 @@ static int numeric_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, char ord_buf[32]; int i, ord_len; - ord = zebraExplain_lookupSU (zh->service->zei, attp.attset_ordinal, + ord = zebraExplain_lookupSU (zh->reg->zei, attp.attset_ordinal, local_attr->local); if (ord < 0) continue; @@ -1774,7 +1774,7 @@ static RSET rpn_search_APT_local (ZebraHandle zh, Z_AttributesPlusTerm *zapt, parms.rset_term = rset_term_create (termz, -1, rank_type); parms.cmp = key_compare_it; parms.key_size = sizeof (struct it_key); - parms.temp_path = res_get (zh->service->res, "setTmpDir"); + parms.temp_path = res_get (zh->res, "setTmpDir"); result = rset_create (rset_kind_temp, &parms); rsfd = rset_open (result, RSETF_WRITE); @@ -1901,7 +1901,7 @@ static RSET rpn_search_APT (ZebraHandle zh, Z_AttributesPlusTerm *zapt, int sort_flag; char termz[IT_MAX_WORD+1]; - zebra_maps_attr (zh->service->zebra_maps, zapt, ®_id, &search_type, + zebra_maps_attr (zh->reg->zebra_maps, zapt, ®_id, &search_type, rank_type, &complete_flag, &sort_flag); logf (LOG_DEBUG, "reg_id=%c", reg_id); @@ -2241,7 +2241,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, attr_init (&use, zapt, 1); use_value = attr_find (&use, &attributeset); - if (zebra_maps_attr (zh->service->zebra_maps, zapt, ®_id, &search_type, + if (zebra_maps_attr (zh->reg->zebra_maps, zapt, ®_id, &search_type, rank_type, &complete_flag, &sort_flag)) { *num_entries = 0; @@ -2269,7 +2269,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, *num_entries = 0; return; } - if (zebraExplain_curDatabase (zh->service->zei, basenames[base_no])) + if (zebraExplain_curDatabase (zh->reg->zei, basenames[base_no])) { zh->errString = basenames[base_no]; zh->errCode = 109; /* Database unavailable */ @@ -2281,7 +2281,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, { int ord; - ord = zebraExplain_lookupSU (zh->service->zei, attp.attset_ordinal, + ord = zebraExplain_lookupSU (zh->reg->zei, attp.attset_ordinal, local_attr->local); if (ord > 0) ords[ord_no++] = ord; @@ -2305,7 +2305,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, struct scan_info *scan_info = scan_info_array + i; struct rpn_char_map_info rcmi; - rpn_char_map_prepare (zh, reg_id, &rcmi); + rpn_char_map_prepare (zh->reg, reg_id, &rcmi); scan_info->before = before; scan_info->after = after; @@ -2323,7 +2323,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, trans_scan_term (zh, zapt, termz+prefix_len, reg_id); - dict_scan (zh->service->dict, termz, &before_tmp, &after_tmp, + dict_scan (zh->reg->dict, termz, &before_tmp, &after_tmp, scan_info, scan_handle); } glist = (ZebraScanEntry *) diff --git a/index/zserver.c b/index/zserver.c index c935479..9f0572c 100644 --- a/index/zserver.c +++ b/index/zserver.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2000, Index Data * All rights reserved. * - * $Id: zserver.c,v 1.84 2002-03-20 20:24:30 adam Exp $ + * $Id: zserver.c,v 1.85 2002-04-04 14:14:13 adam Exp $ */ #include @@ -22,13 +22,6 @@ #include "zserver.h" -#ifndef ZEBRASDR -#define ZEBRASDR 0 -#endif -#if ZEBRASDR -#include "zebrasdr.h" -#endif - static int bend_sort (void *handle, bend_sort_rr *rr); static int bend_delete (void *handle, bend_delete_rr *rr); static int bend_esrequest (void *handle, bend_esrequest_rr *rr); @@ -88,7 +81,7 @@ bend_initresult *bend_init (bend_initrequest *q) xfree (openpass); } } - if (zebra_auth (zh->service, user, passwd)) + if (zebra_auth (zh, user, passwd)) { r->errcode = 222; r->errstring = user; @@ -177,15 +170,19 @@ int bend_search (void *handle, bend_search_rr *r) r->errcode = 0; r->errstring = NULL; + if (zebra_select_databases (zh, r->num_bases, + (const char **) r->basenames)) + { + zebra_result (zh, &r->errcode, &r->errstring); + return 0; + } logf (LOG_LOG, "ResultSet '%s'", r->setname); switch (r->query->which) { case Z_Query_type_1: case Z_Query_type_101: zebra_search_rpn (zh, r->decode, r->stream, r->query->u.type_1, - r->num_bases, r->basenames, r->setname); - r->errcode = zh->errCode; - r->errstring = zh->errString; - r->hits = zh->hits; + r->setname, &r->hits); + zebra_result (zh, &r->errcode, &r->errstring); if (!r->errcode) search_terms (zh, r); break; @@ -210,19 +207,16 @@ int bend_fetch (void *handle, bend_fetch_rr *r) r->last_in_set = 0; zebra_records_retrieve (zh, r->stream, r->setname, r->comp, r->request_format, 1, &retrievalRecord); - if (zh->errCode) /* non Surrogate Diagnostic */ - { - r->errcode = zh->errCode; - r->errstring = zh->errString; - } - else if (retrievalRecord.errCode) /* Surrogate Diagnostic */ + zebra_result (zh, &r->errcode, &r->errstring); + /* non Surrogate Diagnostic OR Surrogate Diagnostic */ + if (r->errcode == 0 && retrievalRecord.errCode) { r->surrogate_flag = 1; r->errcode = retrievalRecord.errCode; r->errstring = retrievalRecord.errString; r->basename = retrievalRecord.base; } - else /* Database Record */ + else if (r->errcode == 0) /* Database Record */ { r->errcode = 0; r->basename = retrievalRecord.base; @@ -238,12 +232,13 @@ static int bend_scan (void *handle, bend_scan_rr *r) ZebraScanEntry *entries; ZebraHandle zh = (ZebraHandle) handle; int is_partial, i; + + zebra_select_databases (zh, r->num_bases, (const char **) r->basenames); r->entries = (struct scan_entry *) odr_malloc (r->stream, sizeof(*r->entries) * r->num_entries); zebra_scan (zh, r->stream, r->term, r->attributeset, - r->num_bases, r->basenames, &r->term_position, &r->num_entries, &entries, &is_partial); if (is_partial) @@ -255,8 +250,7 @@ static int bend_scan (void *handle, bend_scan_rr *r) r->entries[i].term = entries[i].term; r->entries[i].occurrences = entries[i].occurrences; } - r->errcode = zh->errCode; - r->errstring = zh->errString; + zebra_result (zh, &r->errcode, &r->errstring); return 0; } @@ -274,8 +268,7 @@ int bend_sort (void *handle, bend_sort_rr *rr) zebra_sort (zh, rr->stream, rr->num_input_setnames, (const char **) rr->input_setnames, rr->output_setname, rr->sort_sequence, &rr->sort_status); - rr->errcode = zh->errCode; - rr->errstring = zh->errString; + zebra_result (zh, &rr->errcode, &rr->errstring); return 0; } @@ -326,7 +319,6 @@ static int es_admin_request (ZebraHandle zh, Z_AdminEsRequest *r) break; default: yaz_log(LOG_LOG, "unknown admin"); - zh->errCode = 1001; } if (r->toKeep->databaseName) { @@ -346,7 +338,6 @@ static int es_admin (ZebraHandle zh, Z_Admin *r) yaz_log (LOG_LOG, "adm taskpackage (unhandled)"); break; default: - zh->errCode = 1001; break; } @@ -381,8 +372,8 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr) else if (rr->esr->taskSpecificParameters->which == Z_External_ESAdmin) { es_admin (zh, rr->esr->taskSpecificParameters->u.adminService); - rr->errcode = zh->errCode; - rr->errstring = zh->errString; + + zebra_result (zh, &rr->errcode, &rr->errstring); } else if (rr->esr->taskSpecificParameters->which == Z_External_itemOrder) { @@ -637,7 +628,7 @@ int main (int argc, char **argv) struct statserv_options_block *sob; sob = statserv_getcontrol (); - strcpy (sob->configname, FNAME_CONFIG); + strcpy (sob->configname, "zebra.cfg"); sob->bend_start = bend_start; sob->bend_stop = bend_stop; diff --git a/index/zserver.h b/index/zserver.h index 841cb37..fde032a 100644 --- a/index/zserver.h +++ b/index/zserver.h @@ -3,250 +3,12 @@ * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * - * $Id: zserver.h,v 1.54 2002-03-27 07:53:13 adam Exp $ + * $Id: zserver.h,v 1.55 2002-04-04 14:14:13 adam Exp $ */ -#if HAVE_SYS_TIMES_H -#include -#endif - #include -#include - -#include -#include -#include "index.h" #include "zebraapi.h" -#include "zinfo.h" YAZ_BEGIN_CDECL -typedef struct { - char *term; - char *db; - int sysno; - int score; -} *ZebraPosSet; - -typedef struct zebra_set *ZebraSet; - -typedef struct zebra_rank_class { - struct rank_control *control; - int init_flag; - void *class_handle; - struct zebra_rank_class *next; -} *ZebraRankClass; - -struct zebra_service { - char *configName; - struct zebra_session *sessions; - ISAMS isams; -#if ZMBOL - ISAM isam; - ISAMC isamc; - ISAMD isamd; -#endif - Dict dict; - Dict matchDict; - SortIdx sortIdx; - int registerState; /* 0 (no commit pages), 1 (use commit pages) */ - time_t registerChange; - BFiles bfs; - Records records; - ZebraExplainInfo zei; - Res res; - ZebraLockHandle server_lock_cmt; - ZebraLockHandle server_lock_org; - - char *server_path_prefix; - data1_handle dh; - ZebraMaps zebra_maps; - ZebraRankClass rank_classes; - RecTypes recTypes; - Passwd_db passwd_db; - Zebra_mutex_cond session_lock; - int seqno; - int last_val; - int stop_flag; - int active; /* 0=shutdown, 1=enabled and inactive, 2=activated */ -}; - -struct recKeys { - int buf_used; - int buf_max; - char *buf; - char prevAttrSet; - short prevAttrUse; - int prevSeqNo; -}; - -struct sortKey { - char *string; - int length; - int attrSet; - int attrUse; - struct sortKey *next; -}; - -struct zebra_session { - struct zebra_session *next; - struct zebra_service *service; - - struct recKeys keys; - struct sortKey *sortKeys; - - char **key_buf; - size_t ptr_top; - size_t ptr_i; - size_t key_buf_used; - int key_file_no; - char *admin_databaseName; - - ZebraLockHandle lock_normal; - ZebraLockHandle lock_shadow; - - int trans_no; - int destroyed; - ZebraSet sets; - int errCode; - int hits; - char *errString; -#if HAVE_SYS_TIMES_H - struct tms tms1; - struct tms tms2; -#endif - struct recordGroup rGroup; -}; - -struct rank_control { - char *name; - void *(*create)(ZebraService zh); - void (*destroy)(ZebraService zh, void *class_handle); - void *(*begin)(ZebraHandle zh, void *class_handle, RSET rset); - void (*end)(ZebraHandle zh, void *set_handle); - int (*calc)(void *set_handle, int sysno); - void (*add)(void *set_handle, int seqno, int term_index); -}; - -struct term_set_entry { - char *term; - struct term_set_entry *next; -}; - -struct term_set_list { - struct term_set_entry *first; - struct term_set_entry *last; -}; - -RSET rpn_search (ZebraHandle zh, NMEM mem, - Z_RPNQuery *rpn, int num_bases, char **basenames, - const char *setname, ZebraSet sset); - - -void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, - oid_value attributeset, - int num_bases, char **basenames, - int *position, int *num_entries, ZebraScanEntry **list, - int *is_partial); - -RSET rset_trunc (ZebraHandle zh, ISAMS_P *isam_p, int no, - const char *term, int length_term, const char *flags); - -void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type, - const char *db, int set, - int use, const char *term); -ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov); -ZebraSet resultSetGet (ZebraHandle zh, const char *name); -ZebraSet resultSetAddRPN (ZebraHandle zh, ODR stream, ODR decode, - Z_RPNQuery *rpn, int num_bases, char **basenames, - const char *setname); -RSET resultSetRef (ZebraHandle zh, Z_ResultSetId *resultSetId); -void resultSetDestroy (ZebraHandle zh, int num_names, char **names, - int *statuses); - -const char *zebra_resultSetTerms (ZebraHandle zh, const char *setname, - int no, int *count, int *no_max); - -ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name, - int num, int *positions); -void zebraPosSetDestroy (ZebraHandle zh, ZebraPosSet records, int num); - -void resultSetSort (ZebraHandle zh, NMEM nmem, - int num_input_setnames, const char **input_setnames, - const char *output_setname, - Z_SortKeySpecList *sort_sequence, int *sort_status); -void resultSetSortSingle (ZebraHandle zh, NMEM nmem, - ZebraSet sset, RSET rset, - Z_SortKeySpecList *sort_sequence, int *sort_status); -void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset); -void resultSetInvalidate (ZebraHandle zh); - -void zebra_sort (ZebraHandle zh, ODR stream, - int num_input_setnames, const char **input_setnames, - const char *output_setname, Z_SortKeySpecList *sort_sequence, - int *sort_status); - -int zebra_server_lock_init (ZebraService zh); -int zebra_server_lock_destroy (ZebraService zh); -int zebra_server_lock (ZebraService zh, int lockCommit); -void zebra_server_unlock (ZebraService zh, int commitPhase); -int zebra_server_lock_get_state (ZebraService zh, time_t *timep); - -typedef struct attent -{ - int attset_ordinal; - data1_local_attribute *local_attributes; -} attent; - -void zebraRankInstall (ZebraService zh, struct rank_control *ctrl); -ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name); -void zebraRankDestroy (ZebraService zh); - -int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att); - -extern struct rank_control *rank1_class; - -int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream, - oid_value input_format, Z_RecordComposition *comp, - oid_value *output_format, char **rec_bufp, - int *rec_lenp, char **basenamep); - -void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no); -void zebra_index_merge (ZebraHandle zh); - - -int extract_rec_in_mem (ZebraHandle zh, const char *recordType, - const char *buf, size_t buf_size, - const char *databaseName, int delete_flag, - int test_mode, int *sysno, - int store_keys, int store_data, - const char *match_criteria); - -void extract_flushWriteKeys (ZebraHandle zh); - -struct zebra_fetch_control { - off_t offset_end; - off_t record_offset; - off_t record_int_pos; - const char *record_int_buf; - int record_int_len; - int fd; -}; - -int zebra_record_ext_read (void *fh, char *buf, size_t count); -off_t zebra_record_ext_seek (void *fh, off_t offset); -off_t zebra_record_ext_tell (void *fh); -off_t zebra_record_int_seek (void *fh, off_t offset); -off_t zebra_record_int_tell (void *fh); -int zebra_record_int_read (void *fh, char *buf, size_t count); -void zebra_record_int_end (void *fh, off_t offset); - -void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno, - int cmd, struct recKeys *reckeys); -void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno, - int cmd, struct sortKey **skp); -void extract_schema_add (struct recExtractCtrl *p, Odr_oid *oid); -void extract_token_add (RecWord *p); -int explain_extract (void *handle, Record rec, data1_node *n); - YAZ_END_CDECL diff --git a/index/zsets.c b/index/zsets.c index 2aeb072..b9c30ec 100644 --- a/index/zsets.c +++ b/index/zsets.c @@ -3,7 +3,7 @@ * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * - * $Id: zsets.c,v 1.33 2002-03-20 20:24:30 adam Exp $ + * $Id: zsets.c,v 1.34 2002-04-04 14:14:13 adam Exp $ */ #include #include @@ -13,7 +13,7 @@ #include #endif -#include "zserver.h" +#include "index.h" #include #define SORT_IDX_ENTRYSIZE 64 @@ -55,10 +55,12 @@ struct zset_sort_info { }; ZebraSet resultSetAddRPN (ZebraHandle zh, ODR input, ODR output, - Z_RPNQuery *rpn, int num_bases, char **basenames, + Z_RPNQuery *rpn, int num_bases, + char **basenames, const char *setname) { ZebraSet zebraSet; + int i; zh->errCode = 0; zh->errString = NULL; @@ -69,9 +71,14 @@ ZebraSet resultSetAddRPN (ZebraHandle zh, ODR input, ODR output, return 0; zebraSet->locked = 1; zebraSet->rpn = 0; + zebraSet->nmem = nmem_create (); + zebraSet->num_bases = num_bases; - zebraSet->basenames = basenames; - zebraSet->nmem = odr_extract_mem (input); + zebraSet->basenames = + nmem_malloc (zebraSet->nmem, num_bases * sizeof(*zebraSet->basenames)); + for (i = 0; ibasenames[i] = nmem_strdup (zebraSet->nmem, basenames[i]); + zebraSet->rset = rpn_search (zh, output->mem, rpn, zebraSet->num_bases, @@ -273,8 +280,6 @@ ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name, sr = (ZebraPosSet) xmalloc (sizeof(*sr) * num); for (i = 0; iterm_entries; - sr[i].sysno = 0; sr[i].score = -1; sr[i].term = 0; @@ -384,11 +389,11 @@ void resultSetInsertSort (ZebraHandle zh, ZebraSet sset, struct zset_sort_info *sort_info = sset->sort_info; int i, j; - sortIdx_sysno (zh->service->sortIdx, sysno); + sortIdx_sysno (zh->reg->sortIdx, sysno); for (i = 0; iservice->sortIdx, criteria[i].attrUse); - sortIdx_read (zh->service->sortIdx, this_entry.buf[i]); + sortIdx_type (zh->reg->sortIdx, criteria[i].attrUse); + sortIdx_read (zh->reg->sortIdx, this_entry.buf[i]); } i = sort_info->num_entries; while (--i >= 0) @@ -594,7 +599,7 @@ void resultSetSortSingle (ZebraHandle zh, NMEM nmem, case Z_SortKey_sortAttributes: logf (LOG_DEBUG, "Sort: key %d is of type sortAttributes", i+1); sort_criteria[i].attrUse = - zebra_maps_sort (zh->service->zebra_maps, + zebra_maps_sort (zh->reg->zebra_maps, sk->u.sortAttributes, &sort_criteria[i].numerical); logf (LOG_DEBUG, "use value = %d", sort_criteria[i].attrUse); @@ -603,7 +608,7 @@ void resultSetSortSingle (ZebraHandle zh, NMEM nmem, zh->errCode = 116; return; } - if (sortIdx_type (zh->service->sortIdx, sort_criteria[i].attrUse)) + if (sortIdx_type (zh->reg->sortIdx, sort_criteria[i].attrUse)) { zh->errCode = 207; return; @@ -669,7 +674,7 @@ void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset) int psysno = key.sysno; int score; void *handle = - (*rc->begin) (zh, rank_class->class_handle, rset); + (*rc->begin) (zh->reg, rank_class->class_handle, rset); (zebraSet->hits)++; do { @@ -687,7 +692,7 @@ void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset) while (rset_read (rset, rfd, &key, &term_index)); score = (*rc->calc) (handle, psysno); resultSetInsertRank (zh, sort_info, psysno, score, 'A'); - (*rc->end) (zh, handle); + (*rc->end) (zh->reg, handle); } rset_close (rset, rfd); @@ -703,41 +708,41 @@ void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset) ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name) { - ZebraRankClass p = zh->service->rank_classes; + ZebraRankClass p = zh->reg->rank_classes; while (p && strcmp (p->control->name, name)) p = p->next; if (p && !p->init_flag) { if (p->control->create) - p->class_handle = (*p->control->create)(zh->service); + p->class_handle = (*p->control->create)(zh->reg); p->init_flag = 1; } return p; } -void zebraRankInstall (ZebraService zh, struct rank_control *ctrl) +void zebraRankInstall (struct zebra_register *reg, struct rank_control *ctrl) { ZebraRankClass p = (ZebraRankClass) xmalloc (sizeof(*p)); p->control = (struct rank_control *) xmalloc (sizeof(*p->control)); memcpy (p->control, ctrl, sizeof(*p->control)); p->control->name = xstrdup (ctrl->name); p->init_flag = 0; - p->next = zh->rank_classes; - zh->rank_classes = p; + p->next = reg->rank_classes; + reg->rank_classes = p; } -void zebraRankDestroy (ZebraService zh) +void zebraRankDestroy (struct zebra_register *reg) { - ZebraRankClass p = zh->rank_classes; + ZebraRankClass p = reg->rank_classes; while (p) { ZebraRankClass p_next = p->next; if (p->init_flag && p->control->destroy) - (*p->control->destroy)(zh, p->class_handle); + (*p->control->destroy)(reg, p->class_handle); xfree (p->control->name); xfree (p->control); xfree (p); p = p_next; } - zh->rank_classes = NULL; + reg->rank_classes = NULL; } diff --git a/rset/rsisamc.c b/rset/rsisamc.c index 96f6386..285fd17 100644 --- a/rset/rsisamc.c +++ b/rset/rsisamc.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: rsisamc.c,v $ - * Revision 1.9 2002-03-20 20:24:30 adam + * Revision 1.10 2002-04-04 14:14:13 adam + * Multiple registers (alpha early) + * + * Revision 1.9 2002/03/20 20:24:30 adam * Hits per term. Returned in SearchResult-1 * * Revision 1.8 1999/11/30 13:48:04 adam @@ -92,7 +95,6 @@ static void *r_create(RSET ct, const struct rset_control *sel, void *parms) info->is = pt->is; info->pos = pt->pos; info->key_size = pt->key_size; - yaz_log (LOG_LOG, "info->key_size = %d\n", info->key_size); info->cmp = pt->cmp; info->ispt_list = NULL; ct->no_rset_terms = 1; diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 4989c31..ba60a45 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -6,6 +6,6 @@ EXTRA_DIST=t1.cfg t2.cfg t1_SOURCES = t1.c t2_SOURCES = t2.c -CFLAGS = -I$(top_srcdir)/index $(YAZINC) +CFLAGS = -I$(top_srcdir)/index -I$(top_srcdir)/include $(YAZINC) LDADD = ../../index/libzebra.a $(YAZLIB) $(TCL_LIB) diff --git a/util/dirent.c b/util/dirent.c index 2127fd4..232021d 100644 --- a/util/dirent.c +++ b/util/dirent.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dirent.c,v $ - * Revision 1.3 1999-02-02 14:51:38 adam + * Revision 1.4 2002-04-04 14:14:14 adam + * Multiple registers (alpha early) + * + * Revision 1.3 1999/02/02 14:51:38 adam * Updated WIN32 code specific sections. Changed header. * * Revision 1.2 1997/09/17 12:19:24 adam @@ -65,3 +68,16 @@ void closedir(DIR *dd) } #endif + +int zebra_is_abspath (const char *p) +{ + if (*p == '/') + return 1; +#ifdef WIN32 + if (*p == '\\') + return 1; + if (*p && p[1] == ':' && isalpha(*p)) + return 1; +#endif + return 0; +} diff --git a/util/res.c b/util/res.c index d3307e7..a65e506 100644 --- a/util/res.c +++ b/util/res.c @@ -1,95 +1,9 @@ /* - * Copyright (C) 1994-1999, Index Data + * Copyright (C) 1994-2002, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * - * $Log: res.c,v $ - * Revision 1.28 2000-12-01 17:59:08 adam - * Fixed bug regarding online updates on WIN32. - * When zebra.cfg is not available the server will not abort. - * - * Revision 1.27 1999/11/30 13:48:04 adam - * Improved installation. Updated for inclusion of YAZ header files. - * - * Revision 1.26 1999/10/07 09:48:36 adam - * Allow res_get / res_get_def with NULL res. - * - * Revision 1.25 1999/05/26 07:49:14 adam - * C++ compilation. - * - * Revision 1.24 1999/02/02 14:51:42 adam - * Updated WIN32 code specific sections. Changed header. - * - * Revision 1.23 1998/10/28 15:18:55 adam - * Fix for DOS-formatted configuration files. - * - * Revision 1.22 1998/01/12 15:04:32 adam - * Removed exit - call. - * - * Revision 1.21 1997/11/18 10:04:03 adam - * Function res_trav returns number of 'hits'. - * - * Revision 1.20 1997/10/31 12:39:15 adam - * Resouce name can be terminated with either white-space or colon. - * - * Revision 1.19 1997/10/27 14:27:59 adam - * Fixed memory leak. - * - * Revision 1.18 1997/09/17 12:19:24 adam - * Zebra version corresponds to YAZ version 1.4. - * Changed Zebra server so that it doesn't depend on global common_resource. - * - * Revision 1.17 1997/09/09 13:38:19 adam - * Partial port to WIN95/NT. - * - * Revision 1.16 1996/10/29 13:47:49 adam - * Implemented res_get_match. Updated to use zebrautl instead of alexpath. - * - * Revision 1.15 1996/05/22 08:23:43 adam - * Bug fix: trailing blanks in resource values where not removed. - * - * Revision 1.14 1996/04/26 11:51:20 adam - * Resource names are matched by the yaz_matchstr routine instead of strcmp. - * - * Revision 1.13 1995/09/04 12:34:05 adam - * Various cleanup. YAZ util used instead. - * - * Revision 1.12 1995/01/24 16:40:32 adam - * Bug fix. - * - * Revision 1.11 1994/10/05 16:54:52 adam - * Minor changes. - * - * Revision 1.10 1994/10/05 10:47:31 adam - * Small bug fix. - * - * Revision 1.9 1994/09/16 14:41:12 quinn - * Added log warning to res_get_def - * - * Revision 1.8 1994/09/16 14:37:12 quinn - * added res_get_def - * - * Revision 1.7 1994/09/06 13:01:03 quinn - * Removed const from declaration of res_get - * - * Revision 1.6 1994/09/01 17:45:14 adam - * Work on resource manager. - * - * Revision 1.5 1994/08/18 11:02:28 adam - * Implementation of res_write. - * - * Revision 1.4 1994/08/18 10:02:01 adam - * Module alexpath moved from res.c to alexpath.c. Minor changes in res-test.c - * - * Revision 1.3 1994/08/18 09:43:51 adam - * Development of resource manager. Only missing is res_write. - * - * Revision 1.2 1994/08/18 08:23:26 adam - * Res.c now use handles. xmalloc defines xstrdup. - * - * Revision 1.1 1994/08/17 15:34:23 adam - * Initial version of resource manager. - * + * $Id: res.c,v 1.29 2002-04-04 14:14:14 adam Exp $ */ #include #include @@ -104,6 +18,19 @@ #include #include +struct res_entry { + char *name; + char *value; + struct res_entry *next; +}; + +struct res_struct { + struct res_entry *first, *last; + char *name; + int init; + Res def_res; +}; + static struct res_entry *add_entry (Res r) { struct res_entry *resp; @@ -229,7 +156,7 @@ static void reread (Res r) fclose (fr); } -Res res_open (const char *name) +Res res_open (const char *name, Res def_res) { Res r; #ifdef WIN32 @@ -239,12 +166,13 @@ Res res_open (const char *name) #endif { logf (LOG_LOG|LOG_ERRNO, "Cannot access resource file `%s'", name); - return NULL; + return 0; } r = (Res) xmalloc (sizeof(*r)); r->init = 0; r->first = r->last = NULL; r->name = xstrdup (name); + r->def_res = def_res; return r; } @@ -274,13 +202,14 @@ char *res_get (Res r, const char *name) struct res_entry *re; if (!r) - return NULL; + return 0; if (!r->init) reread (r); for (re = r->first; re; re=re->next) if (re->value && !yaz_matchstr (re->name, name)) return re->value; - return NULL; + + return res_get (r->def_res, name); } char *res_get_def (Res r, const char *name, char *def) @@ -346,6 +275,8 @@ int res_trav (Res r, const char *prefix, void *p, (*f)(p, re->name, re->value); no++; } + if (!no) + return res_trav (r->def_res, prefix, p, f); return no; } -- 1.7.10.4