]> git.sur5r.net Git - bacula/bacula/commitdiff
kes Correct return status on db_batch... routines.
authorKern Sibbald <kern@sibbald.com>
Sun, 18 Mar 2007 21:36:28 +0000 (21:36 +0000)
committerKern Sibbald <kern@sibbald.com>
Sun, 18 Mar 2007 21:36:28 +0000 (21:36 +0000)
kes  Add call to db_write_batch_file_records() to migration code.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4361 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/cats/cats.h
bacula/src/cats/protos.h
bacula/src/cats/sql.c
bacula/src/cats/sql_create.c
bacula/src/dird/backup.c
bacula/src/dird/migrate.c
bacula/technotes-2.1

index fa67e07cc0091159a884e45812405a49b45a4cad..85a1a291032f7a99b91294c1b2d4a78667736d59 100644 (file)
@@ -171,9 +171,6 @@ struct B_DB {
 #define sql_fetch_field(x)    my_sqlite_fetch_field(x)
 #define sql_num_fields(x)     ((x)->ncolumn)
 #define SQL_ROW               char**
-#define sql_batch_start(x)    db_batch_start(x)
-#define sql_batch_end(x,y)    db_batch_end(x,y)
-#define sql_batch_insert(x,y) db_batch_insert(x,y)
 #define sql_batch_lock_path_query       my_sqlite_batch_lock_query
 #define sql_batch_lock_filename_query   my_sqlite_batch_lock_query
 #define sql_batch_unlock_tables_query   my_sqlite_batch_unlock_query
@@ -301,9 +298,6 @@ struct B_DB {
 #define sql_fetch_field(x)    my_sqlite_fetch_field(x)
 #define sql_num_fields(x)     ((x)->ncolumn)
 #define SQL_ROW               char**
-#define sql_batch_start(x)    db_batch_start(x)
-#define sql_batch_end(x,y)    db_batch_end(x,y)
-#define sql_batch_insert(x,y) db_batch_insert(x,y)
 #define sql_batch_lock_path_query       my_sqlite_batch_lock_query
 #define sql_batch_lock_filename_query   my_sqlite_batch_lock_query
 #define sql_batch_unlock_tables_query   my_sqlite_batch_unlock_query
@@ -386,9 +380,6 @@ struct B_DB {
 #define sql_fetch_field(x)    mysql_fetch_field((x)->result)
 #define sql_num_fields(x)     (int)mysql_num_fields((x)->result)
 #define sql_batch_start(x)    db_batch_start(x)
-#define sql_batch_end(x,y)    db_batch_end(x,y)
-#define sql_batch_insert(x,y) db_batch_insert(x,y)
-#define sql_batch_lock_path_query       my_mysql_batch_lock_path_query
 #define sql_batch_lock_filename_query   my_mysql_batch_lock_filename_query
 #define sql_batch_unlock_tables_query   my_mysql_batch_unlock_tables_query
 #define sql_batch_fill_filename_query   my_mysql_batch_fill_filename_query
@@ -504,9 +495,6 @@ extern char* my_pg_batch_fill_path_query;
 #define sql_field_seek(x, y)  my_postgresql_field_seek((x), (y))
 #define sql_fetch_field(x)    my_postgresql_fetch_field(x)
 #define sql_num_fields(x)     ((x)->num_fields)
-#define sql_batch_start(x)    my_postgresql_batch_start(x)
-#define sql_batch_end(x,y)    my_postgresql_batch_end(x,y)
-#define sql_batch_insert(x,y) my_postgresql_batch_insert(x,y)
 #define sql_lock_table(x,y)   my_postgresql_lock_table(x, y)
 #define sql_unlock_table(x,y) my_postgresql_unlock_table(x)
 #define sql_batch_lock_path_query       my_pg_batch_lock_path_query
index 4b29aed94d3710bbba7b06b9ea800a622477b2d2..ef11adddcb628f067a6de8e16755e0c07caccf45 100644 (file)
@@ -56,7 +56,7 @@ int db_int64_handler(void *ctx, int num_fields, char **row);
 
 
 /* create.c */
-int db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
+bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
 bool db_create_job_record(JCR *jcr, B_DB *db, JOB_DBR *jr);
 int db_create_media_record(JCR *jcr, B_DB *db, MEDIA_DBR *media_dbr);
 int db_create_client_record(JCR *jcr, B_DB *db, CLIENT_DBR *cr);
@@ -67,10 +67,10 @@ int db_create_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr);
 bool db_create_device_record(JCR *jcr, B_DB *mdb, DEVICE_DBR *dr);
 bool db_create_storage_record(JCR *jcr, B_DB *mdb, STORAGE_DBR *sr);
 bool db_create_mediatype_record(JCR *jcr, B_DB *mdb, MEDIATYPE_DBR *mr);
-int db_create_batch_file_record(JCR *jcr);
-int db_batch_start(B_DB *mdb);
-int db_batch_end(B_DB *mdb, const char *error);
-int db_batch_insert(B_DB *mdb, ATTR_DBR *ar);
+bool db_write_batch_file_records(JCR *jcr);
+bool db_batch_start(B_DB *mdb);
+bool db_batch_end(B_DB *mdb, const char *error);
+bool db_batch_insert(B_DB *mdb, ATTR_DBR *ar);
 
 /* delete.c */
 int db_delete_pool_record(JCR *jcr, B_DB *db, POOL_DBR *pool_dbr);
index 3b2fef0b3ffe560bcf6f281c13d51c5989be2e8a..79296d5d0089aa7f8d450b4e3bc3db153448842c 100644 (file)
@@ -1,17 +1,7 @@
-/*
- * Bacula Catalog Database interface routines
- *
- *     Almost generic set of SQL database interface routines
- *      (with a little more work)
- *
- *    Kern Sibbald, March 2000
- *
- *    Version $Id$
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
+/*
+ * Bacula Catalog Database interface routines
+ *
+ *     Almost generic set of SQL database interface routines
+ *      (with a little more work)
+ *
+ *    Kern Sibbald, March 2000
+ *
+ *    Version $Id$
+ */
 
 /* The following is necessary so that we do not include
  * the dummy external definition of B_DB.
index 282aede04351945b665e856c98ba5a6cd7dc3b6b..e833715975732b54ade29886542b25ee265c116a 100644 (file)
@@ -680,7 +680,11 @@ bool db_create_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr)
  *   - then insert the join between the temp, filename and path tables into file.
  */
 
-int db_batch_start(B_DB *mdb)
+/* 
+ * Returns 1 if OK
+ *         0 if failed
+ */
+bool db_batch_start(B_DB *mdb)
 {
    return sql_query(mdb,
              " CREATE TEMPORARY TABLE batch "
@@ -689,10 +693,14 @@ int db_batch_start(B_DB *mdb)
              "        path blob,            "
              "        name blob,            "
              "        lstat tinyblob,       "
-             "        md5 tinyblob)         ");
+             "        md5 tinyblob)         ") == 0;
 }
 
-int db_batch_insert(B_DB *mdb, ATTR_DBR *ar)
+/* 
+ * Returns 1 if OK
+ *         0 if failed
+ */
+bool db_batch_insert(B_DB *mdb, ATTR_DBR *ar)
 {
    size_t len;
    char *digest;
@@ -714,75 +722,79 @@ int db_batch_insert(B_DB *mdb, ATTR_DBR *ar)
               ar->FileIndex, edit_int64(ar->JobId,ed1), mdb->path, 
               mdb->fname, ar->attr, digest);
 
-   sql_query(mdb, mdb->cmd);
-
-   return mdb->status;
+   return sql_query(mdb, mdb->cmd) == 0;
 }
 
 /* set error to something to abort operation */
