"SELECT PPathId FROM PathHierarchy WHERE PathId = %s",
pathid);
- QUERY_DB(jcr, mdb, mdb->cmd);
+ if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
+ goto bail_out; /* Query failed, just leave */
+ }
+
/* Do we have a result ? */
if (sql_num_rows(mdb) > 0) {
ppathid_cache.insert(pathid);
"VALUES (%s,%lld)",
pathid, (uint64_t) parent.PathId);
- INSERT_DB(jcr, mdb, mdb->cmd);
+ if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
+ goto bail_out; /* Can't insert the record, just leave */
+ }
edit_uint64(parent.PathId, pathid);
path = mdb->path; /* already done */
/*
* 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=0;
uint32_t num;
char jobid[50];
edit_uint64(JobId, jobid);
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;
}
"FROM BaseFiles JOIN File AS F USING (FileId) "
"WHERE BaseFiles.JobId = %s) AS B",
jobid, jobid);
- QUERY_DB(jcr, mdb, mdb->cmd);
+
+ if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
+ Dmsg1(dbglevel, "Can't fill PathVisibility %d\n", (uint32_t)JobId );
+ goto bail_out;
+ }
/* Now we have to do the directory recursion stuff to determine missing
* visibility We try to avoid recursion, to be as fast as possible We also
"AND PathHierarchy.PathId IS NULL "
"ORDER BY Path", jobid);
Dmsg1(dbglevel_sql, "q=%s\n", mdb->cmd);
- QUERY_DB(jcr, mdb, mdb->cmd);
+
+ if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
+ Dmsg1(dbglevel, "Can't get new Path %d\n", (uint32_t)JobId );
+ goto bail_out;
+ }
/* TODO: I need to reuse the DB connection without emptying the result
* So, now i'm copying the result in memory to be able to query the
}
do {
- QUERY_DB(jcr, mdb, mdb->cmd);
- } while (sql_affected_rows(mdb) > 0);
+ ret = QUERY_DB(jcr, mdb, mdb->cmd);
+ } while (ret && sql_affected_rows(mdb) > 0);
Mmsg(mdb->cmd, "UPDATE Job SET HasCache=1 WHERE JobId=%s", jobid);
UPDATE_DB(jcr, mdb, mdb->cmd);
bail_out:
db_end_transaction(jcr, mdb);
db_unlock(mdb);
+ return ret;
}
/*
/*
* 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;
}
/*
{
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;
}
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)
{
POOL_MEM query;
POOL_MEM tmp, tmp2;
- int64_t id, jobid;
+ int64_t id, jobid, prev_jobid;
bool init=false;
bool ret=false;
/* check args */
return false;
}
+ db_lock(db);
+
+ /* Cleanup old tables first */
+ Mmsg(query, "DROP TABLE btemp%s", output_table);
+ db_sql_query(db, query.c_str());
+
+ Mmsg(query, "DROP TABLE %s", output_table);
+ db_sql_query(db, query.c_str());
+
Mmsg(query, "CREATE TABLE btemp%s AS ", output_table);
if (*fileid) { /* Select files with their direct id */
init=true;
- Mmsg(tmp,"SELECT JobId, JobTDate, FileIndex, FilenameId, PathId, FileId "
- "FROM File JOIN Job USING (JobId) WHERE FileId IN (%s)",
+ Mmsg(tmp,"SELECT Job.JobId, JobTDate, FileIndex, FilenameId, "
+ "PathId, FileId "
+ "FROM File JOIN Job USING (JobId) WHERE FileId IN (%s)",
fileid);
pm_strcat(query, tmp.c_str());
}
if (!db_sql_query(db, tmp.c_str(), get_path_handler, (void *)&tmp2)) {
Dmsg0(dbglevel, "Can't search for path\n");
/* print error */
- return false;
+ goto bail_out;
}
if (!strcmp(tmp2.c_str(), "")) { /* path not found */
Dmsg3(dbglevel, "Path not found %lld q=%s s=%s\n",
query.strcat(" UNION ");
}
- Mmsg(tmp, "SELECT JobId, JobTDate, File.FileIndex, File.FilenameId, "
+ Mmsg(tmp, "SELECT Job.JobId, JobTDate, File.FileIndex, File.FilenameId, "
"File.PathId, FileId "
"FROM Path JOIN File USING (PathId) JOIN Job USING (JobId) "
"WHERE Path.Path LIKE '%s' AND File.JobId IN (%s) ",
}
/* expect jobid,fileindex */
- int64_t prev_jobid=0;
+ prev_jobid=0;
while (get_next_id_from_list(&hardlink, &jobid) == 1) {
if (get_next_id_from_list(&hardlink, &id) != 1) {
Dmsg0(dbglevel, "hardlink should be two by two\n");
- return false;
+ goto bail_out;
}
if (jobid != prev_jobid) { /* new job */
if (prev_jobid == 0) { /* first jobid */
tmp.strcat(") UNION ");
query.strcat(tmp.c_str());
}
- Mmsg(tmp, "SELECT JobId, JobTDate, FileIndex, FilenameId, "
+ Mmsg(tmp, "SELECT Job.JobId, JobTDate, FileIndex, FilenameId, "
"PathId, FileId "
"FROM File JOIN Job USING (JobId) WHERE JobId = %lld "
"AND FileIndex IN (%lld", jobid, id);
goto bail_out;
}
- /* TODO: handle basejob and SQLite3 */
- Mmsg(query, sql_bvfs_select[db_get_type_index(db)], output_table, output_table);
+ Mmsg(query, sql_bvfs_select[db_get_type_index(db)],
+ output_table, output_table, output_table);
/* TODO: handle jobid filter */
Dmsg1(dbglevel_sql, "q=%s\n", query.c_str());
bail_out:
Mmsg(query, "DROP TABLE btemp%s", output_table);
db_sql_query(db, query.c_str(), NULL, NULL);
+ db_unlock(db);
return ret;
}