From 5b3e20331aa4b399ee304d90852418364058391a Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Thu, 30 Jul 2009 10:02:02 +0200 Subject: [PATCH] make regression ok --- bacula/src/cats/protos.h | 3 +- bacula/src/cats/sql.c | 2 +- bacula/src/cats/sql_create.c | 63 ++++++++++++++++++++---------------- bacula/src/cats/sql_get.c | 15 +++++++++ bacula/src/dird/backup.c | 9 +++--- bacula/src/dird/ua_restore.c | 6 +++- bacula/src/dird/ua_tree.c | 2 +- 7 files changed, 64 insertions(+), 36 deletions(-) diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index 43cb8fbb3c..4af787d8b0 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -142,11 +142,10 @@ void db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr); int db_update_stats(JCR *jcr, B_DB *mdb, utime_t age); - +bool db_get_used_base_jobids(JCR *jcr, B_DB *mdb, POOLMEM *jobids, POOLMEM *result); bool db_create_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar); bool db_create_base_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar); bool db_commit_base_file_attributes_record(JCR *jcr, B_DB *mdb); -void db_cleanup_base_file(JCR *jcr, B_DB *mdb); bool db_create_base_file_list(JCR *jcr, B_DB *mdb, char *jobids); bool db_get_base_file_list(JCR *jcr, B_DB *mdb, DB_RESULT_HANDLER *result_handler, void *ctx); diff --git a/bacula/src/cats/sql.c b/bacula/src/cats/sql.c index 00a0a9d43d..8e20427958 100644 --- a/bacula/src/cats/sql.c +++ b/bacula/src/cats/sql.c @@ -441,7 +441,7 @@ void db_end_transaction(JCR *jcr, B_DB *mdb) if (jcr && jcr->cached_attribute) { Dmsg0(400, "Flush last cached attribute.\n"); - if (!db_create_file_attributes_record(jcr, mdb, jcr->ar)) { + if (!db_create_attributes_record(jcr, mdb, jcr->ar)) { Jmsg1(jcr, M_FATAL, 0, _("Attribute create error. %s"), db_strerror(jcr->db)); } jcr->cached_attribute = false; diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index 339926c3da..f16689131b 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -843,6 +843,8 @@ bool db_write_batch_file_records(JCR *jcr) */ bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) { + ASSERT(ar->FileType != FT_BASE); + Dmsg1(dbglevel, "Fname=%s\n", ar->fname); Dmsg0(dbglevel, "put_file_into_catalog\n"); @@ -1118,6 +1120,7 @@ const char *create_temp_basefile[4] = { /* Postgresql */ "CREATE TEMPORARY TABLE basefile%lld (" +// "CREATE TABLE basefile%lld (" "Path TEXT," "Name TEXT)", @@ -1139,7 +1142,7 @@ bool db_create_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) { bool ret; if (ar->FileType == FT_BASE) { - ret = db_create_base_file_attributes_record(jcr, mdb, ar); + ret = db_create_base_file_attributes_record(jcr, jcr->db_batch, ar); } else { ret = db_create_file_attributes_record(jcr, mdb, ar); } @@ -1185,11 +1188,27 @@ bool db_create_base_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) return ret; } + +/* + * Cleanup the base file temporary tables + */ +static void db_cleanup_base_file(JCR *jcr, B_DB *mdb) +{ + POOL_MEM buf(PM_MESSAGE); + Mmsg(buf, "DROP TABLE new_basefile%lld", (uint64_t) jcr->JobId); + db_sql_query(mdb, buf.c_str(), NULL, NULL); + + Mmsg(buf, "DROP TABLE basefile%lld", (uint64_t) jcr->JobId); + db_sql_query(mdb, buf.c_str(), NULL, NULL); +} + /* * Put all base file seen in the backup to the BaseFile table + * and cleanup temporary tables */ bool db_commit_base_file_attributes_record(JCR *jcr, B_DB *mdb) { + bool ret; char ed1[50]; POOL_MEM buf(PM_MESSAGE); @@ -1202,20 +1221,9 @@ bool db_commit_base_file_attributes_record(JCR *jcr, B_DB *mdb) "AND A.Name = B.Name " "ORDER BY B.FileId)", edit_uint64(jcr->JobId, ed1), ed1, ed1); - return db_sql_query(mdb, buf.c_str(), NULL, NULL); -} - -/* - * Cleanup the base file temporary tables - */ -void db_cleanup_base_file(JCR *jcr, B_DB *mdb) -{ - POOL_MEM buf(PM_MESSAGE); - Mmsg(buf, "DROP TABLE new_basefile%lld", (uint64_t) jcr->JobId); - db_sql_query(mdb, buf.c_str(), NULL, NULL); - - Mmsg(buf, "DROP TABLE basefile%lld", (uint64_t) jcr->JobId); - db_sql_query(mdb, buf.c_str(), NULL, NULL); + ret = db_sql_query(mdb, buf.c_str(), NULL, NULL); + db_cleanup_base_file(jcr, mdb); + return ret; } /* @@ -1242,18 +1250,19 @@ bool db_create_base_file_list(JCR *jcr, B_DB *mdb, char *jobids) } Mmsg(buf, - "CREATE TEMPORARY TABLE new_basefile%lld AS ( " - "SELECT Path.Path AS Path, Filename.Name AS Name, File.FileIndex AS FileIndex, " - "File.JobId AS JobId, File.LStat AS LStat, File.FileId AS FileId " - "FROM ( " - "SELECT max(FileId) as FileId, PathId, FilenameId " - "FROM (SELECT FileId, PathId, FilenameId FROM File WHERE JobId IN (%s)) AS F " - "GROUP BY PathId, FilenameId " - ") AS Temp " - "JOIN Filename ON (Filename.FilenameId = Temp.FilenameId) " - "JOIN Path ON (Path.PathId = Temp.PathId) " - "JOIN File ON (File.FileId = Temp.FileId) " - "WHERE File.FileIndex > 0)", +"CREATE TEMPORARY TABLE new_basefile%lld AS ( " +//"CREATE TABLE new_basefile%lld AS ( " + "SELECT Path.Path AS Path, Filename.Name AS Name, File.FileIndex AS FileIndex," + "File.JobId AS JobId, File.LStat AS LStat, File.FileId AS FileId " + "FROM ( " + "SELECT max(FileId) as FileId, PathId, FilenameId " + "FROM (SELECT FileId, PathId, FilenameId FROM File WHERE JobId IN (%s)) AS F " + "GROUP BY PathId, FilenameId " + ") AS Temp " + "JOIN Filename ON (Filename.FilenameId = Temp.FilenameId) " + "JOIN Path ON (Path.PathId = Temp.PathId) " + "JOIN File ON (File.FileId = Temp.FileId) " + "WHERE File.FileIndex > 0)", (uint64_t)jcr->JobId, jobids); return db_sql_query(mdb, buf.c_str(), NULL, NULL); } diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index 046ce89909..78a6862038 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -1096,6 +1096,21 @@ bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, return db_sql_query(mdb, buf.c_str(), result_handler, ctx); } +/* + * This procedure gets the base jobid list used by jobids, + * You can specify jobids == result to concat base jobids to current jobids + */ +bool db_get_used_base_jobids(JCR *jcr, B_DB *mdb, POOLMEM *jobids, POOLMEM *result) +{ + POOL_MEM buf; + Mmsg(buf, + "SELECT DISTINCT BaseJobId " + " FROM Job JOIN BaseFiles USING (JobId) " + " WHERE Job.HasBase = 1 " + " AND JobId IN (%s) ", jobids); + return db_sql_query(mdb, buf.c_str(), db_get_int_handler, jobids); +} + /* The decision do change an incr/diff was done before * Full : do nothing * Differential : get the last full id diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index 3e59f0639a..e2c42cf982 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -212,7 +212,7 @@ bool send_accurate_current_files(JCR *jcr) goto bail_out; } - if (jcr->get_JobLevel() == L_FULL) { + if (jcr->HasBase) { db_create_base_file_list(jcr, jcr->db_batch, jobids); db_get_base_file_list(jcr, jcr->db_batch, accurate_list_handler, (void *)jcr); @@ -383,9 +383,10 @@ bool do_backup(JCR *jcr) stat = wait_for_job_termination(jcr); db_write_batch_file_records(jcr); /* used by bulk batch file insert */ - if (jcr->HasBase) { - db_commit_base_file_attributes_record(jcr, jcr->db_batch); - db_cleanup_base_file(jcr, jcr->db_batch); + if (jcr->HasBase && + !db_commit_base_file_attributes_record(jcr, jcr->db_batch)) + { + Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db_batch)); } if (stat == JS_Terminated) { diff --git a/bacula/src/dird/ua_restore.c b/bacula/src/dird/ua_restore.c index 0511fe3c6f..a3d9c08421 100644 --- a/bacula/src/dird/ua_restore.c +++ b/bacula/src/dird/ua_restore.c @@ -1091,6 +1091,10 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx) if (!db_get_file_list(ua->jcr, ua->db, rx->JobIds, insert_tree_handler, (void *)&tree)) { ua->error_msg("%s", db_strerror(ua->db)); } + + if (!db_get_used_base_jobids(ua->jcr, ua->db, rx->JobIds, rx->JobIds)) { + ua->error_msg("%s", db_strerror(ua->db)); + } #else for (p=rx->JobIds; get_next_jobid_from_list(&p, &JobId) > 0; ) { char ed1[50]; @@ -1158,7 +1162,7 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx) for (TREE_NODE *node=first_tree_node(tree.root); node; node=next_tree_node(node)) { Dmsg2(400, "FI=%d node=0x%x\n", node->FileIndex, node); if (node->extract || node->extract_dir) { - Dmsg3(0, "JobId=%lld type=%d FI=%d\n", (uint64_t)node->JobId, node->type, node->FileIndex); + Dmsg3(400, "JobId=%lld type=%d FI=%d\n", (uint64_t)node->JobId, node->type, node->FileIndex); add_findex(rx->bsr, node->JobId, node->FileIndex); if (node->extract && node->type != TN_NEWDIR) { rx->selected_files++; /* count only saved files */ diff --git a/bacula/src/dird/ua_tree.c b/bacula/src/dird/ua_tree.c index 9ac01a0dc7..d3df13ac16 100644 --- a/bacula/src/dird/ua_tree.c +++ b/bacula/src/dird/ua_tree.c @@ -198,7 +198,7 @@ int insert_tree_handler(void *ctx, int num_fields, char **row) node = insert_tree_node(row[0], row[1], type, tree->root, NULL); JobId = str_to_int64(row[3]); FileIndex = str_to_int64(row[2]); - Dmsg2(0, "JobId=%s FileIndex=%s\n", row[3], row[2]); + Dmsg2(400, "JobId=%s FileIndex=%s\n", row[3], row[2]); /* * - The first time we see a file (node->inserted==true), we accept it. * - In the same JobId, we accept only the first copy of a -- 2.39.5