From a5ea5985a282ff55b4f86b47045be40300a746a8 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 11 Dec 2008 10:27:50 +0100 Subject: [PATCH] Partial fix of bug #2338: Drop database does not free up space. The recd{A,B} no longer leaks, but sort register files are still around. --- index/invstat.c | 2 +- index/recindex.h | 2 +- index/records.c | 39 +++++++++++++++++++++++++++++++++++---- index/zebraapi.c | 1 - index/zinfo.c | 4 ++-- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/index/invstat.c b/index/invstat.c index 192c588..52dcd01 100644 --- a/index/invstat.c +++ b/index/invstat.c @@ -291,7 +291,7 @@ int zebra_register_statistics (ZebraHandle zh, int dumpdict) } fprintf (stdout, "%7d- %7d\n", prev, stat_info.isam_occurrences[i]); - rec_prstat(zh->reg->records); + rec_prstat(zh->reg->records, 0); xmalloc_trav("unfreed"); /*! while hunting memory leaks */ zebra_end_read (zh); return 0; diff --git a/index/recindex.h b/index/recindex.h index d353c3c..68d0ac6 100644 --- a/index/recindex.h +++ b/index/recindex.h @@ -86,7 +86,7 @@ ZEBRA_RES rec_close (Records *p); Records rec_open(BFiles bfs, int rw, int compression_method); char *rec_strdup(const char *s, size_t *len); -void rec_prstat(Records p); +void rec_prstat(Records p, int verbose); zint rec_sysno_to_int(zint sysno); diff --git a/index/records.c b/index/records.c index e52368f..07f9e81 100644 --- a/index/records.c +++ b/index/records.c @@ -171,6 +171,7 @@ static ZEBRA_RES rec_release_blocks(Records p, zint sysno) memcpy(block_and_ref + sizeof(freeblock), &ref, sizeof(ref)); if (ref) { + /* there is still a reference to this block.. */ if (bf_write(p->data_BFile[dst_type], freeblock, 0, sizeof(block_and_ref), block_and_ref)) { @@ -179,7 +180,8 @@ static ZEBRA_RES rec_release_blocks(Records p, zint sysno) } return ZEBRA_OK; } - first = 0; + /* the list of blocks can all be removed (ref == 0) */ + first = 0; } if (bf_write(p->data_BFile[dst_type], freeblock, 0, sizeof(freeblock), @@ -206,7 +208,6 @@ static ZEBRA_RES rec_delete_single(Records p, Record rec) if (rec_release_blocks(p, rec_sysno_to_int(rec->sysno)) != ZEBRA_OK) return ZEBRA_FAIL; - yaz_log(YLOG_LOG, "rec_delete_single sysno=" ZINT_FORMAT, rec->sysno); entry.next = p->head.index_free; entry.size = 0; p->head.index_free = rec_sysno_to_int(rec->sysno); @@ -523,8 +524,10 @@ static ZEBRA_RES rec_write_multiple(Records p, int saveCount) e->flag = recordFlagNop; break; - default: + case recordFlagNop: break; + default: + break; } } @@ -983,7 +986,7 @@ char *rec_strdup(const char *s, size_t *len) return p; } -void rec_prstat(Records records) +void rec_prstat(Records records, int verbose) { int i; zint total_bytes = 0; @@ -1003,6 +1006,34 @@ void rec_prstat(Records records) records->head.block_used[i] * records->head.block_size[i]); total_bytes += records->head.block_used[i] * records->head.block_size[i]; + + yaz_log(YLOG_LOG, " Block Last " ZINT_FORMAT, records->head.block_last[i]); + if (verbose) + { /* analyse free lists */ + zint no_free = 0; + zint block_free = records->head.block_free[i]; + WRBUF w = wrbuf_alloc(); + while (block_free) + { + zint nblock; + no_free++; + wrbuf_printf(w, " " ZINT_FORMAT, block_free); + if (bf_read(records->data_BFile[i], + block_free, 0, sizeof(nblock), &nblock) != 1) + { + yaz_log(YLOG_FATAL|YLOG_ERRNO, "read in %s at free block " + ZINT_FORMAT, + records->data_fname[i], block_free); + break; + } + block_free = nblock; + } + yaz_log (YLOG_LOG, + " Number in free list %8" ZINT_FORMAT0, no_free); + if (no_free) + yaz_log(YLOG_LOG, "%s", wrbuf_cstr(w)); + wrbuf_destroy(w); + } } yaz_log (YLOG_LOG, "Total size of record index in bytes %8" ZINT_FORMAT0, diff --git a/index/zebraapi.c b/index/zebraapi.c index 28886ff..0705070 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1453,7 +1453,6 @@ int delete_w_all_handle(const char *info, void *handle) while (isamb_pp_read(pt, &key)) { Record rec; - yaz_log(YLOG_LOG, "SYSNO=" ZINT_FORMAT, key.mem[0]); rec = rec_get(zh->reg->records, key.mem[0]); rec_del(zh->reg->records, &rec); } diff --git a/index/zinfo.c b/index/zinfo.c index cd8bb3f..c0281e0 100644 --- a/index/zinfo.c +++ b/index/zinfo.c @@ -767,12 +767,12 @@ int zebraExplain_removeDatabase(ZebraExplainInfo zei, void *update_handle) rec = rec_get(zei->records, zad->sysno); (*zei->updateFunc)(zei->updateHandle, rec, 0); - rec_free(&rec); + rec_del(zei->records, &rec); } /* remove database record keys and delete it */ rec = rec_get(zei->records, zdi->sysno); (*zei->updateFunc)(zei->updateHandle, rec, 0); - rec_free(&rec); + rec_del(zei->records, &rec); /* remove from list */ *zdip = zdi->next; -- 1.7.10.4