From: Eric Bollengier Date: Sun, 21 Nov 2010 09:43:54 +0000 (+0100) Subject: Add delta option to db_get_file_list() X-Git-Tag: Release-7.0.0~1365 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2c468fb0b85ed227763f925727c31faa865f5012;p=bacula%2Fbacula Add delta option to db_get_file_list() --- diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index 2a0f3376dd..2e0b71a06e 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -123,10 +123,9 @@ int db_get_job_volume_parameters(JCR *jcr, B_DB *mdb, JobId_t JobId, VOL_PARAMS int db_get_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cdbr); int db_get_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr); bool db_get_query_dbids(JCR *jcr, B_DB *mdb, POOL_MEM &query, dbid_list &ids); -bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, bool use_md5, DB_RESULT_HANDLER *result_handler, void *ctx); -bool db_get_file_list_with_delta(JCR *jcr, B_DB *mdb, - char *jobids, bool use_md5, - DB_RESULT_HANDLER *result_handler, void *ctx); +bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, + bool use_md5, bool use_delta, + DB_RESULT_HANDLER *result_handler, void *ctx); bool db_get_base_jobid(JCR *jcr, B_DB *mdb, JOB_DBR *jr, JobId_t *jobid); bool db_accurate_get_jobids(JCR *jcr, B_DB *mdb, JOB_DBR *jr, db_list_ctx *jobids); bool db_get_used_base_jobids(JCR *jcr, B_DB *mdb, POOLMEM *jobids, db_list_ctx *result); diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index e38e5dde04..e4ebfbaca4 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -1084,7 +1084,7 @@ bool db_get_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr) } /* Remove all MD5 from a query (can save lot of memory with many files) */ -static void replace_md5(char *q) +static void strip_md5(char *q) { char *p = q; while ((p = strstr(p, ", MD5"))) { @@ -1103,7 +1103,8 @@ static void replace_md5(char *q) * * TODO: See if we can do the SORT only if needed (as an argument) */ -bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, bool use_md5, +bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, + bool use_md5, bool use_delta, DB_RESULT_HANDLER *result_handler, void *ctx) { if (!*jobids) { @@ -1113,55 +1114,15 @@ bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, bool use_md5, return false; } POOL_MEM buf(PM_MESSAGE); - -#define new_db_get_file_list -#ifdef new_db_get_file_list POOL_MEM buf2(PM_MESSAGE); - Mmsg(buf2, select_recent_version_with_basejob[db_type], - jobids, jobids, jobids, jobids); - - /* bsr code is optimized for JobId sorted, with Delta, we need to get - * them ordered by date. JobTDate and JobId can be mixed if using Copy - * or Migration - */ - Mmsg(buf, -"SELECT Path.Path, Filename.Name, T1.FileIndex, T1.JobId, LStat, MarkId, MD5 " - "FROM ( %s ) AS T1 " - "JOIN Filename ON (Filename.FilenameId = T1.FilenameId) " - "JOIN Path ON (Path.PathId = T1.PathId) " -"WHERE FileIndex > 0 " -"ORDER BY T1.JobTDate, FileIndex ASC",/* Return sorted by JobTDate */ - /* FileIndex for restore code */ - buf2.c_str()); - if (!use_md5) { - replace_md5(buf.c_str()); - } - Dmsg1(100, "q=%s\n", buf.c_str()); -#else - /* - * I am not sure that this works the same as the code in ua_restore.c but it - * is very similar. The accurate-test fails in a restore. Bad file count. - */ - Mmsg(buf, uar_sel_files, jobids); -#endif - - return db_sql_query(mdb, buf.c_str(), result_handler, ctx); -} + if (use_delta) { + Mmsg(buf2, select_recent_version_with_basejob_and_delta[db_type], + jobids, jobids, jobids, jobids); -bool db_get_file_list_with_delta(JCR *jcr, B_DB *mdb, - char *jobids, bool use_md5, - DB_RESULT_HANDLER *result_handler, void *ctx) -{ - if (!*jobids) { - db_lock(mdb); - Mmsg(mdb->errmsg, _("ERR=JobIds are empty\n")); - db_unlock(mdb); - return false; + } else { + Mmsg(buf2, select_recent_version_with_basejob[db_type], + jobids, jobids, jobids, jobids); } - POOL_MEM buf(PM_MESSAGE); - POOL_MEM buf2(PM_MESSAGE); - Mmsg(buf2, select_recent_version_with_basejob_and_delta[db_type], - jobids, jobids, jobids, jobids); /* bsr code is optimized for JobId sorted, with Delta, we need to get * them ordered by date. JobTDate and JobId can be mixed if using Copy @@ -1176,9 +1137,11 @@ bool db_get_file_list_with_delta(JCR *jcr, B_DB *mdb, "ORDER BY T1.JobTDate, FileIndex ASC",/* Return sorted by JobTDate */ /* FileIndex for restore code */ buf2.c_str()); + if (!use_md5) { - replace_md5(buf.c_str()); + strip_md5(buf.c_str()); } + Dmsg1(100, "q=%s\n", buf.c_str()); return db_sql_query(mdb, buf.c_str(), result_handler, ctx); @@ -1302,7 +1265,7 @@ bool db_get_base_file_list(JCR *jcr, B_DB *mdb, bool use_md5, (uint64_t) jcr->JobId); if (!use_md5) { - replace_md5(buf.c_str()); + strip_md5(buf.c_str()); } return db_sql_query(mdb, buf.c_str(), result_handler, ctx); } diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index 7bd06a9eff..668d5c55ca 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -297,7 +297,7 @@ bool send_accurate_current_files(JCR *jcr) } else { db_get_file_list(jcr, jcr->db_batch, - jobids.list, jcr->use_accurate_chksum, + jobids.list, jcr->use_accurate_chksum, false /* no delta */, accurate_list_handler, (void *)jcr); } diff --git a/bacula/src/dird/ua_restore.c b/bacula/src/dird/ua_restore.c index 8377c22a43..73df8ca22a 100644 --- a/bacula/src/dird/ua_restore.c +++ b/bacula/src/dird/ua_restore.c @@ -1117,9 +1117,10 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx) #define new_get_file_list #ifdef new_get_file_list - if (!db_get_file_list_with_delta(ua->jcr, ua->db, - rx->JobIds, false /* do not use md5 */, - insert_tree_handler, (void *)&tree)) + if (!db_get_file_list(ua->jcr, ua->db, + rx->JobIds, false /* do not use md5 */, + true /* get delta */, + insert_tree_handler, (void *)&tree)) { ua->error_msg("%s", db_strerror(ua->db)); } diff --git a/bacula/src/dird/vbackup.c b/bacula/src/dird/vbackup.c index 0edec86976..c579f9989f 100644 --- a/bacula/src/dird/vbackup.c +++ b/bacula/src/dird/vbackup.c @@ -484,6 +484,7 @@ static bool create_bootstrap_file(JCR *jcr, char *jobids) } if (!db_get_file_list(jcr, jcr->db_batch, jobids, false /* don't use md5 */, + true /* use delta */, insert_bootstrap_handler, (void *)rx.bsr)) { Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db_batch)); diff --git a/bacula/src/tools/bbatch.c b/bacula/src/tools/bbatch.c index ef877013ec..7899834868 100644 --- a/bacula/src/tools/bbatch.c +++ b/bacula/src/tools/bbatch.c @@ -196,7 +196,7 @@ int main (int argc, char *argv[]) } start = get_current_btime(); - db_get_file_list(NULL, db, restore_list, false, list_handler, &nb_file); + db_get_file_list(NULL, db, restore_list, false, false, list_handler, &nb_file); end = get_current_btime(); Pmsg3(0, _("Computing file list for jobid=%s files=%lld secs=%d\n"),