ed553df638b4cd7686023758c7e97a73801a8bdb
[idzebra-moved-to-github.git] / isamc / merge-d.c
1 /*
2  * Copyright (c) 1996-1998, Index Data.
3  * See the file LICENSE for details.
4  * Heikki Levanto
5  *
6  * $Id: merge-d.c,v 1.24 1999-10-05 09:57:40 heikki Exp $
7  *
8  * bugs
9  *  sinleton-bit has to be in the high end, not low, so as not to confuse
10  *  ordinary small numbers, like in the next pointer..
11  *
12  * missing
13  *
14  * optimize
15  *  - study and optimize block sizes (later)
16  *  - find a way to decide the size of an empty diffblock (after merge)
17  *  - On allocating more blocks (in append and merge), check the order of 
18  *    blocks, and if needed, swap them. 
19  *  - Write a routine to save/load indexes into a block, save only as many 
20  *    bytes as needed (size, diff, diffindexes)
21  *
22  *
23  * caveat
24  *  There is a confusion about the block addresses. cat or type is the category,
25  *  pos or block is the block number. pp structures keep these two separate,
26  *  and combine when saving the pp. The next pointer in the pp structure is
27  *  also a combined address, but needs to be combined every time it is needed,
28  *  and separated when the partss are needed... This is done with the isamd_
29  *  _block, _type, and _addr macros. The _addr takes block and type as args,
30  *  in that order. This conflicts with the order these are often mentioned in 
31  *  the debug log calls, and other places, leading to small mistakes here
32  *  and there. 
33  *
34  *  Needs cleaning! The way diff blocks are handled in append and reading is
35  *  quite different, and likely to give maintenance problems.
36  *
37  *  log levels (set isamddebug=x in zebra.cfg (or what ever cfg file you use) )
38  *    0 = no logging. Default
39  *    1 = no logging here. isamd logs overall statistics
40  *    2 = Each call to isamd_append with start address and no more
41  *    3 = Start and type of append, start of merge, and result of append
42  *    4 = Block allocations
43  *    5 = Block-level operations (read/write)
44  *    6 = Details about diff blocks etc.
45  *    7 = Log each record as it passes the system (once)
46  *    8 = Log raw and (de)coded data
47  *    9 = Anything else that may be useful
48  *   .. = Anything needed to hunt a specific bug
49  *  (note that all tests in the code are like debug>3, which means 4 or above!)
50  *
51  * Design for the new and improved isamd
52  * Key points:
53  *  - The first block is only diffs, no straight data
54  *  - Additional blocks are straight data
55  *  - When a diff block gets filled up, a data block is created by
56  *    merging the diffs with the data
57  *
58  * Structure
59  *  - Isamd_pp: buffer for diffs and for data
60  *              keep both pos, type, and combined address
61  *              routine to set the address
62  *  - diffbuf: lengths as short ints, or bytes for small blocks
63  *  - keys are of key_struct, not just a number of bytes.
64  *
65  * Routines
66  *  - isamd_append
67  *    - create_new_block if needed
68  *    - append_diffs
69  *      - load_diffs 
70  *      - get diffend, start encoding
71  *      - while input data
72  *        - encode it
73  *        - if no room, then realloc block in larger size
74  *        - if still no room, merge and exit
75  *        - append in the block
76  *
77  * - merge
78  *   - just as before, except that merges also input data directly
79  *   - writes into new data blocks
80  *       
81  *      
82  * - isamd.c: load firstpp, load datablock
83  *            save firstpp, save datablock
84  * - Readlength, writelength - handling right size of len fields
85  * - isamd_read_main_item: take also a merge input structure, and merge it too
86  * - prefilter: cache two inputs, and check if they cancel.
87  * - single-item optimization
88  * 
89  * questions: Should we realloc firstblocks in a different size as the main
90  * blocks. Makes a sideways seek, which is bound to be slowe. But saves some
91  * update time. Compromise: alloc the first one in the size of the datablock,
92  * but increase if necessary. Large blocks get a large diff, ok. Small ones
93  * may get an extra seek in read, but save merges.
94  */
95
96
97 #define NEW_ISAM_D 1  /* not yet ready to delete the old one! */
98
99 #include <stdlib.h>
100 #include <assert.h>
101 #include <string.h>
102 #include <stdio.h>
103 #include <log.h>
104 #include "../index/index.h"
105 #include "isamd-p.h"
106
107
108 struct ISAMD_DIFF_s {
109   int diffidx;
110   int maxidx;
111   struct it_key key;
112   void *decodeData;
113   int mode;
114   int difftype;  
115 };
116
117 #define DT_NONE 0 // no diff, marks end of sequence
118 #define DT_DIFF 1 // ordinarry diff
119 #define DT_MAIN 2 // main data
120 #define DT_INPU 3 // input data to be merged
121 #define DT_DONE 4 // done with all input here
122
123
124
125 /***************************************************************
126  * Input preprocess filter
127  ***************************************************************/
128
129
130 #define FILTER_NOTYET -1  /* no data read in yet, to be done */
131
132 struct ISAMD_FILTER_s {
133   ISAMD_I data;          /* where the data comes from */
134   ISAMD is;              /* for debug flags */
135   struct it_key k1;      /* the next item to be returned */
136   int           m1;      /* mode for k1 */
137   int           r1;      /* result for read of k1, or NOTYET */
138   struct it_key k2;      /* the one after that */
139   int           m2;
140   int           r2;
141 };
142
143 typedef struct ISAMD_FILTER_s *FILTER;
144
145
146 void filter_fill(FILTER F)
147 {
148   while ( (F->r1 == FILTER_NOTYET) || (F->r2 == FILTER_NOTYET) )
149   {
150      if (F->r1==FILTER_NOTYET) 
151      { /* move data forward in the filter */
152         F->k1 = F->k2;
153         F->m1 = F->m2;
154         F->r1 = F->r2;
155         if ( 0 != F->r1 ) /* not eof */
156           F->r2 = FILTER_NOTYET; /* say we want more */
157         if (F->is->method->debug > 9)  
158           logf(LOG_LOG,"filt_fill: shift %d.%d m=%d r=%d",
159              F->k1.sysno, 
160              F->k1.seqno, 
161              F->m1, F->r1);
162      }
163      if (F->r2==FILTER_NOTYET)
164      { /* read new bottom value */
165         char *k_ptr = (char*) &F->k2;
166         F->r2 = (F->data->read_item)(F->data->clientData, &k_ptr, &F->m2); 
167         if (F->is->method->debug > 9)
168           logf(LOG_LOG,"filt_fill: read %d.%d m=%d r=%d",
169              F->k2.sysno, F->k2.seqno, F->m2, F->r2);
170      }  
171      if ( (F->k1.sysno == F->k2.sysno) && 
172           (F->k1.seqno == F->k2.seqno) &&
173           (F->m1 != F->m2) &&
174           (F->r1 >0 ) && (F->r2 >0) )
175      { /* del-ins pair of same key (not eof) , ignore both */
176        if (F->is->method->debug > 9)
177          logf(LOG_LOG,"filt_fill: skipped %d.%d m=%d/%d r=%d/%d",
178             F->k1.sysno, F->k1.seqno, 
179             F->m1,F->m2, F->r1,F->r2);
180        F->r1 = FILTER_NOTYET;
181        F->r2 = FILTER_NOTYET;
182      }
183   } /* while */
184 } /* filter_fill */
185
186
187 FILTER filter_open( ISAMD is, ISAMD_I data )
188 {
189   FILTER F = (FILTER) xmalloc(sizeof(struct ISAMD_FILTER_s));
190   F->is = is;
191   F->data = data;
192   F->k1.sysno=0;
193   F->k1.seqno=0;
194   F->k2=F->k1; 
195   F->m1 = F->m2 = 0;
196   F->r1 = F->r2 = FILTER_NOTYET;
197   filter_fill(F);
198   return F;
199 }
200
201 static void filter_close (FILTER F)
202 {
203   xfree(F);
204 }
205
206 static int filter_read( FILTER F, 
207                         struct it_key *k,
208                         int *mode)
209 {
210   int res;
211   filter_fill(F);
212   if (F->is->method->debug > 9)
213     logf(LOG_LOG,"filt_read: reading %d.%d m=%d r=%d",
214        F->k1.sysno, F->k1.seqno, F->m1, F->r1);
215   res  = F->r1;
216   if(res) 
217   {
218     *k = F->k1;
219     *mode= F->m1;
220   }
221   F->r1 = FILTER_NOTYET;
222   return res;
223 }
224
225 static int filter_isempty(FILTER F)
226 {
227   return ( (0 == F->r1) && (0 == F->r2)) ;
228 }
229
230 static int filter_only_one(FILTER F)
231 {
232   return ( (0 != F->r1) && (0 == F->r2));
233 }
234
235
236
237
238 /***************************************************************
239  * Singleton encoding
240  ***************************************************************/
241 /* When there is only a single item, we don't allocate a block
242  * for it, but code it in the directory entry directly, if it
243  * fits.
244  */
245
246 #define DEC_SYSBITS 15
247 #define DEC_SEQBITS 15
248 #define DEC_MASK(n) ((1<<(n))-1)
249
250 #define SINGLETON_BIT (1<<(DEC_SYSBITS+DEC_SEQBITS+1))
251
252 int is_singleton(ISAMD_P ipos)
253 {
254   return ( ipos != 0 ) && ( ipos & SINGLETON_BIT );
255 }
256
257
258 int singleton_encode(struct it_key *k)
259 /* encodes the key into one int. If it does not fit, returns 0 */
260 {
261   if ( (k->sysno & DEC_MASK(DEC_SYSBITS) ) != k->sysno )
262     return 0;  /* no room dor sysno */
263   if ( (k->seqno & DEC_MASK(DEC_SYSBITS) ) != k->seqno )
264     return 0;  /* no room dor sysno */
265   return (k->sysno | (k->seqno << DEC_SYSBITS) ) | SINGLETON_BIT;
266 }
267  
268 void singleton_decode (int code, struct it_key *k)
269 {
270   assert (code & SINGLETON_BIT);
271   k->sysno = code & DEC_MASK(DEC_SYSBITS);
272   code = code >> DEC_SYSBITS; 
273   k->seqno = code & DEC_MASK(DEC_SEQBITS);
274
275  
276  
277 /***************************************************************
278  * General support routines
279  ***************************************************************/
280
281
282
283 static char *hexdump(unsigned char *p, int len, char *buff) {
284   static char localbuff[128];
285   char bytebuff[8];
286   if (!buff) buff=localbuff;
287   *buff='\0';
288   while (len--) {
289     sprintf(bytebuff,"%02x",*p);
290     p++;
291     strcat(buff,bytebuff);
292     if (len) strcat(buff,",");
293   }
294   return buff;
295 }
296
297
298
299 static void isamd_reduceblock(ISAMD_PP pp)
300 /* takes a large block, and reduces its category if possible */
301 /* Presumably the first block in an isam-list */
302 {
303    if (pp->pos)
304       return; /* existing block, do not touch */
305       /* TODO: Probably we may touch anyway? */
306    if (pp->is->method->debug > 5)  
307      logf(LOG_LOG,"isamd_reduce: start p=%d c=%d sz=%d",
308        pp->pos, pp->cat, pp->size); 
309    while ( ( pp->cat > 0 ) && (!pp->next) && 
310            (pp->offset < pp->is->method->filecat[pp->cat-1].bsize ) )
311       pp->cat--;
312    pp->pos = isamd_alloc_block(pp->is, pp->cat);
313    if (pp->is->method->debug > 5) 
314      logf(LOG_LOG,"isamd_reduce:  got  p=%d c=%d sz=%d",
315        pp->pos, pp->cat, pp->size);    
316 } /* reduceblock */
317
318
319 static int save_first_pp ( ISAMD_PP firstpp)
320 {
321    isamd_buildfirstblock(firstpp);
322    isamd_write_block(firstpp->is,firstpp->cat,firstpp->pos,firstpp->buf);
323    return isamd_addr(firstpp->pos,firstpp->cat);
324 }
325
326  
327 static void save_last_pp (ISAMD_PP pp)
328 {
329    pp->next = 0;/* just to be sure */
330    isamd_buildlaterblock(pp);
331    isamd_write_block(pp->is,pp->cat,pp->pos,pp->buf);
332 }
333
334 #ifdef UNUSED
335 static int save_both_pps (ISAMD_PP firstpp, ISAMD_PP pp)
336 {
337    /* order of things: Better to save firstpp first, if there are just two */
338    /* blocks, but last if there are blocks in between, as these have already */
339    /* been saved... optimise later (that's why this is in its own func...*/
340    int retval = save_first_pp(firstpp);
341    if (firstpp!=pp){ 
342       save_last_pp(pp);
343       isamd_pp_close(pp);
344    }
345    isamd_pp_close(firstpp);
346    return retval;
347 } /* save_both_pps */
348 #endif
349
350
351
352 /***************************************************************
353  * Diffblock handling
354  ***************************************************************/
355
356 void isamd_free_diffs(ISAMD_PP pp)
357 {
358   int i;
359   if (pp->is->method->debug > 5)
360      logf(LOG_LOG,"isamd_free_diffs: pp=%p di=%p", pp, pp->diffinfo);
361   if (!pp->diffinfo) 
362     return;
363   for (i=0;pp->diffinfo[i].difftype!=DT_NONE;i++) 
364       if(pp->diffinfo[i].decodeData)
365       {
366           if (pp->is->method->debug > 8)
367              logf(LOG_LOG,"isamd_free_diffs [%d]=%p",i, 
368                            pp->diffinfo[i].decodeData);
369           (*pp->is->method->code_stop)(ISAMD_DECODE,pp->diffinfo[i].decodeData);
370       } 
371   xfree(pp->diffinfo);
372   if (pp->diffbuf != pp->buf)
373     xfree (pp->diffbuf);  
374   pp->diffbuf=0;
375   pp->diffinfo=0;
376 } /* isamd_free_diffs */
377
378
379 static void getDiffInfo(ISAMD_PP pp )
380 { /* builds the diff info structures from a diffblock */
381    int maxinfos = pp->is->method->filecat[pp->cat].bsize / 5 +2;
382     /* Each diff takes at least 5 bytes. Probably more, but this is safe */
383    int i=1;  /* [0] is used for the main data, [n+1] for merge inputs */
384    int diffsz= maxinfos * sizeof(struct ISAMD_DIFF_s);
385    int maxsz = pp->is->method->filecat[pp->is->max_cat].bsize;
386    int diffidx = ISAMD_BLOCK_OFFSET_1;
387
388    pp->diffinfo = xmalloc( diffsz ); 
389    pp->offset = pp->size+1; /* used this block up */
390    memset(pp->diffinfo,'\0',diffsz);
391    if (pp->is->method->debug > 5)   
392       logf(LOG_LOG,"isamd_getDiffInfo: %d=%d:%d->%d, ix=%d mx=%d",
393          isamd_addr(pp->pos, pp->cat), pp->cat, pp->pos, pp->next,
394          diffidx,maxinfos);
395    
396    /* duplicate the buffer for diffs */
397    /* (so that we can read the next real buffer(s) */
398    assert(0==pp->diffbuf);
399    pp->diffbuf=xmalloc(maxsz);
400    memcpy(pp->diffbuf, pp->buf, maxsz);
401    
402    pp->diffinfo[0].maxidx=-1; /* mark as special */
403    pp->diffinfo[0].difftype=DT_MAIN;
404
405    while (i<maxinfos) 
406    {  
407       if ( diffidx+sizeof(int) > pp->is->method->filecat[pp->cat].bsize )
408       {
409          if (pp->is->method->debug > 5)
410            logf(LOG_LOG,"isamd_getDiffInfo:Near end (no room for len) at ix=%d n=%d",
411                diffidx, i);
412          return; /* whole block done */
413       }
414       memcpy( &pp->diffinfo[i].maxidx, &pp->diffbuf[diffidx], sizeof(int) );
415       pp->diffinfo[i].difftype=DT_DIFF;
416       if (pp->is->method->debug > 5)
417         logf(LOG_LOG,"isamd_getDiffInfo: max=%d ix=%d dbuf=%p",
418           pp->diffinfo[i].maxidx, diffidx, pp->diffbuf);
419
420       if ( (pp->is->method->debug > 0) &&
421          (pp->diffinfo[i].maxidx > pp->is->method->filecat[pp->cat].bsize) )
422       { 
423          logf(LOG_LOG,"Bad MaxIx!!! %s:%d: diffidx=%d", 
424                        __FILE__,__LINE__, diffidx);
425          logf(LOG_LOG,"i=%d maxix=%d bsz=%d", i, pp->diffinfo[i].maxidx,
426                        pp->is->method->filecat[pp->cat].bsize);
427          logf(LOG_LOG,"pp=%d=%d:%d  pp->nx=%d=%d:%d",
428                        isamd_addr(pp->pos,pp->cat), pp->pos, pp->cat,
429                        pp->next, isamd_type(pp->next), isamd_block(pp->next) );                      
430       }
431       assert(pp->diffinfo[i].maxidx <= pp->is->method->filecat[pp->cat].bsize+1);
432
433       if (0==pp->diffinfo[i].maxidx)
434       {
435          if (pp->is->method->debug > 5)  //!!! 4
436            logf(LOG_LOG,"isamd_getDiffInfo:End mark at ix=%d n=%d",
437                diffidx, i);
438          return; /* end marker */
439       }
440       diffidx += sizeof(int);
441       pp->diffinfo[i].decodeData = (*pp->is->method->code_start)(ISAMD_DECODE);
442       pp->diffinfo[i].diffidx = diffidx;
443       if (pp->is->method->debug > 5)
444         logf(LOG_LOG,"isamd_getDiff[%d]:%d-%d %s",
445           i,diffidx-sizeof(int),pp->diffinfo[i].maxidx,
446           hexdump((char *)&pp->diffbuf[diffidx-4],8,0) );
447       diffidx=pp->diffinfo[i].maxidx;
448       if ( diffidx > pp->is->method->filecat[pp->cat].bsize )
449         return; /* whole block done */
450       ++i;
451    }
452    assert (!"too many diff sequences in the block");
453 }
454
455 /***************************************************************
456  * Main block operations
457  ***************************************************************/
458
459
460 static ISAMD_PP get_new_main_block( ISAMD_PP firstpp, ISAMD_PP pp)
461 {  /* allocates a new block for the main data, and links it in */
462   int newblock;
463   if (0 == firstpp->next) 
464   {  /* special case, pp not yet allocated. */
465      /*Started as largest size, that's fine */
466      pp->pos = isamd_alloc_block(pp->is,pp->cat);
467      firstpp->next = isamd_addr(pp->pos,pp->cat);
468      if (pp->is->method->debug >3) 
469         logf(LOG_LOG,"isamd_build: Alloc 1. dblock  p=%d=%d:%d",
470            isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos);
471   }
472   newblock=isamd_alloc_block(pp->is,pp->cat);
473   pp->next=isamd_addr(newblock,pp->cat);
474   isamd_buildlaterblock(pp);
475   isamd_write_block(pp->is,pp->cat,pp->pos,pp->buf);
476   if (pp->is->method->debug >3) 
477      logf(LOG_LOG,"isamd_build: Alloc nxt %d=%d:%d -> %d=%d:%d",
478         isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos,
479         isamd_addr(newblock,pp->cat), pp->cat, newblock);
480   pp->next=0;
481   pp->pos=newblock;
482   pp->size=pp->offset=ISAMD_BLOCK_OFFSET_N;  
483   return pp;
484 } /* get_new_main_block */
485
486
487 static ISAMD_PP  append_main_item(ISAMD_PP firstpp, 
488                                   ISAMD_PP pp, 
489                                   struct it_key *i_key)
490 {  /* appends one item in the main data block, allocates new if needed */
491    char *i_item= (char *) i_key;  /* same as char */
492    char *i_ptr=i_item;
493    char codebuff[128];
494    char *c_ptr = codebuff;
495    int codelen;
496    char hexbuff[64];
497
498    int maxsize = pp->is->method->filecat[pp->is->max_cat].bsize; 
499
500    c_ptr=codebuff;
501    i_ptr=i_item;
502    (*pp->is->method->code_item)(ISAMD_ENCODE, pp->decodeClientData,
503                                 &c_ptr, &i_ptr);
504    codelen = c_ptr - codebuff;
505    assert ( (codelen<128) && (codelen>0));
506    if (pp->is->method->debug >7)
507       logf(LOG_LOG,"isamd:build: coded %s nk=%d,ofs=%d-%d",
508           hexdump(codebuff, c_ptr-codebuff,hexbuff), firstpp->numKeys+1,
509           pp->offset, pp->offset+codelen);
510
511    if (pp->offset + codelen > maxsize )
512    { /* oops, block full - get a new one */
513       pp =  get_new_main_block( firstpp, pp );
514       /* reset encoging and code again */
515       (*pp->is->method->code_reset)(pp->decodeClientData);
516       c_ptr=codebuff;
517       i_ptr=i_item;
518       (*pp->is->method->code_item)(ISAMD_ENCODE, pp->decodeClientData, 
519                                    &c_ptr, &i_ptr);
520       codelen = c_ptr - codebuff;
521       assert ( (codelen<128) && (codelen>0));
522       if (pp->is->method->debug >7)
523          logf(LOG_LOG,"isamd:build: recoded into %s  (nk=%d)",
524              hexdump(codebuff, c_ptr-codebuff,hexbuff), firstpp->numKeys+1);
525    } /* block full */    
526
527    assert (pp->offset + codelen <= maxsize );
528    
529    /* write the data into pp, now we must have room */ 
530    memcpy(&(pp->buf[pp->offset]),codebuff,codelen);
531    pp->offset += codelen;
532    pp->size += codelen;
533    firstpp->numKeys++;
534    /* clear the next 4 bytes in block, to avoid confusions with diff lens */
535    /* dirty, it should not be done here, but something slips somewhere, and */
536    /* I hope this fixes it...  - Heikki */
537    codelen = pp->offset;
538    while ( (codelen < maxsize ) && (codelen <= pp->offset+4) )
539      pp->buf[codelen++] = '\0';
540    return pp;    
541 } /* append_main_item */
542
543
544 /***************************************************************
545  * Read with merge
546  ***************************************************************/
547
548 /* Reads one item and corrects for the diffs, if any */
549 /* return 1 for ok, 0 for eof */
550 int isamd_read_item_merge (
551                      ISAMD_PP pp, 
552                      char **dst,
553                      struct it_key *p_key,  /* the data item that didn't fit*/
554               /*       ISAMD_I data)  */    /* more input data comes here */
555                      FILTER filt)           /* more input data comes here */
556 {                    /* The last two args can be null for ordinary reads */
557   char *keyptr;
558   char *codeptr;
559   char *codestart;
560   int winner=0; /* which diff holds the day */
561   int i; /* looping diffs */
562   int cmp;
563   int retry=1;
564   int oldoffs;
565   int rc;
566
567   if (!pp->diffinfo)  
568   { /* first time */
569      getDiffInfo(pp);
570
571      for(i=1; pp->diffinfo[i].difftype!=DT_NONE; i++)
572        ;  /* find last diff */
573      if (p_key)  
574      {  /* we have an extra item to inject into the merge */
575        if (pp->is->method->debug >9)  //!!!!!
576           logf(LOG_LOG,"isamd_read_item: going to merge with %d.%d",
577                p_key->sysno, p_key->seqno);
578        pp->diffinfo[i].key = *p_key;  /* the key merge could not handle */
579        pp->diffinfo[i].mode = pp->diffinfo[i].key.seqno & 1;
580        pp->diffinfo[i].key.seqno >>= 1;
581        pp->diffinfo[i].difftype=DT_INPU;
582        if (pp->is->method->debug > 7)
583          logf(LOG_LOG,"isamd_read_item: inpu key %d sys=%d  seq=%d=2*%d+%d",
584             i, p_key->sysno,
585             pp->diffinfo[i].key.seqno*2 + pp->diffinfo[1].mode,
586             pp->diffinfo[i].key.seqno,
587             pp->diffinfo[i].mode);
588        p_key->sysno=p_key->seqno=0;  /* used it up */
589      }
590
591      if (filt)
592      { /* we have a whole input stream to inject */
593        pp->diffinfo[i].difftype=DT_INPU;
594      }
595   } /* first time */ 
596         
597   while (retry)
598
599   {
600      retry=0;     
601      winner = 0;
602      for (i=0; (!retry) && (pp->diffinfo[i].difftype); i++)
603      {
604         if (0==pp->diffinfo[i].key.sysno)
605         {/* read a new one, if possible */
606            if ((pp->diffinfo[i].difftype==DT_DIFF) &&
607              (pp->diffinfo[i].diffidx < pp->diffinfo[i].maxidx))
608            { /* a normal kind of diff */
609               oldoffs=pp->diffinfo[i].diffidx;
610               codeptr= codestart = &(pp->diffbuf[pp->diffinfo[i].diffidx]);
611               keyptr=(char *)&(pp->diffinfo[i].key);
612               (*pp->is->method->code_item)(ISAMD_DECODE,
613                     pp->diffinfo[i].decodeData, &keyptr, &codeptr);
614               pp->diffinfo[i].diffidx += codeptr-codestart;
615               pp->diffinfo[i].mode = pp->diffinfo[i].key.seqno & 1;
616               pp->diffinfo[i].key.seqno = pp->diffinfo[i].key.seqno >>1 ;
617               if (pp->is->method->debug > 9)
618                 logf(LOG_LOG,"isamd_read_item: dif[%d] at %d-%d: %s",
619                   i,oldoffs, pp->diffinfo[i].diffidx,
620                   hexdump(pp->buf+oldoffs, pp->diffinfo[i].diffidx-oldoffs,0));
621               if (pp->is->method->debug > 7)
622                 logf(LOG_LOG,"isamd_read_item: rd dif[%d] %d.%d (%x.%x)",
623                   i,
624                   pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
625                   pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno);
626            }
627            else if ( pp->diffinfo[i].difftype==DT_MAIN)
628            { /* read a main item */
629               assert(i==0);  /* main data goes before any diffs */
630               oldoffs=pp->offset;
631               keyptr=(char*) &(pp->diffinfo[0].key);
632               rc= isamd_read_main_item(pp,&keyptr);
633               if (0==rc) 
634               { /* eof */
635                  if (pp->is->method->debug > 7)
636                    logf(LOG_LOG,"isamd_read_item: eof (rc=%d) main ",
637                            rc);
638                 pp->diffinfo[i].maxidx=-1;
639                 pp->diffinfo[i].key.sysno=0;
640                 pp->diffinfo[i].key.seqno=0;
641                 pp->diffinfo[i].difftype= DT_DONE;
642               } 
643               else
644               { /* not eof */
645                  pp->diffinfo[i].mode = 1;
646                  if (pp->is->method->debug > 7)
647                    logf(LOG_LOG,"isamd_read_item: rd main %d-%d %d.%d (%x.%x) m=%d",
648                      oldoffs,pp->offset,
649                      pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
650                      pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
651                      pp->diffinfo[i].mode);
652               } /* not eof */
653            }
654            else if (pp->diffinfo[i].difftype==DT_INPU)
655            {
656               keyptr = (char *) &pp->diffinfo[i].key;
657          /*     rc = (*data->read_item)(data->clientData, &keyptr, &pp->diffinfo[i].mode); */
658               rc = filter_read(filt, &pp->diffinfo[i].key, 
659                                      &pp->diffinfo[i].mode); 
660               if (!rc) 
661               {  /* did not get it */
662                  pp->diffinfo[i].key.sysno=0;
663                  pp->diffinfo[i].maxidx=0; /* signal the end */
664                  pp->diffinfo[i].difftype=DT_DONE;
665               }
666               if (pp->is->method->debug >7)
667                  logf(LOG_LOG,"merge: read inpu m=%d %d.%d (%x.%x)",
668                     pp->diffinfo[i].mode, 
669                     pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
670                     pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno );        
671            } /* read an input item */
672         } /* read a new one */
673         
674         if (pp->is->method->debug > 8)
675           logf(LOG_LOG,"isamd_read_item: considering d%d %d.%d ix=%d mx=%d",
676                i, pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
677                   pp->diffinfo[i].diffidx,   pp->diffinfo[i].maxidx);
678             
679         if ( 0!= pp->diffinfo[i].key.sysno)
680         { /* got a key, compare */
681           if (i!=winner)
682              cmp=key_compare(&pp->diffinfo[i].key, &pp->diffinfo[winner].key);
683           else
684              cmp=-1;
685           if (0==pp->diffinfo[winner].key.sysno)
686             cmp=-1; /* end of main sequence, take all diffs */
687           if (cmp<0)
688           {
689              if (pp->is->method->debug > 8)
690                logf(LOG_LOG,"isamd_read_item: ins [%d]%d.%d < [%d]%d.%d",
691                  i,  
692                  pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
693                  winner, 
694                  pp->diffinfo[winner].key.sysno, pp->diffinfo[winner].key.seqno);
695              if (pp->diffinfo[i].mode)  /* insert diff, should always be */
696                winner = i;
697              else
698              {
699                if (pp->is->method->debug > 1)
700                  logf(LOG_LOG,"delete diff for nonexisting item");
701                assert(!"delete diff for nonexisting item");  
702                /* is an assert too steep here? Not really.*/
703              }
704           } /* earlier key */
705           else if (cmp==0)
706           {
707              if (!pp->diffinfo[i].mode) /* delete diff. should always be */
708              {
709                 if (pp->is->method->debug > 8)
710                   logf(LOG_LOG,"isamd_read_item: del %d at%d %d.%d (%x.%x)",
711                     i, winner,
712                     pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
713                     pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno);
714                 pp->diffinfo[winner].key.sysno=0; /* delete it */
715              }
716              else
717                 if (pp->is->method->debug > 2)
718                   logf(LOG_LOG,"isamd_read_item: duplicate ins %d at%d %d.%d (%x.%x)",
719                     i, winner,
720                     pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
721                     pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno);
722                 /* skip the insert, since we already have it in the base */
723                 /* Should we fail an assertion here??? */
724              pp->diffinfo[i].key.sysno=0; /* done with the delete */
725              retry=1; /* start all over again */
726           } /* matching key */
727           /* else it is a later key, its turn will come */
728         } /* got a key */
729      } /* for each diff */
730   } /* not retry */
731
732   if ( pp->diffinfo[winner].key.sysno)
733   {
734     if (pp->is->method->debug > 7)
735       logf(LOG_LOG,"isamd_read_item: got %d  %d.%d (%x.%x)",
736         winner,
737         pp->diffinfo[winner].key.sysno, pp->diffinfo[winner].key.seqno,
738         pp->diffinfo[winner].key.sysno, pp->diffinfo[winner].key.seqno);
739     memcpy(*dst, &pp->diffinfo[winner].key, sizeof(struct it_key) );
740     *dst += sizeof(struct it_key);
741     pp->diffinfo[winner].key.sysno=0; /* used that one up */
742     cmp= 1;
743   } 
744   else 
745   {
746     if (pp->is->method->debug > 7)
747       logf(LOG_LOG,"isamd_read_item: eof w=%d  %d.%d (%x.%x)",
748         winner,
749         pp->diffinfo[winner].key.sysno, pp->diffinfo[winner].key.seqno,
750         pp->diffinfo[winner].key.sysno, pp->diffinfo[winner].key.seqno);
751     assert(winner==0); /* if nothing found, nothing comes from a diff */
752     cmp= 0; /* eof */
753   }
754   if (cmp)
755     ++(pp->is->no_read_keys);
756   else
757     ++(pp->is->no_read_eof);
758
759   return cmp;
760    
761 } /* isamd_read_item */
762
763
764 int isamd_read_item (ISAMD_PP pp, char **dst)
765 {
766   return isamd_read_item_merge(pp,dst,0,0);
767 }
768
769
770 /***************************************************************
771  * Merge
772  ***************************************************************/
773
774 static int merge ( ISAMD_PP firstpp,      /* first pp (with diffs) */
775                    struct it_key *p_key,  /* the data item that didn't fit*/
776               /*     ISAMD_I data) */     /* more input data comes here */
777                    FILTER filt)           /* more input data arriving here */
778 {
779   int diffidx;  
780   int killblk=0;
781   struct it_key r_key;
782   char * r_ptr;
783   int r_more = 1;
784   ISAMD_PP pp;
785   ISAMD_PP readpp=firstpp;
786   int retval=0;
787   int diffcat = firstpp->cat;  /* keep the category of the diffblock even */
788                                /* if it is going to be empty now. */
789                                /* Alternative: Make it the minimal, and */
790                                /* resize later. Saves disk, but will lead */
791                                /* into bad seeks. */
792   
793   ++(readpp->is->no_merges);
794      
795   /* set up diffs as they should be for reading */
796   diffidx = ISAMD_BLOCK_OFFSET_1; 
797   //readpp->diffbuf=readpp->buf;  // diffinfo has to duplicate it!
798   //getDiffInfo(readpp);  // first read will make the diffinfo, at init
799   
800   if (readpp->is->method->debug >4) 
801       logf(LOG_LOG,"isamd_merge: f=%d=%d:%d n=%d=%d:%d",
802         isamd_addr(firstpp->pos,firstpp->cat), firstpp->cat, firstpp->pos,
803         firstpp->next, isamd_type(firstpp->next), isamd_block(firstpp->next));  
804
805   /* release our data block. Do before reading, when pos is stable ! */
806   killblk=firstpp->pos;
807   if (killblk)
808   {
809       isamd_release_block(firstpp->is, firstpp->cat, killblk);
810       if (readpp->is->method->debug >3)   
811           logf(LOG_LOG,"isamd_merge: released old firstblock %d (%d:%d)",
812               isamd_addr(killblk,firstpp->cat), firstpp->cat, killblk );
813   }
814   
815
816   r_ptr= (char *) &r_key;
817 /*  r_more = isamd_read_item_merge( readpp, &r_ptr, p_key, data); */
818   r_more = isamd_read_item_merge( readpp, &r_ptr, p_key, filt);
819   if (!r_more)  
820   { /* oops, all data has been deleted! what to do??? */
821     /* never mind, we have at least one more delta to add to the block */
822     /* pray that is not a delete as well... */
823     r_key.sysno = 0;
824     r_key.seqno = 0;
825      if (readpp->is->method->debug >5) 
826          logf(LOG_LOG,"isamd_merge:all data has been deleted (nk=%d) ",
827             readpp->numKeys);
828   }
829
830
831   /* set up the new blocks for simple writing */
832   firstpp=isamd_pp_open(readpp->is,isamd_addr(0, diffcat));
833   firstpp->pos=isamd_alloc_block(firstpp->is,diffcat);
834   if (readpp->is->method->debug >3)   
835       logf(LOG_LOG,"isamd_merge: allocated new firstpp %d=%d:%d",
836           isamd_addr(firstpp->pos,firstpp->cat), firstpp->cat, firstpp->pos );
837   
838   pp=isamd_pp_open(readpp->is,isamd_addr(0,readpp->is->max_cat) );
839   pp->offset=pp->size=ISAMD_BLOCK_OFFSET_N;
840   
841   while (r_more)
842   {
843      if (readpp->is->method->debug >6) 
844          logf(LOG_LOG,"isamd_merge: got key %d.%d",
845            r_key.sysno, r_key.seqno );
846      pp= append_main_item(firstpp, pp, &r_key);
847
848      if ( (readpp->pos != killblk ) && (0!=readpp->pos) )
849      {  /* pos can get to 0 at end of main seq, if still diffs left...*/
850         if (readpp->is->method->debug >3)  
851             logf(LOG_LOG,"isamd_merge: released block %d (%d:%d) now %d=%d:%d",
852                 isamd_addr(killblk,readpp->cat), readpp->cat, killblk,
853                 isamd_addr(readpp->pos,readpp->cat),readpp->cat, readpp->pos );
854         isamd_release_block(readpp->is, readpp->cat, readpp->pos);
855         killblk=readpp->pos;
856      }
857
858      /* (try to) read next item */
859      r_ptr= (char *) &r_key;
860      r_more = isamd_read_item_merge( readpp, &r_ptr,0,filt);
861
862   } /* while read */
863   
864   
865 //  firstpp->diffs=0; 
866
867
868   isamd_reduceblock(pp);  /* reduce size if possible */
869   if (0==firstpp->next)
870     firstpp->next = isamd_addr(pp->pos,pp->cat);
871   save_last_pp(pp);
872   if (readpp->is->method->debug >4) 
873       logf(LOG_LOG,"isamd_merge: saved last block %d=%d:%d",
874             isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos);
875   isamd_pp_close(pp);
876
877   if (readpp->is->method->debug >5) 
878         logf(LOG_LOG,"isamd_merge: closing readpp %d=%d:%d di=%p",
879               isamd_addr(readpp->pos,readpp->cat), readpp->cat, readpp->pos,
880               readpp->diffinfo);
881   isamd_pp_close(readpp); /* pos is 0 by now, at eof. close works anyway */
882
883   if (readpp->is->method->debug >2)  
884       logf(LOG_LOG,"isamd_merge: merge ret f=%d=%d:%d pp=%d=%d:%d",
885             isamd_addr(firstpp->pos,pp->cat), firstpp->cat, firstpp->pos,
886             isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos);
887
888   firstpp->size = firstpp->offset = ISAMD_BLOCK_OFFSET_1;  /* nothing there */
889   memset(firstpp->buf,'\0',firstpp->is->method->filecat[firstpp->cat].bsize);
890   save_first_pp(firstpp);
891   retval = isamd_addr(firstpp->pos, firstpp->cat);
892   isamd_pp_close(firstpp);
893
894   return retval; 
895   
896 } /* merge */
897
898
899
900
901 /***************************************************************
902  * Appending diffs 
903  ***************************************************************/
904
905
906
907 static int append_diffs(
908       ISAMD is, 
909       ISAMD_P ipos, 
910       /*ISAMD_I data)*/
911       FILTER filt)
912 {
913    struct it_key i_key;    /* one input item */
914    char *i_item = (char *) &i_key;  /* same as chars */
915    char *i_ptr=i_item;
916    int i_more =1;
917    int i_mode;     /* 0 for delete, 1 for insert */ 
918
919    ISAMD_PP firstpp;
920    char hexbuff[64];
921    int diffidx=0;
922    int maxsize=0;
923    int difflenidx;
924    char codebuff[128];
925    char *c_ptr = codebuff;
926    int codelen;
927    int merge_rc;
928    int retval=0;
929
930    if (0==ipos)
931    {
932        firstpp=isamd_pp_open(is, isamd_addr(0,0) );
933        firstpp->size=firstpp->offset=ISAMD_BLOCK_OFFSET_1;
934          /* create in smallest category, will expand later */
935        ++(is->no_fbuilds);
936    } 
937    else
938    {
939        firstpp=isamd_pp_open(is, ipos);
940        ++(is->no_appds);
941    }
942
943    if (is->method->debug >2) 
944       logf(LOG_LOG,"isamd_appd: Start ipos=%d=%d:%d n=%d=%d:%d nk=%d",
945         ipos, isamd_type(ipos), isamd_block(ipos),
946         firstpp->next, isamd_type(firstpp->next), isamd_block(firstpp->next),
947         firstpp->numKeys);
948    maxsize = is->method->filecat[firstpp->cat].bsize; 
949    
950    difflenidx = diffidx = firstpp->size;
951    
952    diffidx+=sizeof(int);  /* difflen will be stored here */
953    
954    /* read first input */
955    //i_ptr = i_item;   //!!!
956    i_more = filter_read(filt, &i_key, &i_mode); 
957    /* i_more = (*data->read_item)(data->clientData, &i_ptr, &i_mode); */
958
959    if (is->method->debug >6)
960       logf(LOG_LOG,"isamd_appd: start m=%d %d.%d=%x.%x: %d",
961          i_mode, 
962          i_key.sysno, i_key.seqno, 
963          i_key.sysno, i_key.seqno,
964          i_key.sysno*2+i_mode);
965
966    while (i_more)
967    {     
968       /* store the mode bit inside key */
969       assert( ((i_key.seqno<<1)>>1) == i_key.seqno); /* can spare the bit */
970       i_key.seqno = i_key.seqno * 2 + i_mode;  
971
972       c_ptr=codebuff;
973       i_ptr=i_item; 
974       (*is->method->code_item)(ISAMD_ENCODE, firstpp->decodeClientData, 
975                                &c_ptr, &i_ptr);
976       codelen = c_ptr - codebuff;
977       assert ( (codelen<128) && (codelen>0));
978       if (is->method->debug >7)
979          logf(LOG_LOG,"isamd_appd: coded %d: %s (nk=%d) (ix=%d)",
980              codelen, hexdump(codebuff, codelen,hexbuff), 
981              firstpp->numKeys,diffidx);
982
983       if (diffidx + codelen > maxsize )
984       { /* block full */
985          while ( (firstpp->cat < firstpp->is->max_cat) &&
986                  (diffidx + codelen > maxsize) )
987          { /* try to increase the block size */
988              if (firstpp->pos > 0)  /* free the old block if allocated */
989                  isamd_release_block(is, firstpp->cat, firstpp->pos);
990              ++firstpp->cat;
991              maxsize = is->method->filecat[firstpp->cat].bsize; 
992              firstpp->pos=0; /* need to allocate it when saving */             
993              if (is->method->debug >3)
994                 logf(LOG_LOG,"isamd_appd: increased diff block sz to %d (%d)",
995                    firstpp->cat, maxsize);
996          }
997          if  ((firstpp->cat >= firstpp->is->max_cat) &&
998                  (diffidx + codelen > maxsize) )
999          { /* max size - can't help, need to merge it */
1000              if (is->method->debug >7)
1001                 logf(LOG_LOG,"isamd_appd: need to merge");
1002              if (is->method->debug >9)  //!!!!!
1003                 logf(LOG_LOG,"isamd_appd: going to merge with m=%d %d.%d",
1004                      i_mode, i_key.sysno, i_key.seqno);
1005              merge_rc = merge (firstpp, &i_key, filt);
1006              if (0!=merge_rc)
1007                return merge_rc;  /* merge handled them all ! */
1008              assert(!"merge returned zero ??");
1009          } /* need to merge */
1010       } /* block full */
1011
1012       if (!( diffidx+codelen <= maxsize )) 
1013       { /* bug hunting */
1014          logf(LOG_LOG,"OOPS, diffidx problem: d=%d c=%d s=%d > m=%d",
1015            diffidx, codelen, diffidx+codelen, maxsize);
1016          logf(LOG_LOG,"ipos=%d f=%d=%d:%d",
1017            ipos, 
1018            isamd_addr(firstpp->pos, firstpp->cat),
1019            firstpp->cat, firstpp->pos );
1020       }
1021       assert ( diffidx+codelen <= maxsize );
1022       
1023       /* save the diff */ 
1024       memcpy(&(firstpp->buf[diffidx]),codebuff,codelen);
1025       diffidx += codelen;
1026       firstpp->size = firstpp->offset = diffidx;
1027       
1028       if (i_mode)
1029         firstpp->numKeys++; /* insert diff */
1030       else
1031         firstpp->numKeys--; /* delete diff */ 
1032
1033       /* update length of this diff run */
1034       memcpy(&(firstpp->buf[difflenidx]),&diffidx,sizeof(diffidx));
1035       
1036       /* (try to) read the next input */
1037       i_ptr = i_item;
1038       i_more = filter_read(filt, &i_key, &i_mode); 
1039     /*  i_more = (*data->read_item)(data->clientData, &i_ptr, &i_mode); */
1040       if ( (i_more) && (is->method->debug >6) )
1041          logf(LOG_LOG,"isamd_appd: got m=%d %d.%d=%x.%x: %d",
1042             i_mode, 
1043             i_key.sysno, i_key.seqno, 
1044             i_key.sysno, i_key.seqno,
1045             i_key.sysno*2+i_mode);
1046    } /* more loop */
1047
1048    /* clear the next difflen, if room for such */
1049    difflenidx = diffidx;
1050    while ( (difflenidx-diffidx<=sizeof(int)+1) && (difflenidx<maxsize))
1051      firstpp->buf[difflenidx++]='\0';
1052
1053    if (0==firstpp->pos)  /* need to (re)alloc the block */
1054       firstpp->pos = isamd_alloc_block(is, firstpp->cat);
1055
1056    retval = save_first_pp( firstpp );
1057    isamd_pp_close(firstpp);
1058     
1059    return retval;
1060 } /* append_diffs */
1061
1062
1063
1064
1065 /*************************************************************
1066  * isamd_append itself
1067  *************************************************************/
1068
1069 ISAMD_P isamd_append (ISAMD is, ISAMD_P ipos, ISAMD_I data)
1070 {
1071    FILTER F = filter_open(is,data);
1072    ISAMD_P rc=0;
1073
1074    int olddebug= is->method->debug;
1075    if (ipos == 7320)
1076      is->method->debug = 99;  /*!*/
1077      
1078    if ( filter_isempty(F) ) /* can be, if del-ins of the same */
1079    {
1080       if (is->method->debug >3) 
1081          logf(LOG_LOG,"isamd_appd: nothing to do for %d=",ipos);
1082       filter_close(F);
1083       ++(is->no_non);
1084       return ipos; /* without doing anything at all */
1085    }
1086
1087    if ( ( 0==ipos) && filter_only_one(F) )
1088    {
1089       struct it_key k;
1090       int mode;
1091       filter_read(F,&k,&mode);     
1092       assert(mode); 
1093       rc = singleton_encode(&k);
1094       if (is->method->debug >9) 
1095          logf(LOG_LOG,"isamd_appd: singleton %d (%x)",
1096            rc,rc);
1097       if (rc)
1098         is->no_singles++;
1099       assert ( (rc==0) || is_singleton(rc) );
1100    }
1101    if ( 0==rc) /* either not single, or it did not fit */
1102    {
1103       rc = append_diffs(is,ipos,F); 
1104       assert ( ! is_singleton(rc) ); 
1105         /* can happen if we run out of bits, so that block numbers overflow */
1106         /* to SINGLETON_BIT */
1107    }
1108    filter_close(F);
1109
1110    if (is->method->debug >2) 
1111       logf(LOG_LOG,"isamd_appd: ret %d=%x (%d=%x)",
1112         rc,rc,ipos,ipos);
1113    is->method->debug=olddebug; /*!*/
1114    return rc;
1115 } /*  isamd_append */
1116
1117
1118
1119
1120
1121
1122
1123 /*
1124  * $Log: merge-d.c,v $
1125  * Revision 1.24  1999-10-05 09:57:40  heikki
1126  * Tuning the isam-d (and fixed a small "detail")
1127  *
1128  * Revision 1.23  1999/09/27 14:36:36  heikki
1129  * singletons
1130  *
1131  * Revision 1.22  1999/09/23 18:01:18  heikki
1132  * singleton optimising
1133  *
1134  * Revision 1.21  1999/09/21 17:36:43  heikki
1135  * Added filter function. Not much of effect on the small test set...
1136  *
1137  * Revision 1.20  1999/09/20 15:48:06  heikki
1138  * Small changes
1139  *
1140  * Revision 1.19  1999/09/13 13:28:28  heikki
1141  * isam-d optimizing: merging input data in the same go
1142  *
1143  * Revision 1.18  1999/08/25 18:09:24  heikki
1144  * Starting to optimize
1145  *
1146  * Revision 1.17  1999/08/24 13:17:42  heikki
1147  * Block sizes, comments
1148  *
1149  * Revision 1.16  1999/08/24 10:12:02  heikki
1150  * Comments about optimising
1151  *
1152  * Revision 1.15  1999/08/22 08:26:34  heikki
1153  * COmments
1154  *
1155  * Revision 1.14  1999/08/20 12:25:58  heikki
1156  * Statistics in isamd
1157  *
1158  * Revision 1.13  1999/08/18 13:59:19  heikki
1159  * Fixed another unlikely difflen bug
1160  *
1161  * Revision 1.12  1999/08/18 13:28:17  heikki
1162  * Set log levels to decent values
1163  *
1164  * Revision 1.11  1999/08/18 10:37:11  heikki
1165  * Fixed (another) difflen bug
1166  *
1167  * Revision 1.10  1999/08/18 09:13:31  heikki
1168  * Fixed a detail
1169  *
1170  * Revision 1.9  1999/08/17 19:46:53  heikki
1171  * Fixed a memory leak
1172  *
1173  * Revision 1.8  1999/08/07 11:30:59  heikki
1174  * Bug fixing (still a mem leak somewhere)
1175  *
1176  * Revision 1.7  1999/08/04 14:21:18  heikki
1177  * isam-d seems to be working.
1178  *
1179  * Revision 1.6  1999/07/23 15:43:05  heikki
1180  * Hunted a few bugs in isam-d. Still crashes on the long test run
1181  *
1182  * Revision 1.5  1999/07/23 13:58:52  heikki
1183  * merged closer to working, still fails on filling a separate, large block
1184  *
1185  * Revision 1.4  1999/07/21 14:53:55  heikki
1186  * isamd read and write functions work, except when block full
1187  * Merge missing still. Need to split some functions
1188  *
1189  * Revision 1.1  1999/07/14 13:14:47  heikki
1190  * Created empty
1191  *
1192  *
1193  */
1194
1195