Prevent zebra_clean from deleting files for uncommited trans.
[idzebra-moved-to-github.git] / index / zebraapi.c
index 66e9f87..09c0e1a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zebraapi.c,v 1.262 2007-10-31 16:56:14 adam Exp $
+/* $Id: zebraapi.c,v 1.267 2007-12-18 13:41:27 adam Exp $
    Copyright (C) 1995-2007
    Index Data ApS
 
@@ -381,7 +381,6 @@ struct zebra_register *zebra_register_open(ZebraService zs, const char *name,
     data1_set_tabroot (reg->dh, reg_path);
     reg->recTypes = recTypes_init (zs->record_classes, reg->dh);
 
-    reg->index_types = 0;
     reg->zebra_maps =
        zebra_maps_open(res, reg_path, profilePath);
     if (!reg->zebra_maps)
@@ -421,32 +420,8 @@ struct zebra_register *zebra_register_open(ZebraService zs, const char *name,
        record_compression = REC_COMPRESS_BZIP2;
 
     {
-        const char *index_types_fname = res_get(res, "indextypes");
-        if (index_types_fname)
-        {
-            char tmp_full_name[1024];
-
-            if (!yaz_filepath_resolve(index_types_fname,
-                                      profilePath,
-                                      reg_path,
-                                      tmp_full_name))
-            {
-                yaz_log(YLOG_WARN, "Could not find %s", index_types_fname);
-                ret = ZEBRA_FAIL;
-            }
-            else
-            {
-                reg->index_types = zebra_index_types_create(
-                    tmp_full_name);
-                yaz_log(YLOG_LOG, "zebra_index_types_create returned %p", 
-                        reg->index_types);
-            }
-        }
-
-    }
-    {
        const char *index_fname = res_get_def(res, "index", "default.idx");
-       if (index_fname && *index_fname)
+       if (index_fname && *index_fname && strcmp(index_fname, "none"))
        {
            if (zebra_maps_read_file(reg->zebra_maps, index_fname) != ZEBRA_OK)
                ret = ZEBRA_FAIL;
@@ -604,7 +579,6 @@ static void zebra_register_close(ZebraService zs, struct zebra_register *reg)
 
     recTypes_destroy (reg->recTypes);
     zebra_maps_close (reg->zebra_maps);
-    zebra_index_types_destroy(reg->index_types);
     zebraRankDestroy (reg);
     bfs_destroy (reg->bfs);
     data1_destroy (reg->dh);
@@ -1175,7 +1149,6 @@ ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
                recs[i].errCode =
                    zebra_record_fetch(zh, setname,
                                        poset[i].sysno, poset[i].score,
-                                      hit_snippet,
                                       stream, input_format, comp,
                                       &recs[i].format, &buf, &len,
                                       &recs[i].base, &recs[i].errString);
@@ -1251,7 +1224,6 @@ ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
                     const char *setname)
 {
     ZEBRA_RES res;
-    RSET limit_rset = 0;
 
     ZEBRA_CHECK_HANDLE(zh);
 
@@ -1269,21 +1241,10 @@ ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
        *num_entries = 0;
        return ZEBRA_FAIL;
     }
-    if (setname)
-    {
-       limit_rset = resultSetRef(zh, setname);
-       if (!limit_rset)
-       {
-           zebra_setError(zh, 
-                          YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
-                          setname);
-           zebra_end_read (zh);
-           return ZEBRA_FAIL;
-       }
-    }
+
     res = rpn_scan(zh, stream, zapt, attributeset,
                    zh->num_basenames, zh->basenames, position,
-                   num_entries, entries, is_partial, limit_rset);
+                   num_entries, entries, is_partial, setname);
     zebra_end_read(zh);
     return res;
 }
@@ -1592,7 +1553,7 @@ static void zebra_set_state (ZebraHandle zh, int val, int seqno)
     long p = getpid();
     FILE *f;
     ASSERTZH;
-    yaz_log(log_level, "zebra_set_state v=%d seq=%d", val, seqno);
+    yaz_log(log_level, "zebra_set_state v=%c seq=%d", val, seqno);
 
     sprintf (state_fname, "state.%s.LCK", zh->reg_name);
     fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname);
@@ -1944,14 +1905,12 @@ ZEBRA_RES zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status)
         if (val != 'd')
         {
             BFiles bfs = bfs_create (rval, zh->path_reg);
-            yaz_log (YLOG_DEBUG, "deleting shadow val=%c", val);
             bf_commitClean (bfs, rval);
             bfs_destroy (bfs);
         }
         if (!rval)
             seqno++;
         zebra_set_state (zh, 'o', seqno);
-        
         zebra_unlock (zh->lock_shadow);
         zebra_unlock (zh->lock_normal);
         
@@ -2007,6 +1966,7 @@ static ZEBRA_RES zebra_commit_ex(ZebraHandle zh, int clean_only)
 
     ASSERTZH;
 
+    yaz_log(log_level, "zebra_commit_ex clean_only=%d", clean_only);
     zebra_select_default_database(zh);
     if (!zh->res)
     {
@@ -2038,6 +1998,11 @@ static ZEBRA_RES zebra_commit_ex(ZebraHandle zh, int clean_only)
         yaz_log(YLOG_WARN, "previous transaction didn't reach commit");
         clean_only = 1;
     }
+    else if (val == 'c')
+    {
+        /* commit has started. We can not remove it anymore */
+        clean_only = 0;
+    }
 
     if (rval && *rval)
         bf_cache (bfs, rval);
@@ -2049,7 +2014,7 @@ static ZEBRA_RES zebra_commit_ex(ZebraHandle zh, int clean_only)
         {
             zebra_set_state(zh, 'c', seqno);
             
-            yaz_log(YLOG_DEBUG, "commit start");
+            yaz_log(log_level, "commit start");
             if (bf_commitExec (bfs))
                 res = ZEBRA_FAIL;
         }