From: Adam Dickmeiss Date: Mon, 9 Oct 2006 22:10:00 +0000 (+0000) Subject: Simplify and optimize commit clean operation X-Git-Tag: ZEBRA.2.0.6~102 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=3946190aece0417a4ad4e40946dfcb9f1bca4755;p=idzebra-moved-to-github.git Simplify and optimize commit clean operation --- diff --git a/bfile/bfile.c b/bfile/bfile.c index 0bb409e..72d1b14 100644 --- a/bfile/bfile.c +++ b/bfile/bfile.c @@ -1,4 +1,4 @@ -/* $Id: bfile.c,v 1.48 2006-08-14 10:40:05 adam Exp $ +/* $Id: bfile.c,v 1.49 2006-10-09 22:10:00 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -329,8 +329,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) @@ -377,17 +377,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/cfile.h b/bfile/cfile.h index c6b6ba6..c027e9d 100644 --- a/bfile/cfile.h +++ b/bfile/cfile.h @@ -1,4 +1,4 @@ -/* $Id: cfile.h,v 1.19 2006-08-14 10:40:05 adam Exp $ +/* $Id: cfile.h,v 1.20 2006-10-09 22:10:00 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -80,7 +80,6 @@ CFile cf_open (MFile mf, MFile_area area, const char *fname, int block_size, int wflag, int *firstp); int cf_read (CFile cf, zint no, int offset, int nbytes, void *buf); int cf_write (CFile cf, zint no, int offset, int nbytes, const void *buf); -void cf_unlink (CFile cf); void cf_commit (CFile cf); YAZ_END_CDECL diff --git a/bfile/commit.c b/bfile/commit.c index a4dacda..9fda156 100644 --- a/bfile/commit.c +++ b/bfile/commit.c @@ -1,4 +1,4 @@ -/* $Id: commit.c,v 1.28 2006-08-14 10:40:05 adam Exp $ +/* $Id: commit.c,v 1.29 2006-10-09 22:10:00 adam Exp $ Copyright (C) 1995-2006 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) - { - yaz_log (YLOG_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 21ea322..06d4781 100644 --- a/bfile/mfile.c +++ b/bfile/mfile.c @@ -1,4 +1,4 @@ -/* $Id: mfile.c,v 1.67 2006-08-14 10:40:05 adam Exp $ +/* $Id: mfile.c,v 1.68 2006-10-09 22:10:00 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -252,7 +252,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]; @@ -309,24 +308,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; @@ -338,13 +324,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; @@ -352,7 +341,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) { @@ -384,7 +372,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); @@ -437,7 +424,7 @@ int mf_close(MFile mf) { int i; - yaz_log (YLOG_DEBUG, "mf_close(%s) unlink=%d", mf->name, mf->unlink_flag); + yaz_log (YLOG_DEBUG, "mf_close(%s)", mf->name); assert(mf->open); for (i = 0; i < mf->no_files; i++) { @@ -449,8 +436,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; @@ -598,24 +583,6 @@ int mf_write(MFile mf, zint 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; -} - int mf_area_directory_stat(MFile_area ma, int no, const char **directory, double *used_bytes, double *max_bytes) { diff --git a/bfile/mfile.h b/bfile/mfile.h index 7b5be30..71fbf9d 100644 --- a/bfile/mfile.h +++ b/bfile/mfile.h @@ -1,4 +1,4 @@ -/* $Id: mfile.h,v 1.6 2006-08-14 10:40:05 adam Exp $ +/* $Id: mfile.h,v 1.7 2006-10-09 22:10:00 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -85,7 +85,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; @@ -135,15 +134,9 @@ int mf_read(MFile mf, zint no, int offset, int nbytes, void *buf); int mf_write(MFile mf, zint 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); /* \brief gets statistics about directory in metafile area \param ma the area