Set log levels to decent values
authorHeikki Levanto <heikki@indexdata.dk>
Wed, 18 Aug 1999 13:28:16 +0000 (13:28 +0000)
committerHeikki Levanto <heikki@indexdata.dk>
Wed, 18 Aug 1999 13:28:16 +0000 (13:28 +0000)
isamc/isamd.c
isamc/merge-d.c

index 6013abd..3052990 100644 (file)
@@ -1,10 +1,14 @@
 /*
  * Copyright (c) 1995-1998, Index Data.
  * See the file LICENSE for details.
- * Heikki Levanto
- * 
+ * $Id: isamd.c,v 1.8 1999-08-18 13:28:16 heikki Exp $ 
+ *
  * Isamd - isam with diffs 
+ * Programmed by: Heikki Levanto
  *
+ * Todo
+ *  - Statistics are missing and/or completely wrong
+ *  - Lots of code stolen from isamc, not all needed any more
  */
 
 
@@ -29,7 +33,7 @@ ISAMD_M isamd_getmethod (ISAMD_M me)
 {
     static struct ISAMD_filecat_s def_cat[] = {
 #if SMALL_TEST
-/*        blocksz,   max keys before switching size. Unused time being */
+/*        blocksz,   max. Unused time being */
         {    20,   40 },
        {    32,    0 },
 #else
@@ -51,13 +55,9 @@ ISAMD_M isamd_getmethod (ISAMD_M me)
         { 32768,   0  },
 */
 
-/* assume about 2 bytes per pointer, when compressed. The head uses */
-/* 16 bytes, and other blocks use 8 for header info... If you want 3 */
-/* blocks of 32 bytes, say max 16+24+24 = 64 keys */
-
     };
-    ISAMD_M m = (ISAMD_M) xmalloc (sizeof(*m));  /*??? never released??? */
-    m->filecat = def_cat;
+    ISAMD_M m = (ISAMD_M) xmalloc (sizeof(*m));  /* never released! */
+    m->filecat = def_cat;                        /* ok, only alloc'd once */
 
     m->code_start = NULL;
     m->code_item = NULL;
@@ -66,7 +66,7 @@ ISAMD_M isamd_getmethod (ISAMD_M me)
 
     m->compare_item = NULL;
 
-    m->debug = 1;
+    m->debug = 0; /* default to no debug */
 
     m->max_blocks_mem = 10;
 
@@ -89,11 +89,11 @@ ISAMD isamd_open (BFiles bfs, const char *name, int writeflag, ISAMD_M method)
     assert (filecat);
 
     /* determine number of block categories */
-    if (is->method->debug)
+    if (is->method->debug>0)
         logf (LOG_LOG, "isamd: bsize  maxkeys");
     do
     {
-        if (is->method->debug)
+        if (is->method->debug>0)
             logf (LOG_LOG, "isamd:%6d %6d",
                   filecat[i].bsize, filecat[i].mblocks);
     } while (filecat[i++].mblocks);
@@ -104,13 +104,6 @@ ISAMD isamd_open (BFiles bfs, const char *name, int writeflag, ISAMD_M method)
     assert (is->max_cat <=8 ); /* we have only 3 bits for it */
     
     is->files = (ISAMD_file) xmalloc (sizeof(*is->files)*is->no_files);
-    if (writeflag)
-    {
-      /* TODO - what ever needs to be done here... */
-    }
-    else
-    {
-    }
 
     for (i = 0; i<is->no_files; i++)
     {
@@ -168,7 +161,7 @@ int isamd_close (ISAMD is)
 {
     int i;
 
-    if (is->method->debug)
+    if (is->method->debug>0)
     {
        logf (LOG_LOG, "isamd:    next    forw   mid-f    prev   backw   mid-b");
        for (i = 0; i<is->no_files; i++)
@@ -184,7 +177,7 @@ int isamd_close (ISAMD is)
                  (double) is->files[i].sum_backward/is->files[i].no_backward
                  : 0.0);
     }
-    if (is->method->debug)
+    if (is->method->debug>0)
         logf (LOG_LOG, "isamd:  writes   reads skipped   alloc released  remap");
     for (i = 0; i<is->no_files; i++)
     {
@@ -193,7 +186,7 @@ int isamd_close (ISAMD is)
         if (is->files[i].head_is_dirty)
             bf_write (is->files[i].bf, 0, 0, sizeof(ISAMD_head),
                  &is->files[i].head);
-        if (is->method->debug)
+        if (is->method->debug>0)
             logf (LOG_LOG, "isamd:%8d%8d%8d%8d%8d%8d",
                   is->files[i].no_writes,
                   is->files[i].no_reads,
@@ -214,13 +207,15 @@ int isamd_close (ISAMD is)
 int isamd_read_block (ISAMD is, int cat, int pos, char *dst)
 {
     ++(is->files[cat].no_reads);
+    if (is->method->debug > 6)
+        logf (LOG_LOG, "isamd: read_block %d %d", cat, pos);
     return bf_read (is->files[cat].bf, pos, 0, 0, dst);
 }
 
 int isamd_write_block (ISAMD is, int cat, int pos, char *src)
 {
     ++(is->files[cat].no_writes);
-    if (is->method->debug > 2)
+    if (is->method->debug > 6)
         logf (LOG_LOG, "isamd: write_block %d %d", cat, pos);
     return bf_write (is->files[cat].bf, pos, 0, 0, src);
 }
@@ -229,7 +224,7 @@ int isamd_write_dblock (ISAMD is, int cat, int pos, char *src,
                       int nextpos, int offset)
 {
     ISAMD_BLOCK_SIZE size = offset + ISAMD_BLOCK_OFFSET_N;
-    if (is->method->debug > 2)
+    if (is->method->debug > 4)
         logf (LOG_LOG, "isamd: write_dblock. size=%d nextpos=%d",
               (int) size, nextpos);
     src -= ISAMD_BLOCK_OFFSET_N;
@@ -388,14 +383,14 @@ int isamd_alloc_block (ISAMD is, int cat)
     }
     if (!block)
         block = alloc_block (is, cat);
-    if (is->method->debug > 3)
+    if (is->method->debug > 4)
         logf (LOG_LOG, "isamd: alloc_block in cat %d: %d", cat, block);
     return block;
 }
 
 void isamd_release_block (ISAMD is, int cat, int pos)
 {
-    if (is->method->debug > 3)
+    if (is->method->debug > 4)
         logf (LOG_LOG, "isamd: release_block in cat %d: %d", cat, pos);
     assert(pos!=0);
     
@@ -443,7 +438,7 @@ void isamd_pp_close (ISAMD_PP pp)
     isamd_free_diffs(pp);  /* see merge-d.h */
     xfree (pp->buf);
     xfree (pp);
-    if (is->method->debug > 2)
+    if (is->method->debug > 5)
        logf (LOG_LOG, "isamd_pp_close %p %d=%d:%d  sz=%d n=%d=%d:%d",
              pp, isamd_addr(pp->pos, pp->cat), pp->cat, pp->pos, pp->size, 
              pp->next, isamd_type(pp->next), isamd_block(pp->next) );
@@ -490,12 +485,8 @@ ISAMD_PP isamd_pp_open (ISAMD is, ISAMD_P ipos)
         assert (pp->next != pp->pos);
         pp->offset = src - pp->buf; 
         assert (pp->offset == ISAMD_BLOCK_OFFSET_1);
-//        if (is->method->debug > 2)
-//           logf (LOG_LOG, "isamd_pp_open  %p %d=%d:%d  sz=%d n=%d=%d:%d",
-//                 pp, isamd_addr(pp->pos, pp->cat), pp->cat, pp->pos, pp->size, 
-//                 pp->next, isamd_type(pp->next), isamd_block(pp->next) );
     }
-    if (is->method->debug > 2)
+    if (is->method->debug > 5)
        logf (LOG_LOG, "isamd_pp_open  %p %d=%d:%d  sz=%d n=%d=%d:%d",
              pp, isamd_addr(pp->pos, pp->cat), pp->cat, pp->pos, pp->size, 
              pp->next, isamd_type(pp->next), isamd_block(pp->next) );
@@ -519,7 +510,7 @@ void isamd_buildfirstblock(ISAMD_PP pp){
   memcpy(dst, &pp->diffs, sizeof(pp->diffs));
   dst += sizeof(pp->diffs);  
   assert (dst - pp->buf  == ISAMD_BLOCK_OFFSET_1);
-  if (pp->is->method->debug > 2)
+  if (pp->is->method->debug > 5)
      logf (LOG_LOG, "isamd: first: sz=%d  p=%d/%d>%d/%d nk=%d d=%d",
            pp->size, 
            pp->cat, pp->pos, 
@@ -536,7 +527,7 @@ void isamd_buildlaterblock(ISAMD_PP pp){
   memcpy(dst, &pp->size,sizeof(pp->size));
   dst += sizeof(pp->size);
   assert (dst - pp->buf  == ISAMD_BLOCK_OFFSET_N);
-  if (pp->is->method->debug > 2)
+  if (pp->is->method->debug > 5)
      logf (LOG_LOG, "isamd: l8r: sz=%d  p=%d/%d>%d/%d",
            pp->size, 
            pp->pos, pp->cat, 
@@ -607,12 +598,10 @@ int isamd_read_main_item (ISAMD_PP pp, char **dst)
         /* assume block is non-empty */
         assert (src - pp->buf == ISAMD_BLOCK_OFFSET_N);
         assert (pp->next != isamd_addr(pp->pos,pp->cat));
-        //if (pp->deleteFlag)
-        //    isamd_release_block (is, pp->cat, pp->pos);
         (*is->method->code_reset)(pp->decodeClientData);
         (*is->method->code_item)(ISAMD_DECODE, pp->decodeClientData, dst, &src);
         pp->offset = src - pp->buf; 
-        if (is->method->debug > 2)
+        if (is->method->debug > 4)
             logf (LOG_LOG, "isamd: read_block size=%d %d %d next=%d",
                  pp->size, pp->cat, pp->pos, pp->next);
         return 2;
@@ -693,8 +682,8 @@ void isamd_pp_dump (ISAMD is, ISAMD_P ipos)
 
 /*
  * $Log: isamd.c,v $
- * Revision 1.7  1999-08-18 10:45:27  heikki
- * Another fix for the difflen problem.
+ * Revision 1.8  1999-08-18 13:28:16  heikki
+ * Set log levels to decent values
  *
  * Revision 1.6  1999/08/17 19:44:25  heikki
  * Fixed memory leaks
index ba70e7c..2444adb 100644 (file)
@@ -3,7 +3,7 @@
  * See the file LICENSE for details.
  * Heikki Levanto
  *
- * $Id: merge-d.c,v 1.11 1999-08-18 10:37:11 heikki Exp $
+ * $Id: merge-d.c,v 1.12 1999-08-18 13:28:17 heikki Exp $
  *
  * todo
  *  - Clean up log levels
  *  - single-entry optimizing
  *  - study and optimize block sizes (later)
  *  - Clean up the different ways diffs are handled in writing and reading
+ *  - Keep a merge-count in the firstpp, and if the block has already been
+ *    merged, reduce it to a larger size even if it could fit in a small one!
+ *  - Keep minimum freespace in the category table, and use that in reduce!
  *
  * bugs
+ *  - Still has not been able to run a complete long test on bagel!
  *
  * caveat
  *  There is a confusion about the block addresses. cat or type is the category,
  *  log levels (set isamd=x in zebra.cfg (or what ever cfg file you use) )
  *  NOT IMPLEMEMTED YET !!!
  *    0 = no logging. Default
- *    1 = Each call to isamd_append with start address and no more
- *    2 = Start and type of append, start of merge, and result of append
- *    3 = Block allocations
- *    4 = Block-level operations (read/write)
- *    5 = Details about diff blocks etc.
- *    6 = Log each record as it passes the system (once)
- *    7 = Log raw and (de)coded data
- *    8 = Anything else that may be useful
- *    9 = Anything needed toi hunt a specific bug
+ *    1 = no logging here. isamd logs overall statistics
+ *    2 = Each call to isamd_append with start address and no more
+ *    3 = Start and type of append, start of merge, and result of append
+ *    4 = Block allocations
+ *    5 = Block-level operations (read/write)
+ *    6 = Details about diff blocks etc.
+ *    7 = Log each record as it passes the system (once)
+ *    8 = Log raw and (de)coded data
+ *    9 = Anything else that may be useful
+ *   .. = Anything needed toi hunt a specific bug
+ *  (note that all tests in the code are like debug>3, which means 4 or above!)
  */
 
 #include <stdlib.h>
@@ -99,10 +105,10 @@ static void getDiffInfo(ISAMD_PP pp, int diffidx)
    int i=1;  /* [0] is used for the main data */
    int diffsz= maxinfos * sizeof(struct ISAMD_DIFF_s);
 
-   pp->diffinfo = xmalloc( diffsz );  /*!!!*/ /* does not always get freed */
+   pp->diffinfo = xmalloc( diffsz ); 
    memset(pp->diffinfo,'\0',diffsz);
-   if (pp->is->method->debug > 1)   //4
-     logf(LOG_LOG,"isamd_getDiffInfo: %d (%d:%d), ix=%d mx=%d",
+   if (pp->is->method->debug > 5)   
+      logf(LOG_LOG,"isamd_getDiffInfo: %d (%d:%d), ix=%d mx=%d",
          isamd_addr(pp->pos, pp->cat), pp->cat, pp->pos, diffidx,maxinfos);
    assert(pp->diffbuf);
 
@@ -110,7 +116,7 @@ static void getDiffInfo(ISAMD_PP pp, int diffidx)
    {  
       if ( diffidx+sizeof(int) > pp->is->method->filecat[pp->cat].bsize )
       {
-         if (pp->is->method->debug > 4)
+         if (pp->is->method->debug > 5)
            logf(LOG_LOG,"isamd_getDiffInfo:Near end (no room for len) at ix=%d n=%d",
                diffidx, i);
          return; /* whole block done */
@@ -121,7 +127,8 @@ static void getDiffInfo(ISAMD_PP pp, int diffidx)
         logf(LOG_LOG,"isamd_getDiffInfo: max=%d ix=%d dbuf=%p",
           pp->diffinfo[i].maxidx, diffidx, pp->diffbuf);
 
-      if (pp->diffinfo[i].maxidx > pp->is->method->filecat[pp->cat].bsize)
+      if ( (pp->is->method->debug > 0) &&
+         (pp->diffinfo[i].maxidx > pp->is->method->filecat[pp->cat].bsize) )
       { /* bug-hunting, this fails on some long runs that log too much */
          logf(LOG_LOG,"Bad MaxIx!!! %s:%d: diffidx=%d", 
                        __FILE__,__LINE__, diffidx);
@@ -135,7 +142,7 @@ static void getDiffInfo(ISAMD_PP pp, int diffidx)
 
       if (0==pp->diffinfo[i].maxidx)
       {
-         if (pp->is->method->debug > 1)  //!!! 4
+         if (pp->is->method->debug > 5)  //!!! 4
            logf(LOG_LOG,"isamd_getDiffInfo:End mark at ix=%d n=%d",
                diffidx, i);
          return; /* end marker */
@@ -143,7 +150,7 @@ static void getDiffInfo(ISAMD_PP pp, int diffidx)
       diffidx += sizeof(int);
       pp->diffinfo[i].decodeData = (*pp->is->method->code_start)(ISAMD_DECODE);
       pp->diffinfo[i].diffidx = diffidx;
-      if (pp->is->method->debug > 4)
+      if (pp->is->method->debug > 5)
         logf(LOG_LOG,"isamd_getDiff[%d]:%d-%d %s",
           i,diffidx-sizeof(int),pp->diffinfo[i].maxidx,
           hexdump((char *)&pp->diffbuf[diffidx-4],8,0) );
@@ -168,7 +175,7 @@ static void loadDiffs(ISAMD_PP pp)
       isamd_read_block (pp->is, isamd_type(diffaddr), 
                                 isamd_block(diffaddr), pp->diffbuf );
       diffidx= ISAMD_BLOCK_OFFSET_N; 
-      if (pp->is->method->debug > 1) //4 !!!
+      if (pp->is->method->debug > 4)
         logf(LOG_LOG,"isamd_LoadDiffs: loaded block %d=%d:%d, d=%d ix=%d",
           diffaddr, isamd_type(diffaddr),isamd_block(diffaddr), 
           pp->diffs,diffidx);
@@ -177,7 +184,7 @@ static void loadDiffs(ISAMD_PP pp)
    { /* integrated block, just set the pointers */
      pp->diffbuf = pp->buf;
      diffidx = pp->size;  /* size is the beginning of diffs, diffidx the end*/
-      if (pp->is->method->debug > 1)  // 4 !!!
+      if (pp->is->method->debug > 4)
         logf(LOG_LOG,"isamd_LoadDiffs: within %d=%d:%d, d=%d ix=%d ",
           isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos, pp->diffs, diffidx);
    }
@@ -188,13 +195,13 @@ static void loadDiffs(ISAMD_PP pp)
 void isamd_free_diffs(ISAMD_PP pp)
 {
   int i;
-  if (pp->is->method->debug > 4)
+  if (pp->is->method->debug > 5)
      logf(LOG_LOG,"isamd_free_diffs: pp=%p di=%p", pp, pp->diffinfo);
   if (!pp->diffinfo) 
     return;
   for (i=1;pp->diffinfo[i].decodeData;i++) 
   {
-      if (pp->is->method->debug > 4)
+      if (pp->is->method->debug > 8)
          logf(LOG_LOG,"isamd_free_diffs [%d]=%p",i, 
                        pp->diffinfo[i].decodeData);
       (*pp->is->method->code_stop)(ISAMD_DECODE,pp->diffinfo[i].decodeData);
@@ -228,7 +235,7 @@ int isamd_read_item (ISAMD_PP pp, char **dst)
      { /* 0 is special case, main data. */
         keyptr=(char*) &(pp->diffinfo[0].key);
         pp->diffinfo[0].mode = ! isamd_read_main_item(pp,&keyptr);
-        if (pp->is->method->debug > 4)
+        if (pp->is->method->debug > 7)
           logf(LOG_LOG,"isamd_read_item: read main %d.%d (%x.%x)",
             pp->diffinfo[0].key.sysno, pp->diffinfo[0].key.seqno,
             pp->diffinfo[0].key.sysno, pp->diffinfo[0].key.seqno);
@@ -236,7 +243,7 @@ int isamd_read_item (ISAMD_PP pp, char **dst)
      winner = 0;
      for (i=1; (!retry) && (pp->diffinfo[i].decodeData); i++)
      {
-        if (pp->is->method->debug > 4)
+        if (pp->is->method->debug > 8)
           logf(LOG_LOG,"isamd_read_item: considering d%d %d.%d ix=%d mx=%d",
                i, pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
                   pp->diffinfo[i].diffidx,   pp->diffinfo[i].maxidx);
@@ -251,7 +258,7 @@ int isamd_read_item (ISAMD_PP pp, char **dst)
            pp->diffinfo[i].diffidx += codeptr-codestart;
            pp->diffinfo[i].mode = pp->diffinfo[i].key.seqno & 1;
            pp->diffinfo[i].key.seqno = pp->diffinfo[i].key.seqno >>1 ;
-           if (pp->is->method->debug > 4)
+           if (pp->is->method->debug > 7)
              logf(LOG_LOG,"isamd_read_item: read diff[%d] %d.%d (%x.%x)",i,
                pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
                pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno);
@@ -263,7 +270,7 @@ int isamd_read_item (ISAMD_PP pp, char **dst)
             cmp=-1; /* end of main sequence, take all diffs */
           if (cmp<0)
           {
-             if (pp->is->method->debug > 4)
+             if (pp->is->method->debug > 8)
                logf(LOG_LOG,"isamd_read_item: ins %d<%d %d.%d (%x.%x) < %d.%d (%x.%x)",
                  i, winner,
                  pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
@@ -274,13 +281,13 @@ int isamd_read_item (ISAMD_PP pp, char **dst)
                winner = i;
              else
                assert(!"delete diff for nonexisting item");  
-               /* is an assert too steep here?*/
+               /* is an assert too steep here? Not really.*/
           } /* earlier key */
           else if (cmp==0)
           {
              if (!pp->diffinfo[i].mode) /* delete diff. should always be */
              {
-                if (pp->is->method->debug > 4)
+                if (pp->is->method->debug > 8)
                   logf(LOG_LOG,"isamd_read_item: del %d at%d %d.%d (%x.%x)",
                     i, winner,
                     pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
@@ -288,12 +295,13 @@ int isamd_read_item (ISAMD_PP pp, char **dst)
                 pp->diffinfo[winner].key.sysno=0; /* delete it */
              }
              else
-                if (pp->is->method->debug > 4)
+                if (pp->is->method->debug > 2)
                   logf(LOG_LOG,"isamd_read_item: duplicate ins %d at%d %d.%d (%x.%x)",
                     i, winner,
                     pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
                     pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno);
                 /* skip the insert, since we already have it in the base */
+                /* Should we fail an assertion here??? */
              pp->diffinfo[i].key.sysno=0; /* done with the delete */
              retry=1; /* start all over again */
           } /* matching key */
@@ -304,7 +312,7 @@ int isamd_read_item (ISAMD_PP pp, char **dst)
 
   if ( pp->diffinfo[winner].key.sysno)
   {
-    if (pp->is->method->debug > 4)
+    if (pp->is->method->debug > 7)
       logf(LOG_LOG,"isamd_read_item: got %d  %d.%d (%x.%x)",
         winner,
         pp->diffinfo[winner].key.sysno, pp->diffinfo[winner].key.seqno,
@@ -316,7 +324,7 @@ int isamd_read_item (ISAMD_PP pp, char **dst)
   } 
   else 
   {
-    if (pp->is->method->debug > 4)
+    if (pp->is->method->debug > 7)
       logf(LOG_LOG,"isamd_read_item: eof w=%d  %d.%d (%x.%x)",
         winner,
         pp->diffinfo[winner].key.sysno, pp->diffinfo[winner].key.seqno,
@@ -338,14 +346,14 @@ static void isamd_reduceblock(ISAMD_PP pp)
 {
    if (pp->pos)
       return; /* existing block, do not touch */
-   if (pp->is->method->debug > 1)  // 2 !!!
+   if (pp->is->method->debug > 5)  
      logf(LOG_LOG,"isamd_reduce: start p=%d c=%d sz=%d",
        pp->pos, pp->cat, pp->size); 
    while ( ( pp->cat > 0 ) && (!pp->next) && 
            (pp->offset < pp->is->method->filecat[pp->cat-1].bsize ) )
       pp->cat--;
    pp->pos = isamd_alloc_block(pp->is, pp->cat);
-   if (pp->is->method->debug > 1) // 2 !!!
+   if (pp->is->method->debug > 5) 
      logf(LOG_LOG,"isamd_reduce:  got  p=%d c=%d sz=%d",
        pp->pos, pp->cat, pp->size);    
 } /* reduceblock */
@@ -396,7 +404,7 @@ static ISAMD_PP read_diff_block(ISAMD_PP firstpp, int* p_diffidx)
          pp->pos = isamd_alloc_block(pp->is, pp->cat);
          firstpp->diffs = pp->pos*2 +1;
          diffidx = pp->size = pp->offset = ISAMD_BLOCK_OFFSET_N;
-         if (pp->is->method->debug >3) 
+         if (pp->is->method->debug >5) 
              logf(LOG_LOG,"isamd_appd: alloc diff  (d=%d) %d=%d:%d ix=%d",
                    firstpp->diffs,
                    isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos, 
@@ -410,7 +418,7 @@ static ISAMD_PP read_diff_block(ISAMD_PP firstpp, int* p_diffidx)
         while ( ( i < pp->is->method->filecat[pp->cat].bsize) && 
                 ( i <= diffidx + sizeof(int)))
             pp->buf[i++]='\0';
-        if (pp->is->method->debug >1) //!!! 3
+        if (pp->is->method->debug >5) 
              logf(LOG_LOG,"isamd_appd: set up diffhead  (d=%d) %d=%d:%d ix=%d",
                    firstpp->diffs,
                    isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos, 
@@ -423,7 +431,7 @@ static ISAMD_PP read_diff_block(ISAMD_PP firstpp, int* p_diffidx)
       { /* diffs in a separate block, load it */
         pp=isamd_pp_open(pp->is, isamd_addr(firstpp->diffs/2,pp->cat));
         diffidx = pp->offset= pp->size;
-        if (pp->is->method->debug >1)  // 3 !!! 
+        if (pp->is->method->debug >5) 
            logf(LOG_LOG,"isamd_appd: loaded diff (d=%d) %d=%d:%d ix=%d",
                  firstpp->diffs,
                  isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos, 
@@ -432,7 +440,7 @@ static ISAMD_PP read_diff_block(ISAMD_PP firstpp, int* p_diffidx)
       else
       { /* diffs within the nead */
          diffidx= pp->diffs/2;
-         if (pp->is->method->debug >1)  // 3 !!! 
+         if (pp->is->method->debug >5)  
             logf(LOG_LOG,"isamd_appd: diffs in head d=%d %d=%d:%d ix=%d sz=%d",
                      pp->diffs,
                      isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos, 
@@ -470,7 +478,7 @@ static ISAMD_PP get_new_main_block( ISAMD_PP firstpp, ISAMD_PP pp)
       pp->size = pp->offset = ISAMD_BLOCK_OFFSET_N; 
       pp->next=0;
       if (pp->is->method->debug >3) 
-         logf(LOG_LOG,"isamd_build: Alloc2 f=%d (%d:%d) n=%d(%d:%d)",
+         logf(LOG_LOG,"isamd_g_mainblk: Alloc2 f=%d=%d:%d n=%d=%d:%d",
             isamd_addr(firstpp->pos,firstpp->cat), 
             firstpp->cat, firstpp->pos,
             isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos );
@@ -480,7 +488,7 @@ static ISAMD_PP get_new_main_block( ISAMD_PP firstpp, ISAMD_PP pp)
       newblock = isamd_alloc_block(pp->is, firstpp->cat);
       pp->next = isamd_addr(newblock,firstpp->cat);
       if (pp->is->method->debug >3) 
-         logf(LOG_LOG,"isamd_build: Alloc new after p=%d=%d:%d  n=%d=%d:%d",
+         logf(LOG_LOG,"isamd_build: Alloc1 after p=%d=%d:%d->%d=%d:%d",
             isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos,
             isamd_addr(newblock,pp->cat), pp->cat, newblock );
       isamd_buildlaterblock(pp);
@@ -488,7 +496,6 @@ static ISAMD_PP get_new_main_block( ISAMD_PP firstpp, ISAMD_PP pp)
       pp->size = pp->offset = ISAMD_BLOCK_OFFSET_N;
       pp->next=0;
       pp->cat = firstpp->cat;
-//      pp->pos = isamd_block(firstpp->next); /* ???? FIRSTPP ???? */
       pp->pos = newblock;
       pp->cat = firstpp->cat; /* is already, never mind */
    }
@@ -515,7 +522,7 @@ static ISAMD_PP  append_main_item(ISAMD_PP firstpp,
    (*pp->is->method->code_item)(ISAMD_ENCODE, encoder_data, &c_ptr, &i_ptr);
    codelen = c_ptr - codebuff;
    assert ( (codelen<128) && (codelen>0));
-   if (pp->is->method->debug >3)
+   if (pp->is->method->debug >7)
       logf(LOG_LOG,"isamd:build: coded into %s  (nk=%d)",
           hexdump(codebuff, c_ptr-codebuff,hexbuff), firstpp->numKeys+1);
 
@@ -529,7 +536,7 @@ static ISAMD_PP  append_main_item(ISAMD_PP firstpp,
       (*pp->is->method->code_item)(ISAMD_ENCODE, encoder_data, &c_ptr, &i_ptr);
       codelen = c_ptr - codebuff;
       assert ( (codelen<128) && (codelen>0));
-      if (pp->is->method->debug >3)
+      if (pp->is->method->debug >7)
          logf(LOG_LOG,"isamd:build: recoded into %s  (nk=%d)",
              hexdump(codebuff, c_ptr-codebuff,hexbuff), firstpp->numKeys+1);
    } /* block full */    
@@ -568,10 +575,10 @@ static int isamd_build_first_block(ISAMD is, ISAMD_I data)
    
    encoder_data=(*is->method->code_start)(ISAMD_ENCODE);
    
-   if (is->method->debug >3)
-      logf(LOG_LOG,"isamd_bld start: p=%d c=%d sz=%d maxsz=%d ",
-         pp->pos, pp->cat, pp->size, 
-         pp->is->method->filecat[pp->is->max_cat].bsize); 
+   if (is->method->debug >2)
+      logf(LOG_LOG,"isamd_bld start: p=%d=%d:%d sz=%d maxsz=%d ",
+         isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos, 
+         pp->size, pp->is->method->filecat[pp->is->max_cat].bsize); 
 
    /* read first input */
    i_ptr = i_item;
@@ -579,7 +586,7 @@ static int isamd_build_first_block(ISAMD is, ISAMD_I data)
    if (i_more)
      assert( i_ptr-i_item == sizeof(i_key) );
 
-   if (pp->is->method->debug >3)
+   if (pp->is->method->debug >7)
       logf(LOG_LOG,"isamd: build_fi start: m=%d %s",
          i_mode, hexdump(i_item,i_ptr-i_item,hexbuff) );
 
@@ -594,8 +601,8 @@ static int isamd_build_first_block(ISAMD is, ISAMD_I data)
       i_ptr = i_item;
       i_more = (*data->read_item)(data->clientData, &i_ptr, &i_mode); 
       
-      if ( (i_more) && (pp->is->method->debug >3) )
-         logf(LOG_LOG,"isamd: build_fi start: m=%d %s",
+      if ( (i_more) && (pp->is->method->debug >7) )
+         logf(LOG_LOG,"isamd: build_fi read: m=%d %s",
             i_mode, hexdump(i_item,i_ptr-i_item,hexbuff) );
       
    } /* i_more */
@@ -635,11 +642,12 @@ static int merge ( ISAMD_PP *p_firstpp,   /* first pp of the chain */
      readpp->diffbuf= xmalloc( diffidx); /* copy diffs to where read wants*/
      memcpy( readpp->diffbuf, &((*p_pp)->buf[0]), diffidx);
      diffidx = ISAMD_BLOCK_OFFSET_N;
-     if (readpp->is->method->debug >1) {  //!!! 3
-         logf(LOG_LOG,"isamd_merge:separate diffs at ix=%d", 
-                 diffidx);
-         logf(LOG_LOG,"isamd_merge: dbuf=%p (from %p) pp=%p", 
-                  readpp->diffbuf, &((*p_pp)->buf[0]), (*p_pp) );
+     if (readpp->is->method->debug >2) 
+     { 
+        logf(LOG_LOG,"isamd_merge:separate diffs at ix=%d", 
+                diffidx);
+        logf(LOG_LOG,"isamd_merge: dbuf=%p (from %p) pp=%p", 
+                 readpp->diffbuf, &((*p_pp)->buf[0]), (*p_pp) );
      }
   }
   else
@@ -648,13 +656,13 @@ static int merge ( ISAMD_PP *p_firstpp,   /* first pp of the chain */
      diffidx=readpp->size;
      readpp->diffs = diffidx*2+0;
      readpp->diffbuf=readpp->buf; 
-     if (readpp->is->method->debug >1)  //!!! 3 
+     if (readpp->is->method->debug >2)  
          logf(LOG_LOG,"isamd_merge:local diffs at %d: %s", 
            diffidx,hexdump(&(readpp->diffbuf[diffidx]),8,0));
   }
 
   getDiffInfo(readpp,diffidx);
-  if (readpp->is->method->debug >3) 
+  if (readpp->is->method->debug >8) 
          logf(LOG_LOG,"isamd_merge: diffinfo=%p", readpp->diffinfo);
   
 
@@ -662,7 +670,7 @@ static int merge ( ISAMD_PP *p_firstpp,   /* first pp of the chain */
   {  /* we had a separate diff block, release it, we have copied the data */
      isamd_release_block(readpp->is, readpp->cat, killblk);
      isamd_pp_close (*p_pp);
-     if (readpp->is->method->debug >1)  // 3 !!! 
+     if (readpp->is->method->debug >3)  
          logf(LOG_LOG,"isamd_merge: released diff block %d=%d:%d",
               isamd_addr(killblk,readpp->cat), readpp->cat, killblk );
   }
@@ -672,7 +680,7 @@ static int merge ( ISAMD_PP *p_firstpp,   /* first pp of the chain */
   killblk=readpp->pos;
   assert(killblk);
   isamd_release_block(readpp->is, readpp->cat, killblk);
-  if (readpp->is->method->debug >1)  //!!! 3 
+  if (readpp->is->method->debug >3)   
       logf(LOG_LOG,"isamd_merge: released old firstblock %d (%d:%d)",
                isamd_addr(killblk,readpp->cat), readpp->cat, killblk );
 
@@ -684,7 +692,7 @@ static int merge ( ISAMD_PP *p_firstpp,   /* first pp of the chain */
     /* pray that is not a delete as well... */
     r_key.sysno = 0;
     r_key.seqno = 0;
-     if (readpp->is->method->debug >1) 
+     if (readpp->is->method->debug >3) 
          logf(LOG_LOG,"isamd_merge:all data has been deleted (nk=%d) ",
             readpp->numKeys);
     assert (readpp->numKeys == 0);
@@ -698,14 +706,14 @@ static int merge ( ISAMD_PP *p_firstpp,   /* first pp of the chain */
   
   while (r_more)
   {
-     if (readpp->is->method->debug >4) 
+     if (readpp->is->method->debug >6) 
          logf(LOG_LOG,"isamd_merge: got key %d.%d",
            r_key.sysno, r_key.seqno );
      pp= append_main_item(firstpp, pp, &r_key, encoder_data);
 
      if ( (readpp->pos != killblk ) && (0!=readpp->pos) )
      {  /* pos can get to 0 at end of main seq, if still diffs left...*/
-        if (readpp->is->method->debug >1) //!!! 3 
+        if (readpp->is->method->debug >3)  
             logf(LOG_LOG,"isamd_merge: released block %d (%d:%d) now %d=%d:%d",
                 isamd_addr(killblk,readpp->cat), readpp->cat, killblk,
                 isamd_addr(readpp->pos,readpp->cat),readpp->cat, readpp->pos );
@@ -722,20 +730,20 @@ static int merge ( ISAMD_PP *p_firstpp,   /* first pp of the chain */
   /* TODO: while pkey is an insert, and after last key inserted, append it */
   /* will prevent multiple merges on large insert runs */  
 
-  /* set things up so that merge can continue */
+  /* set things up so that append can continue */
   isamd_reduceblock(firstpp);
   firstpp->diffs=0; 
 
   if (firstpp!=pp) 
   { /* the last data block is of no interest any more */
     save_last_pp(pp);
-    if (readpp->is->method->debug >1) 
+    if (readpp->is->method->debug >4) 
         logf(LOG_LOG,"isamd_merge: saved last block %d=%d:%d",
               isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos);
     isamd_pp_close(pp);
   }
 
-  if (readpp->is->method->debug >3) 
+  if (readpp->is->method->debug >5) 
         logf(LOG_LOG,"isamd_merge: closing readpp %d=%d:%d di=%p",
               isamd_addr(readpp->pos,readpp->cat), readpp->cat, readpp->pos,
               readpp->diffinfo);
@@ -745,7 +753,7 @@ static int merge ( ISAMD_PP *p_firstpp,   /* first pp of the chain */
   
   *p_firstpp = firstpp; 
 
-  if (readpp->is->method->debug >1)   //!!! 3
+  if (readpp->is->method->debug >2)  
       logf(LOG_LOG,"isamd_merge: merge ret  %d=%d:%d nx=%d=%d:%d d=%d=2*%d+%d",
             isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos,
             pp->next, isamd_type(pp->next), isamd_block(pp->next),
@@ -783,7 +791,7 @@ static int append_diffs(ISAMD is, ISAMD_P ipos, ISAMD_I data)
    int merge_rc;
 
    firstpp=isamd_pp_open(is, ipos);
-   if (is->method->debug >1)  //!!! 3
+   if (is->method->debug >2) 
       logf(LOG_LOG,"isamd_appd: Start ipos=%d=%d:%d d=%d=%d*2+%d nk=%d",
         ipos, isamd_type(ipos), isamd_block(ipos),
         firstpp->diffs, firstpp->diffs/2, firstpp->diffs & 1, firstpp->numKeys);
@@ -798,7 +806,7 @@ static int append_diffs(ISAMD is, ISAMD_P ipos, ISAMD_I data)
    i_ptr = i_item;
    i_more = (*data->read_item)(data->clientData, &i_ptr, &i_mode); 
 
-   if (is->method->debug >3)
+   if (is->method->debug >6)
       logf(LOG_LOG,"isamd_appd: start with m=%d %s",
          i_mode, hexdump(i_item,i_ptr-i_item,hexbuff) );
 
@@ -813,7 +821,7 @@ static int append_diffs(ISAMD is, ISAMD_P ipos, ISAMD_I data)
       (*is->method->code_item)(ISAMD_ENCODE, encoder_data, &c_ptr, &i_ptr);
       codelen = c_ptr - codebuff;
       assert ( (codelen<128) && (codelen>0));
-      if (is->method->debug >3)
+      if (is->method->debug >7)
          logf(LOG_LOG,"isamd_appd: coded into %d: %s (nk=%d) (ix=%d)",
              codelen, hexdump(codebuff, codelen,hexbuff), 
              firstpp->numKeys,diffidx);
@@ -823,7 +831,7 @@ static int append_diffs(ISAMD is, ISAMD_P ipos, ISAMD_I data)
          if (is->method->debug >3)
             logf(LOG_LOG,"isamd_appd: block full (ix=%d mx=%d lix=%d)",
                diffidx, maxsize, difflenidx);
-         if (is->method->debug >5)
+         if (is->method->debug >8)
             logf(LOG_LOG,"isamd_appd: block pp=%p buf=%p [%d]:%s",
                pp, pp->buf, 
                difflenidx, hexdump(&pp->buf[difflenidx],8,0));
@@ -844,7 +852,7 @@ static int append_diffs(ISAMD is, ISAMD_P ipos, ISAMD_I data)
          (*is->method->code_item)(ISAMD_ENCODE, encoder_data, &c_ptr, &i_ptr);
          codelen = c_ptr - codebuff;
          assert ( (codelen<128) && (codelen>0));
-         if (is->method->debug >3)
+         if (is->method->debug >7)
             logf(LOG_LOG,"isamd_appd: recoded into %d: %s (nk=%d) (ix=%d)",
                 codelen, hexdump(codebuff, codelen,hexbuff), 
                 firstpp->numKeys,diffidx);
@@ -869,7 +877,7 @@ static int append_diffs(ISAMD is, ISAMD_P ipos, ISAMD_I data)
       /* (try to) read the next input */
       i_ptr = i_item;
       i_more = (*data->read_item)(data->clientData, &i_ptr, &i_mode); 
-      if ( (i_more) && (is->method->debug >3) )
+      if ( (i_more) && (is->method->debug >6) )
          logf(LOG_LOG,"isamd_appd: got m=%d %s",
             i_mode, hexdump(i_item,i_ptr-i_item,hexbuff) );
    } /* more loop */
@@ -916,7 +924,10 @@ ISAMD_P isamd_append (ISAMD is, ISAMD_P ipos, ISAMD_I data)
 
 /*
  * $Log: merge-d.c,v $
- * Revision 1.11  1999-08-18 10:37:11  heikki
+ * Revision 1.12  1999-08-18 13:28:17  heikki
+ * Set log levels to decent values
+ *
+ * Revision 1.11  1999/08/18 10:37:11  heikki
  * Fixed (another) difflen bug
  *
  * Revision 1.10  1999/08/18 09:13:31  heikki