From ae14be135d7d1a0b8d428977d5e6d4d03c660b3b Mon Sep 17 00:00:00 2001 From: Heikki Levanto Date: Wed, 4 Aug 1999 14:21:18 +0000 Subject: [PATCH] isam-d seems to be working. --- isamc/isamd.c | 26 +++++++++---- isamc/merge-d.c | 109 +++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 87 insertions(+), 48 deletions(-) diff --git a/isamc/isamd.c b/isamc/isamd.c index f3f219a..78d2dbc 100644 --- a/isamc/isamd.c +++ b/isamc/isamd.c @@ -28,20 +28,23 @@ static void init_fc (ISAMD is, int cat); #define ISAMD_FREELIST_CHUNK 1 -#define SMALL_TEST 1 +#define SMALL_TEST 0 ISAMD_M isamd_getmethod (ISAMD_M me) { static struct ISAMD_filecat_s def_cat[] = { #if SMALL_TEST -/* blocksz, max keys before switching size */ +/* blocksz, max keys before switching size. Unused time being */ { 32, 40 }, { 128, 0 }, #else - { 24, 40 }, - { 2048, 2048 }, - { 16384, 0 }, - + { 24, 1 }, + { 32, 1 }, + { 64, 1 }, + { 128, 1 }, + { 256, 1 }, + { 1024, 1 }, + { 2048, 0 }, #endif /* old values from isamc, long time ago... @@ -101,8 +104,10 @@ ISAMD isamd_open (BFiles bfs, const char *name, int writeflag, ISAMD_M method) } while (filecat[i++].mblocks); is->no_files = i; is->max_cat = --i; - + assert (is->no_files > 0); + 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) { @@ -397,6 +402,8 @@ void isamd_release_block (ISAMD is, int cat, int pos) { if (is->method->debug > 3) logf (LOG_LOG, "isamd: release_block in cat %d: %d", cat, pos); + assert(pos!=0); + if (is->files[cat].fc_list) { int j; @@ -679,7 +686,10 @@ void isamd_pp_dump (ISAMD is, ISAMD_P ipos) /* * $Log: isamd.c,v $ - * Revision 1.3 1999-07-21 14:24:50 heikki + * Revision 1.4 1999-08-04 14:21:18 heikki + * isam-d seems to be working. + * + * Revision 1.3 1999/07/21 14:24:50 heikki * isamd write and read functions ok, except when diff block full. * (merge not yet done) * diff --git a/isamc/merge-d.c b/isamc/merge-d.c index 9f54c54..4d43713 100644 --- a/isamc/merge-d.c +++ b/isamc/merge-d.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Heikki Levanto * - * $Id: merge-d.c,v 1.6 1999-07-23 15:43:05 heikki Exp $ + * $Id: merge-d.c,v 1.7 1999-08-04 14:21:18 heikki Exp $ * * todo * - merge when needed @@ -439,12 +439,18 @@ static ISAMD_PP get_new_main_block( ISAMD_PP firstpp, ISAMD_PP pp) { /* it was not the first block */ 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", + isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos, + isamd_addr(newblock,pp->cat), pp->cat, newblock ); isamd_buildlaterblock(pp); isamd_write_block(pp->is,pp->cat,pp->pos,pp->buf); pp->size = pp->offset = ISAMD_BLOCK_OFFSET_N; pp->next=0; pp->cat = firstpp->cat; - pp->pos = isamd_block(firstpp->next); +// pp->pos = isamd_block(firstpp->next); /* ???? FIRSTPP ???? */ + pp->pos = newblock; + pp->cat = firstpp->cat; /* is already, never mind */ } return pp; } /* get_new_main_block */ @@ -574,16 +580,8 @@ static int merge ( ISAMD_PP *p_firstpp, /* first pp of the chain */ /* set up diffs as they should be for reading */ readpp->offset= ISAMD_BLOCK_OFFSET_1; - if (*p_pp == *p_firstpp) - { /* integrated diffs */ - diffidx=readpp->size; - readpp->diffs = diffidx*2+0; - readpp->diffbuf=readpp->buf; /*? does this get freed right ??? */ - if (readpp->is->method->debug >3) - logf(LOG_LOG,"isamd_merge:local diffs at %d: %s", - diffidx,hexdump(&(readpp->diffbuf[diffidx]),8,0)); - } - else +// if (*p_pp == *p_firstpp) /* not the way to check it !! */ + if ( (*p_firstpp)->diffs & 1 ) { /* separate diff block in *p_pp */ killblk = readpp->diffs/2; diffidx = readpp->is->method->filecat[readpp->cat].bsize; @@ -597,8 +595,36 @@ static int merge ( ISAMD_PP *p_firstpp, /* first pp of the chain */ readpp->diffbuf, &((*p_pp)->buf[0]), (*p_pp) ); } } + else + { /* integrated diffs */ + assert ( *p_pp == *p_firstpp ); /* can only be in the first block */ + diffidx=readpp->size; + readpp->diffs = diffidx*2+0; + readpp->diffbuf=readpp->buf; /*? does this get freed right?? */ + if (readpp->is->method->debug >3) + logf(LOG_LOG,"isamd_merge:local diffs at %d: %s", + diffidx,hexdump(&(readpp->diffbuf[diffidx]),8,0)); + } + getDiffInfo(readpp,diffidx); + if (killblk) + { /* we had a separate diff block, release it, we have the data */ + isamd_release_block(readpp->is, readpp->cat, killblk); + 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 ); + } + + + /* release our data block. Do before reading, when pos is stable! */ + killblk=readpp->pos; + assert(killblk); + isamd_release_block(readpp->is, readpp->cat, killblk); + 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 ); + r_ptr= (char *) &r_key; r_more = isamd_read_item( readpp, &r_ptr); if (!r_more) @@ -613,19 +639,7 @@ static int merge ( ISAMD_PP *p_firstpp, /* first pp of the chain */ assert (readpp->numKeys == 0); } - if (killblk) - { /* we had a separate diff block, release it, we have the data */ - isamd_release_block(readpp->is, readpp->cat, killblk); - 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 ); - } - killblk=readpp->pos; - isamd_release_block(readpp->is, readpp->cat, killblk); - 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 ); - + /* set up the new blocks for simple writing */ firstpp=pp=isamd_pp_open(readpp->is,isamd_addr(0, readpp->is->max_cat)); firstpp->size = firstpp->offset = ISAMD_BLOCK_OFFSET_1; @@ -638,12 +652,13 @@ static int merge ( ISAMD_PP *p_firstpp, /* first pp of the chain */ r_key.sysno, r_key.seqno ); pp= append_main_item(firstpp, pp, &r_key, encoder_data); - if ( readpp->pos != killblk ) - { - isamd_release_block(readpp->is, readpp->cat, readpp->pos); + 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 >3) - logf(LOG_LOG,"isamd_merge: released data block %d (%d:%d)", - killblk, isamd_type(killblk), isamd_block(killblk) ); + 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 ); + isamd_release_block(readpp->is, readpp->cat, readpp->pos); killblk=readpp->pos; } @@ -705,9 +720,9 @@ static int append_diffs(ISAMD is, ISAMD_P ipos, ISAMD_I data) firstpp=isamd_pp_open(is, ipos); if (is->method->debug >4) - logf(LOG_LOG,"isamd_appd: Start ipos=%d=%d:%d d=%d=%d*2+%d", + 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->diffs, firstpp->diffs/2, firstpp->diffs & 1, firstpp->numKeys); pp=read_diff_block(firstpp, &diffidx); encoder_data=(*is->method->code_start)(ISAMD_ENCODE); maxsize = is->method->filecat[pp->cat].bsize; @@ -749,15 +764,26 @@ static int append_diffs(ISAMD is, ISAMD_P ipos, ISAMD_I data) pp, pp->buf, difflenidx, hexdump(&pp->buf[difflenidx],8,0)); merge_rc = merge (&firstpp, &pp, &i_key); - if (merge_rc) + if (0!=merge_rc) return merge_rc; /* merge handled them all ! */ - /* set things up so we can continue */ - pp = read_diff_block(firstpp, &diffidx); - (*is->method->code_reset)(encoder_data); - maxsize = is->method->filecat[pp->cat].bsize; - difflenidx=diffidx; - diffidx+=sizeof(int); + /* set things up so we can continue */ + pp = read_diff_block(firstpp, &diffidx); + (*is->method->code_reset)(encoder_data); + maxsize = is->method->filecat[pp->cat].bsize; + difflenidx=diffidx; + diffidx+=sizeof(int); + + /* code the current input key again */ + c_ptr=codebuff; + i_ptr=i_item; + (*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) + logf(LOG_LOG,"isamd_appd: recoded into %d: %s (nk=%d) (ix=%d)", + codelen, hexdump(codebuff, codelen,hexbuff), + firstpp->numKeys,diffidx); } /* block full */ @@ -814,7 +840,10 @@ ISAMD_P isamd_append (ISAMD is, ISAMD_P ipos, ISAMD_I data) /* * $Log: merge-d.c,v $ - * Revision 1.6 1999-07-23 15:43:05 heikki + * Revision 1.7 1999-08-04 14:21:18 heikki + * isam-d seems to be working. + * + * Revision 1.6 1999/07/23 15:43:05 heikki * Hunted a few bugs in isam-d. Still crashes on the long test run * * Revision 1.5 1999/07/23 13:58:52 heikki -- 1.7.10.4