2 ===================================================================
3 --- src/cats/sql.c (révision 7344)
4 +++ src/cats/sql.c (copie de travail)
10 + * Open a new connexion to mdb catalog. This function is used
11 + * by batch and accurate mode.
13 +bool db_open_batch_connexion(JCR *jcr, B_DB *mdb)
17 +#ifdef HAVE_BATCH_FILE_INSERT
18 + multi_db=true; /* we force a new connexion only if batch insert is enabled */
21 + if (!jcr->db_batch) {
22 + jcr->db_batch = db_init_database(jcr,
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");
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);
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);
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)
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)
67 int JobStatus = jcr->JobStatus;
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");
75 Dmsg1(dbglevel, "Fname=%s\n", ar->fname);
76 Dmsg0(dbglevel, "put_file_into_catalog\n");
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,
87 - 1 /* multi_db = true */);
88 - if (!jcr->db_batch) {
89 - Mmsg1(&mdb->errmsg, _("Could not init batch database: \"%s\".\n"),
91 - Jmsg1(jcr, M_FATAL, 0, "%s", mdb->errmsg);
94 + /* Open the dedicated connexion */
95 + if (!jcr->batch_started) {
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)) {
106 if (!sql_batch_start(jcr, jcr->db_batch)) {
108 "Can't start batch mode: ERR=%s", db_strerror(jcr->db_batch));
109 Jmsg1(jcr, M_FATAL, 0, "%s", mdb->errmsg);
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;
116 B_DB *bdb = jcr->db_batch;
118 @@ -895,12 +876,12 @@
122 - if (bdb->changes > 100000) {
123 - db_write_batch_file_records(jcr);
125 - sql_batch_start(jcr, bdb);
128 + * if (bdb->changes > 100000) {
129 + * db_write_batch_file_records(jcr);
130 + * bdb->changes = 0;
131 + * sql_batch_start(jcr, bdb);
135 return sql_batch_insert(jcr, bdb, ar);
138 ===================================================================
139 --- src/jcr.h (révision 7344)
140 +++ src/jcr.h (copie de travail)
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 */
152 Index: src/dird/backup.c
153 ===================================================================
154 --- src/dird/backup.c (révision 7344)
155 +++ src/dird/backup.c (copie de travail)
159 POOLMEM *jobids = get_pool_memory(PM_FNAME);
161 db_accurate_get_jobids(jcr, jcr->db, &jcr->jr, jobids);
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);
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");
174 + db_get_file_list(jcr, jcr->db_batch, jobids, accurate_list_handler, (void *)jcr);
176 + /* TODO: close the batch connexion ? (can be used very soon) */
178 free_pool_memory(jobids);
179 free_pool_memory(nb);
181 jcr->file_bsock->signal(BNET_EOD);
182 - /* TODO: use response() ? */
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;
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;
199 - jcr->db_batch = NULL;
201 db_close_database(jcr, jcr->db);