Bump copyright year
[idzebra-moved-to-github.git] / bfile / cfile.c
index 4774072..f0bcccb 100644 (file)
@@ -1,8 +1,5 @@
-/* $Id: cfile.c,v 1.39 2006-11-14 08:12:06 adam Exp $
-   Copyright (C) 1995-2006
-   Index Data ApS
-
-This file is part of the Zebra server.
+/* This file is part of the Zebra server.
+   Copyright (C) 1994-2010 Index Data
 
 Zebra is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -29,6 +26,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "mfile.h"
 #include "cfile.h"
 
+/** \brief set to 1 if extra commit/shadow check is to be performed */
+#define EXTRA_CHECK 0
+
 static int write_head(CFile cf)
 {
     int left = cf->head.hash_size * sizeof(zint);
@@ -86,8 +86,7 @@ CFile cf_open(MFile mf, MFile_area area, const char *fname,
     /* avoid valgrind warnings, but set to something nasty */
     memset(cf, 'Z', sizeof(*cf));
 
-    yaz_log(YLOG_DEBUG, "cf: open %s %s", cf->rmf->name,
-            wflag ? "rdwr" : "rd");
+    yaz_log(YLOG_DEBUG, "cf: open %s %s", fname, wflag ? "rdwr" : "rd");
    
     cf->block_mf = 0;
     cf->hash_mf = 0;
@@ -132,7 +131,7 @@ CFile cf_open(MFile mf, MFile_area area, const char *fname,
     if (ret == 0 || !cf->head.state)
     {
         *firstp = 1;
-        cf->head.state = 1;
+        cf->head.state = CFILE_STATE_HASH;
         cf->head.block_size = block_size;
         cf->head.hash_size = 199;
         hash_bytes = cf->head.hash_size * sizeof(zint);
@@ -164,7 +163,7 @@ CFile cf_open(MFile mf, MFile_area area, const char *fname,
         hash_bytes = cf->head.hash_size * sizeof(zint);
         assert(cf->head.next_bucket > 0);
         assert(cf->head.next_block > 0);
-        if (cf->head.state == 1)
+        if (cf->head.state == CFILE_STATE_HASH)
             cf->array = (zint *) xmalloc(hash_bytes);
         else
             cf->array = NULL;
@@ -174,7 +173,7 @@ CFile cf_open(MFile mf, MFile_area area, const char *fname,
             return 0;
         }
     }
-    if (cf->head.state == 1)
+    if (cf->head.state == CFILE_STATE_HASH)
     {
         cf->parray = (struct CFile_hash_bucket **)
            xmalloc(cf->head.hash_size * sizeof(*cf->parray));
@@ -343,20 +342,19 @@ static int cf_lookup_hash(CFile cf, zint no, zint *vno)
         }
         if (hb)
             continue;
-#if 0
-        /* extra check ... */
+#if EXTRA_CHECK
         for (hb = cf->bucket_lru_back; hb; hb = hb->lru_next)
         {
             if (hb->ph.this_bucket == block_no)
             {
                 yaz_log(YLOG_FATAL, "Found hash bucket on other chain(1)");
-                abort();
+                return -1;
             }
             for (i = 0; i<HASH_BUCKET && hb->ph.vno[i]; i++)
                 if (hb->ph.no[i] == no)
                 {
                     yaz_log(YLOG_FATAL, "Found hash bucket on other chain (2)");
-                    abort();
+                    return -1;
                 }
         }
 #endif
@@ -397,7 +395,7 @@ static int cf_moveto_flat(CFile cf)
          ZINT_FORMAT,
        cf->no_hits, cf->no_miss, cf->bucket_in_memory, 
         cf->head.next_bucket - cf->head.first_bucket);
-    assert(cf->head.state == 1);
+    assert(cf->head.state == CFILE_STATE_HASH);
     if (flush_bucket(cf, -1))
         return -1;
     assert(cf->bucket_in_memory == 0);
@@ -424,7 +422,7 @@ static int cf_moveto_flat(CFile cf)
     cf->array = NULL;
     xfree(cf->parray);
     cf->parray = NULL;
-    cf->head.state = 2;
+    cf->head.state = CFILE_STATE_FLAT;
     cf->dirty = 1;
     return 0;
 }
@@ -476,14 +474,13 @@ static zint cf_new_hash(CFile cf, zint no)
         if (hb)
             continue;
 
-#if 0
-        /* extra check ... */
+#if EXTRA_CHECK
         for (hb = cf->bucket_lru_back; hb; hb = hb->lru_next)
         {
             if (hb->ph.this_bucket == *bucketpp)
             {
                 yaz_log(YLOG_FATAL, "Found hash bucket on other chain");
-                abort();
+                return 0;
             }
         }
 #endif
@@ -645,6 +642,7 @@ int cf_close(CFile cf)
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab