]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/sql_get.c
Tweak mutex order for SD
[bacula/bacula] / bacula / src / cats / sql_get.c
index b192eb9cf6aec80e1e6d1aeda6400d91f6d38f1d..3147b3a73c2397ec3f4ce8e2906a7785e687c64b 100644 (file)
@@ -116,7 +116,7 @@ int db_get_file_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr, FILE_DBR *fdbr)
    int stat = 0;
    char ed1[50], ed2[50], ed3[50];
 
-   if (jcr->get_JobLevel() == L_VERIFY_DISK_TO_CATALOG) {
+   if (jcr->getJobLevel() == L_VERIFY_DISK_TO_CATALOG) {
       Mmsg(mdb->cmd,
 "SELECT FileId, LStat, MD5 FROM File,Job WHERE "
 "File.JobId=Job.JobId AND File.PathId=%s AND "
@@ -151,11 +151,6 @@ int db_get_file_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr, FILE_DBR *fdbr)
    if (QUERY_DB(jcr, mdb, mdb->cmd)) {
       mdb->num_rows = sql_num_rows(mdb);
       Dmsg1(050, "get_file_record num_rows=%d\n", (int)mdb->num_rows);
-      if (mdb->num_rows > 1) {
-         Mmsg1(mdb->errmsg, _("get_file_record want 1 got rows=%d\n"),
-            mdb->num_rows);
-         Dmsg1(000, "=== Problem!  %s", mdb->errmsg);
-      }
       if (mdb->num_rows >= 1) {
          if ((row = sql_fetch_row(mdb)) == NULL) {
             Mmsg1(mdb->errmsg, _("Error fetching row: %s\n"), sql_strerror(mdb));
@@ -164,6 +159,13 @@ int db_get_file_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr, FILE_DBR *fdbr)
             bstrncpy(fdbr->LStat, row[1], sizeof(fdbr->LStat));
             bstrncpy(fdbr->Digest, row[2], sizeof(fdbr->Digest));
             stat = 1;
+            if (mdb->num_rows > 1) {
+               Mmsg3(mdb->errmsg, _("get_file_record want 1 got rows=%d PathId=%s FilenameId=%s\n"),
+                  mdb->num_rows, 
+                  edit_int64(fdbr->PathId, ed1), 
+                  edit_int64(fdbr->FilenameId, ed2));
+               Dmsg1(000, "=== Problem!  %s", mdb->errmsg);
+            }
          }
       } else {
          Mmsg2(mdb->errmsg, _("File record for PathId=%s FilenameId=%s not found.\n"),
@@ -428,7 +430,7 @@ int db_get_job_volume_parameters(JCR *jcr, B_DB *mdb, JobId_t JobId, VOL_PARAMS
    db_lock(mdb);
    Mmsg(mdb->cmd,
 "SELECT VolumeName,MediaType,FirstIndex,LastIndex,StartFile,"
-"JobMedia.EndFile,StartBlock,JobMedia.EndBlock,Copy,"
+"JobMedia.EndFile,StartBlock,JobMedia.EndBlock,"
 "Slot,StorageId,InChanger"
 " FROM JobMedia,Media WHERE JobMedia.JobId=%s"
 " AND JobMedia.MediaId=Media.MediaId ORDER BY VolIndex,JobMediaId",
@@ -467,10 +469,9 @@ int db_get_job_volume_parameters(JCR *jcr, B_DB *mdb, JobId_t JobId, VOL_PARAMS
                EndBlock = str_to_uint64(row[7]);
                Vols[i].StartAddr = (((uint64_t)StartFile)<<32) | StartBlock;
                Vols[i].EndAddr =   (((uint64_t)EndFile)<<32) | EndBlock;
-//             Vols[i].Copy = str_to_uint64(row[8]);
-               Vols[i].Slot = str_to_uint64(row[9]);
-               StorageId = str_to_uint64(row[10]);
-               Vols[i].InChanger = str_to_uint64(row[11]);
+               Vols[i].Slot = str_to_uint64(row[8]);
+               StorageId = str_to_uint64(row[9]);
+               Vols[i].InChanger = str_to_uint64(row[10]);
                Vols[i].Storage[0] = 0;
                SId[i] = StorageId;
             }
@@ -609,13 +610,15 @@ bool db_get_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pdbr)
       Mmsg(mdb->cmd,
 "SELECT PoolId,Name,NumVols,MaxVols,UseOnce,UseCatalog,AcceptAnyVolume,"
 "AutoPrune,Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
-"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId,ScratchPoolId FROM Pool WHERE Pool.PoolId=%s", 
+"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId,ScratchPoolId,"
+"ActionOnPurge FROM Pool WHERE Pool.PoolId=%s", 
          edit_int64(pdbr->PoolId, ed1));
    } else {                           /* find by name */
       Mmsg(mdb->cmd,
 "SELECT PoolId,Name,NumVols,MaxVols,UseOnce,UseCatalog,AcceptAnyVolume,"
 "AutoPrune,Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
-"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId,ScratchPoolId FROM Pool WHERE Pool.Name='%s'", 
+"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId,ScratchPoolId,"
+"ActionOnPurge FROM Pool WHERE Pool.Name='%s'", 
          pdbr->Name);
    }
    if (QUERY_DB(jcr, mdb, mdb->cmd)) {
@@ -649,6 +652,7 @@ bool db_get_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pdbr)
             bstrncpy(pdbr->LabelFormat, row[16]!=NULL?row[16]:"", sizeof(pdbr->LabelFormat));
             pdbr->RecyclePoolId = str_to_int64(row[17]);
             pdbr->ScratchPoolId = str_to_int64(row[18]);
+            pdbr->ActionOnPurge = str_to_int32(row[19]);
             ok = true;
          }
       }
@@ -950,7 +954,7 @@ bool db_get_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
          "MaxVolFiles,Recycle,Slot,FirstWritten,LastWritten,InChanger,"
          "EndFile,EndBlock,VolParts,LabelType,LabelDate,StorageId,"
          "Enabled,LocationId,RecycleCount,InitialWrite,"
-         "ScratchPoolId,RecyclePoolId,VolReadTime,VolWriteTime "
+         "ScratchPoolId,RecyclePoolId,VolReadTime,VolWriteTime,ActionOnPurge "
          "FROM Media WHERE MediaId=%s", 
          edit_int64(mr->MediaId, ed1));
    } else {                           /* find by name */
@@ -960,7 +964,7 @@ bool db_get_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
          "MaxVolFiles,Recycle,Slot,FirstWritten,LastWritten,InChanger,"
          "EndFile,EndBlock,VolParts,LabelType,LabelDate,StorageId,"
          "Enabled,LocationId,RecycleCount,InitialWrite,"
-         "ScratchPoolId,RecyclePoolId,VolReadTime,VolWriteTime "
+         "ScratchPoolId,RecyclePoolId,VolReadTime,VolWriteTime,ActionOnPurge "
          "FROM Media WHERE VolumeName='%s'", mr->VolumeName);
    }
 
