Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/idzebra
authorMike Taylor <mike@miketaylor.org.uk>
Sun, 21 Jun 2009 09:16:52 +0000 (10:16 +0100)
committerMike Taylor <mike@miketaylor.org.uk>
Sun, 21 Jun 2009 09:16:52 +0000 (10:16 +0100)
NEWS
configure.ac
debian/changelog
index/zebraapi.c
index/zebrasrv.c
isamb/isamb.c
rset/rsmultiandor.c

diff --git a/NEWS b/NEWS
index afa0f4a..ffb4d50 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,9 @@
+--- 2.0.38 2009/06/19
+
+Improved estimated hits for AND operation (bug #2907)
+
+Fixed problem with register area growing after "drop DB". (bug #2913).
+
 --- 2.0.37 2009/05/18
 
 Example with marc21 is now installed and part of packages.
index c3d7d64..936f76a 100644 (file)
@@ -2,7 +2,7 @@ dnl This file is part of the Zebra server.
 dnl   Copyright (C) 1994-2009 Index Data
 dnl
 AC_PREREQ(2.60)
-AC_INIT([idzebra],[2.0.37],[zebra-help@indexdata.dk])
+AC_INIT([idzebra],[2.0.38],[zebra-help@indexdata.dk])
 AC_CONFIG_SRCDIR(configure.ac)
 AC_CONFIG_AUX_DIR(config)
 AM_INIT_AUTOMAKE([1.9])
index 8a2039b..48a92df 100644 (file)
@@ -1,3 +1,9 @@
+idzebra (2.0.38-1indexdata) unstable; urgency=low
+
+  * Upstream.
+
+ -- Adam Dickmeiss <adam@indexdata.dk>  Fri, 19 Jun 2009 21:31:41 +0200
+
 idzebra (2.0.37-1indexdata) unstable; urgency=low
 
   * Upstream.
index a343014..2b69a2d 100644 (file)
@@ -61,20 +61,24 @@ static ZEBRA_RES zebra_check_handle(ZebraHandle zh)
 
 #define ZEBRA_CHECK_HANDLE(zh) if (zebra_check_handle(zh) != ZEBRA_OK) return ZEBRA_FAIL
 
-static void zebra_chdir(ZebraService zs)
+static int zebra_chdir(ZebraService zs)
 {
     const char *dir ;
+    int r;
     ASSERTZS;
     yaz_log(log_level, "zebra_chdir");
     dir = res_get(zs->global_res, "chdir");
     if (!dir)
-       return;
+       return 0;
     yaz_log(YLOG_DEBUG, "chdir %s", dir);
 #ifdef WIN32
-    _chdir(dir);
+    r = _chdir(dir);
 #else
-    chdir(dir);
+    r = chdir(dir);
 #endif
+    if (r)
+        yaz_log(YLOG_FATAL|YLOG_ERRNO, "chdir %s", dir);
+    return r;
 }
 
 static ZEBRA_RES zebra_flush_reg(ZebraHandle zh)
@@ -239,7 +243,11 @@ ZebraService zebra_start_res(const char *configName, Res def_res, Res over_res)
         zh->global_res = res;
         zh->sessions = 0;
         
-        zebra_chdir(zh);
+        if (zebra_chdir(zh))
+        {
+            xfree(zh);
+            return 0;
+        }
         
         zebra_mutex_cond_init(&zh->session_lock);
        passwd_plain = res_get(zh->global_res, "passwd");
@@ -328,7 +336,6 @@ struct zebra_register *zebra_register_open(ZebraService zs, const char *name,
     int record_compression = REC_COMPRESS_NONE;
     const char *recordCompression = 0;
     const char *profilePath;
-    char cwd[1024];
     int sort_type = ZEBRA_SORT_TYPE_FLAT;
     ZEBRA_RES ret = ZEBRA_OK;
 
@@ -374,7 +381,6 @@ struct zebra_register *zebra_register_open(ZebraService zs, const char *name,
        }
     }
 
-    getcwd(cwd, sizeof(cwd)-1);
     profilePath = res_get_def(res, "profilePath", 0);
 
     data1_set_tabpath(reg->dh, profilePath);
@@ -1628,7 +1634,11 @@ static void zebra_get_state(ZebraHandle zh, char *val, int *seqno)
 
     if (f)
     {
-        fscanf(f, "%c %d", val, seqno);
+        if (fscanf(f, "%c %d", val, seqno) != 2)
+        {
+            yaz_log(YLOG_ERRNO|YLOG_WARN, "fscan fail %s",
+                    state_fname);
+        }
         fclose(f);
     }
     xfree(fname);
index fad0df7..0404b8f 100644 (file)
@@ -770,7 +770,11 @@ static void bend_start(struct statserv_options_block *sob)
            char pidstr[30];
        
            sprintf(pidstr, "%ld", (long) getpid());
-           write(fd, pidstr, strlen(pidstr));
+           if (write(fd, pidstr, strlen(pidstr)) != strlen(pidstr))
+            {
+                yaz_log(YLOG_ERRNO|YLOG_FATAL, "write fail %s", pidfname);
+                exit(1);
+            }
         }
     }
 #endif
index 13bb0cf..0ade1bf 100644 (file)
@@ -569,6 +569,10 @@ struct ISAMB_block *new_block(ISAMB b, int leaf, int cat)
         zint block_no;
         block_no = b->file[cat].head.last_block++;
         p->pos = block_no * CAT_MAX + cat;