-int db_batch_end(B_DB *mdb, const char *error)
+/* 
+ * Returns 1 if OK
+ *         0 if failed
+ */
+bool db_batch_end(B_DB *mdb, const char *error)
 {
    
    Dmsg0(50, "db_batch_end started");
 
    if (mdb) {
       mdb->status = 0;
-      return mdb->status;
    }
-   return 0;
+   return true;
 }
 
-int db_create_batch_file_record(JCR *jcr)
+/* 
+ * Returns 1 if OK
+ *         0 if failed
+ */
+bool db_write_batch_file_records(JCR *jcr)
 {
    Dmsg0(50,"db_create_file_record : no files");
 
    if (!jcr->db_batch) {         /* no files to backup ? */
       Dmsg0(50,"db_create_file_record : no files\n");
-      return 0;
+      return true;
    }
 
-   if (sql_batch_end(jcr->db_batch, NULL)) {
+   if (!db_batch_end(jcr->db_batch, NULL)) {
       Jmsg(jcr, M_FATAL, 0, "Bad batch end %s\n", jcr->db_batch->errmsg);
-      return 1;
+      return false;
+   }
+
+   if (job_canceled(jcr)) {
+      return false;
    }
 
    /* we have to lock tables */
-   if (sql_query(jcr->db_batch, sql_batch_lock_path_query))
-   {
+   if (sql_query(jcr->db_batch, sql_batch_lock_path_query) != 0) {
       Jmsg(jcr, M_FATAL, 0, "Can't lock Path table %s\n", jcr->db_batch->errmsg);
-      return 1;
+      return false;
    }
 
-   if (sql_query(jcr->db_batch, sql_batch_fill_path_query))
-   {
+   if (sql_query(jcr->db_batch, sql_batch_fill_path_query) != 0) {
       Jmsg(jcr, M_FATAL, 0, "Can't fill Path table %s\n",jcr->db_batch->errmsg);
       sql_query(jcr->db_batch, sql_batch_unlock_tables_query);
-      return 1;
+      return false;
    }
    
-   if (sql_query(jcr->db_batch, sql_batch_unlock_tables_query))
-   {
+   if (sql_query(jcr->db_batch, sql_batch_unlock_tables_query) !=0) {
       Jmsg(jcr, M_FATAL, 0, "Can't unlock Path table %s\n", jcr->db_batch->errmsg);
-      return 1;      
+      return false;      
    }
 
    /* we have to lock tables */
-   if (sql_query(jcr->db_batch, sql_batch_lock_filename_query))
-   {
+   if (sql_query(jcr->db_batch, sql_batch_lock_filename_query) != 0) {
       Jmsg(jcr, M_FATAL, 0, "Can't lock Filename table %s\n", jcr->db_batch->errmsg);
-      return 1;
+      return false;
    }
    
-   if (sql_query(jcr->db_batch, sql_batch_fill_filename_query))
-   {
+   if (sql_query(jcr->db_batch, sql_batch_fill_filename_query) != 0) {
       Jmsg(jcr,M_FATAL,0,"Can't fill Filename table %s\n",jcr->db_batch->errmsg);
       sql_query(jcr->db_batch, sql_batch_unlock_tables_query);
-      return 1;            
+      return false;            
    }
 
-   if (sql_query(jcr->db_batch, sql_batch_unlock_tables_query)) {
+   if (sql_query(jcr->db_batch, sql_batch_unlock_tables_query) != 0) {
       Jmsg(jcr, M_FATAL, 0, "Can't unlock Filename table %s\n", jcr->db_batch->errmsg);
-      return 1;
+      return false;
    }
    
    if (sql_query(jcr->db_batch, 
@@ -791,15 +803,15 @@ int db_create_batch_file_record(JCR *jcr)
        "         Filename.FilenameId,batch.LStat, batch.MD5               "
        "  FROM batch                                                      "
        "    JOIN Path ON (batch.Path = Path.Path)                         "
-       "    JOIN Filename ON (batch.Name = Filename.Name)                 "))
+       "    JOIN Filename ON (batch.Name = Filename.Name)                 ") != 0)
    {
       Jmsg(jcr, M_FATAL, 0, "Can't fill File table %s\n", jcr->db_batch->errmsg);
-      return 1;
+      return false;
    }
 
    sql_query(jcr->db_batch, "DROP TABLE batch");
 
-   return 0;
+   return true;
 }
 
 #ifdef HAVE_BATCH_FILE_INSERT
@@ -812,7 +824,7 @@ int db_create_batch_file_record(JCR *jcr)
  *  how many times it occurs.  This is this subroutine, we separate
  *  the file and the path and fill temporary tables with this three records.
  */
-int db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
+bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
 {
    Dmsg1(dbglevel, "Fname=%s\n", ar->fname);
    Dmsg0(dbglevel, "put_file_into_catalog\n");
@@ -833,10 +845,13 @@ int db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
          if (jcr->db_batch) {
             Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db_batch));
          }
-         return 0;
+         return false;
       }      
       
-      sql_batch_start(jcr->db_batch);
+      if (!db_batch_start(jcr->db_batch)) {
+         Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db_batch));
+         return false;
+      }
    }
 
    B_DB *bdb = jcr->db_batch;
