From eb2b742588ce07fb4516bbca22c93b938b13e433 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 15 Mar 2000 15:00:30 +0000 Subject: [PATCH] First work on threaded version. --- bfile/bfile.c | 29 ++++- bfile/mfile.c | 27 +++-- configure | 170 ++++++++++++++++++++------ configure.in | 22 +++- include/bfile.h | 3 +- include/mfile.h | 22 ++-- include/zebra-lock.h | 37 ++++++ index/attribute.c | 11 +- index/locksrv.c | 15 ++- index/rank1.c | 9 +- index/retrieve.c | 16 ++- index/trunc.c | 33 +++--- index/zebraapi.c | 108 ++++++++++------- index/zebraapi.h | 27 +++-- index/zrpn.c | 104 ++++++++-------- index/zserver.c | 323 ++++++++++++++++++++++++++++++++++++++++++++++++-- index/zserver.h | 73 +++++++----- index/zsets.c | 24 ++-- util/Makefile.in | 4 +- util/zebra-lock.c | 102 ++++++++++++++++ 20 files changed, 910 insertions(+), 249 deletions(-) create mode 100644 include/zebra-lock.h create mode 100644 util/zebra-lock.c diff --git a/bfile/bfile.c b/bfile/bfile.c index d328d48..ce6972d 100644 --- a/bfile/bfile.c +++ b/bfile/bfile.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: bfile.c,v $ - * Revision 1.31 1999-12-08 15:03:11 adam + * 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 * Implemented bf_reset. * * Revision 1.30 1999/10/14 14:33:49 adam @@ -189,6 +192,7 @@ void bf_cache (BFiles bfs, const char *spec) int bf_close (BFile bf) { + zebra_lock_rdwr_destroy (&bf->rdwr_lock); if (bf->cf) cf_close (bf->cf); mf_close (bf->mf); @@ -233,6 +237,7 @@ BFile bf_open (BFiles bfs, const char *name, int block_size, int wflag) xfree (tmp); return 0; } + zebra_lock_rdwr_init (&tmp->rdwr_lock); return(tmp); } @@ -240,16 +245,28 @@ int bf_read (BFile bf, int no, int offset, int nbytes, void *buf) { int r; - if (bf->cf && (r=cf_read (bf->cf, no, offset, nbytes, buf)) != -1) - return r; - return mf_read (bf->mf, no, offset, nbytes, buf); + zebra_lock_rdwr_rlock (&bf->rdwr_lock); + if (bf->cf) + { + if ((r = cf_read (bf->cf, no, offset, nbytes, buf)) == -1) + r = mf_read (bf->mf, no, offset, nbytes, buf); + } + else + r = mf_read (bf->mf, no, offset, nbytes, buf); + zebra_lock_rdwr_runlock (&bf->rdwr_lock); + return r; } int bf_write (BFile bf, int no, int offset, int nbytes, const void *buf) { + int r; + zebra_lock_rdwr_wlock (&bf->rdwr_lock); if (bf->cf) - return cf_write (bf->cf, no, offset, nbytes, buf); - return mf_write (bf->mf, no, offset, nbytes, buf); + r = cf_write (bf->cf, no, offset, nbytes, buf); + else + r = mf_write (bf->mf, no, offset, nbytes, buf); + zebra_lock_rdwr_wunlock (&bf->rdwr_lock); + return r; } int bf_commitExists (BFiles bfs) diff --git a/bfile/mfile.c b/bfile/mfile.c index 31bc486..684d6b0 100644 --- a/bfile/mfile.c +++ b/bfile/mfile.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: mfile.c,v $ - * Revision 1.36 1999-12-08 15:03:11 adam + * Revision 1.37 2000-03-15 15:00:30 adam + * First work on threaded version. + * + * Revision 1.36 1999/12/08 15:03:11 adam * Implemented bf_reset. * * Revision 1.35 1999/10/14 14:33:50 adam @@ -137,6 +140,7 @@ #include #include +#include #include #include @@ -153,7 +157,8 @@ static int scan_areadef(MFile_area ma, const char *name, const char *ad) for (;;) { const char *ad0 = ad; - int i = 0, fact = 1, multi, size = 0; + int i = 0, fact = 1, multi; + off_t size = 0; while (*ad == ' ' || *ad == '\t') ad++; @@ -198,9 +203,10 @@ static int scan_areadef(MFile_area ma, const char *name, const char *ad) size = size*10 + (*ad++ - '0'); switch (*ad) { - case 'B': case 'b': multi = 1; break; - case 'K': case 'k': multi = 1024; break; - case 'M': case 'm': multi = 1048576; break; + case 'B': case 'b': multi = 1; break; + case 'K': case 'k': multi = 1024; break; + case 'M': case 'm': multi = 1048576; break; + case 'G': case 'g': multi = 1073741824; break; case '\0': logf (LOG_FATAL, "Missing unit: %s", ad0); return -1; @@ -381,6 +387,7 @@ void mf_destroy(MFile_area ma) { xfree (m->files[i].path); } + zebra_mutex_destroy (&meta_f->mutex); meta_f = meta_f->next; xfree (m); } @@ -438,8 +445,10 @@ MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag) mnew = (meta_file *) xmalloc(sizeof(*mnew)); strcpy(mnew->name, name); /* allocate one, empty file */ + zebra_mutex_init (&mnew->mutex); mnew->no_files = 1; - mnew->files[0].bytes = mnew->files[0].blocks = 0; + mnew->files[0].bytes = 0; + mnew->files[0].blocks = 0; mnew->files[0].top = -1; mnew->files[0].number = 0; mnew->files[0].fd = -1; @@ -514,6 +523,7 @@ int mf_read(MFile mf, int no, int offset, int nbytes, void *buf) { int rd, toread; + zebra_mutex_lock (&mf->mutex); if ((rd = file_position(mf, no, offset)) < 0) { if (rd == -2) @@ -528,7 +538,8 @@ int mf_read(MFile mf, int no, int offset, int nbytes, void *buf) mf->files[mf->cur_file].path); exit(1); } - else if (rd < toread) + zebra_mutex_unlock (&mf->mutex); + if (rd < toread) return 0; else return 1; @@ -544,6 +555,7 @@ int mf_write(MFile mf, int no, int offset, int nbytes, const void *buf) char tmp[FILENAME_MAX+1]; unsigned char dummych = '\xff'; + zebra_mutex_lock (&mf->mutex); if ((ps = file_position(mf, no, offset)) < 0) exit(1); /* file needs to grow */ @@ -620,6 +632,7 @@ int mf_write(MFile mf, int no, int offset, int nbytes, const void *buf) mf->name, mf->cur_file); exit(1); } + zebra_mutex_unlock (&mf->mutex); return 0; } diff --git a/configure b/configure index b9e6688..d92e3db 100755 --- a/configure +++ b/configure @@ -16,6 +16,8 @@ ac_help="$ac_help ac_help="$ac_help --with-yazconfig=DIR yaz-config in DIR (example /home/yaz-1.5)" ac_help="$ac_help + --disable-threads disable threads" +ac_help="$ac_help --with-tclconfig=DIR tclConfig.sh in DIR" # Initialize some variables set by options. @@ -539,7 +541,7 @@ fi # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:543: checking for $ac_word" >&5 +echo "configure:545: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -569,7 +571,7 @@ if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:573: checking for $ac_word" >&5 +echo "configure:575: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -620,7 +622,7 @@ fi # Extract the first word of "cl", so it can be a program name with args. set dummy cl; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:624: checking for $ac_word" >&5 +echo "configure:626: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -652,7 +654,7 @@ fi fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:656: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 +echo "configure:658: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. @@ -663,12 +665,12 @@ cross_compiling=$ac_cv_prog_cc_cross cat > conftest.$ac_ext << EOF -#line 667 "configure" +#line 669 "configure" #include "confdefs.h" main(){return(0);} EOF -if { (eval echo configure:672: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:674: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then ac_cv_prog_cc_works=yes # If we can't run a trivial program, we are probably using a cross compiler. if (./conftest; exit) 2>/dev/null; then @@ -694,12 +696,12 @@ if test $ac_cv_prog_cc_works = no; then { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:698: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 +echo "configure:700: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 cross_compiling=$ac_cv_prog_cc_cross echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -echo "configure:703: checking whether we are using GNU C" >&5 +echo "configure:705: checking whether we are using GNU C" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -708,7 +710,7 @@ else yes; #endif EOF -if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:712: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then +if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:714: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then ac_cv_prog_gcc=yes else ac_cv_prog_gcc=no @@ -727,7 +729,7 @@ ac_test_CFLAGS="${CFLAGS+set}" ac_save_CFLAGS="$CFLAGS" CFLAGS= echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 -echo "configure:731: checking whether ${CC-cc} accepts -g" >&5 +echo "configure:733: checking whether ${CC-cc} accepts -g" >&5 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -759,7 +761,7 @@ else fi echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:763: checking how to run the C preprocessor" >&5 +echo "configure:765: checking how to run the C preprocessor" >&5 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= @@ -774,13 +776,13 @@ else # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:784: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:786: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -791,13 +793,13 @@ else rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:801: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:803: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -808,13 +810,13 @@ else rm -rf conftest* CPP="${CC-cc} -nologo -E" cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:818: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:820: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -869,7 +871,7 @@ ac_configure=$ac_aux_dir/configure # This should be Cygnus configure. # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # ./install, which can be erroneously created by make from ./install.sh. echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6 -echo "configure:873: checking for a BSD compatible install" >&5 +echo "configure:875: checking for a BSD compatible install" >&5 if test -z "$INSTALL"; then if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -924,7 +926,7 @@ test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' # Extract the first word of "ranlib", so it can be a program name with args. set dummy ranlib; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:928: checking for $ac_word" >&5 +echo "configure:930: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -988,7 +990,7 @@ else # Extract the first word of "yaz-config", so it can be a program name with args. set dummy yaz-config; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:992: checking for $ac_word" >&5 +echo "configure:994: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_path_yazconfig'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1024,13 +1026,103 @@ fi fi fi echo $ac_n "checking for YAZ""... $ac_c" 1>&6 -echo "configure:1028: checking for YAZ" >&5 +echo "configure:1030: checking for YAZ" >&5 if test -r $yazconfig; then . $yazconfig echo "$ac_t""$yazconfig" 1>&6 else echo "$ac_t""Not found" 1>&6 fi +# Check whether --enable-threads or --disable-threads was given. +if test "${enable_threads+set}" = set; then + enableval="$enable_threads" + enable_threads=$enableval +else + enable_threads=yes +fi + +if test "$enable_threads" = "yes"; then + echo $ac_n "checking for main in -lpthread""... $ac_c" 1>&6 +echo "configure:1047: checking for main in -lpthread" >&5 +ac_lib_var=`echo pthread'_'main | sed 'y%./+-%__p_%'` +if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + ac_save_LIBS="$LIBS" +LIBS="-lpthread $LIBS" +cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=yes" +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=no" +fi +rm -f conftest* +LIBS="$ac_save_LIBS" + +fi +if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then + echo "$ac_t""yes" 1>&6 + ac_tr_lib=HAVE_LIB`echo pthread | sed -e 's/[^a-zA-Z0-9_]/_/g' \ + -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` + cat >> confdefs.h <&6 +fi + + echo $ac_n "checking for working POSIX Threads""... $ac_c" 1>&6 +echo "configure:1090: checking for working POSIX Threads" >&5 + cat > conftest.$ac_ext < + int func(void *p) { return 0; } + +int main() { + + pthread_t pthread_id; + int r = pthread_create (&pthread_id, 0, func, 0); +; return 0; } +EOF +if { (eval echo configure:1103: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then + rm -rf conftest* + thread_ok=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + thread_ok=no +fi +rm -f conftest* + if test "$thread_ok" = "yes"; then + echo "$ac_t""yes" 1>&6 + cat >> confdefs.h <<\EOF +#define HAVE_PTHREAD_H 1 +EOF + + cat >> confdefs.h <<\EOF +#define _REENTRANT 1 +EOF + + else + echo "$ac_t""no" 1>&6 + fi +fi TCL_LIB="" TCL_INCLUDE="" tclconfig=NONE @@ -1047,7 +1139,7 @@ echo $ac_n "checking for prefix by $ac_c" 1>&6 # Extract the first word of "tclsh", so it can be a program name with args. set dummy tclsh; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:1051: checking for $ac_word" >&5 +echo "configure:1143: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_path_TCLSH'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1088,7 +1180,7 @@ fi prefix=${saveprefix} fi echo $ac_n "checking for Tcl""... $ac_c" 1>&6 -echo "configure:1092: checking for Tcl" >&5 +echo "configure:1184: checking for Tcl" >&5 if test -r ${tclconfig}/tclConfig.sh; then . ${tclconfig}/tclConfig.sh if test -r ${tclconfig}/../generic/tcl.h; then @@ -1112,17 +1204,17 @@ for ac_hdr in sys/times.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1116: checking for $ac_hdr" >&5 +echo "configure:1208: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1126: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1218: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -1149,7 +1241,7 @@ fi done echo $ac_n "checking for bzCompressInit in -lbz2""... $ac_c" 1>&6 -echo "configure:1153: checking for bzCompressInit in -lbz2" >&5 +echo "configure:1245: checking for bzCompressInit in -lbz2" >&5 ac_lib_var=`echo bz2'_'bzCompressInit | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1157,7 +1249,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lbz2 $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1264: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1200,17 +1292,17 @@ if test "$ac_cv_lib_bz2_bzCompressInit" = "yes"; then do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1204: checking for $ac_hdr" >&5 +echo "configure:1296: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1214: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1306: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -1238,12 +1330,12 @@ done fi echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 -echo "configure:1242: checking for ANSI C header files" >&5 +echo "configure:1334: checking for ANSI C header files" >&5 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include @@ -1251,7 +1343,7 @@ else #include EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1255: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1347: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -1268,7 +1360,7 @@ rm -f conftest* if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -1286,7 +1378,7 @@ fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -1307,7 +1399,7 @@ if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext < #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') @@ -1318,7 +1410,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); exit (0); } EOF -if { (eval echo configure:1322: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1414: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then : else diff --git a/configure.in b/configure.in index 7d7d074..e08d6b1 100644 --- a/configure.in +++ b/configure.in @@ -1,5 +1,5 @@ dnl Zebra, Index Data Aps, 1994-1999 -dnl $Id: configure.in,v 1.16 2000-03-01 10:02:04 adam Exp $ +dnl $Id: configure.in,v 1.17 2000-03-15 15:00:30 adam Exp $ dnl See the file LICENSE.2 for details. dnl AC_INIT(include/zebraver.h) @@ -60,6 +60,26 @@ else AC_MSG_RESULT(Not found) fi dnl +dnl ------ Threads +AC_ARG_ENABLE(threads, [ --disable-threads disable threads],[enable_threads=$enableval],[enable_threads=yes]) +if test "$enable_threads" = "yes"; then + AC_CHECK_LIB(pthread,main) + AC_MSG_CHECKING(for working POSIX Threads) + AC_TRY_LINK([#include + int func(void *p) { return 0; } + ],[ + pthread_t pthread_id; + int r = pthread_create (&pthread_id, 0, func, 0);], + thread_ok=yes,thread_ok=no) + if test "$thread_ok" = "yes"; then + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_PTHREAD_H) + AC_DEFINE(_REENTRANT) + else + AC_MSG_RESULT(no) + fi +fi +dnl dnl ------ Look for Tcl dnl See if user has specified location of tclConfig.sh; otherwise dnl see if tclConfig.sh exists in same prefix lcoation as tclsh; otherwise diff --git a/include/bfile.h b/include/bfile.h index 66b935e..d3c9380 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.18 1999-12-08 15:03:11 adam Exp $ + * $Id: bfile.h,v 1.19 2000-03-15 15:00:30 adam Exp $ */ #ifndef BFILE_H @@ -25,6 +25,7 @@ void bfs_destroy (BFiles bfiles); typedef struct BFile_struct { MFile mf; + Zebra_lock_rdwr rdwr_lock; struct CFile_struct *cf; } *BFile, BFile_struct; diff --git a/include/mfile.h b/include/mfile.h index c4a67e8..dc62499 100644 --- a/include/mfile.h +++ b/include/mfile.h @@ -3,22 +3,23 @@ * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * - * $Id: mfile.h,v 1.12 1999-12-08 15:03:11 adam Exp $ + * $Id: mfile.h,v 1.13 2000-03-15 15:00:30 adam Exp $ */ #ifndef MFILE_H #define MFILE_H #include +#include #ifndef FILENAME_MAX #include #define FILENAME_MAX MAXPATHLEN #endif -#ifdef __cplusplus -extern "C" { -#endif +#include + +YAZ_BEGIN_CDECL #define MF_MIN_BLOCKS_CREAT 1 /* minimum free blocks in new dir */ #define MF_MAX_PARTS 28 /* max # of part-files per metafile */ @@ -28,8 +29,8 @@ extern "C" { typedef struct mf_dir { char name[FILENAME_MAX+1]; - int max_bytes; /* allocated bytes in this dir. */ - int avail_bytes; /* bytes left */ + off_t max_bytes; /* allocated bytes in this dir. */ + off_t avail_bytes; /* bytes left */ struct mf_dir *next; } mf_dir; @@ -38,7 +39,7 @@ typedef struct part_file int number; int top; int blocks; - int bytes; + off_t bytes; mf_dir *dir; char *path; int fd; @@ -58,6 +59,7 @@ typedef struct meta_file int min_bytes_creat; /* minimum bytes required to enter directory */ MFile_area ma; int wr; + Zebra_mutex mutex; struct meta_file *next; } *MFile, meta_file; @@ -68,6 +70,7 @@ typedef struct MFile_area_struct mf_dir *dirs; struct meta_file *mfiles; struct MFile_area_struct *next; /* global list of active areas */ + Zebra_mutex mutex; } MFile_area_struct; /* @@ -115,8 +118,7 @@ void mf_reset(MFile_area ma); * Unlink the file by name, rather than MFile-handle. */ int mf_unlink_name(MFile_area, const char *name); -#ifdef __cplusplus -} -#endif + +YAZ_END_CDECL #endif diff --git a/include/zebra-lock.h b/include/zebra-lock.h new file mode 100644 index 0000000..b7d6164 --- /dev/null +++ b/include/zebra-lock.h @@ -0,0 +1,37 @@ + +#ifndef ZEBRA_LOCK_H +#define ZEBRA_LOCK_H + +#if HAVE_PTHREAD_H +#include +#endif + +#include + +YAZ_BEGIN_CDECL + +typedef struct { + pthread_mutex_t mutex; +} Zebra_mutex; + +YAZ_EXPORT int zebra_mutex_init (Zebra_mutex *p); +YAZ_EXPORT int zebra_mutex_destroy (Zebra_mutex *p); +YAZ_EXPORT int zebra_mutex_lock (Zebra_mutex *p); +YAZ_EXPORT int zebra_mutex_unlock (Zebra_mutex *p); + +typedef struct { + int readers_reading; + int writers_writing; + pthread_mutex_t mutex; + pthread_cond_t lock_free; +} Zebra_lock_rdwr; + +YAZ_EXPORT int zebra_lock_rdwr_init (Zebra_lock_rdwr *p); +YAZ_EXPORT int zebra_lock_rdwr_destroy (Zebra_lock_rdwr *p); +YAZ_EXPORT int zebra_lock_rdwr_rlock (Zebra_lock_rdwr *p); +YAZ_EXPORT int zebra_lock_rdwr_wlock (Zebra_lock_rdwr *p); +YAZ_EXPORT int zebra_lock_rdwr_runlock (Zebra_lock_rdwr *p); +YAZ_EXPORT int zebra_lock_rdwr_wunlock (Zebra_lock_rdwr *p); + +YAZ_END_CDECL +#endif diff --git a/index/attribute.c b/index/attribute.c index d01230e..e3aedba 100644 --- a/index/attribute.c +++ b/index/attribute.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: attribute.c,v $ - * Revision 1.11 1999-11-30 13:48:03 adam + * 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 * Improved installation. Updated for inclusion of YAZ header files. * * Revision 1.10 1999/02/02 14:50:49 adam @@ -71,10 +74,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->dh, set))) + if (!(p = data1_attset_search_id (zi->service->dh, set))) { - zebraExplain_loadAttsets (zi->dh, zi->res); - p = data1_attset_search_id (zi->dh, set); + zebraExplain_loadAttsets (zi->service->dh, zi->service->res); + p = data1_attset_search_id (zi->service->dh, set); } if (!p) return -2; diff --git a/index/locksrv.c b/index/locksrv.c index 22ea3b5..10cf881 100644 --- a/index/locksrv.c +++ b/index/locksrv.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: locksrv.c,v $ - * Revision 1.13 1999-05-26 07:49:13 adam + * Revision 1.14 2000-03-15 15:00:30 adam + * First work on threaded version. + * + * Revision 1.13 1999/05/26 07:49:13 adam * C++ compilation. * * Revision 1.12 1999/02/02 14:50:58 adam @@ -64,7 +67,7 @@ #include "zserver.h" -int zebra_server_lock_init (ZebraHandle zi) +int zebra_server_lock_init (ZebraService zi) { char path_prefix[1024]; @@ -80,7 +83,7 @@ int zebra_server_lock_init (ZebraHandle zi) return 0; } -int zebra_server_lock_destroy (ZebraHandle zi) +int zebra_server_lock_destroy (ZebraService zi) { xfree (zi->server_path_prefix); zebra_lock_destroy (zi->server_lock_cmt); @@ -89,7 +92,7 @@ int zebra_server_lock_destroy (ZebraHandle zi) return 0; } -int zebra_server_lock (ZebraHandle zi, int commitPhase) +int zebra_server_lock (ZebraService zi, int commitPhase) { if (!zi->server_lock_cmt) { @@ -125,7 +128,7 @@ int zebra_server_lock (ZebraHandle zi, int commitPhase) return 0; } -void zebra_server_unlock (ZebraHandle zi, int commitPhase) +void zebra_server_unlock (ZebraService zi, int commitPhase) { if (zi->server_lock_org == NULL) return; @@ -141,7 +144,7 @@ void zebra_server_unlock (ZebraHandle zi, int commitPhase) } } -int zebra_server_lock_get_state (ZebraHandle zi, time_t *timep) +int zebra_server_lock_get_state (ZebraService zi, time_t *timep) { char path[1024]; char buf[256]; diff --git a/index/rank1.c b/index/rank1.c index 84d4159..d947684 100644 --- a/index/rank1.c +++ b/index/rank1.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: rank1.c,v $ - * Revision 1.5 1999-05-26 07:49:13 adam + * Revision 1.6 2000-03-15 15:00:30 adam + * First work on threaded version. + * + * Revision 1.5 1999/05/26 07:49:13 adam * C++ compilation. * * Revision 1.4 1999/02/02 14:51:01 adam @@ -62,7 +65,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 (ZebraHandle zh) +static void *create (ZebraService zh) { struct rank_class_info *ci = (struct rank_class_info *) xmalloc (sizeof(*ci)); @@ -76,7 +79,7 @@ static void *create (ZebraHandle 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 (ZebraHandle zh, void *class_handle) +static void destroy (ZebraService zh, void *class_handle) { struct rank_class_info *ci = (struct rank_class_info *) class_handle; diff --git a/index/retrieve.c b/index/retrieve.c index 1600665..34f0dc0 100644 --- a/index/retrieve.c +++ b/index/retrieve.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: retrieve.c,v $ - * Revision 1.11 1999-10-29 10:00:00 adam + * Revision 1.12 2000-03-15 15:00:30 adam + * First work on threaded version. + * + * Revision 1.11 1999/10/29 10:00:00 adam * Fixed minor bug where database name wasn't set in zebra_record_fetch. * * Revision 1.10 1999/05/26 07:49:13 adam @@ -126,14 +129,14 @@ int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream, RecordAttr *recordAttr; void *clientData; - rec = rec_get (zh->records, sysno); + rec = rec_get (zh->service->records, sysno); if (!rec) { logf (LOG_DEBUG, "rec_get fail on sysno=%d", sysno); *basenamep = 0; return 14; } - recordAttr = rec_init_attr (zh->zei, rec); + recordAttr = rec_init_attr (zh->service->zei, rec); file_type = rec->info[recInfo_fileType]; fname = rec->info[recInfo_filename]; @@ -141,7 +144,8 @@ int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream, *basenamep = (char *) odr_malloc (stream, strlen(basename)+1); strcpy (*basenamep, basename); - if (!(rt = recType_byName (zh->recTypes, file_type, subType, &clientData))) + if (!(rt = recType_byName (zh->service->recTypes, + file_type, subType, &clientData))) { logf (LOG_WARN, "Retrieve: Cannot handle type %s", file_type); return 14; @@ -249,8 +253,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->dh; - retrieveCtrl.res = zh->res; + retrieveCtrl.dh = zh->service->dh; + retrieveCtrl.res = zh->service->res; (*rt->retrieve)(clientData, &retrieveCtrl); *output_format = retrieveCtrl.output_format; *rec_bufp = (char *) retrieveCtrl.rec_buf; diff --git a/index/trunc.c b/index/trunc.c index 3063cd2..d446cf4 100644 --- a/index/trunc.c +++ b/index/trunc.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: trunc.c,v $ - * Revision 1.16 1999-11-30 13:48:03 adam + * Revision 1.17 2000-03-15 15:00:30 adam + * First work on threaded version. + * + * Revision 1.16 1999/11/30 13:48:03 adam * Improved installation. Updated for inclusion of YAZ header files. * * Revision 1.15 1999/07/20 13:59:18 adam @@ -181,7 +184,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, rset_temp_parms parms; parms.key_size = sizeof(struct it_key); - parms.temp_path = res_get (zi->res, "setTmpDir"); + parms.temp_path = res_get (zi->service->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); @@ -249,7 +252,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, heap_close (ti); } #if ZMBOL - else if (zi->isam) + else if (zi->service->isam) { ISPT *ispt; int i; @@ -261,7 +264,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->isam, isam_p[from+i]); + ispt[i] = is_position (zi->service->isam, isam_p[from+i]); if (is_readkey (ispt[i], ti->tmpbuf)) heap_insert (ti, ti->tmpbuf, i); else @@ -301,7 +304,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, heap_close (ti); xfree (ispt); } - else if (zi->isamc) + else if (zi->service->isamc) { ISAMC_PP *ispt; int i; @@ -313,7 +316,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->isamc, isam_p[from+i]); + ispt[i] = isc_pp_open (zi->service->isamc, isam_p[from+i]); if (isc_pp_read (ispt[i], ti->tmpbuf)) heap_insert (ti, ti->tmpbuf, i); else @@ -354,7 +357,7 @@ static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length, xfree (ispt); } #endif - else if (zi->isams) + else if (zi->service->isams) { ISAMS_PP *ispt; int i; @@ -366,7 +369,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->isams, isam_p[from+i]); + ispt[i] = isams_pp_open (zi->service->isams, isam_p[from+i]); if (isams_pp_read (ispt[i], ti->tmpbuf)) heap_insert (ti, ti->tmpbuf, i); else @@ -444,41 +447,41 @@ 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->isams) + if (zi->service->isams) { if (no == 1) { rset_isams_parms parms; parms.pos = *isam_p; - parms.is = zi->isams; + parms.is = zi->service->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->isam) + else if (zi->service->isam) { if (no == 1) { rset_isam_parms parms; parms.pos = *isam_p; - parms.is = zi->isam; + parms.is = zi->service->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->isamc) + else if (zi->service->isamc) { if (no == 1) { rset_isamc_parms parms; parms.pos = *isam_p; - parms.is = zi->isamc; + parms.is = zi->service->isamc; parms.rset_term = rset_term_create (term, length, flags); return rset_create (rset_kind_isamc, &parms); } @@ -489,7 +492,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->isamc; + parms.isc = zi->service->isamc; 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 fa596e4..1bb461b 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zebraapi.c,v $ - * Revision 1.27 2000-02-24 12:31:17 adam + * Revision 1.28 2000-03-15 15:00:30 adam + * First work on threaded version. + * + * Revision 1.27 2000/02/24 12:31:17 adam * Added zebra_string_norm. * * Revision 1.26 1999/11/30 13:48:03 adam @@ -108,7 +111,7 @@ #include #include "zserver.h" -static void zebra_chdir (ZebraHandle zh) +static void zebra_chdir (ZebraService zh) { const char *dir = res_get (zh->res, "chdir"); if (!dir) @@ -121,15 +124,15 @@ static void zebra_chdir (ZebraHandle zh) #endif } -static void zebra_register_unlock (ZebraHandle zh); +static void zebra_register_unlock (ZebraService zh); -static int zebra_register_lock (ZebraHandle zh) +static int zebra_register_lock (ZebraService zh) { time_t lastChange; int state; + int errCode = 0; - zh->errCode = 0; - zh->errString = 0; + errCode = 0; zebra_chdir (zh); @@ -192,19 +195,19 @@ static int zebra_register_lock (ZebraHandle zh) if (!(zh->records = rec_open (zh->bfs, 0, 0))) { logf (LOG_WARN, "rec_open"); - zh->errCode = 2; + errCode = 2; } else { if (!(zh->dict = dict_open (zh->bfs, FNAME_DICT, 40, 0, 0))) { logf (LOG_WARN, "dict_open"); - zh->errCode = 2; + errCode = 2; } if (!(zh->sortIdx = sortIdx_open (zh->bfs, 0))) { logf (LOG_WARN, "sortIdx_open"); - zh->errCode = 2; + errCode = 2; } if (res_get_match (zh->res, "isam", "s", ISAM_DEFAULT)) { @@ -213,7 +216,7 @@ static int zebra_register_lock (ZebraHandle zh) key_isams_m(zh->res, &isams_m)))) { logf (LOG_WARN, "isams_open"); - zh->errCode = 2; + errCode = 2; } } #if ZMBOL @@ -223,7 +226,7 @@ static int zebra_register_lock (ZebraHandle zh) sizeof (struct it_key), zh->res))) { logf (LOG_WARN, "is_open"); - zh->errCode = 2; + errCode = 2; } } else if (res_get_match (zh->res, "isam", "c", ISAM_DEFAULT)) @@ -233,27 +236,28 @@ static int zebra_register_lock (ZebraHandle zh) 0, key_isamc_m(zh->res, &isamc_m)))) { logf (LOG_WARN, "isc_open"); - zh->errCode = 2; + errCode = 2; } } #endif - zh->zei = zebraExplain_open (zh->records, zh->dh, zh->res, 0, 0, 0); + zh->zei = zebraExplain_open (zh->records, zh->dh, + zh->res, 0, 0, 0); if (!zh->zei) { logf (LOG_WARN, "Cannot obtain EXPLAIN information"); - zh->errCode = 2; + errCode = 2; } } - if (zh->errCode) + if (errCode) { zebra_register_unlock (zh); zh->registerState = -1; return -1; } - return 0; + return errCode; } -static void zebra_register_unlock (ZebraHandle zh) +static void zebra_register_unlock (ZebraService zh) { static int waitSec = -1; @@ -280,11 +284,24 @@ static void zebra_register_unlock (ZebraHandle zh) zebra_server_unlock (zh, zh->registerState); } -ZebraHandle zebra_open (const char *configName) +ZebraHandle zebra_open (ZebraService service) { ZebraHandle zh; zh = (ZebraHandle) xmalloc (sizeof(*zh)); + + zh->service = service; + zh->sets = 0; + + return zh; +} + +ZebraService zebra_start (const char *configName) +{ + ZebraService zh = xmalloc (sizeof(*zh)); + zh->configName = xstrdup(configName); + zh->sessions = 0; + yaz_log (LOG_LOG, "zebra_start %s", configName); if (!(zh->res = res_open (configName))) { logf (LOG_WARN, "Failed to read resources `%s'", configName); @@ -309,7 +326,6 @@ ZebraHandle zebra_open (const char *configName) } bf_lockDir (zh->bfs, res_get (zh->res, "lockDir")); data1_set_tabpath (zh->dh, res_get(zh->res, "profilePath")); - zh->sets = NULL; zh->registerState = -1; /* trigger open of registers! */ zh->registerChange = 0; zh->recTypes = recTypes_init (zh->dh); @@ -318,8 +334,6 @@ ZebraHandle zebra_open (const char *configName) zh->records = NULL; zh->zebra_maps = zebra_maps_open (zh->res); zh->rank_classes = NULL; - zh->errCode = 0; - zh->errString = 0; zebraRankInstall (zh, rank1_class); @@ -336,14 +350,17 @@ ZebraHandle zebra_open (const char *configName) return zh; } -void zebra_close (ZebraHandle zh) +void zebra_stop(ZebraService zh) { if (!zh) - return; + return ; + yaz_log (LOG_LOG, "zebra_stop"); + + /* wait for sessions to die ...... */ + zebra_chdir (zh); if (zh->records) { - resultSetDestroy (zh, -1, 0, 0); zebraExplain_close (zh->zei, 0, 0); dict_close (zh->dict); sortIdx_close (zh->sortIdx); @@ -368,6 +385,17 @@ void zebra_close (ZebraHandle zh) if (zh->passwd_db) passwd_db_close (zh->passwd_db); res_close (zh->res); + + xfree (zh->configName); + xfree (zh); +} + +void zebra_close (ZebraHandle zh) +{ + if (!zh) + return ; + resultSetDestroy (zh, -1, 0, 0); + xfree (zh); } @@ -425,7 +453,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->res, "mapdb", &info, map_basenames_func); + res_trav (zh->service->res, "mapdb", &info, map_basenames_func); for (i = 0; inum_bases; i++) if (p->basenames[i] && p->new_num_bases < p->new_num_max) @@ -444,12 +472,12 @@ void zebra_search_rpn (ZebraHandle zh, ODR stream, ODR decode, const char *setname) { zh->hits = 0; - if (zebra_register_lock (zh)) + if (zebra_register_lock (zh->service)) return; map_basenames (zh, stream, &num_bases, &basenames); resultSetAddRPN (zh, stream, decode, query, num_bases, basenames, setname); - zebra_register_unlock (zh); + zebra_register_unlock (zh->service); } void zebra_records_retrieve (ZebraHandle zh, ODR stream, @@ -460,7 +488,7 @@ void zebra_records_retrieve (ZebraHandle zh, ODR stream, ZebraPosSet poset; int i, *pos_array; - if (zebra_register_lock (zh)) + if (zebra_register_lock (zh->service)) return; pos_array = (int *) xmalloc (num_recs * sizeof(*pos_array)); for (i = 0; iservice); xfree (pos_array); } @@ -508,7 +536,7 @@ void zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, int *position, int *num_entries, ZebraScanEntry **entries, int *is_partial) { - if (zebra_register_lock (zh)) + if (zebra_register_lock (zh->service)) { *entries = 0; *num_entries = 0; @@ -518,7 +546,7 @@ void zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, rpn_scan (zh, stream, zapt, attributeset, num_bases, basenames, position, num_entries, entries, is_partial); - zebra_register_unlock (zh); + zebra_register_unlock (zh->service); } void zebra_sort (ZebraHandle zh, ODR stream, @@ -526,11 +554,11 @@ void zebra_sort (ZebraHandle zh, ODR stream, const char *output_setname, Z_SortKeySpecList *sort_sequence, int *sort_status) { - if (zebra_register_lock (zh)) + if (zebra_register_lock (zh->service)) return; resultSetSort (zh, stream->mem, num_input_setnames, input_setnames, output_setname, sort_sequence, sort_status); - zebra_register_unlock (zh); + zebra_register_unlock (zh->service); } int zebra_deleleResultSet(ZebraHandle zh, int function, @@ -538,7 +566,7 @@ int zebra_deleleResultSet(ZebraHandle zh, int function, int *statuses) { int i, status; - if (zebra_register_lock (zh)) + if (zebra_register_lock (zh->service)) return Z_DeleteStatus_systemProblemAtTarget; switch (function) { @@ -549,7 +577,7 @@ int zebra_deleleResultSet(ZebraHandle zh, int function, resultSetDestroy (zh, -1, 0, statuses); break; } - zebra_register_unlock (zh); + zebra_register_unlock (zh->service); status = Z_DeleteStatus_success; for (i = 0; ihits; } -int zebra_auth (ZebraHandle zh, const char *user, const char *pass) +int zebra_auth (ZebraService zh, const char *user, const char *pass) { if (!zh->passwd_db || !passwd_db_auth (zh->passwd_db, user, pass)) return 0; @@ -599,9 +627,9 @@ void zebra_setGroup (ZebraHandle zh, const char *group) } -void zebra_admin (ZebraHandle zh, const char *command) +void zebra_admin_create (ZebraHandle zh, const char *database) { - + } int zebra_string_norm (ZebraHandle zh, unsigned reg_id, @@ -609,9 +637,9 @@ int zebra_string_norm (ZebraHandle zh, unsigned reg_id, char *output_str, int output_len) { WRBUF wrbuf; - if (!zh->zebra_maps) + if (!zh->service->zebra_maps) return -1; - wrbuf = zebra_replace(zh->zebra_maps, reg_id, "", + wrbuf = zebra_replace(zh->service->zebra_maps, reg_id, "", input_str, input_len); if (!wrbuf) return -2; diff --git a/index/zebraapi.h b/index/zebraapi.h index b8ab5bf..d5168ac 100644 --- a/index/zebraapi.h +++ b/index/zebraapi.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zebraapi.h,v $ - * Revision 1.9 2000-02-24 12:31:17 adam + * Revision 1.10 2000-03-15 15:00:31 adam + * First work on threaded version. + * + * Revision 1.9 2000/02/24 12:31:17 adam * Added zebra_string_norm. * * Revision 1.8 1999/11/30 13:48:03 adam @@ -38,9 +41,7 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif +YAZ_BEGIN_CDECL /* Retrieval Record Descriptor */ typedef struct { @@ -59,10 +60,11 @@ typedef struct { char *term; /* scan term string */ } ZebraScanEntry; -typedef struct zebra_info *ZebraHandle; +typedef struct zebra_session *ZebraHandle; +typedef struct zebra_service *ZebraService; /* Open Zebra using file 'configName' (usually zebra.cfg) */ -YAZ_EXPORT ZebraHandle zebra_open (const char *configName); +YAZ_EXPORT ZebraHandle zebra_open (ZebraService zs); /* Search using RPN-Query */ YAZ_EXPORT void zebra_search_rpn (ZebraHandle zh, ODR input, ODR output, @@ -104,14 +106,17 @@ YAZ_EXPORT char *zebra_errAdd (ZebraHandle zh); YAZ_EXPORT int zebra_hits (ZebraHandle zh); /* do authentication */ -YAZ_EXPORT int zebra_auth (ZebraHandle zh, const char *user, const char *pass); +YAZ_EXPORT int zebra_auth (ZebraService zh, const char *user, const char *pass); /* Character normalisation on specific register . This routine is subject to change - do not use. */ YAZ_EXPORT int zebra_string_norm (ZebraHandle zh, unsigned reg_id, const char *input_str, int input_len, char *output_str, int output_len); - -#ifdef __cplusplus -} -#endif + +YAZ_EXPORT void zebra_admin_create (ZebraHandle zh, const char *db); + +YAZ_EXPORT ZebraService zebra_start (const char *configName); +YAZ_EXPORT void zebra_stop (ZebraService zs); + +YAZ_END_CDECL diff --git a/index/zrpn.c b/index/zrpn.c index 03e0f5e..4e1acd9 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zrpn.c,v $ - * Revision 1.101 2000-03-02 14:35:03 adam + * Revision 1.102 2000-03-15 15:00:31 adam + * First work on threaded version. + * + * Revision 1.101 2000/03/02 14:35:03 adam * Fixed proximity handling. * * Revision 1.100 1999/12/28 15:48:12 adam @@ -377,9 +380,9 @@ static const char **rpn_char_map_handler (void *vp, const char **from, int len) static void rpn_char_map_prepare (ZebraHandle zh, int reg_type, struct rpn_char_map_info *map_info) { - map_info->zm = zh->zebra_maps; + map_info->zm = zh->service->zebra_maps; map_info->reg_type = reg_type; - dict_grep_cmap (zh->dict, map_info, rpn_char_map_handler); + dict_grep_cmap (zh->service->dict, map_info, rpn_char_map_handler); } typedef struct { @@ -472,7 +475,8 @@ static void term_untrans (ZebraHandle zh, int reg_type, { while (*src) { - const char *cp = zebra_maps_output (zh->zebra_maps, reg_type, &src); + const char *cp = zebra_maps_output (zh->service->zebra_maps, + reg_type, &src); if (!cp) *dst++ = *src++; else @@ -932,7 +936,8 @@ static int string_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, switch (relation_value) { case 1: - if (!term_100 (zh->zebra_maps, reg_type, term_sub, term_component, + if (!term_100 (zh->service->zebra_maps, reg_type, + term_sub, term_component, space_split, term_dst)) return 0; logf (LOG_DEBUG, "Relation <"); @@ -961,7 +966,8 @@ static int string_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, *term_tmp = '\0'; break; case 2: - if (!term_100 (zh->zebra_maps, reg_type, term_sub, term_component, + if (!term_100 (zh->service->zebra_maps, reg_type, + term_sub, term_component, space_split, term_dst)) return 0; logf (LOG_DEBUG, "Relation <="); @@ -991,8 +997,8 @@ static int string_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, *term_tmp = '\0'; break; case 5: - if (!term_100 (zh->zebra_maps, reg_type, term_sub, term_component, - space_split, term_dst)) + if (!term_100 (zh->service->zebra_maps, reg_type, + term_sub, term_component, space_split, term_dst)) return 0; logf (LOG_DEBUG, "Relation >"); @@ -1023,8 +1029,8 @@ static int string_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, *term_tmp = '\0'; break; case 4: - if (!term_100 (zh->zebra_maps, reg_type, term_sub, term_component, - space_split, term_dst)) + if (!term_100 (zh->service->zebra_maps, reg_type, term_sub, + term_component, space_split, term_dst)) return 0; logf (LOG_DEBUG, "Relation >="); @@ -1060,8 +1066,8 @@ static int string_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, case 3: default: logf (LOG_DEBUG, "Relation ="); - if (!term_100 (zh->zebra_maps, reg_type, term_sub, term_component, - space_split, term_dst)) + if (!term_100 (zh->service->zebra_maps, reg_type, term_sub, + term_component, space_split, term_dst)) return 0; strcat (term_tmp, "("); strcat (term_tmp, term_component); @@ -1133,7 +1139,7 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, } return -1; } - if (zebraExplain_curDatabase (zh->zei, basenames[base_no])) + if (zebraExplain_curDatabase (zh->service->zei, basenames[base_no])) { zh->errCode = 109; /* Database unavailable */ zh->errString = basenames[base_no]; @@ -1146,7 +1152,7 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, char ord_buf[32]; int i, ord_len; - ord = zebraExplain_lookupSU (zh->zei, attp.attset_ordinal, + ord = zebraExplain_lookupSU (zh->service->zei, attp.attset_ordinal, local_attr->local); if (ord < 0) continue; @@ -1185,59 +1191,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->dict, term_dict, 0, grep_info, &max_pos, - 0, grep_handle); + r = dict_lookup_grep (zh->service->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->zebra_maps, reg_type, + if (!term_100 (zh->service->zebra_maps, reg_type, &termp, term_dict + j, space_split, term_dst)) return 0; strcat (term_dict, ".*)"); - dict_lookup_grep (zh->dict, term_dict, 0, grep_info, + dict_lookup_grep (zh->service->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->zebra_maps, reg_type, + if (!term_100 (zh->service->zebra_maps, reg_type, &termp, term_dict + j, space_split, term_dst)) return 0; strcat (term_dict, ")"); - dict_lookup_grep (zh->dict, term_dict, 0, grep_info, + dict_lookup_grep (zh->service->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->zebra_maps, reg_type, + if (!term_100 (zh->service->zebra_maps, reg_type, &termp, term_dict + j, space_split, term_dst)) return 0; strcat (term_dict, ".*)"); - dict_lookup_grep (zh->dict, term_dict, 0, grep_info, + dict_lookup_grep (zh->service->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->zebra_maps, reg_type, + if (!term_101 (zh->service->zebra_maps, reg_type, &termp, term_dict + j, space_split, term_dst)) return 0; strcat (term_dict, ")"); - r = dict_lookup_grep (zh->dict, term_dict, 0, grep_info, + r = dict_lookup_grep (zh->service->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->zebra_maps, reg_type, + if (!term_102 (zh->service->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->dict, term_dict, 0, grep_info, + r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info, &max_pos, 0, grep_handle); if (r) logf (LOG_WARN, "dict_lookup_grep err, trunc=regular: %d", @@ -1246,12 +1252,12 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, case 103: /* Regexp-2 */ r = 1; term_dict[j++] = '('; - if (!term_103 (zh->zebra_maps, reg_type, + if (!term_103 (zh->service->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->dict, term_dict, r, grep_info, + r = dict_lookup_grep (zh->service->dict, term_dict, r, grep_info, &max_pos, 2, grep_handle); if (r) logf (LOG_WARN, "dict_lookup_grep err, trunc=eregular: %d", @@ -1259,33 +1265,33 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, break; case 104: /* process # and ! in term */ term_dict[j++] = '('; - if (!term_104 (zh->zebra_maps, reg_type, + if (!term_104 (zh->service->zebra_maps, reg_type, &termp, term_dict + j, space_split, term_dst)) return 0; strcat (term_dict, ")"); - r = dict_lookup_grep (zh->dict, term_dict, 0, grep_info, + r = dict_lookup_grep (zh->service->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->zebra_maps, reg_type, + if (!term_105 (zh->service->zebra_maps, reg_type, &termp, term_dict + j, space_split, term_dst, 1)) return 0; strcat (term_dict, ")"); - r = dict_lookup_grep (zh->dict, term_dict, 0, grep_info, + r = dict_lookup_grep (zh->service->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->zebra_maps, reg_type, + if (!term_105 (zh->service->zebra_maps, reg_type, &termp, term_dict + j, space_split, term_dst, 0)) return 0; strcat (term_dict, ")"); - r = dict_lookup_grep (zh->dict, term_dict, 0, grep_info, + r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info, &max_pos, 0, grep_handle); if (r) logf (LOG_WARN, "dict_lookup_grep err, trunc=*/!: %d", r); @@ -1324,7 +1330,7 @@ static void trans_scan_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, while ((len = (cp_end - cp)) > 0) { - map = zebra_maps_input (zh->zebra_maps, reg_type, &cp, len); + map = zebra_maps_input (zh->service->zebra_maps, reg_type, &cp, len); if (**map == *CHR_SPACE) space_map = *map; else @@ -1411,7 +1417,7 @@ static RSET rpn_prox (ZebraHandle zh, RSET *rset, int rset_no, flags); parms.rset_term->nn = min_nn; parms.key_size = sizeof (struct it_key); - parms.temp_path = res_get (zh->res, "setTmpDir"); + parms.temp_path = res_get (zh->service->res, "setTmpDir"); result = rset_create (rset_kind_temp, &parms); rsfd_result = rset_open (result, RSETF_WRITE); @@ -1469,7 +1475,7 @@ static RSET rpn_prox (ZebraHandle zh, RSET *rset, int rset_no, flags); parms.rset_term->nn = min_nn; parms.key_size = sizeof (struct it_key); - parms.temp_path = res_get (zh->res, "setTmpDir"); + parms.temp_path = res_get (zh->service->res, "setTmpDir"); result = rset_create (rset_kind_temp, &parms); rsfd_result = rset_open (result, RSETF_WRITE); @@ -1593,7 +1599,7 @@ char *normalize_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, break; } if (ex_list) - wrbuf = zebra_replace(zh->zebra_maps, reg_id, ex_list, + wrbuf = zebra_replace(zh->service->zebra_maps, reg_id, ex_list, termz, strlen(termz)); if (!wrbuf) return nmem_strdup(stream, termz); @@ -1817,7 +1823,7 @@ static int numeric_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, logf (LOG_DEBUG, "numeric relation value=%d", relation_value); - if (!term_100 (zh->zebra_maps, reg_type, term_sub, term_tmp, 1, + if (!term_100 (zh->service->zebra_maps, reg_type, term_sub, term_tmp, 1, term_dst)) return 0; term_value = atoi (term_tmp); @@ -1845,7 +1851,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->dict, term_dict, 0, grep_info, max_pos, + r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info, max_pos, 0, grep_handle); if (r) logf (LOG_WARN, "dict_lookup_grep fail, rel=gt: %d", r); @@ -1893,7 +1899,7 @@ static int numeric_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, zh->errCode = 121; return -1; } - if (zebraExplain_curDatabase (zh->zei, basenames[base_no])) + if (zebraExplain_curDatabase (zh->service->zei, basenames[base_no])) { zh->errCode = 109; /* Database unavailable */ zh->errString = basenames[base_no]; @@ -1906,7 +1912,7 @@ static int numeric_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, char ord_buf[32]; int i, ord_len; - ord = zebraExplain_lookupSU (zh->zei, attp.attset_ordinal, + ord = zebraExplain_lookupSU (zh->service->zei, attp.attset_ordinal, local_attr->local); if (ord < 0) continue; @@ -2020,7 +2026,7 @@ static RSET rpn_search_APT_local (ZebraHandle zh, Z_AttributesPlusTerm *zapt, parms.rset_term = rset_term_create (termz, -1, rank_type); parms.key_size = sizeof (struct it_key); - parms.temp_path = res_get (zh->res, "setTmpDir"); + parms.temp_path = res_get (zh->service->res, "setTmpDir"); result = rset_create (rset_kind_temp, &parms); rsfd = rset_open (result, RSETF_WRITE); @@ -2145,7 +2151,7 @@ static RSET rpn_search_APT (ZebraHandle zh, Z_AttributesPlusTerm *zapt, int sort_flag; char termz[IT_MAX_WORD+1]; - zebra_maps_attr (zh->zebra_maps, zapt, ®_id, &search_type, + zebra_maps_attr (zh->service->zebra_maps, zapt, ®_id, &search_type, &rank_type, &complete_flag, &sort_flag); logf (LOG_DEBUG, "reg_id=%c", reg_id); @@ -2478,7 +2484,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->zebra_maps, zapt, ®_id, &search_type, + if (zebra_maps_attr (zh->service->zebra_maps, zapt, ®_id, &search_type, &rank_type, &complete_flag, &sort_flag)) { zh->errCode = 113; @@ -2504,7 +2510,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, *num_entries = 0; return; } - if (zebraExplain_curDatabase (zh->zei, basenames[base_no])) + if (zebraExplain_curDatabase (zh->service->zei, basenames[base_no])) { zh->errString = basenames[base_no]; zh->errCode = 109; /* Database unavailable */ @@ -2515,7 +2521,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, { int ord; - ord = zebraExplain_lookupSU (zh->zei, attp.attset_ordinal, + ord = zebraExplain_lookupSU (zh->service->zei, attp.attset_ordinal, local_attr->local); if (ord > 0) ords[ord_no++] = ord; @@ -2556,8 +2562,8 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, trans_scan_term (zh, zapt, termz+prefix_len, reg_id); - dict_scan (zh->dict, termz, &before_tmp, &after_tmp, scan_info, - scan_handle); + dict_scan (zh->service->dict, termz, &before_tmp, &after_tmp, + scan_info, scan_handle); } glist = (ZebraScanEntry *) odr_malloc (stream, (before+after)*sizeof(*glist)); diff --git a/index/zserver.c b/index/zserver.c index 3b060d5..9afe88a 100644 --- a/index/zserver.c +++ b/index/zserver.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zserver.c,v $ - * Revision 1.75 1999-11-30 13:48:04 adam + * Revision 1.76 2000-03-15 15:00:31 adam + * First work on threaded version. + * + * Revision 1.75 1999/11/30 13:48:04 adam * Improved installation. Updated for inclusion of YAZ header files. * * Revision 1.74 1999/11/29 15:13:26 adam @@ -276,6 +279,9 @@ #endif #include +#ifdef ASN_COMPILED +#include +#endif #include "zserver.h" @@ -288,6 +294,7 @@ 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); bend_initresult *bend_init (bend_initrequest *q) { @@ -302,6 +309,7 @@ bend_initresult *bend_init (bend_initrequest *q) r->errstring = 0; q->bend_sort = bend_sort; q->bend_delete = bend_delete; + q->bend_esrequest = bend_esrequest; q->implementation_name = "Z'mbol Information Server"; q->implementation_version = "Z'mbol 1.0"; @@ -309,7 +317,7 @@ bend_initresult *bend_init (bend_initrequest *q) logf (LOG_DEBUG, "bend_init"); sob = statserv_getcontrol (); - if (!(zh = zebra_open (sob->configname))) + if (!(zh = zebra_open (sob->handle))) { logf (LOG_FATAL, "Failed to open Zebra `%s'", sob->configname); r->errcode = 1; @@ -330,7 +338,7 @@ bend_initresult *bend_init (bend_initrequest *q) xfree (openpass); } } - if (zebra_auth (zh, user, passwd)) + if (zebra_auth (zh->service, user, passwd)) { r->errcode = 222; r->errstring = user; @@ -465,9 +473,292 @@ int bend_delete (void *handle, bend_delete_rr *rr) return 0; } -#ifndef WIN32 +static int es_admin_request (ZebraHandle zh, Z_AdminEsRequest *r) +{ + switch (r->toKeep->which) + { + case Z_ESAdminOriginPartToKeep_reIndex: + yaz_log(LOG_LOG, "adm-reindex"); + break; + case Z_ESAdminOriginPartToKeep_truncate: + yaz_log(LOG_LOG, "adm-truncate"); + break; + case Z_ESAdminOriginPartToKeep_delete: + yaz_log(LOG_LOG, "adm-delete"); + break; + case Z_ESAdminOriginPartToKeep_create: + yaz_log(LOG_LOG, "adm-create"); + zebra_admin_create (zh, r->toKeep->databaseName); + break; + case Z_ESAdminOriginPartToKeep_import: + yaz_log(LOG_LOG, "adm-import"); + break; + case Z_ESAdminOriginPartToKeep_refresh: + yaz_log(LOG_LOG, "adm-refresh"); + break; + case Z_ESAdminOriginPartToKeep_commit: + yaz_log(LOG_LOG, "adm-commit"); + break; + default: + yaz_log(LOG_LOG, "unknown admin"); + zh->errCode = 1001; + } + if (r->toKeep->databaseName) + { + yaz_log(LOG_LOG, "database %s", r->toKeep->databaseName); + } + return 0; +} + +static int es_admin (ZebraHandle zh, Z_Admin *r) +{ + switch (r->which) + { + case Z_Admin_esRequest: + es_admin_request (zh, r->u.esRequest); + break; + case Z_Admin_taskPackage: + yaz_log (LOG_LOG, "adm taskpackage (unhandled)"); + break; + default: + zh->errCode = 1001; + break; + } + + return 0; +} + +int bend_esrequest (void *handle, bend_esrequest_rr *rr) +{ + ZebraHandle zh = (ZebraHandle) handle; + + yaz_log(LOG_LOG, "function: %d", *rr->esr->function); + if (rr->esr->packageName) + yaz_log(LOG_LOG, "packagename: %s", rr->esr->packageName); + yaz_log(LOG_LOG, "Waitaction: %d", *rr->esr->waitAction); + + if (!rr->esr->taskSpecificParameters) + { + yaz_log (LOG_WARN, "No task specific parameters"); + } + 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; + } + else if (rr->esr->taskSpecificParameters->which == Z_External_itemOrder) + { + Z_ItemOrder *it = rr->esr->taskSpecificParameters->u.itemOrder; + yaz_log (LOG_LOG, "Received ItemOrder"); + switch (it->which) + { +#ifdef ASN_COMPILED + case Z_IOItemOrder_esRequest: +#else + case Z_ItemOrder_esRequest: +#endif + { + Z_IORequest *ir = it->u.esRequest; + Z_IOOriginPartToKeep *k = ir->toKeep; + Z_IOOriginPartNotToKeep *n = ir->notToKeep; + + if (k && k->contact) + { + if (k->contact->name) + yaz_log(LOG_LOG, "contact name %s", k->contact->name); + if (k->contact->phone) + yaz_log(LOG_LOG, "contact phone %s", k->contact->phone); + if (k->contact->email) + yaz_log(LOG_LOG, "contact email %s", k->contact->email); + } + if (k->addlBilling) + { + yaz_log(LOG_LOG, "Billing info (not shown)"); + } + + if (n->resultSetItem) + { + yaz_log(LOG_LOG, "resultsetItem"); + yaz_log(LOG_LOG, "setId: %s", n->resultSetItem->resultSetId); + yaz_log(LOG_LOG, "item: %d", *n->resultSetItem->item); + } +#ifdef ASN_COMPILED + if (n->itemRequest) + { + Z_External *r = (Z_External*) n->itemRequest; + ILL_ItemRequest *item_req = 0; + ILL_Request *ill_req = 0; + if (r->direct_reference) + { + oident *ent = oid_getentbyoid(r->direct_reference); + if (ent) + yaz_log(LOG_LOG, "OID %s", ent->desc); + if (ent && ent->value == VAL_ISO_ILL_1) + { + yaz_log (LOG_LOG, "ItemRequest"); + if (r->which == ODR_EXTERNAL_single) + { + odr_setbuf(rr->decode, + r->u.single_ASN1_type->buf, + r->u.single_ASN1_type->len, 0); + + if (!ill_ItemRequest (rr->decode, &item_req, 0, 0)) + { + yaz_log (LOG_LOG, + "Couldn't decode ItemRequest %s near %d", + odr_errmsg(odr_geterror(rr->decode)), + odr_offset(rr->decode)); + yaz_log(LOG_LOG, "PDU dump:"); + odr_dumpBER(log_file(), + r->u.single_ASN1_type->buf, + r->u.single_ASN1_type->len); + } + if (rr->print) + { + ill_ItemRequest (rr->print, &item_req, 0, + "ItemRequest"); + odr_reset (rr->print); + } + } + if (!item_req && r->which == ODR_EXTERNAL_single) + { + yaz_log (LOG_LOG, "ILLRequest"); + odr_setbuf(rr->decode, + r->u.single_ASN1_type->buf, + r->u.single_ASN1_type->len, 0); + + if (!ill_Request (rr->decode, &ill_req, 0, 0)) + { + yaz_log (LOG_LOG, + "Couldn't decode ILLRequest %s near %d", + odr_errmsg(odr_geterror(rr->decode)), + odr_offset(rr->decode)); + yaz_log(LOG_LOG, "PDU dump:"); + odr_dumpBER(log_file(), + r->u.single_ASN1_type->buf, + r->u.single_ASN1_type->len); + } + if (rr->print) + { + ill_Request (rr->print, &ill_req, 0, + "ILLRequest"); + odr_reset (rr->print); + } + } + } + } + if (item_req) + { + yaz_log (LOG_LOG, "ILL protocol version = %d", + *item_req->protocol_version_num); + } + } +#endif + } + break; + } + } + else if (rr->esr->taskSpecificParameters->which == Z_External_update) + { + Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.update; + yaz_log (LOG_LOG, "Received DB Update"); + if (up->which == Z_IUUpdate_esRequest) + { + Z_IUUpdateEsRequest *esRequest = up->u.esRequest; + Z_IUOriginPartToKeep *toKeep = esRequest->toKeep; + Z_IUSuppliedRecords *notToKeep = esRequest->notToKeep; + + yaz_log (LOG_LOG, "action"); + if (toKeep->action) + { + switch (*toKeep->action) + { + case Z_IUOriginPartToKeep_recordInsert: + yaz_log (LOG_LOG, " recordInsert"); + break; + case Z_IUOriginPartToKeep_recordReplace: + yaz_log (LOG_LOG, " recordUpdate"); + break; + case Z_IUOriginPartToKeep_recordDelete: + yaz_log (LOG_LOG, " recordDelete"); + break; + case Z_IUOriginPartToKeep_elementUpdate: + yaz_log (LOG_LOG, " elementUpdate"); + break; + case Z_IUOriginPartToKeep_specialUpdate: + yaz_log (LOG_LOG, " specialUpdate"); + break; + default: + yaz_log (LOG_LOG, " unknown (%d)", *toKeep->action); + } + } + if (toKeep->databaseName) + { + yaz_log (LOG_LOG, "database: %s", toKeep->databaseName); + if (!strcmp(toKeep->databaseName, "fault")) + { + rr->errcode = 109; + rr->errstring = toKeep->databaseName; + } + if (!strcmp(toKeep->databaseName, "accept")) + rr->errcode = -1; + } + if (notToKeep) + { + int i; + for (i = 0; i < notToKeep->num; i++) + { + Z_External *rec = notToKeep->elements[i]->record; + + if (rec->direct_reference) + { + struct oident *oident; + oident = oid_getentbyoid(rec->direct_reference); + if (oident) + yaz_log (LOG_LOG, "record %d type %s", i, + oident->desc); + } + switch (rec->which) + { + case Z_External_sutrs: + if (rec->u.octet_aligned->len > 170) + yaz_log (LOG_LOG, "%d bytes:\n%.168s ...", + rec->u.sutrs->len, + rec->u.sutrs->buf); + else + yaz_log (LOG_LOG, "%d bytes:\n%s", + rec->u.sutrs->len, + rec->u.sutrs->buf); + break; + case Z_External_octet : + if (rec->u.octet_aligned->len > 170) + yaz_log (LOG_LOG, "%d bytes:\n%.168s ...", + rec->u.octet_aligned->len, + rec->u.octet_aligned->buf); + else + yaz_log (LOG_LOG, "%d bytes\n%s", + rec->u.octet_aligned->len, + rec->u.octet_aligned->buf); + } + } + } + } + } + else + { + yaz_log (LOG_WARN, "Unknown Extended Service(%d)", + rr->esr->taskSpecificParameters->which); + + } + return 0; +} + static void bend_start (struct statserv_options_block *sob) { +#ifdef WIN32 + +#else if (!sob->inetd) { char *pidfile = "zebrasrv.pid"; @@ -483,8 +774,18 @@ static void bend_start (struct statserv_options_block *sob) close (fd); } } -} #endif + if (sob->handle) + zebra_stop((ZebraService) sob->handle); + sob->handle = zebra_start(sob->configname); +} + +static void bend_stop(struct statserv_options_block *sob) +{ + if (sob->handle) + zebra_stop(sob->handle); + sob->handle = 0; +} int main (int argc, char **argv) { @@ -492,13 +793,15 @@ int main (int argc, char **argv) sob = statserv_getcontrol (); strcpy (sob->configname, FNAME_CONFIG); -#ifndef WIN32 sob->bend_start = bend_start; -#endif + sob->bend_stop = bend_stop; + + if (sob->dynamic) + { + sob->dynamic = 0; + sob->threads = 1; + } statserv_setcontrol (sob); -#if ZEBRASDR - zebraSdr_std (); -#endif return statserv_main (argc, argv); } diff --git a/index/zserver.h b/index/zserver.h index 0b49c28..823ae27 100644 --- a/index/zserver.h +++ b/index/zserver.h @@ -1,10 +1,13 @@ /* - * Copyright (C) 1994-1999, Index Data + * Copyright (C) 1994-2000, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: zserver.h,v $ - * Revision 1.45 1999-11-30 13:48:04 adam + * Revision 1.46 2000-03-15 15:00:31 adam + * First work on threaded version. + * + * Revision 1.45 1999/11/30 13:48:04 adam * Improved installation. Updated for inclusion of YAZ header files. * * Revision 1.44 1999/11/04 15:00:45 adam @@ -163,6 +166,10 @@ #include #endif +#if HAVE_PTHREADS_H +#include +#endif + #include #include @@ -172,9 +179,7 @@ #include "zebraapi.h" #include "zinfo.h" -#ifdef __cplusplus -extern "C" { -#endif +YAZ_BEGIN_CDECL typedef struct { int sysno; @@ -190,26 +195,22 @@ typedef struct zebra_rank_class { struct zebra_rank_class *next; } *ZebraRankClass; -struct zebra_info { - int registerState; /* 0 (no commit pages), 1 (use commit pages) */ - time_t registerChange; - ZebraSet sets; - Dict dict; - SortIdx sortIdx; +struct zebra_service { + char *configName; + struct zebra_session *sessions; ISAMS isams; #if ZMBOL ISAM isam; ISAMC isamc; #endif + Dict dict; + SortIdx sortIdx; + int registerState; /* 0 (no commit pages), 1 (use commit pages) */ + time_t registerChange; + BFiles bfs; Records records; - int errCode; - int hits; - char *errString; ZebraExplainInfo zei; - data1_handle dh; - BFiles bfs; Res res; - ZebraLockHandle server_lock_cmt; ZebraLockHandle server_lock_org; char *server_path_prefix; @@ -217,16 +218,32 @@ struct zebra_info { struct tms tms1; struct tms tms2; #endif + data1_handle dh; ZebraMaps zebra_maps; ZebraRankClass rank_classes; RecTypes recTypes; Passwd_db passwd_db; }; +struct zebra_session { +#if HAVE_PTHREADS_H + pthread_t *pthread_session; +#endif + struct zebra_session *next; + struct zebra_info *info; + struct zebra_service *service; + + ZebraSet sets; + int errCode; + int hits; + char *errString; + +}; + struct rank_control { char *name; - void *(*create)(ZebraHandle zh); - void (*destroy)(ZebraHandle zh, void *class_handle); + 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); @@ -273,11 +290,11 @@ void zebra_sort (ZebraHandle zh, ODR stream, const char *output_setname, Z_SortKeySpecList *sort_sequence, int *sort_status); -int zebra_server_lock_init (ZebraHandle zh); -int zebra_server_lock_destroy (ZebraHandle zh); -int zebra_server_lock (ZebraHandle zh, int lockCommit); -void zebra_server_unlock (ZebraHandle zh, int commitPhase); -int zebra_server_lock_get_state (ZebraHandle zh, time_t *timep); +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 { @@ -285,9 +302,9 @@ typedef struct attent data1_local_attribute *local_attributes; } attent; -void zebraRankInstall (ZebraHandle zh, struct rank_control *ctrl); +void zebraRankInstall (ZebraService zh, struct rank_control *ctrl); ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name); -void zebraRankDestroy (ZebraHandle zh); +void zebraRankDestroy (ZebraService zh); int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att); @@ -298,6 +315,4 @@ int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream, oid_value *output_format, char **rec_bufp, int *rec_lenp, char **basenamep); -#ifdef __cplusplus -} -#endif +YAZ_END_CDECL diff --git a/index/zsets.c b/index/zsets.c index d0ce024..c6a03c2 100644 --- a/index/zsets.c +++ b/index/zsets.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zsets.c,v $ - * Revision 1.24 1999-11-04 15:00:45 adam + * Revision 1.25 2000-03-15 15:00:31 adam + * First work on threaded version. + * + * Revision 1.24 1999/11/04 15:00:45 adam * Implemented delete result set(s). * * Revision 1.23 1999/05/26 07:49:13 adam @@ -369,11 +372,11 @@ void resultSetInsertSort (ZebraHandle zh, ZebraSet sset, struct zset_sort_info *sort_info = sset->sort_info; int i, j; - sortIdx_sysno (zh->sortIdx, sysno); + sortIdx_sysno (zh->service->sortIdx, sysno); for (i = 0; isortIdx, criteria[i].attrUse); - sortIdx_read (zh->sortIdx, this_entry.buf[i]); + sortIdx_type (zh->service->sortIdx, criteria[i].attrUse); + sortIdx_read (zh->service->sortIdx, this_entry.buf[i]); } i = sort_info->num_entries; while (--i >= 0) @@ -559,14 +562,15 @@ 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->zebra_maps, sk->u.sortAttributes); + zebra_maps_sort (zh->service->zebra_maps, + sk->u.sortAttributes); logf (LOG_DEBUG, "use value = %d", sort_criteria[i].attrUse); if (sort_criteria[i].attrUse == -1) { zh->errCode = 116; return; } - if (sortIdx_type (zh->sortIdx, sort_criteria[i].attrUse)) + if (sortIdx_type (zh->service->sortIdx, sort_criteria[i].attrUse)) { zh->errCode = 207; return; @@ -657,19 +661,19 @@ void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset) ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name) { - ZebraRankClass p = zh->rank_classes; + ZebraRankClass p = zh->service->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); + p->class_handle = (*p->control->create)(zh->service); p->init_flag = 1; } return p; } -void zebraRankInstall (ZebraHandle zh, struct rank_control *ctrl) +void zebraRankInstall (ZebraService zh, struct rank_control *ctrl) { ZebraRankClass p = (ZebraRankClass) xmalloc (sizeof(*p)); p->control = (struct rank_control *) xmalloc (sizeof(*p->control)); @@ -680,7 +684,7 @@ void zebraRankInstall (ZebraHandle zh, struct rank_control *ctrl) zh->rank_classes = p; } -void zebraRankDestroy (ZebraHandle zh) +void zebraRankDestroy (ZebraService zh) { ZebraRankClass p = zh->rank_classes; while (p) diff --git a/util/Makefile.in b/util/Makefile.in index 6adcf8b..7a5335f 100644 --- a/util/Makefile.in +++ b/util/Makefile.in @@ -1,7 +1,7 @@ # Copyright (C) 1994-1998, Index Data ApS # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile.in,v 1.4 1999-11-30 13:48:04 adam Exp $ +# $Id: Makefile.in,v 1.5 2000-03-15 15:00:31 adam Exp $ SHELL=/bin/sh @@ -18,7 +18,7 @@ INCLUDE=-I../include $(YAZINC) TPROG=opt-test DEFS=$(CDEFS) $(INCLUDE) -DUSE_CRYPT=0 LIB=../lib/zebrautl.a -PO = res.o charmap.o zebramap.o passwddb.o +PO = res.o charmap.o zebramap.o passwddb.o zebra-lock.o all: $(LIB) diff --git a/util/zebra-lock.c b/util/zebra-lock.c new file mode 100644 index 0000000..6739a18 --- /dev/null +++ b/util/zebra-lock.c @@ -0,0 +1,102 @@ + +#include + +#include + +int zebra_mutex_init (Zebra_mutex *p) +{ + pthread_mutex_init (&p->mutex, 0); + return 0; +} + +int zebra_mutex_destroy (Zebra_mutex *p) +{ + pthread_mutex_destroy (&p->mutex); + return 0; +} + +int zebra_mutex_lock (Zebra_mutex *p) +{ + pthread_mutex_lock (&p->mutex); + return 0; +} + +int zebra_mutex_unlock (Zebra_mutex *p) +{ + pthread_mutex_unlock (&p->mutex); + return 0; +} + +int zebra_lock_rdwr_init (Zebra_lock_rdwr *p) +{ + p->readers_reading = 0; + p->writers_writing = 0; + pthread_mutex_init (&p->mutex, 0); + pthread_cond_init (&p->lock_free, 0); + return 0; +} + +int zebra_lock_rdwr_destroy (Zebra_lock_rdwr *p) +{ + assert (p->readers_reading == 0); + assert (p->writers_writing == 0); + pthread_mutex_destroy (&p->mutex); + pthread_cond_destroy (&p->lock_free); + return 0; +} + +int zebra_lock_rdwr_rlock (Zebra_lock_rdwr *p) +{ + pthread_mutex_lock (& p->mutex); + while (p->writers_writing) + pthread_cond_wait (&p->lock_free, &p->mutex); + p->readers_reading++; + pthread_mutex_unlock(&p->mutex); + return 0; +} + +int zebra_lock_rdwr_wlock (Zebra_lock_rdwr *p) +{ + pthread_mutex_lock (&p->mutex); + while (p->writers_writing || p->readers_reading) + pthread_cond_wait (&p->lock_free, &p->mutex); + p->writers_writing++; + pthread_mutex_unlock (&p->mutex); + return 0; +} + +int zebra_lock_rdwr_runlock (Zebra_lock_rdwr *p) +{ + pthread_mutex_lock (&p->mutex); + if (p->readers_reading == 0) + { + pthread_mutex_unlock (&p->mutex); + return -1; + } + else + { + p->readers_reading--; + if (p->readers_reading == 0) + pthread_cond_signal (&p->lock_free); + pthread_mutex_unlock (&p->mutex); + } + return 0; +} + +int zebra_lock_rdwr_wunlock (Zebra_lock_rdwr *p) +{ + pthread_mutex_lock (&p->mutex); + if (p->writers_writing == 0) + { + pthread_mutex_unlock (&p->mutex); + return -1; + } + else + { + p->writers_writing--; + pthread_cond_broadcast(&p->lock_free); + pthread_mutex_unlock(&p->mutex); + } + return 0; +} + -- 1.7.10.4