From: Adam Dickmeiss Date: Wed, 4 Oct 2006 09:07:19 +0000 (+0000) Subject: Simplify and optimize commit clean operation. X-Git-Tag: ZEBRA.1.3.40~2 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=1798f96ed4fcb8f80ae78a8f73eca902338142b0;p=idzebra-moved-to-github.git Simplify and optimize commit clean operation. --- diff --git a/bfile/bfile.c b/bfile/bfile.c index 45610b8..0d90913 100644 --- a/bfile/bfile.c +++ b/bfile/bfile.c @@ -1,4 +1,4 @@ -/* $Id: bfile.c,v 1.35.2.1 2006-08-14 10:38:50 adam Exp $ +/* $Id: bfile.c,v 1.35.2.2 2006-10-04 09:07:19 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -199,8 +199,8 @@ void bf_reset (BFiles bfs) { if (!bfs) return; - mf_reset (bfs->commit_area); - mf_reset (bfs->register_area); + mf_reset(bfs->commit_area, 1); + mf_reset(bfs->register_area, 1); } void bf_commitExec (BFiles bfs) @@ -247,17 +247,8 @@ void bf_commitClean (BFiles bfs, const char *spec) mustDisable = 1; } - if (!(inf = open_cache (bfs, "rb"))) - return ; - while (fscanf (inf, "%s %d", path, &block_size) == 2) - { - mf = mf_open (bfs->register_area, path, block_size, 0); - cf = cf_open (mf, bfs->commit_area, path, block_size, 1, &firstTime); - cf_unlink (cf); - cf_close (cf); - mf_close (mf); - } - fclose (inf); + mf_reset(bfs->commit_area, 1); + unlink_cache (bfs); if (mustDisable) bf_cache (bfs, 0); diff --git a/bfile/commit.c b/bfile/commit.c index e2f66b1..3f92dde 100644 --- a/bfile/commit.c +++ b/bfile/commit.c @@ -1,4 +1,4 @@ -/* $Id: commit.c,v 1.16.2.1 2006-08-14 10:38:50 adam Exp $ +/* $Id: commit.c,v 1.16.2.2 2006-10-04 09:07:19 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -31,20 +31,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define CF_OPTIMIZE_COMMIT 0 -void cf_unlink (CFile cf) -{ - if (cf->bucket_in_memory) - { - logf (LOG_FATAL, "Cannot unlink potential dirty cache"); - exit (1); - } - cf->head.state = 0; - cf->dirty = 1; - mf_unlink (cf->block_mf); - mf_unlink (cf->hash_mf); -} - - #if CF_OPTIMIZE_COMMIT struct map_cache_entity { int from; diff --git a/bfile/mfile.c b/bfile/mfile.c index e2b9b72..8bbce07 100644 --- a/bfile/mfile.c +++ b/bfile/mfile.c @@ -1,4 +1,4 @@ -/* $Id: mfile.c,v 1.52.2.1 2006-08-14 10:38:50 adam Exp $ +/* $Id: mfile.c,v 1.52.2.2 2006-10-04 09:07:19 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps @@ -244,7 +244,6 @@ MFile_area mf_init(const char *name, const char *spec, const char *base) meta_f->next = ma->mfiles; meta_f->open = 0; meta_f->cur_file = -1; - meta_f->unlink_flag = 0; ma->mfiles = meta_f; strcpy(meta_f->name, metaname); part_f = &meta_f->files[0]; @@ -301,24 +300,11 @@ void mf_destroy(MFile_area ma) dp = dp->next; xfree (d); } - meta_f = ma->mfiles; - while (meta_f) - { - int i; - meta_file *m = meta_f; - - for (i = 0; ino_files; i++) - { - xfree (m->files[i].path); - } - zebra_mutex_destroy (&meta_f->mutex); - meta_f = meta_f->next; - xfree (m); - } + mf_reset(ma, 0); xfree (ma); } -void mf_reset(MFile_area ma) +void mf_reset(MFile_area ma, int unlink_flag) { meta_file *meta_f; @@ -330,13 +316,16 @@ void mf_reset(MFile_area ma) int i; meta_file *m = meta_f; + meta_f = meta_f->next; + assert (!m->open); for (i = 0; ino_files; i++) { - unlink (m->files[i].path); + if (unlink_flag) + unlink (m->files[i].path); xfree (m->files[i].path); } - meta_f = meta_f->next; + zebra_mutex_destroy (&m->mutex); xfree (m); } ma->mfiles = 0; @@ -344,7 +333,6 @@ void mf_reset(MFile_area ma) /* * Open a metafile. - * If !ma, Use MF_DEFAULT_AREA. */ MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag) { @@ -376,7 +364,6 @@ MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag) mnew->files[0].top = -1; mnew->files[0].number = 0; mnew->files[0].fd = -1; - mnew->unlink_flag = 0; mnew->min_bytes_creat = MF_MIN_BLOCKS_CREAT * block_size; for (dp = ma->dirs; dp && dp->max_bytes >= 0 && dp->avail_bytes < mnew->min_bytes_creat; dp = dp->next); @@ -441,8 +428,6 @@ int mf_close(MFile mf) close(mf->files[i].fd); mf->files[i].fd = -1; } - if (mf->unlink_flag) - unlink(mf->files[i].path); } mf->open = 0; return 0; @@ -587,27 +572,3 @@ int mf_write(MFile mf, int no, int offset, int nbytes, const void *buf) return 0; } -/* - * Destroy a metafile, unlinking component files. File must be open. - */ -int mf_unlink(MFile mf) -{ - if (mf->open) - mf->unlink_flag = 1; - else - { - int i; - for (i = 0; ino_files; i++) - unlink(mf->files[i].path); - } - return 0; -} - -/* - * Unlink the file by name, rather than MFile-handle. File should be closed. - */ -int mf_unlink_name(MFile_area ma, const char *name) -{ - abort(); - return 0; -} diff --git a/include/mfile.h b/include/mfile.h index 63ce4e6..07657f4 100644 --- a/include/mfile.h +++ b/include/mfile.h @@ -1,4 +1,4 @@ -/* $Id: mfile.h,v 1.21.2.1 2006-08-14 10:38:56 adam Exp $ +/* $Id: mfile.h,v 1.21.2.2 2006-10-04 09:07:19 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps @@ -91,7 +91,6 @@ typedef struct meta_file int no_files; int cur_file; int open; /* is this file open? */ - int unlink_flag; int blocksize; mfile_off_t min_bytes_creat; /* minimum bytes required to enter directory */ MFile_area ma; @@ -141,15 +140,9 @@ int mf_read(MFile mf, int no, int offset, int nbytes, void *buf); int mf_write(MFile mf, int no, int offset, int nbytes, const void *buf); /* - * Destroy a metafile, unlinking component files. File must be open. - */ -int mf_unlink(MFile mf); - - -/* * Destroy all metafiles. No files may be opened. */ -void mf_reset(MFile_area ma); +void mf_reset(MFile_area ma, int unlink_flag); /* * Unlink the file by name, rather than MFile-handle.