]> git.sur5r.net Git - bacula/bacula/commitdiff
Fix problem in BVFS with concurrent queries
authorEric Bollengier <eric@baculasystems.com>
Fri, 20 Apr 2012 08:48:59 +0000 (10:48 +0200)
committerEric Bollengier <eric@baculasystems.com>
Fri, 20 Apr 2012 09:07:18 +0000 (11:07 +0200)
bacula/src/cats/bvfs.c
bacula/src/cats/bvfs.h
bacula/src/dird/ua_dotcmds.c

index 2cf70ba6b2a5bc2d415ee4177ea2c1c5e86a2c70..c2b08d699129ca2c81269e2f28659d0606037d08 100644 (file)
@@ -318,14 +318,16 @@ bail_out:
 
 /* 
  * Internal function to update path_hierarchy cache with a shared pathid cache
+ * return Error 0
+ *        OK    1
  */
-static void update_path_hierarchy_cache(JCR *jcr,
+static int update_path_hierarchy_cache(JCR *jcr,
                                         B_DB *mdb,
                                         pathid_cache &ppathid_cache,
                                         JobId_t JobId)
 {
    Dmsg0(dbglevel, "update_path_hierarchy_cache()\n");
-   int ret;
+   int ret=0;
    uint32_t num;
    char jobid[50];
    edit_uint64(JobId, jobid);
@@ -337,6 +339,7 @@ static void update_path_hierarchy_cache(JCR *jcr,
    
    if (!QUERY_DB(jcr, mdb, mdb->cmd) || sql_num_rows(mdb) > 0) {
       Dmsg1(dbglevel, "already computed %d\n", (uint32_t)JobId );
+      ret = 1;
       goto bail_out;
    }
 
@@ -434,6 +437,7 @@ static void update_path_hierarchy_cache(JCR *jcr,
 bail_out:
    db_end_transaction(jcr, mdb);
    db_unlock(mdb);
+   return ret;
 }
 
 /* 
@@ -524,24 +528,28 @@ void bvfs_update_cache(JCR *jcr, B_DB *mdb)
 /*
  * Update the bvfs cache for given jobids (1,2,3,4)
  */
-void
+int
 bvfs_update_path_hierarchy_cache(JCR *jcr, B_DB *mdb, char *jobids)
 {
    pathid_cache ppathid_cache;
    JobId_t JobId;
    char *p;
+   int ret=1;
 
    for (p=jobids; ; ) {
       int stat = get_next_jobid_from_list(&p, &JobId);
       if (stat < 0) {
-         return;
+         return 0;
       }
       if (stat == 0) {
          break;
       }
       Dmsg1(dbglevel, "Updating cache for %lld\n", (uint64_t)JobId);
-      update_path_hierarchy_cache(jcr, mdb, ppathid_cache, JobId);
+      if (!update_path_hierarchy_cache(jcr, mdb, ppathid_cache, JobId)) {
+         ret = 0;
+      }
    }
+   return ret;
 }
 
 /* 
@@ -557,7 +565,9 @@ bool Bvfs::ch_dir(const char *path)
 {
    pm_strcpy(db->path, path);
    db->pnl = strlen(db->path);
+   db_lock(db);
    ch_dir(db_get_path_record(jcr, db)); 
+   db_unlock(db);
    return pwd_id != 0;
 }
 
@@ -604,8 +614,12 @@ void Bvfs::get_all_file_versions(DBId_t pathid, DBId_t fnid, const char *client)
 
 DBId_t Bvfs::get_root()
 {
+   int p;
    *db->path = 0;
-   return db_get_path_record(jcr, db);
+   db_lock(db);
+   p = db_get_path_record(jcr, db);
+   db_unlock(db);
+   return p;
 }
 
 static int path_handler(void *ctx, int fields, char **row)
index 5e5f39fb5aedcc18b59b12bad3c70e1106a93752..5be7d903eb2fc2e563006822daf6ee537be33d2e 100644 (file)
@@ -197,7 +197,7 @@ private:
 #define bvfs_is_version(row) ((row)[BVFS_Type][0] == BVFS_FILE_VERSION)
 
 
-void bvfs_update_path_hierarchy_cache(JCR *jcr, B_DB *mdb, char *jobids);
+int bvfs_update_path_hierarchy_cache(JCR *jcr, B_DB *mdb, char *jobids);
 void bvfs_update_cache(JCR *jcr, B_DB *mdb);
 char *bvfs_parent_dir(char *path);
 
index dc4f75e5a23953583db3acd51c50efb4a897af1c..c90052b2ef6b79460add898e01e8b1801ba82c34 100644 (file)
@@ -186,7 +186,10 @@ static bool dot_bvfs_update(UAContext *ua, const char *cmd)
 
    int pos = find_arg_with_value(ua, "jobid");
    if (pos != -1 && is_a_number_list(ua->argv[pos])) {
-      bvfs_update_path_hierarchy_cache(ua->jcr, ua->db, ua->argv[pos]);
+      if (!bvfs_update_path_hierarchy_cache(ua->jcr, ua->db, ua->argv[pos])) {
+         ua->error_msg("ERROR: BVFS reported a problem for %s\n", 
+                       ua->argv[pos]);
+      }
    } else {
       /* update cache for all jobids */
       bvfs_update_cache(ua->jcr, ua->db);