Updated footer comment
[idzebra-moved-to-github.git] / index / kinput.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1994-2009 Index Data
3
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19  
20 #include <fcntl.h>
21 #ifdef WIN32
22 #include <io.h>
23 #endif
24 #if HAVE_UNISTD_H
25 #include <unistd.h>
26 #endif
27 #include <stdlib.h>
28 #include <string.h>
29 #include <stdio.h>
30 #include <assert.h>
31
32 #include "index.h"
33
34 #define KEY_SIZE (1+sizeof(struct it_key))
35 #define INP_NAME_MAX 768
36
37 struct key_file {
38     int   no;            /* file no */
39     off_t offset;        /* file offset */
40     unsigned char *buf;  /* buffer block */
41     size_t buf_size;     /* number of read bytes in block */
42     size_t chunk;        /* number of bytes allocated */
43     size_t buf_ptr;      /* current position in buffer */
44     char *prev_name;     /* last word read */
45     void *decode_handle;
46     off_t length;        /* length of file */
47                          /* handler invoked in each read */
48     void (*readHandler)(struct key_file *keyp, void *rinfo);
49     void *readInfo;
50     Res res;
51 };
52
53 #if 0
54 static void pkey(const char *b, int mode)
55 {
56     key_logdump_txt(YLOG_LOG, b, mode ? "i" : "d");
57 }
58 #endif
59
60
61 void getFnameTmp(Res res, char *fname, int no)
62 {
63     const char *pre;
64     
65     pre = res_get_def(res, "keyTmpDir", ".");
66     sprintf(fname, "%s/key%d.tmp", pre, no);
67 }
68
69 void extract_get_fname_tmp(ZebraHandle zh, char *fname, int no)
70 {
71     const char *pre;
72     
73     pre = res_get_def(zh->res, "keyTmpDir", ".");
74     sprintf(fname, "%s/key%d.tmp", pre, no);
75 }
76
77 void key_file_chunk_read(struct key_file *f)
78 {
79     int nr = 0, r = 0, fd;
80     char fname[1024];
81     getFnameTmp(f->res, fname, f->no);
82     fd = open(fname, O_BINARY|O_RDONLY);
83
84     f->buf_ptr = 0;
85     f->buf_size = 0;
86     if (fd == -1)
87     {
88         yaz_log(YLOG_WARN|YLOG_ERRNO, "cannot open %s", fname);
89         return ;
90     }
91     if (!f->length)
92     {
93         if ((f->length = lseek(fd, 0L, SEEK_END)) == (off_t) -1)
94         {
95             yaz_log(YLOG_WARN|YLOG_ERRNO, "cannot seek %s", fname);
96             close(fd);
97             return ;
98         }
99     }
100     if (lseek(fd, f->offset, SEEK_SET) == -1)
101     {
102         yaz_log(YLOG_WARN|YLOG_ERRNO, "cannot seek %s", fname);
103         close(fd);
104         return ;
105     }
106     while (f->chunk - nr > 0)
107     {
108         r = read(fd, f->buf + nr, f->chunk - nr);
109         if (r <= 0)
110             break;
111         nr += r;
112     }
113     if (r == -1)
114     {
115         yaz_log(YLOG_WARN|YLOG_ERRNO, "read of %s", fname);
116         close(fd);
117         return;
118     }
119     f->buf_size = nr;
120     if (f->readHandler)
121         (*f->readHandler)(f, f->readInfo);
122     close(fd);
123 }
124
125 void key_file_destroy(struct key_file *f)
126 {
127     iscz1_stop(f->decode_handle);
128     xfree(f->buf);
129     xfree(f->prev_name);
130     xfree(f);
131 }
132
133 struct key_file *key_file_init(int no, int chunk, Res res)
134 {
135     struct key_file *f;
136
137     f = (struct key_file *) xmalloc(sizeof(*f));
138     f->res = res;
139     f->decode_handle = iscz1_start();
140     f->no = no;
141     f->chunk = chunk;
142     f->offset = 0;
143     f->length = 0;
144     f->readHandler = NULL;
145     f->buf = (unsigned char *) xmalloc(f->chunk);
146     f->prev_name = (char *) xmalloc(INP_NAME_MAX);
147     *f->prev_name = '\0';
148     key_file_chunk_read(f);
149     return f;
150 }
151
152 int key_file_getc(struct key_file *f)
153 {
154     if (f->buf_ptr < f->buf_size)
155         return f->buf[(f->buf_ptr)++];
156     if (f->buf_size < f->chunk)
157         return EOF;
158     f->offset += f->buf_size;
159     key_file_chunk_read(f);
160     if (f->buf_ptr < f->buf_size)
161         return f->buf[(f->buf_ptr)++];
162     else
163         return EOF;
164 }
165
166 int key_file_read(struct key_file *f, char *key)
167 {
168     int i, c;
169     char srcbuf[128];
170     const char *src = srcbuf;
171     char *dst;
172     int j;
173
174     c = key_file_getc(f);
175     if (c == 0)
176     {
177         strcpy(key, f->prev_name);
178         i = 1+strlen(key);
179     }
180     else if (c == EOF)
181         return 0;
182     else
183     {
184         i = 0;
185         key[i++] = c;
186         while ((c = key_file_getc(f)))
187         {
188             if (i <= IT_MAX_WORD)
189                 key[i++] = c;
190         }
191         key[i++] = '\0';
192         strcpy(f->prev_name, key);
193         iscz1_reset(f->decode_handle);
194     }
195     c = key_file_getc(f); /* length +  insert/delete combined */
196     key[i++] = c & 128;
197     c = c & 127;
198     for (j = 0; j < c; j++)
199         srcbuf[j] = key_file_getc(f);
200     dst = key + i;
201     iscz1_decode(f->decode_handle, &dst, &src);
202
203 #if 0
204     /* debugging */
205     if (1)
206     {
207         struct it_key k;
208         memcpy(&k, key+i, sizeof(k));
209         if (!k.mem[1])
210             yaz_log(YLOG_LOG, "00 KEY");
211     }
212 #endif
213     return i + sizeof(struct it_key);
214 }
215
216 struct heap_info {
217     struct {
218         struct key_file **file;
219         char   **buf;
220     } info;
221     int    heapnum;
222     int    *ptr;
223     int    (*cmp)(const void *p1, const void *p2);
224     struct zebra_register *reg;
225     ZebraHandle zh;
226     zint no_diffs;
227     zint no_updates;
228     zint no_deletions;
229     zint no_insertions;
230     zint no_iterations;
231 };
232
233 static struct heap_info *key_heap_malloc(void)
234 {  /* malloc and clear it */
235     struct heap_info *hi;
236     hi = (struct heap_info *) xmalloc(sizeof(*hi));
237     hi->info.file = 0;
238     hi->info.buf = 0;
239     hi->heapnum = 0;
240     hi->ptr = 0;
241     hi->no_diffs = 0;
242     hi->no_diffs = 0;
243     hi->no_updates = 0;
244     hi->no_deletions = 0;
245     hi->no_insertions = 0;
246     hi->no_iterations = 0;
247     return hi;
248 }
249
250 struct heap_info *key_heap_init_file(ZebraHandle zh,
251                                      int nkeys,
252                                      int (*cmp)(const void *p1, const void *p2))
253 {
254     struct heap_info *hi;
255     int i;
256
257     hi = key_heap_malloc();
258     hi->zh = zh;
259     hi->info.file = (struct key_file **)
260         xmalloc(sizeof(*hi->info.file) * (1+nkeys));
261     hi->info.buf = (char **) xmalloc(sizeof(*hi->info.buf) * (1+nkeys));
262     hi->ptr = (int *) xmalloc(sizeof(*hi->ptr) * (1+nkeys));
263     hi->cmp = cmp;
264     for (i = 0; i<= nkeys; i++)
265     {
266         hi->ptr[i] = i;
267         hi->info.buf[i] = (char *) xmalloc(INP_NAME_MAX);
268     }
269     return hi;
270 }
271
272 void key_heap_destroy(struct heap_info *hi, int nkeys)
273 {
274     int i;
275     for (i = 0; i<=nkeys; i++)
276         xfree(hi->info.buf[i]);
277     xfree(hi->info.buf);
278     xfree(hi->ptr);
279     xfree(hi->info.file);
280     xfree(hi);
281 }
282
283 static void key_heap_swap(struct heap_info *hi, int i1, int i2)
284 {
285     int swap;
286
287     swap = hi->ptr[i1];
288     hi->ptr[i1] = hi->ptr[i2];
289     hi->ptr[i2] = swap;
290 }
291
292
293 static void key_heap_delete(struct heap_info *hi)
294 {
295     int cur = 1, child = 2;
296
297     assert(hi->heapnum > 0);
298
299     key_heap_swap(hi, 1, hi->heapnum);
300     hi->heapnum--;
301     while (child <= hi->heapnum) {
302         if (child < hi->heapnum &&
303             (*hi->cmp)(&hi->info.buf[hi->ptr[child]],
304                        &hi->info.buf[hi->ptr[child+1]]) > 0)
305             child++;
306         if ((*hi->cmp)(&hi->info.buf[hi->ptr[cur]],
307                        &hi->info.buf[hi->ptr[child]]) > 0)
308         {            
309             key_heap_swap(hi, cur, child);
310             cur = child;
311             child = 2*cur;
312         }
313         else
314             break;
315     }
316 }
317
318 static void key_heap_insert(struct heap_info *hi, const char *buf, int nbytes,
319                              struct key_file *kf)
320 {
321     int cur, parent;
322
323     cur = ++(hi->heapnum);
324     memcpy(hi->info.buf[hi->ptr[cur]], buf, nbytes);
325     hi->info.file[hi->ptr[cur]] = kf;
326
327     parent = cur/2;
328     while (parent && (*hi->cmp)(&hi->info.buf[hi->ptr[parent]],
329                                 &hi->info.buf[hi->ptr[cur]]) > 0)
330     {
331         key_heap_swap(hi, cur, parent);
332         cur = parent;
333         parent = cur/2;
334     }
335 }
336
337 static int heap_read_one(struct heap_info *hi, char *name, char *key)
338 {
339     int n, r;
340     char rbuf[INP_NAME_MAX];
341     struct key_file *kf;
342
343     if (!hi->heapnum)
344         return 0;
345     n = hi->ptr[1];
346     strcpy(name, hi->info.buf[n]);
347     kf = hi->info.file[n];
348     r = strlen(name);
349     memcpy(key, hi->info.buf[n] + r+1, KEY_SIZE);
350     key_heap_delete(hi);
351     if ((r = key_file_read(kf, rbuf)))
352         key_heap_insert(hi, rbuf, r, kf);
353     hi->no_iterations++;
354     return 1;
355 }
356
357 #define PR_KEY_LOW 0
358 #define PR_KEY_TOP 0
359
360 /* for debugging only */
361 void zebra_log_dict_entry(ZebraHandle zh, const char *s)
362 {
363     char dst[IT_MAX_WORD+1];
364     int ord;
365     int len = key_SU_decode(&ord, (const unsigned char *) s);
366     const char *index_type;
367
368     if (!zh)
369         yaz_log(YLOG_LOG, "ord=%d", ord);
370     else
371     {
372         const char *string_index;
373         const char *db = 0;
374         zebraExplain_lookup_ord(zh->reg->zei,
375                                 ord, &index_type, &db, &string_index);
376
377         zebra_term_untrans(zh, index_type, dst, s + len);
378
379         yaz_log(YLOG_LOG, "ord=%d index_type=%s index=%s term=%s",
380                 ord, index_type, string_index, dst);
381     }
382 }
383
384 struct heap_cread_info {
385     char prev_name[INP_NAME_MAX];
386     char cur_name[INP_NAME_MAX];
387     char *key;
388     char *key_1, *key_2;
389     int mode_1, mode_2;
390     int sz_1, sz_2;
391     struct heap_info *hi;
392     int first_in_list;
393     int more;
394     int ret;
395     int look_level;
396 };
397
398 static int heap_cread_item(void *vp, char **dst, int *insertMode);
399
400 int heap_cread_item2(void *vp, char **dst, int *insertMode)
401 {
402     struct heap_cread_info *p = (struct heap_cread_info *) vp;
403     int level = 0;
404
405     if (p->look_level)
406     {
407         if (p->look_level > 0)
408         {
409             *insertMode = 1;
410             p->look_level--;
411         }
412         else
413         {
414             *insertMode = 0;
415             p->look_level++;
416         }
417         memcpy(*dst, p->key_1, p->sz_1);
418 #if 0
419         yaz_log(YLOG_LOG, "DUP level=%d", p->look_level);
420         pkey(*dst, *insertMode);
421 #endif
422         (*dst) += p->sz_1;
423         return 1;
424     }
425     if (p->ret == 0)    /* lookahead was 0?. Return that in read next round */
426     {
427         p->ret = -1;
428         return 0;
429     }
430     else if (p->ret == -1) /* Must read new item ? */
431     {
432         char *dst_1 = p->key_1;
433         p->ret = heap_cread_item(vp, &dst_1, &p->mode_1);
434         p->sz_1 = dst_1 - p->key_1;
435     }
436     else
437     {        /* lookahead in 2 . Now in 1. */
438         p->sz_1 = p->sz_2;
439         p->mode_1 = p->mode_2;
440         memcpy(p->key_1, p->key_2, p->sz_2);
441     }
442     if (p->mode_1)
443         level = 1;     /* insert */
444     else
445         level = -1;    /* delete */
446     while(1)
447     {
448         char *dst_2 = p->key_2;
449         p->ret = heap_cread_item(vp, &dst_2, &p->mode_2);
450         if (!p->ret)
451         {
452             if (level)
453                 break;
454             p->ret = -1;
455             return 0;
456         }
457         p->sz_2 = dst_2 - p->key_2;
458
459         if (key_compare(p->key_1, p->key_2) == 0)
460         {
461             if (p->mode_2) /* adjust level according to deletes/inserts */
462                 level++;
463             else
464                 level--;
465         }
466         else
467         {
468             if (level)
469                 break;
470             /* all the same. new round .. */
471             p->sz_1 = p->sz_2;
472             p->mode_1 = p->mode_2;
473             memcpy(p->key_1, p->key_2, p->sz_1);
474             if (p->mode_1)
475                 level = 1;     /* insert */
476             else
477                 level = -1;    /* delete */
478         }
479     }
480     /* outcome is insert (1) or delete (0) depending on final level */
481     if (level > 0)
482     {
483         *insertMode = 1;
484         level--;
485     }
486     else
487     {
488         *insertMode = 0;
489         level++;
490     }
491     p->look_level = level;
492     memcpy(*dst, p->key_1, p->sz_1);
493 #if 0
494     pkey(*dst, *insertMode);
495 #endif
496     (*dst) += p->sz_1;
497     return 1;
498 }
499       
500 int heap_cread_item(void *vp, char **dst, int *insertMode)
501 {
502     struct heap_cread_info *p = (struct heap_cread_info *) vp;
503     struct heap_info *hi = p->hi;
504
505     if (p->first_in_list)
506     {
507         *insertMode = p->key[0];
508         memcpy(*dst, p->key+1, sizeof(struct it_key));
509 #if PR_KEY_LOW
510         zebra_log_dict_entry(hi->zh, p->cur_name);
511         pkey(*dst, *insertMode);
512 #endif
513         (*dst) += sizeof(struct it_key);
514         p->first_in_list = 0;
515         return 1;
516     }
517     strcpy(p->prev_name, p->cur_name);
518     if (!(p->more = heap_read_one(hi, p->cur_name, p->key)))
519         return 0;
520     if (*p->cur_name && strcmp(p->cur_name, p->prev_name))
521     {
522         p->first_in_list = 1;
523         return 0;
524     }
525     *insertMode = p->key[0];
526     memcpy(*dst, p->key+1, sizeof(struct it_key));
527 #if PR_KEY_LOW
528     zebra_log_dict_entry(hi->zh, p->cur_name);
529     pkey(*dst, *insertMode);
530 #endif
531     (*dst) += sizeof(struct it_key);
532     return 1;
533 }
534
535 int heap_inpc(struct heap_cread_info *hci, struct heap_info *hi)
536 {
537     ISAMC_I *isamc_i = (ISAMC_I *) xmalloc(sizeof(*isamc_i));
538
539     isamc_i->clientData = hci;
540     isamc_i->read_item = heap_cread_item2;
541
542     while (hci->more)
543     {
544         char this_name[INP_NAME_MAX];
545         ISAM_P isamc_p, isamc_p2;
546         char *dict_info;
547
548         strcpy(this_name, hci->cur_name);
549         assert(hci->cur_name[0]);
550         hi->no_diffs++;
551         if ((dict_info = dict_lookup(hi->reg->dict, hci->cur_name)))
552         {
553             memcpy(&isamc_p, dict_info+1, sizeof(ISAM_P));
554             isamc_p2 = isamc_p;
555             isamc_merge(hi->reg->isamc, &isamc_p2, isamc_i);
556             if (!isamc_p2)
557             {
558                 hi->no_deletions++;
559                 if (!dict_delete(hi->reg->dict, this_name))
560                     abort();
561             }
562             else 
563             {
564                 hi->no_updates++;
565                 if (isamc_p2 != isamc_p)
566                     dict_insert(hi->reg->dict, this_name,
567                                  sizeof(ISAM_P), &isamc_p2);
568             }
569         } 
570         else
571         {
572             isamc_p = 0;
573             isamc_merge(hi->reg->isamc, &isamc_p, isamc_i);
574             hi->no_insertions++;
575             if (isamc_p)
576                 dict_insert(hi->reg->dict, this_name,
577                              sizeof(ISAM_P), &isamc_p);
578         }
579     }
580     xfree(isamc_i);
581     return 0;
582
583
584 int heap_inpb(struct heap_cread_info *hci, struct heap_info *hi)
585 {
586     ISAMC_I *isamc_i = (ISAMC_I *) xmalloc(sizeof(*isamc_i));
587
588     isamc_i->clientData = hci;
589     isamc_i->read_item = heap_cread_item2;
590
591     while (hci->more)
592     {
593         char this_name[INP_NAME_MAX];
594         ISAM_P isamc_p, isamc_p2;
595         char *dict_info;
596
597         strcpy(this_name, hci->cur_name);
598         assert(hci->cur_name[0]);
599         hi->no_diffs++;
600
601 #if 0
602         assert(hi->zh);
603         zebra_log_dict_entry(hi->zh, hci->cur_name);
604 #endif
605         if ((dict_info = dict_lookup(hi->reg->dict, hci->cur_name)))
606         {
607             memcpy(&isamc_p, dict_info+1, sizeof(ISAM_P));
608             isamc_p2 = isamc_p;
609             isamb_merge(hi->reg->isamb, &isamc_p2, isamc_i);
610             if (!isamc_p2)
611             {
612                 hi->no_deletions++;
613                 if (!dict_delete(hi->reg->dict, this_name))
614                     abort();
615             }
616             else 
617             {
618                 hi->no_updates++;
619                 if (isamc_p2 != isamc_p)
620                     dict_insert(hi->reg->dict, this_name,
621                                  sizeof(ISAM_P), &isamc_p2);
622             }
623         } 
624         else
625         {
626             isamc_p = 0;
627             isamb_merge(hi->reg->isamb, &isamc_p, isamc_i);
628             hi->no_insertions++;
629             if (isamc_p)
630                 dict_insert(hi->reg->dict, this_name,
631                              sizeof(ISAM_P), &isamc_p);
632         }
633     }
634     xfree(isamc_i);
635     return 0;
636
637
638 int heap_inps(struct heap_cread_info *hci, struct heap_info *hi)
639 {
640     ISAMS_I isams_i = (ISAMS_I) xmalloc(sizeof(*isams_i));
641
642     isams_i->clientData = hci;
643     isams_i->read_item = heap_cread_item;
644
645     while (hci->more)
646     {
647         char this_name[INP_NAME_MAX];
648         ISAM_P isams_p;
649         char *dict_info;
650
651         strcpy(this_name, hci->cur_name);
652         assert(hci->cur_name[0]);
653         hi->no_diffs++;
654         if (!(dict_info = dict_lookup(hi->reg->dict, hci->cur_name)))
655         {
656             isams_p = isams_merge(hi->reg->isams, isams_i);
657             hi->no_insertions++;
658             dict_insert(hi->reg->dict, this_name, sizeof(ISAM_P), &isams_p);
659         }
660         else
661         {
662             yaz_log(YLOG_FATAL, "isams doesn't support this kind of update");
663             break;
664         }
665     }
666     xfree(isams_i);
667     return 0;
668
669
670 struct progressInfo {
671     time_t   startTime;
672     time_t   lastTime;
673     off_t    totalBytes;
674     off_t    totalOffset;
675 };
676
677 void progressFunc(struct key_file *keyp, void *info)
678 {
679     struct progressInfo *p = (struct progressInfo *) info;
680     time_t now, remaining;
681
682     if (keyp->buf_size <= 0 || p->totalBytes <= 0)
683         return ;
684     time (&now);
685
686     if (now >= p->lastTime+10)
687     {
688         p->lastTime = now;
689         remaining = (time_t) ((now - p->startTime)*
690             ((double) p->totalBytes/p->totalOffset - 1.0));
691         if (remaining <= 130)
692             yaz_log(YLOG_LOG, "Merge %2.1f%% completed; %ld seconds remaining",
693                  (100.0*p->totalOffset) / p->totalBytes, (long) remaining);
694         else
695             yaz_log(YLOG_LOG, "Merge %2.1f%% completed; %ld minutes remaining",
696                  (100.0*p->totalOffset) / p->totalBytes, (long) remaining/60);
697     }
698     p->totalOffset += keyp->buf_size;
699 }
700
701 #ifndef R_OK
702 #define R_OK 4
703 #endif
704
705 void zebra_index_merge(ZebraHandle zh)
706 {
707     struct key_file **kf = 0;
708     char rbuf[1024];
709     int i, r;
710     struct heap_info *hi;
711     struct progressInfo progressInfo;
712     int nkeys = key_block_get_no_files(zh->reg->key_block);
713
714     if (nkeys == 0)
715         return;
716     
717     if (nkeys < 0)
718     {
719         char fname[1024];
720         nkeys = 0;
721         while (1)
722         {
723             extract_get_fname_tmp (zh, fname, nkeys+1);
724             if (access(fname, R_OK) == -1)
725                 break;
726             nkeys++;
727         }
728         if (!nkeys)
729             return ;
730     }
731     kf = (struct key_file **) xmalloc((1+nkeys) * sizeof(*kf));
732     progressInfo.totalBytes = 0;
733     progressInfo.totalOffset = 0;
734     time(&progressInfo.startTime);
735     time(&progressInfo.lastTime);
736     for (i = 1; i<=nkeys; i++)
737     {
738         kf[i] = key_file_init(i, 8192, zh->res);
739         kf[i]->readHandler = progressFunc;
740         kf[i]->readInfo = &progressInfo;
741         progressInfo.totalBytes += kf[i]->length;
742         progressInfo.totalOffset += kf[i]->buf_size;
743     }
744     hi = key_heap_init_file(zh, nkeys, key_qsort_compare);
745     hi->reg = zh->reg;
746     
747     for (i = 1; i<=nkeys; i++)
748         if ((r = key_file_read(kf[i], rbuf)))
749             key_heap_insert(hi, rbuf, r, kf[i]);
750
751     if (1)
752     {
753         struct heap_cread_info hci;
754         
755         hci.key = (char *) xmalloc(KEY_SIZE);
756         hci.key_1 = (char *) xmalloc(KEY_SIZE);
757         hci.key_2 = (char *) xmalloc(KEY_SIZE);
758         hci.ret = -1;
759         hci.first_in_list = 1;
760         hci.hi = hi;
761         hci.look_level = 0;
762         hci.more = heap_read_one(hi, hci.cur_name, hci.key);    
763         
764         if (zh->reg->isams)
765             heap_inps(&hci, hi);
766         if (zh->reg->isamc)
767             heap_inpc(&hci, hi);
768         if (zh->reg->isamb)
769             heap_inpb(&hci, hi);
770         
771         xfree(hci.key);
772         xfree(hci.key_1);
773         xfree(hci.key_2);
774     }
775         
776     for (i = 1; i<=nkeys; i++)
777     {
778         extract_get_fname_tmp (zh, rbuf, i);
779         unlink(rbuf);
780     }
781     for (i = 1; i<=nkeys; i++)
782         key_file_destroy(kf[i]);
783     xfree(kf);
784     if (hi->no_iterations)
785     { /* do not log if nothing happened */
786         yaz_log(YLOG_LOG, "Iterations: isam/dict " 
787                 ZINT_FORMAT "/" ZINT_FORMAT,
788                 hi->no_iterations, hi->no_diffs);
789         yaz_log(YLOG_LOG, "Dict: inserts/updates/deletions: "
790                 ZINT_FORMAT "/" ZINT_FORMAT "/" ZINT_FORMAT,
791                 hi->no_insertions, hi->no_updates, hi->no_deletions);
792     }
793     key_block_destroy(&zh->reg->key_block);
794     key_heap_destroy(hi, nkeys);
795 }
796 /*
797  * Local variables:
798  * c-basic-offset: 4
799  * c-file-style: "Stroustrup"
800  * indent-tabs-mode: nil
801  * End:
802  * vim: shiftwidth=4 tabstop=8 expandtab
803  */
804