+        if (b->log_freelist)
+            yaz_log(b->log_freelist, "got block " 
+                    ZINT_FORMAT " from last %d:" ZINT_FORMAT, p->pos,
+                    cat, p->pos/CAT_MAX);
     }
     else
     {
@@ -584,8 +588,10 @@ struct ISAMB_block *new_block(ISAMB b, int leaf, int cat)
                 zebra_exit("isamb:new_block");
             }
         }
-        yaz_log(b->log_freelist, "got block " ZINT_FORMAT " from freelist %d:" ZINT_FORMAT, p->pos,
-                cat, p->pos/CAT_MAX);
+        if (b->log_freelist)
+            yaz_log(b->log_freelist, "got block " 
+                    ZINT_FORMAT " from freelist %d:" ZINT_FORMAT, p->pos,
+                    cat, p->pos/CAT_MAX);
         memcpy(&b->file[cat].head.free_list, p->buf, sizeof(zint));
     }
     p->cat = cat;
@@ -664,6 +670,7 @@ void close_block(ISAMB b, struct ISAMB_block *p)
                 p->pos, p->cat, p->pos/CAT_MAX);
         memcpy(p->buf, &b->file[p->cat].head.free_list, sizeof(zint));
         b->file[p->cat].head.free_list = p->pos;
+        b->file[p->cat].head_dirty = 1;
         if (!cache_block(b, p->pos, p->buf, 1))
         {
             yaz_log(b->log_io, "bf_write: close_block (deleted)");
index ff1610c..6b1fd19 100644 (file)
@@ -52,7 +52,8 @@ static int r_forward_and(RSFD rfd, void *buf, TERMID *term,
                      const void *untilbuf);
 static int r_forward_or(RSFD rfd, void *buf, TERMID *term,
                      const void *untilbuf);
-static void r_pos (RSFD rfd, double *current, double *total);
+static void r_pos_and(RSFD rfd, double *current, double *total);
+static void r_pos_or(RSFD rfd, double *current, double *total);
 static void r_get_terms(RSET ct, TERMID *terms, int maxterms, int *curterm);
 
 static const struct rset_control control_or = 
@@ -63,7 +64,7 @@ static const struct rset_control control_or =
     r_open_or,
     r_close,
     r_forward_or,
-    r_pos,
+    r_pos_or,
     r_read_or,
     r_write,
 };
@@ -76,7 +77,7 @@ static const struct rset_control control_and =
     r_open_and,
     r_close,
     r_forward_and,
-    r_pos,
+    r_pos_and,
     r_read_and,
     r_write,
 };
@@ -526,7 +527,8 @@ static int r_read_and (RSFD rfd, void *buf, TERMID *term)
             }
             if (p->skip)
                 continue;  /* skip again.. eventually tailcount will be 0 */
-           (p->hits)++;
+            if (p->tailcount == 0)
+                (p->hits)++;
             return 1;
         } 
         /* not tailing, forward until all records match, and set up */
@@ -604,21 +606,31 @@ static int r_forward_and(RSFD rfd, void *buf, TERMID *term,
     return r_read_and(rfd,buf,term);
 }
 
-static void r_pos (RSFD rfd, double *current, double *total)
+static void r_pos_x(RSFD rfd, double *current, double *total, int and_op)
 {
     RSET ct = rfd->rset;
     struct rfd_private *mrfd = 
        (struct rfd_private *)(rfd->priv);
-    double cur, tot;
-    double scur = 0.0, stot = 0.0;
+    double ratio = and_op ? 0.0 : 1.0;
     int i;
     for (i = 0; i<ct->no_children; i++){
+        double nratio, cur, tot;
         rset_pos(mrfd->items[i].fd, &cur, &tot);
-        yaz_log(log_level, "r_pos: %d %0.1f %0.1f", i, cur,tot); 
-        scur += cur;
-        stot += tot;
+        yaz_log(log_level, "r_pos: %d %0.1f %0.1f", i, cur,tot);
+        
+        nratio = cur / tot;
+        if (and_op)
+        {
+            if (nratio > ratio)
+                ratio = nratio;
+        }
+        else
+        {
+            if (nratio < ratio)
+                ratio = nratio;
+        }
     }
-    if (stot < 1.0) { /* nothing there */
+    if (ratio == 0.0 || ratio == 1.0) { /* nothing there */
         *current = 0;
         *total = 0;
         yaz_log(log_level, "r_pos: NULL  %0.1f %0.1f",  *current, *total);
@@ -626,11 +638,21 @@ static void r_pos (RSFD rfd, double *current, double *total)
     else
     {
        *current = (double) (mrfd->hits);
-       *total = *current*stot/scur;
+       *total = *current / ratio;
        yaz_log(log_level, "r_pos: =  %0.1f %0.1f",  *current, *total);
     }
 }
 
+static void r_pos_and(RSFD rfd, double *current, double *total)
+{
+    r_pos_x(rfd, current, total, 1);
+}
+
+static void r_pos_or(RSFD rfd, double *current, double *total)
+{
+    r_pos_x(rfd, current, total, 0);
+}
+
 static int r_write (RSFD rfd, const void *buf)
 {
     yaz_log (YLOG_FATAL, "multior set type is read-only");