@@ -857,13 +872,13 @@ int db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
 
 /*
    if (jcr->changes > 100000) {
-      sql_batch_end(bdb, NULL);
-      sql_batch_start(bdb);
+      db_batch_end(bdb, NULL);
+      db_batch_start(bdb);
       jcr->changes = 0;
    }
 */
 
-   return (sql_batch_insert(bdb, ar) == 0);
+   return db_batch_insert(bdb, ar);
 }
 
 #else  /* ! HAVE_BATCH_FILE_INSERT */
@@ -877,9 +892,8 @@ int db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
  *  how many times it occurs.  This is this subroutine, we separate
  *  the file and the path and create three database records.
  */
-int db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
+bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
 {
-
    db_lock(mdb);
    Dmsg1(dbglevel, "Fname=%s\n", ar->fname);
    Dmsg0(dbglevel, "put_file_into_catalog\n");
@@ -916,11 +930,11 @@ int db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
 
    Dmsg3(dbglevel, "CreateAttributes Path=%s File=%s FilenameId=%d\n", mdb->path, mdb->fname, ar->FilenameId);
    db_unlock(mdb);
-   return 1;
+   return true;
 
 bail_out:
    db_unlock(mdb);
-   return 0;
+   return false;
 }
 
 
@@ -1081,6 +1095,11 @@ static int db_create_filename_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
    return ar->FilenameId > 0;
 }
 
