]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/accurate-batch.patch
Cleanup patches a bit
[bacula/bacula] / bacula / patches / testing / accurate-batch.patch
1 Index: src/cats/sql.c
2 ===================================================================
3 --- src/cats/sql.c      (révision 7344)
4 +++ src/cats/sql.c      (copie de travail)
5 @@ -635,5 +635,43 @@
6     return;
7  }
8  
9 +/* 
10 + * Open a new connexion to mdb catalog. This function is used
11 + * by batch and accurate mode.
12 + */
13 +bool db_open_batch_connexion(JCR *jcr, B_DB *mdb)
14 +{
15 +   int multi_db=false;
16  
17 +#ifdef HAVE_BATCH_FILE_INSERT
18 +   multi_db=true;              /* we force a new connexion only if batch insert is enabled */
19 +#endif
20 +
21 +   if (!jcr->db_batch) {
22 +      jcr->db_batch = db_init_database(jcr, 
23 +                                      mdb->db_name, 
24 +                                      mdb->db_user,
25 +                                      mdb->db_password, 
26 +                                      mdb->db_address,
27 +                                      mdb->db_port,
28 +                                      mdb->db_socket,
29 +                                      multi_db /* multi_db = true when using batch mode */);
30 +      if (!jcr->db_batch) {
31 +         Jmsg0(jcr, M_FATAL, 0, "Could not init batch connexion");
32 +         return false;
33 +      }
34 +
35 +      if (!db_open_database(jcr, jcr->db_batch)) {
36 +         Mmsg2(&jcr->db_batch->errmsg,  _("Could not open database \"%s\": ERR=%s\n"),
37 +              jcr->db_batch->db_name, db_strerror(jcr->db_batch));
38 +         Jmsg1(jcr, M_FATAL, 0, "%s", jcr->db_batch->errmsg);
39 +         return false;
40 +      }      
41 +      Dmsg3(100, "initdb ref=%d connected=%d db=%p\n", jcr->db_batch->ref_count,
42 +            jcr->db_batch->connected, jcr->db_batch->db);
43 +
44 +   }
45 +   return true;
46 +}
47 +
48  #endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL*/
49 Index: src/cats/protos.h
50 ===================================================================
51 --- src/cats/protos.h   (révision 7344)
52 +++ src/cats/protos.h   (copie de travail)
53 @@ -49,6 +49,7 @@
54                         int mult_db_connections);
55  int  db_open_database(JCR *jcr, B_DB *db);
56  void db_close_database(JCR *jcr, B_DB *db);
57 +bool db_open_batch_connexion(JCR *jcr, B_DB *mdb);
58  void db_escape_string(JCR *jcr, B_DB *db, char *snew, char *old, int len);
59  char *db_strerror(B_DB *mdb);
60  int  db_next_index(JCR *jcr, B_DB *mdb, char *table, char *index);
61 Index: src/cats/sql_create.c
62 ===================================================================
63 --- src/cats/sql_create.c       (révision 7344)
64 +++ src/cats/sql_create.c       (copie de travail)
65 @@ -758,7 +758,7 @@
66  {
67     int JobStatus = jcr->JobStatus;
68  
69 -   if (!jcr->db_batch) {         /* no files to backup ? */
70 +   if (!jcr->batch_started) {         /* no files to backup ? */
71        Dmsg0(50,"db_create_file_record : no files\n");
72        return true;
73     }
74 @@ -845,38 +845,19 @@
75     Dmsg1(dbglevel, "Fname=%s\n", ar->fname);
76     Dmsg0(dbglevel, "put_file_into_catalog\n");
77  
78 -   if (!jcr->db_batch) {
79 -      Dmsg2(100, "Opendb attr. Stream=%d fname=%s\n", ar->Stream, ar->fname);
80 -      jcr->db_batch = db_init_database(jcr, 
81 -                                      mdb->db_name, 
82 -                                      mdb->db_user,
83 -                                      mdb->db_password, 
84 -                                      mdb->db_address,
85 -                                      mdb->db_port,
86 -                                      mdb->db_socket,
87 -                                      1 /* multi_db = true */);
88 -      if (!jcr->db_batch) {
89 -         Mmsg1(&mdb->errmsg, _("Could not init batch database: \"%s\".\n"),
90 -                        jcr->db->db_name);
91 -         Jmsg1(jcr, M_FATAL, 0, "%s", mdb->errmsg);
92 -         return false;
93 -      }
94 +   /* Open the dedicated connexion */
95 +   if (!jcr->batch_started) {
96  
97 -      if (!db_open_database(jcr, jcr->db_batch)) {
98 -         Mmsg2(&mdb->errmsg,  _("Could not open database \"%s\": ERR=%s\n"),
99 -              jcr->db->db_name, db_strerror(jcr->db_batch));
100 -         Jmsg1(jcr, M_FATAL, 0, "%s", mdb->errmsg);
101 +      if (!db_open_batch_connexion(jcr, mdb)) {
102           return false;
103 -      }      
104 -      
105 +      }
106        if (!sql_batch_start(jcr, jcr->db_batch)) {
107           Mmsg1(&mdb->errmsg, 
108                "Can't start batch mode: ERR=%s", db_strerror(jcr->db_batch));
109           Jmsg1(jcr, M_FATAL, 0, "%s", mdb->errmsg);
110           return false;
111        }
112 -      Dmsg3(100, "initdb ref=%d connected=%d db=%p\n", jcr->db_batch->ref_count,
113 -            jcr->db_batch->connected, jcr->db_batch->db);
114 +      jcr->batch_started = true;
115     }
116     B_DB *bdb = jcr->db_batch;
117  
118 @@ -895,12 +876,12 @@
119  
120  
121  /*
122 -   if (bdb->changes > 100000) {
123 -      db_write_batch_file_records(jcr);
124 -      bdb->changes = 0;
125 -      sql_batch_start(jcr, bdb);
126 -   }
127 -*/
128 + * if (bdb->changes > 100000) {
129 + *    db_write_batch_file_records(jcr);
130 + *    bdb->changes = 0;
131 + *     sql_batch_start(jcr, bdb);
132 + * }
133 + */
134  
135     return sql_batch_insert(jcr, bdb, ar);
136  }
137 Index: src/jcr.h
138 ===================================================================
139 --- src/jcr.h   (révision 7344)
140 +++ src/jcr.h   (copie de travail)
141 @@ -226,7 +226,8 @@
142     bool cached_attribute;             /* set if attribute is cached */
143     POOLMEM *attr;                     /* Attribute string from SD */
144     B_DB *db;                          /* database pointer */
145 -   B_DB *db_batch;                    /* database pointer for batch insert */
146 +   B_DB *db_batch;                    /* database pointer for batch and accurate */
147 +   bool batch_started;                /* is batch mode already started ? */
148     ATTR_DBR *ar;                      /* DB attribute record */
149     guid_list *id_list;                /* User/group id to name list */
150     bool accurate;                     /* true if job is accurate */
151  
152 Index: src/dird/backup.c
153 ===================================================================
154 --- src/dird/backup.c   (révision 7344)
155 +++ src/dird/backup.c   (copie de travail)
156 @@ -133,6 +133,7 @@
157        return true;
158     }
159     POOLMEM *jobids = get_pool_memory(PM_FNAME);
160 +
161     db_accurate_get_jobids(jcr, jcr->db, &jcr->jr, jobids);
162  
163     if (*jobids == 0) {
164 @@ -150,13 +151,19 @@
165     Dmsg2(200, "jobids=%s nb=%s\n", jobids, nb);
166     jcr->file_bsock->fsend("accurate files=%s\n", nb); 
167  
168 -   db_get_file_list(jcr, jcr->db, jobids, accurate_list_handler, (void *)jcr);
169 +   if (!db_open_batch_connexion(jcr, jcr->db)) {
170 +      Jmsg0(jcr, M_FATAL, 0, "Can't get dedicate sql connexion");
171 +      return false;
172 +   }
173  
174 +   db_get_file_list(jcr, jcr->db_batch, jobids, accurate_list_handler, (void *)jcr);
175 +
176 +   /* TODO: close the batch connexion ? (can be used very soon) */
177 +
178     free_pool_memory(jobids);
179     free_pool_memory(nb);
180  
181     jcr->file_bsock->signal(BNET_EOD);
182 -   /* TODO: use response() ? */
183  
184     return true;
185  }
186 Index: src/dird/job.c
187 ===================================================================
188 --- src/dird/job.c      (révision 7344)
189 +++ src/dird/job.c      (copie de travail)
190 @@ -960,10 +960,10 @@
191        pthread_cond_destroy(&jcr->term_wait);
192        jcr->term_wait_inited = false;
193     }
194 -   if (jcr->db_batch && jcr->db_batch != jcr->db) {
195 +   if (jcr->db_batch) {
196        db_close_database(jcr, jcr->db_batch);
197 +      jcr->db_batch = NULL;
198     }
199 -   jcr->db_batch = NULL;
200     if (jcr->db) {
201        db_close_database(jcr, jcr->db);
202        jcr->db = NULL;