]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/accurate-rm-tokyo-add-rblist.patch
ebl cleanup
[bacula/bacula] / bacula / patches / testing / accurate-rm-tokyo-add-rblist.patch
1 Index: src/filed/accurate.c
2 ===================================================================
3 --- src/filed/accurate.c        (revision 7617)
4 +++ src/filed/accurate.c        (working copy)
5 @@ -33,182 +33,46 @@
6  #include "bacula.h"
7  #include "filed.h"
8  
9 -static int dbglvl=200;
10 +static int dbglvl=2;
11  
12  typedef struct PrivateCurFile {
13 -#ifndef USE_TCADB
14 -   hlink link;
15 -#endif
16 -   char *fname;                 /* not stored with tchdb mode */
17 +   rblink link;
18 +   char *fname;
19     time_t ctime;
20     time_t mtime;
21     bool seen;
22  } CurFile;
23  
24 -#ifdef USE_TCADB
25 -static void realfree(void *p);  /* used by tokyo code */
26 -
27 -/*
28 - * Update hash element seen=1
29 - */
30 -static bool accurate_mark_file_as_seen(JCR *jcr, CurFile *elt)
31 +static int my_cmp(void *item1, void *item2)
32  {
33 -   bool ret=true;
34 -
35 -   elt->seen = 1;
36 -   if (!tcadbput(jcr->file_list, 
37 -                 elt->fname, strlen(elt->fname)+1, 
38 -                 elt, sizeof(CurFile)))
39 -   { /* TODO: disabling accurate mode ?  */
40 -      Jmsg(jcr, M_ERROR, 1, _("Can't update accurate hash disk\n"));
41 -      ret = false;
42 -   }
43 -
44 -   return ret;
45 +   CurFile *elt1, *elt2;
46 +   elt1 = (CurFile *) item1;
47 +   elt2 = (CurFile *) item2;
48 +   return strcmp(elt1->fname, elt2->fname);
49  }
50  
51 -static bool accurate_lookup(JCR *jcr, char *fname, CurFile *ret)
52 +static bool accurate_mark_file_as_seen(JCR *jcr, CurFile *elt)
53  {
54 -   bool found=false;
55 -   ret->seen = 0;
56 -   int size;
57 -   CurFile *elt;
58 -
59 -   elt = (CurFile*)tcadbget(jcr->file_list, 
60 -                            fname, strlen(fname)+1, &size);
61 -   if (elt)
62 -   {
63 -      /* TODO: don't malloc/free results */
64 -      found = true;
65 -      elt->fname = fname;
66 -      memcpy(ret, elt, sizeof(CurFile));
67 -      realfree(elt);
68 -//    Dmsg1(dbglvl, "lookup <%s> ok\n", fname);
69 +   /* TODO: just use elt->seen = 1 */
70 +   CurFile *temp = (CurFile *)jcr->file_list->search(elt, my_cmp);
71 +   if (temp) {
72 +      temp->seen = 1;              /* records are in memory */
73     }
74 -   return found;
75 -}
76 -
77 -/* Create tokyo dbm hash file 
78 - * If something goes wrong, we cancel accurate mode.
79 - */
80 -static bool accurate_init(JCR *jcr, int nbfile)
81 -{
82 -   jcr->file_list = tcadbnew();
83 -//
84 -//   tchdbsetcache(jcr->file_list, 300000);
85 -//   tchdbtune(jcr->file_list,
86 -//           nbfile,            /* nb bucket 0.5n to 4n */
87 -//           6,                 /* size of element 2^x */
88 -//           16,
89 -//           0);                /* options like compression */
90 -//
91 -   jcr->hash_name  = get_pool_memory(PM_MESSAGE);
92 -   POOLMEM *temp = get_pool_memory(PM_MESSAGE);
93 -
94 -   if (nbfile > 500000) {
95 -      make_unique_filename(&jcr->hash_name, jcr->JobId, "accurate");
96 -      pm_strcat(jcr->hash_name, ".tcb");
97 -      Mmsg(temp, "%s#bnum=%i#mode=e#opts=l",
98 -           jcr->hash_name, nbfile*4); 
99 -      Dmsg1(dbglvl, "Doing accurate hash on disk %s\n", jcr->hash_name);
100 -   } else {
101 -      Dmsg0(dbglvl, "Doing accurate hash on memory\n");
102 -      pm_strcpy(jcr->hash_name, "*");
103 -      pm_strcpy(temp, "*");
104 -   }
105 -   
106 -   if(!tcadbopen(jcr->file_list, jcr->hash_name)){
107 -      Jmsg(jcr, M_ERROR, 1, _("Can't open accurate hash disk\n"));
108 -      Jmsg(jcr, M_INFO, 1, _("Disabling accurate mode\n"));
109 -      tcadbdel(jcr->file_list);
110 -      jcr->file_list = NULL;
111 -      jcr->accurate = false;
112 -   }
113 -   free_pool_memory(temp);
114 -   return jcr->file_list != NULL;
115 -}
116 -
117 -/* This function is called at the end of backup
118 - * We walk over all hash disk element, and we check
119 - * for elt.seen.
120 - */
121 -bool accurate_send_deleted_list(JCR *jcr)
122 -{
123 -   char *key;
124 -   CurFile *elt;
125 -   int size;
126 -   FF_PKT *ff_pkt;
127 -   int stream = STREAM_UNIX_ATTRIBUTES;
128 -
129 -   if (!jcr->accurate || jcr->get_JobLevel() == L_FULL) {
130 -      goto bail_out;
131 -   }
132 -
133 -   if (jcr->file_list == NULL) {
134 -      goto bail_out;
135 -   }
136 -
137 -   ff_pkt = init_find_files();
138 -   ff_pkt->type = FT_DELETED;
139 -
140 -   /* traverse records */
141 -   tcadbiterinit(jcr->file_list);
142 -   while((key = tcadbiternext2(jcr->file_list)) != NULL) {
143 -      elt = (CurFile *) tcadbget(jcr->file_list, 
144 -                                 key, strlen(key)+1, &size);
145 -      if (elt)
146 -      {
147 -         if (!elt->seen) {      /* already seen */
148 -            ff_pkt->fname = key;
149 -            ff_pkt->statp.st_mtime = elt->mtime;
150 -            ff_pkt->statp.st_ctime = elt->ctime;
151 -            encode_and_send_attributes(jcr, ff_pkt, stream);
152 -         }
153 -         realfree(elt);
154 -      }
155 -      realfree(key);            /* tokyo cabinet have to use real free() */
156 -   }
157 -
158 -   term_find_files(ff_pkt);
159 -bail_out:
160 -   /* TODO: clean htable when this function is not reached ? */
161 -   if (jcr->file_list) {
162 -      if(!tcadbclose(jcr->file_list)){
163 -         Jmsg(jcr, M_ERROR, 1, _("Can't close accurate hash disk\n"));
164 -      }
165 -
166 -      /* delete the object */
167 -      tcadbdel(jcr->file_list);
168 -      if (!bstrcmp(jcr->hash_name, "*")) {
169 -         unlink(jcr->hash_name);
170 -      }
171 -
172 -      free_pool_memory(jcr->hash_name);
173 -      jcr->hash_name = NULL;
174 -      jcr->file_list = NULL;
175 -   }
176     return true;
177  }
178  
179 -#else  /* HTABLE mode */
180 -
181 -static bool accurate_mark_file_as_seen(JCR *jcr, CurFile *elt)
182 -{
183 -   CurFile *temp = (CurFile *)jcr->file_list->lookup(elt->fname);
184 -   temp->seen = 1;              /* records are in memory */
185 -   return true;
186 -}
187 -
188  static bool accurate_lookup(JCR *jcr, char *fname, CurFile *ret)
189  {
190     bool found=false;
191     ret->seen = 0;
192  
193 -   CurFile *temp = (CurFile *)jcr->file_list->lookup(fname);
194 +   CurFile search;
195 +   search.fname = fname;
196 +   CurFile *temp = (CurFile *)jcr->file_list->search(&search, my_cmp);
197     if (temp) {
198        memcpy(ret, temp, sizeof(CurFile));
199        found=true;
200 -//    Dmsg1(dbglvl, "lookup <%s> ok\n", fname);
201 +      Dmsg1(dbglvl, "lookup <%s> ok\n", fname);
202     }
203  
204     return found;
205 @@ -217,8 +81,7 @@
206  static bool accurate_init(JCR *jcr, int nbfile)
207  {
208     CurFile *elt = NULL;
209 -   jcr->file_list = (htable *)malloc(sizeof(htable));
210 -   jcr->file_list->init(elt, &elt->link, nbfile);
211 +   jcr->file_list = New(rblist(elt, &elt->link));
212     return true;
213  }
214  
215 @@ -243,7 +106,7 @@
216     ff_pkt = init_find_files();
217     ff_pkt->type = FT_DELETED;
218  
219 -   foreach_htable(elt, jcr->file_list) {
220 +   foreach_rblist(elt, jcr->file_list) {
221        if (!elt->seen) { /* already seen */
222           Dmsg2(dbglvl, "deleted fname=%s seen=%i\n", elt->fname, elt->seen);
223           ff_pkt->fname = elt->fname;
224 @@ -258,15 +121,12 @@
225  bail_out:
226     /* TODO: clean htable when this function is not reached ? */
227     if (jcr->file_list) {
228 -      jcr->file_list->destroy();
229 -      free(jcr->file_list);
230 +      delete jcr->file_list;
231        jcr->file_list = NULL;
232     }
233     return true;
234  }
235  
236 -#endif /* common code */
237 -
238  static bool accurate_add_file(JCR *jcr, char *fname, char *lstat)
239  {
240     bool ret = true;
241 @@ -278,25 +138,15 @@
242     elt.mtime = statp.st_mtime;
243     elt.seen = 0;
244  
245 -#ifdef USE_TCADB
246 -   if (!tcadbput(jcr->file_list,
247 -                 fname, strlen(fname)+1,
248 -                 &elt, sizeof(CurFile)))
249 -   {
250 -      Jmsg(jcr, M_ERROR, 1, _("Can't update accurate hash disk ERR=%s\n"));
251 -      ret = false;
252 -   }
253 -#else  /* HTABLE */
254     CurFile *item;
255     /* we store CurFile, fname and ctime/mtime in the same chunk */
256 -   item = (CurFile *)jcr->file_list->hash_malloc(sizeof(CurFile)+strlen(fname)+1);
257 +   item = (CurFile *)malloc(sizeof(CurFile)+strlen(fname)+1);
258     memcpy(item, &elt, sizeof(CurFile));
259     item->fname  = (char *)item+sizeof(CurFile);
260     strcpy(item->fname, fname);
261 -   jcr->file_list->insert(item->fname, item); 
262 -#endif
263 +   jcr->file_list->insert(item, my_cmp); 
264  
265 -// Dmsg2(dbglvl, "add fname=<%s> lstat=%s\n", fname, lstat);
266 +   Dmsg2(dbglvl, "add fname=<%s> lstat=%s\n", fname, lstat);
267     return ret;
268  }
269  
270 @@ -399,17 +249,3 @@
271  
272     return true;
273  }
274 -
275 -#ifdef USE_TCADB
276 -
277 -/*
278 - * Tokyo Cabinet library doesn't use smartalloc by default
279 - * results need to be released with real free()
280 - */
281 -#undef free
282 -void realfree(void *p)
283 -{
284 -   free(p);
285 -}
286 -
287 -#endif
288 Index: src/jcr.h
289 ===================================================================
290 --- src/jcr.h   (revision 7618)
291 +++ src/jcr.h   (working copy)
292 @@ -350,12 +350,7 @@
293     CRYPTO_CTX crypto;                 /* Crypto ctx */
294     DIRRES* director;                  /* Director resource */
295     bool VSS;                          /* VSS used by FD */
296 -#ifdef USE_TCADB
297 -   TCADB *file_list;                  /* Previous file list (accurate mode) */
298 -   POOLMEM *hash_name;
299 -#else
300 -   htable *file_list;                 /* Previous file list (accurate mode) */
301 -#endif
302 +   rblist *file_list;                 /* Previous file list (accurate mode) */
303  #endif /* FILE_DAEMON */
304  
305