Fix a bug where second-half of block in leaf split could become
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 18 Mar 2005 12:05:11 +0000 (12:05 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 18 Mar 2005 12:05:11 +0000 (12:05 +0000)
larger than max block size.

isamb/isamb.c
isamb/tstisamb.c

index 675c21e..8245f98 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: isamb.c,v 1.73 2005-03-08 14:02:15 adam Exp $
+/* $Id: isamb.c,v 1.74 2005-03-18 12:05:11 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -966,17 +966,29 @@ int insert_leaf (ISAMB b, struct ISAMB_block **sp1, void *lookahead_item,
             }
         }
     }
-    maxp = dst_buf + b->file[b->no_cat-1].head.block_max + quater;
+
     /* this loop runs when we are "appending" to a leaf page. That is
        either it's empty (new) or all file items have been read in
        previous loop */
+
+    /* determine maximum ptr for tail */
+    if (half2)
+    {
+       /* split already. No more splits - fill up to one full (Extra) block */
+       maxp = half2 + b->file[b->no_cat-1].head.block_max;
+    }
+    else
+    {
+       /* no split. Fill up to 1+1/4 block */
+       maxp = dst_buf + b->file[b->no_cat-1].head.block_max + quater;
+    }
     while (lookahead_item)
     {
         char *dst_item;
        const char *src = lookahead_item;
         char *dst_0 = dst;
         
-       /* compare lookahead with max item */
+       /* if we have a lookahead item, we stop if we exceed the value of it */
         if (max_item &&
             (*b->method->compare_item)(max_item, lookahead_item) <= 0)
         {
index c2e2024..5a07f57 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: tstisamb.c,v 1.17 2005-01-16 23:38:34 adam Exp $
+/* $Id: tstisamb.c,v 1.18 2005-03-18 12:05:11 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -229,6 +229,29 @@ void tst_forward(ISAMB isb, int n)
     isamb_unlink(isb, isamc_p);
 }
 
+void tst_append(ISAMB isb, int n)
+{
+    ISAMC_I isamc_i;
+    ISAMB_P isamb_p = 0;
+    struct read_info ri;
+    int i;
+    int chunk = 10;
+
+    for (i = 0; i < n; i += chunk)
+    {
+       /* insert a number of entries */
+       ri.no = 0;
+       ri.step = 1;
+       ri.max = i + chunk;
+       ri.insertMode = 1;
+       
+       isamc_i.clientData = &ri;
+       isamc_i.read_item = code_read;
+       
+       isamb_p = isamb_merge (isb, isamb_p , &isamc_i);
+    }
+}
+
 int main(int argc, char **argv)
 {
     BFiles bfs;
@@ -270,7 +293,10 @@ int main(int argc, char **argv)
     tst_insert(isb, 100);
     tst_insert(isb, 500);
     tst_insert(isb, 10000);
+
     tst_forward(isb, 10000);
+
+    tst_append(isb, 10000);
     /* close isam handle */
     isamb_close(isb);