+bool db_write_batch_file_records(JCR *jcr)
+{
+   return true;
+}
+
 #endif /* ! HAVE_BATCH_FILE_INSERT */
 
 #endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL */
index 65d96641bcd9a44ac61524d248b383a7d9b4b072..9ff2db7c6cfb5a793970ed7e63738f140a679b73 100644 (file)
@@ -233,9 +233,7 @@ bool do_backup(JCR *jcr)
 
    /* Pickup Job termination data */
    stat = wait_for_job_termination(jcr);
-#ifdef HAVE_BATCH_FILE_INSERT
-   db_create_batch_file_record(jcr);   /* used by bulk batch file insert */
-#endif
+   db_write_batch_file_records(jcr);    /* used by bulk batch file insert */
    if (stat == JS_Terminated) {
       backup_cleanup(jcr, stat);
       return true;
index f6b369d5a47a71932d20a53ef3472fe31630d93b..33a744488af9cb33c698a37ef9bfc99a76cbd155 100644 (file)
@@ -377,8 +377,8 @@ bool do_migration(JCR *jcr)
    /* Pickup Job termination data */
    /* Note, the SD stores in jcr->JobFiles/ReadBytes/JobBytes/Errors */
    wait_for_storage_daemon_termination(jcr);
-
    set_jcr_job_status(jcr, jcr->SDJobStatus);
+   db_write_batch_file_records(jcr);    /* used by bulk batch file insert */
    if (jcr->JobStatus != JS_Terminated) {
       return false;
    }
index e8495420d9b0c539389328afbc0870d3b74dc2e5..001ac7f802e094f5908b99e5c2a8d511637651fc 100644 (file)
@@ -2,7 +2,9 @@
 
 General:
 18Mar07
-ebl  Fix AfterJob timming
+kes  Correct return status on db_batch... routines.
+kes  Add call to db_write_batch_file_records() to migration code.
+ebl  Fix AfterJob timing
 kes  Move the checking of the database in initializion of the Director
      to after we drop privileges.  This avoids the need for both root
      and bacula access to the DB.