From: Eric Bollengier Date: Mon, 28 Apr 2008 18:45:25 +0000 (+0000) Subject: ebl try to cleanup hash driver X-Git-Tag: Release-3.0.0~1531 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=5f92612551bf94a1ab52b5dd5d16850e560a5696;p=bacula%2Fbacula ebl try to cleanup hash driver git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6852 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/filed/accurate.c b/bacula/src/filed/accurate.c index 5c78f8eb8a..c75d785d66 100644 --- a/bacula/src/filed/accurate.c +++ b/bacula/src/filed/accurate.c @@ -43,44 +43,12 @@ typedef struct PrivateCurFile { bool seen; } CurFile; -bool accurate_add_file(JCR *jcr, char *fname, char *lstat) -{ - CurFile elt; - struct stat statp; - int LinkFIc; - decode_stat(lstat, &statp, &LinkFIc); /* decode catalog stat */ - elt.ctime = statp.st_ctime; - elt.mtime = statp.st_mtime; - elt.seen = 0; - #ifdef USE_TCHDB - if (!tchdbputasync(jcr->file_list, - fname, strlen(fname)+1, - &elt, sizeof(CurFile))) - { - Dmsg1(2, "Can't add <%s> to file_list\n", fname); - /* TODO: check error */ - } -#else /* HTABLE */ - CurFile *item; - /* we store CurFile, fname and ctime/mtime in the same chunk */ - item = (CurFile *)jcr->file_list->hash_malloc(sizeof(CurFile)+strlen(fname)+1); - memcpy(item, &elt, sizeof(CurFile)); - item->fname = (char *)item+sizeof(CurFile); - strcpy(item->fname, fname); - jcr->file_list->insert(item->fname, item); -#endif - Dmsg2(2, "add fname=<%s> lstat=%s\n", fname, lstat); - return true; -} - -bool accurate_mark_file_as_seen(JCR *jcr, CurFile *elt) +static bool accurate_mark_file_as_seen(JCR *jcr, CurFile *elt) { bool ret=true; - CurFile deb; -#ifdef USE_TCHDB elt->seen = 1; if (!tchdbputasync(jcr->file_list, elt->fname, strlen(elt->fname)+1, @@ -90,19 +58,14 @@ bool accurate_mark_file_as_seen(JCR *jcr, CurFile *elt) ret = false; /* TODO: add error message */ } -#else /* HTABLE */ - CurFile *temp = (CurFile *)jcr->file_list->lookup(elt->fname); - temp->seen = 1; -#endif return ret; } -bool accurate_lookup(JCR *jcr, char *fname, CurFile *ret) +static bool accurate_lookup(JCR *jcr, char *fname, CurFile *ret) { bool found=false; ret->seen = 0; -#ifdef USE_TCHDB if (tchdbget3(jcr->file_list, fname, strlen(fname)+1, ret, sizeof(CurFile)) != -1) @@ -111,14 +74,6 @@ bool accurate_lookup(JCR *jcr, char *fname, CurFile *ret) ret->fname = fname; } -#else /* HTABLE */ - CurFile *temp = (CurFile *)jcr->file_list->lookup(fname); - if (temp) { - memcpy(ret, temp, sizeof(CurFile)); - found=true; - } -#endif - if (found) { Dmsg1(2, "lookup <%s> ok\n", fname); } @@ -126,31 +81,197 @@ bool accurate_lookup(JCR *jcr, char *fname, CurFile *ret) return found; } -bool accurate_init(JCR *jcr, int nbfile) +static bool accurate_init(JCR *jcr, int nbfile) { -#ifdef USE_TCHDB jcr->file_list = tchdbnew(); tchdbsetcache(jcr->file_list, 300000); tchdbtune(jcr->file_list, nbfile, /* nb bucket 0.5n to 4n */ - 7, /* size of element 2^x */ + 6, /* size of element 2^x */ 16, 0); /* options like compression */ /* TODO: make accurate file unique */ - POOL_MEM buf; - Mmsg(buf, "/tmp/casket.hdb.%i", jcr->JobId); - if(!tchdbopen(jcr->file_list, buf.c_str(), HDBOWRITER | HDBOCREAT)){ + POOLMEM *name = get_pool_memory(PM_MESSAGE); + make_unique_filename(name, jcr->JobId, "accurate"); + + if(!tchdbopen(jcr->file_list, name, HDBOWRITER | HDBOCREAT)){ /* TODO: handle error creation */ //ecode = tchdbecode(hdb); //fprintf(stderr, "open error: %s\n", tchdberrmsg(ecode)); } + free_pool_memory(name); + return true; +} -#else /* HTABLE */ + +bool accurate_send_deleted_list(JCR *jcr) +{ + CurFile elt; + FF_PKT *ff_pkt; + int stream = STREAM_UNIX_ATTRIBUTES; + + if (!jcr->accurate || jcr->JobLevel == L_FULL) { + goto bail_out; + } + + if (jcr->file_list == NULL) { + goto bail_out; + } + + ff_pkt = init_find_files(); + ff_pkt->type = FT_DELETED; + + char *key; + /* traverse records */ + tchdbiterinit(jcr->file_list); + while((key = tchdbiternext2(jcr->file_list)) != NULL) { + if (tchdbget3(jcr->file_list, + key, strlen(key)+1, + &elt, sizeof(CurFile)) != -1) + { + if (!elt.seen) { + ff_pkt->fname = key; + ff_pkt->statp.st_mtime = elt.mtime; + ff_pkt->statp.st_ctime = elt.ctime; + encode_and_send_attributes(jcr, ff_pkt, stream); + Dmsg1(2, "deleted <%s>\n", key); + } +// free(key); + + } else { /* TODO: add error message */ + Dmsg1(2, "No value for <%s> key\n", key); + } + } + + term_find_files(ff_pkt); +bail_out: + /* TODO: clean htable when this function is not reached ? */ + if (jcr->file_list) { + if(!tchdbclose(jcr->file_list)){ +// ecode = tchdbecode(hdb); +// fprintf(stderr, "close error: %s\n", tchdberrmsg(ecode)); + } + + /* delete the object */ + tchdbdel(jcr->file_list); + + POOLMEM *name = get_pool_memory(PM_MESSAGE); + make_unique_filename(name, jcr->JobId, "accurate"); + +// unlink(name); + + free_pool_memory(name); + + jcr->file_list = NULL; + } + return true; +} + +#else /* HTABLE mode */ + +static bool accurate_mark_file_as_seen(JCR *jcr, CurFile *elt) +{ + CurFile *temp = (CurFile *)jcr->file_list->lookup(elt->fname); + temp->seen = 1; /* records are in memory */ + return true; +} + +static bool accurate_lookup(JCR *jcr, char *fname, CurFile *ret) +{ + bool found=false; + ret->seen = 0; + + CurFile *temp = (CurFile *)jcr->file_list->lookup(fname); + if (temp) { + memcpy(ret, temp, sizeof(CurFile)); + found=true; + } + + if (found) { + Dmsg1(2, "lookup <%s> ok\n", fname); + } + + return found; +} + +static bool accurate_init(JCR *jcr, int nbfile) +{ CurFile *elt=NULL; jcr->file_list = (htable *)malloc(sizeof(htable)); jcr->file_list->init(elt, &elt->link, nbfile); + return true; +} + +bool accurate_send_deleted_list(JCR *jcr) +{ + CurFile *elt; + FF_PKT *ff_pkt; + int stream = STREAM_UNIX_ATTRIBUTES; + + if (!jcr->accurate || jcr->JobLevel == L_FULL) { + goto bail_out; + } + + if (jcr->file_list == NULL) { + goto bail_out; + } + + ff_pkt = init_find_files(); + ff_pkt->type = FT_DELETED; + + foreach_htable (elt, jcr->file_list) { + if (!elt->seen) { /* already seen */ + Dmsg2(1, "deleted fname=%s seen=%i\n", elt->fname, elt->seen); + ff_pkt->fname = elt->fname; + ff_pkt->statp.st_mtime = elt->mtime; + ff_pkt->statp.st_ctime = elt->ctime; + encode_and_send_attributes(jcr, ff_pkt, stream); + } +// free(elt->fname); + } + + term_find_files(ff_pkt); +bail_out: + /* TODO: clean htable when this function is not reached ? */ + if (jcr->file_list) { + jcr->file_list->destroy(); + free(jcr->file_list); + jcr->file_list = NULL; + } + return true; +} + +#endif + +static bool accurate_add_file(JCR *jcr, char *fname, char *lstat) +{ + CurFile elt; + struct stat statp; + int LinkFIc; + decode_stat(lstat, &statp, &LinkFIc); /* decode catalog stat */ + elt.ctime = statp.st_ctime; + elt.mtime = statp.st_mtime; + elt.seen = 0; + +#ifdef USE_TCHDB + if (!tchdbputasync(jcr->file_list, + fname, strlen(fname)+1, + &elt, sizeof(CurFile))) + { + Dmsg1(2, "Can't add <%s> to file_list\n", fname); + /* TODO: check error */ + } +#else /* HTABLE */ + CurFile *item; + /* we store CurFile, fname and ctime/mtime in the same chunk */ + item = (CurFile *)jcr->file_list->hash_malloc(sizeof(CurFile)+strlen(fname)+1); + memcpy(item, &elt, sizeof(CurFile)); + item->fname = (char *)item+sizeof(CurFile); + strcpy(item->fname, fname); + jcr->file_list->insert(item->fname, item); #endif + Dmsg2(2, "add fname=<%s> lstat=%s\n", fname, lstat); return true; } @@ -259,81 +380,3 @@ int accurate_cmd(JCR *jcr) return true; } - -bool accurate_send_deleted_list(JCR *jcr) -{ - CurFile *elt; - FF_PKT *ff_pkt; - int stream = STREAM_UNIX_ATTRIBUTES; - - if (!jcr->accurate || jcr->JobLevel == L_FULL) { - goto bail_out; - } - - if (jcr->file_list == NULL) { - goto bail_out; - } - - ff_pkt = init_find_files(); - ff_pkt->type = FT_DELETED; - -#ifdef USE_TCHDB - char *key; - CurFile item; - elt = &item; - /* traverse records */ - tchdbiterinit(jcr->file_list); - while((key = tchdbiternext2(jcr->file_list)) != NULL) { - if (tchdbget3(jcr->file_list, - key, strlen(key)+1, - elt, sizeof(CurFile)) != -1) - { - if (!elt->seen) { - ff_pkt->fname = key; - ff_pkt->statp.st_mtime = elt->mtime; - ff_pkt->statp.st_ctime = elt->ctime; - encode_and_send_attributes(jcr, ff_pkt, stream); - Dmsg1(2, "deleted <%s>\n", key); - } - // free(key); - - } else { /* TODO: add error message */ - Dmsg1(2, "No value for <%s> key\n", key); - } - } -#else - foreach_htable (elt, jcr->file_list) { - if (!elt->seen) { /* already seen */ - Dmsg2(1, "deleted fname=%s seen=%i\n", elt->fname, elt->seen); - ff_pkt->fname = elt->fname; - ff_pkt->statp.st_mtime = elt->mtime; - ff_pkt->statp.st_ctime = elt->ctime; - encode_and_send_attributes(jcr, ff_pkt, stream); - } -// free(elt->fname); - } -#endif - - term_find_files(ff_pkt); -bail_out: - /* TODO: clean htable when this function is not reached ? */ - if (jcr->file_list) { -#ifdef USE_TCHDB - if(!tchdbclose(jcr->file_list)){ -// ecode = tchdbecode(hdb); -// fprintf(stderr, "close error: %s\n", tchdberrmsg(ecode)); - } - - /* delete the object */ - tchdbdel(jcr->file_list); - POOL_MEM buf; - Mmsg(buf, "/tmp/casket.hdb.%i", jcr->JobId); -// unlink("/tmp/casket.hdb"); -#else - jcr->file_list->destroy(); - free(jcr->file_list); -#endif - jcr->file_list = NULL; - } - return true; -}