Fixed update-bug
[idzebra-moved-to-github.git] / isam / physical.c
index 9dccb47..d8883f1 100644 (file)
@@ -4,7 +4,17 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: physical.c,v $
- * Revision 1.7  1995-12-06 14:48:27  quinn
+ * Revision 1.10  1996-03-19 19:22:44  quinn
+ * Fixed update-bug
+ *
+ * Revision 1.9  1996/02/06  10:19:57  quinn
+ * Attempt at fixing bug. Not all blocks were read before they were unlinked
+ * prior to a remap operation.
+ *
+ * Revision 1.8  1996/01/29  09:47:11  quinn
+ * Fixed mean little bug in the read-table code.
+ *
+ * Revision 1.7  1995/12/06  14:48:27  quinn
  * Fixed some strange bugs.
  *
  * Revision 1.6  1995/09/04  12:33:47  adam
@@ -78,7 +88,7 @@ int is_p_read_partial(is_mtable *tab, is_mblock *block)
     is_mbuf *buf;
 
     assert(block->state == IS_MBSTATE_UNREAD);
-    block->data = buf =  xmalloc_mbuf(IS_MBUF_TYPE_LARGE);
+    block->data = buf = xmalloc_mbuf(IS_MBUF_TYPE_LARGE);
     toread = tab->is->types[tab->pos_type].blocksize;
     if (toread > is_mbuf_size[buf->type])
     {
@@ -113,7 +123,7 @@ int is_p_read_partial(is_mtable *tab, is_mblock *block)
        block->state = IS_MBSTATE_CLEAN;
     }
     else
-       block->bread = buf->num * is_keysize(tab->is);
+       block->bread = buf->offset + buf->num * is_keysize(tab->is);
     return 0;
 }
 
@@ -201,6 +211,7 @@ void is_p_sync(is_mtable *tab)
        {
            memcpy(type->dbuf + sum, b->data + b->offset, v = b->num *
                is_keysize(tab->is));
+
            sum += v;
            assert(sum <= type->blocksize);
        }
@@ -221,11 +232,13 @@ void is_p_unmap(is_mtable *tab)
     is_mblock *p;
 
     for (p = tab->data; p; p = p->next)
+    {
        if (p->diskpos >= 0)
        {
            is_freestore_free(tab->is, tab->pos_type, p->diskpos);
            p->diskpos = -1;
        }
+    }
 }
 
 static is_mbuf *mbuf_takehead(is_mbuf **mb, int *num, int keysize)
@@ -288,8 +301,26 @@ void is_p_align(is_mtable *tab)
            else
            {
                tab->data = tab->data->next;
-               tab->data->state = IS_MBSTATE_DIRTY;
                next = tab->data;
+               if (next)
+               {
+                   if (next->state < IS_MBSTATE_CLEAN)
+                   {
+                       if (is_p_read_full(tab, next) < 0)
+                       {
+                           logf(LOG_FATAL, "Error during re-alignment");
+                           abort();
+                       }
+                       if (next->nextpos && !next->next)
+                       {
+                           next->next = xmalloc_mblock();
+                           next->next->diskpos = next->nextpos;
+                           next->next->state = IS_MBSTATE_UNREAD;
+                           next->next->data = 0;
+                       }
+                   }
+                   next->state = IS_MBSTATE_DIRTY; /* force re-process */
+               }
            }
            if (mblock->diskpos >= 0)
                is_freestore_free(tab->is, tab->pos_type, mblock->diskpos);