int mult_db_connections);
int db_open_database(JCR *jcr, B_DB *db);
void db_close_database(JCR *jcr, B_DB *db);
+bool db_open_batch_connexion(JCR *jcr, B_DB *mdb);
void db_escape_string(JCR *jcr, B_DB *db, char *snew, char *old, int len);
char *db_strerror(B_DB *mdb);
int db_next_index(JCR *jcr, B_DB *mdb, char *table, char *index);
return;
}
+/*
+ * Open a new connexion to mdb catalog. This function is used
+ * by batch and accurate mode.
+ */
+bool db_open_batch_connexion(JCR *jcr, B_DB *mdb)
+{
+ int multi_db=false;
+
+#ifdef HAVE_BATCH_FILE_INSERT
+ multi_db=true; /* we force a new connexion only if batch insert is enabled */
+#endif
+
+ if (!jcr->db_batch) {
+ jcr->db_batch = db_init_database(jcr,
+ mdb->db_name,
+ mdb->db_user,
+ mdb->db_password,
+ mdb->db_address,
+ mdb->db_port,
+ mdb->db_socket,
+ multi_db /* multi_db = true when using batch mode */);
+ if (!jcr->db_batch) {
+ Jmsg0(jcr, M_FATAL, 0, "Could not init batch connexion");
+ return false;
+ }
+
+ if (!db_open_database(jcr, jcr->db_batch)) {
+ Mmsg2(&jcr->db_batch->errmsg, _("Could not open database \"%s\": ERR=%s\n"),
+ jcr->db_batch->db_name, db_strerror(jcr->db_batch));
+ Jmsg1(jcr, M_FATAL, 0, "%s", jcr->db_batch->errmsg);
+ return false;
+ }
+ Dmsg3(100, "initdb ref=%d connected=%d db=%p\n", jcr->db_batch->ref_count,
+ jcr->db_batch->connected, jcr->db_batch->db);
+
+ }
+ return true;
+}
#endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL*/
{
int JobStatus = jcr->JobStatus;
- if (!jcr->db_batch) { /* no files to backup ? */
+ if (!jcr->batch_started) { /* no files to backup ? */
Dmsg0(50,"db_create_file_record : no files\n");
return true;
}
Dmsg1(dbglevel, "Fname=%s\n", ar->fname);
Dmsg0(dbglevel, "put_file_into_catalog\n");
- if (!jcr->db_batch) {
- Dmsg2(100, "Opendb attr. Stream=%d fname=%s\n", ar->Stream, ar->fname);
- jcr->db_batch = db_init_database(jcr,
- mdb->db_name,
- mdb->db_user,
- mdb->db_password,
- mdb->db_address,
- mdb->db_port,
- mdb->db_socket,
- 1 /* multi_db = true */);
- if (!jcr->db_batch) {
- Mmsg1(&mdb->errmsg, _("Could not init batch database: \"%s\".\n"),
- jcr->db->db_name);
- Jmsg1(jcr, M_FATAL, 0, "%s", mdb->errmsg);
- return false;
- }
+ /* Open the dedicated connexion */
+ if (!jcr->batch_started) {
- if (!db_open_database(jcr, jcr->db_batch)) {
- Mmsg2(&mdb->errmsg, _("Could not open database \"%s\": ERR=%s\n"),
- jcr->db->db_name, db_strerror(jcr->db_batch));
- Jmsg1(jcr, M_FATAL, 0, "%s", mdb->errmsg);
+ if (!db_open_batch_connexion(jcr, mdb)) {
return false;
- }
-
+ }
if (!sql_batch_start(jcr, jcr->db_batch)) {
Mmsg1(&mdb->errmsg,
"Can't start batch mode: ERR=%s", db_strerror(jcr->db_batch));
Jmsg1(jcr, M_FATAL, 0, "%s", mdb->errmsg);
return false;
}
- Dmsg3(100, "initdb ref=%d connected=%d db=%p\n", jcr->db_batch->ref_count,
- jcr->db_batch->connected, jcr->db_batch->db);
+ jcr->batch_started = true;
}
B_DB *bdb = jcr->db_batch;
/*
- if (bdb->changes > 100000) {
- db_write_batch_file_records(jcr);
- bdb->changes = 0;
- sql_batch_start(jcr, bdb);
- }
-*/
+ * if (bdb->changes > 100000) {
+ * db_write_batch_file_records(jcr);
+ * bdb->changes = 0;
+ * sql_batch_start(jcr, bdb);
+ * }
+ */
return sql_batch_insert(jcr, bdb, ar);
}
return true;
}
POOLMEM *jobids = get_pool_memory(PM_FNAME);
+
db_accurate_get_jobids(jcr, jcr->db, &jcr->jr, jobids);
if (*jobids == 0) {
Dmsg2(200, "jobids=%s nb=%s\n", jobids, nb);
jcr->file_bsock->fsend("accurate files=%s\n", nb);
- db_get_file_list(jcr, jcr->db, jobids, accurate_list_handler, (void *)jcr);
+ if (!db_open_batch_connexion(jcr, jcr->db)) {
+ Jmsg0(jcr, M_FATAL, 0, "Can't get dedicate sql connexion");
+ return false;
+ }
+
+ db_get_file_list(jcr, jcr->db_batch, jobids, accurate_list_handler, (void *)jcr);
+
+ /* TODO: close the batch connexion ? (can be used very soon) */
free_pool_memory(jobids);
free_pool_memory(nb);
jcr->file_bsock->signal(BNET_EOD);
- /* TODO: use response() ? */
return true;
}
pthread_cond_destroy(&jcr->term_wait);
jcr->term_wait_inited = false;
}
- if (jcr->db_batch && jcr->db_batch != jcr->db) {
+ if (jcr->db_batch) {
db_close_database(jcr, jcr->db_batch);
+ jcr->db_batch = NULL;
+ jcr->batch_started = false;
}
- jcr->db_batch = NULL;
if (jcr->db) {
db_close_database(jcr, jcr->db);
jcr->db = NULL;
bool cached_attribute; /* set if attribute is cached */
POOLMEM *attr; /* Attribute string from SD */
B_DB *db; /* database pointer */
- B_DB *db_batch; /* database pointer for batch insert */
+ B_DB *db_batch; /* database pointer for batch and accurate */
+ bool batch_started; /* is batch mode already started ? */
ATTR_DBR *ar; /* DB attribute record */
guid_list *id_list; /* User/group id to name list */
bool accurate; /* true if job is accurate */
remove reader/writer in FOPTS????
General:
+22Sep08
+ebl Use a dedicate DB link to compute and send the accurate list
+ file to the client.
21Sep08
kes Fix compile errors in filed/fd_plugin.c.
20Sep08