@@ -1018,6 +1022,7 @@ bool db_get_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
             mr->RecyclePoolId = str_to_int64(row[34]);
             mr->VolReadTime = str_to_int64(row[35]);
             mr->VolWriteTime = str_to_int64(row[36]);
+            mr->ActionOnPurge = str_to_int32(row[37]);
             
             ok = true;
          }
@@ -1068,10 +1073,8 @@ bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids,
 #define new_db_get_file_list
 #ifdef new_db_get_file_list
    POOL_MEM buf2(PM_MESSAGE);
-   Dmsg1(0, "sql=%s\n", select_recent_version_with_basejob[db_type]);
    Mmsg(buf2, select_recent_version_with_basejob[db_type], 
         jobids, jobids, jobids, jobids);
-   Dmsg1(0, "sql=%s\n", buf2.c_str());
    Mmsg(buf,
 "SELECT Path.Path, Filename.Name, Temp.FileIndex, Temp.JobId, LStat, MD5 "
  "FROM ( %s ) AS Temp "
@@ -1081,7 +1084,6 @@ bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids,
 "ORDER BY Temp.JobId, FileIndex ASC",/* Return sorted by JobId, */
                                      /* FileIndex for restore code */ 
         buf2.c_str());
-   Dmsg1(0, "sql=%s\n", buf.c_str());
 #else
    /*  
     * I am not sure that this works the same as the code in ua_restore.c but it
@@ -1104,7 +1106,7 @@ bool db_get_used_base_jobids(JCR *jcr, B_DB *mdb,
  "SELECT DISTINCT BaseJobId "
  "  FROM Job JOIN BaseFiles USING (JobId) "
  " WHERE Job.HasBase = 1 "
- "   AND JobId IN (%s) ", jobids);
+ "   AND Job.JobId IN (%s) ", jobids);
    return db_sql_query(mdb, buf.c_str(), db_list_handler, result);
 }
 
@@ -1223,13 +1225,16 @@ bool db_get_base_file_list(JCR *jcr, B_DB *mdb,
 
 bool db_get_base_jobid(JCR *jcr, B_DB *mdb, JOB_DBR *jr, JobId_t *jobid)
 {
-   char date[MAX_TIME_LENGTH];
-   int64_t id = *jobid = 0;
    POOL_MEM query(PM_FNAME);
+   utime_t StartTime;
+   db_int64_ctx lctx;
+   char date[MAX_TIME_LENGTH];
+   bool ret=false;
+   *jobid = 0;
 
 // char clientid[50], filesetid[50];
 
-   utime_t StartTime = (jr->StartTime)?jr->StartTime:time(NULL);
+   StartTime = (jr->StartTime)?jr->StartTime:time(NULL);
    bstrutime(date, sizeof(date),  StartTime + 1);
 
    /* we can take also client name, fileset, etc... */
@@ -1250,31 +1255,16 @@ bool db_get_base_jobid(JCR *jcr, B_DB *mdb, JOB_DBR *jr, JobId_t *jobid)
         date);
 
    Dmsg1(10, "db_get_base_jobid q=%s\n", query.c_str());
-   if (!db_sql_query(mdb, query.c_str(), db_int64_handler, &id)) {
+   if (!db_sql_query(mdb, query.c_str(), db_int64_handler, &lctx)) {
       goto bail_out;
    }
-   *jobid = (JobId_t) id;
+   *jobid = (JobId_t) lctx.value;
 
-   Dmsg1(10, "db_get_base_jobid=%lld\n", id);
-   return true;
+   Dmsg1(10, "db_get_base_jobid=%lld\n", *jobid);
+   ret = true;
 
 bail_out:
-   return false;
-}
-
-/*
- * Use to build a string of int list from a query. "10,20,30"
- */
-int db_get_int_handler(void *ctx, int num_fields, char **row)
-{
-   POOLMEM *ret = (POOLMEM *)ctx;
-   if (num_fields == 1) {
-      if (ret[0]) {
-         pm_strcat(ret, ",");
-      }
-      pm_strcat(ret, row[0]);
-   }
-   return 0;
+   return ret;
 }
 
 #endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL || HAVE_DBI */