LIBSRCS = mysql.c bdb.c dbi.c \
sql.c sql_cmds.c sql_create.c sql_delete.c sql_find.c \
sql_get.c sql_list.c sql_update.c sqlite.c \
- postgresql.c
+ postgresql.c bvfs.c
LIBOBJS = $(LIBSRCS:.c=$(DEFAULT_OBJECT_TYPE))
LIBBACSQL_LT_CURRENT = 1
#define sql_fetch_field(x) my_sqlite_fetch_field(x)
#define sql_num_fields(x) ((x)->ncolumn)
#define SQL_ROW char**
+#define SQL_MATCH "MATCH"
#define sql_batch_start(x,y) my_batch_start(x,y)
#define sql_batch_end(x,y,z) my_batch_end(x,y,z)
#define sql_batch_end(x,y,z) my_batch_end(x,y,z)
#define sql_batch_insert(x,y,z) my_batch_insert(x,y,z)
#define SQL_ROW char**
+#define SQL_MATCH "MATCH"
#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
#define sql_num_fields(x) (int)mysql_num_fields((x)->result)
#define SQL_ROW MYSQL_ROW
#define SQL_FIELD MYSQL_FIELD
+#define SQL_MATCH "MATCH"
#define sql_batch_start(x,y) my_batch_start(x,y)
#define sql_batch_end(x,y,z) my_batch_end(x,y,z)
#define SQL_ROW POSTGRESQL_ROW
#define SQL_FIELD POSTGRESQL_FIELD
+#define SQL_MATCH "~"
#else
extern const char* my_dbi_batch_unlock_tables_query[4];
extern const char* my_dbi_batch_fill_filename_query[4];
extern const char* my_dbi_batch_fill_path_query[4];
+extern const char* my_dbi_match[4];
/* "Generic" names for easier conversion */
#define sql_store_result(x) (x)->result
#define sql_strerror(x) my_dbi_strerror(x)
#define sql_num_rows(x) dbi_result_get_numrows((x)->result)
#define sql_data_seek(x, i) my_dbi_data_seek((x), (i))
+#define SQL_MATCH my_dbi_match[db_type]
/* #define sql_affected_rows(x) dbi_result_get_numrows_affected((x)->result) */
#define sql_affected_rows(x) 1
#define sql_insert_id(x,y) my_dbi_sql_insert_id((x), (y))
/* SQLite3 */
"COMMIT"};
+const char *my_dbi_match[4] = {
+ /* Mysql */
+ "MATCH",
+ /* Postgresql */
+ "~",
+ /* SQLite */
+ "MATCH",
+ /* SQLite3 */
+ "MATCH"
+};
+
const char *my_dbi_batch_fill_path_query[4] = {
/* Mysql */
"INSERT INTO Path (Path) "
int db_int64_handler(void *ctx, int num_fields, char **row);
void db_thread_cleanup();
void _dbg_print_db(JCR *jcr, FILE *fp);
+int db_int_handler(void *ctx, int num_fields, char **row);
/* sql_create.c */
+int db_create_path_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);
bool db_find_failed_job_since(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM *stime, int &JobLevel);
/* sql_get.c */
+int db_get_path_record(JCR *jcr, B_DB *mdb);
bool db_get_pool_record(JCR *jcr, B_DB *db, POOL_DBR *pdbr);
int db_get_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr);
bool db_get_job_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr);
/*
* Called here to retrieve an integer from the database
*/
-static int int_handler(void *ctx, int num_fields, char **row)
+int db_int_handler(void *ctx, int num_fields, char **row)
{
uint32_t *val = (uint32_t *)ctx;
const char *query = "SELECT VersionId FROM Version";
bacula_db_version = 0;
- if (!db_sql_query(mdb, query, int_handler, (void *)&bacula_db_version)) {
+ if (!db_sql_query(mdb, query, db_int_handler, (void *)&bacula_db_version)) {
Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg);
return false;
}
#ifndef HAVE_BATCH_FILE_INSERT
static int db_create_file_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
static int db_create_filename_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
-static int db_create_path_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
#endif /* HAVE_BATCH_FILE_INSERT */
}
+/* Create a Unique record for the Path -- no duplicates */
+int db_create_path_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
+{
+ SQL_ROW row;
+ int stat;
+ mdb->esc_name = check_pool_memory_size(mdb->esc_name, 2*mdb->pnl+2);
+ db_escape_string(jcr, mdb, mdb->esc_name, mdb->path, mdb->pnl);
+
+ if (mdb->cached_path_id != 0 && mdb->cached_path_len == mdb->pnl &&
+ strcmp(mdb->cached_path, mdb->path) == 0) {
+ ar->PathId = mdb->cached_path_id;
+ return 1;
+ }
+ Mmsg(mdb->cmd, "SELECT PathId FROM Path WHERE Path='%s'", mdb->esc_name);
+
+ if (QUERY_DB(jcr, mdb, mdb->cmd)) {
+ mdb->num_rows = sql_num_rows(mdb);
+ if (mdb->num_rows > 1) {
+ char ed1[30];
+ Mmsg2(&mdb->errmsg, _("More than one Path!: %s for path: %s\n"),
+ edit_uint64(mdb->num_rows, ed1), mdb->path);
+ Jmsg(jcr, M_WARNING, 0, "%s", mdb->errmsg);
+ }
+ /* Even if there are multiple paths, take the first one */
+ if (mdb->num_rows >= 1) {
+ if ((row = sql_fetch_row(mdb)) == NULL) {
+ Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
+ Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+ sql_free_result(mdb);
+ ar->PathId = 0;
+ ASSERT(ar->PathId);
+ return 0;
+ }
+ ar->PathId = str_to_int64(row[0]);
+ sql_free_result(mdb);
+ /* Cache path */
+ if (ar->PathId != mdb->cached_path_id) {
+ mdb->cached_path_id = ar->PathId;
+ mdb->cached_path_len = mdb->pnl;
+ pm_strcpy(mdb->cached_path, mdb->path);
+ }
+ ASSERT(ar->PathId);
+ return 1;
+ }
+ sql_free_result(mdb);
+ }
+
+ Mmsg(mdb->cmd, "INSERT INTO Path (Path) VALUES ('%s')", mdb->esc_name);
+
+ if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
+ Mmsg2(&mdb->errmsg, _("Create db Path record %s failed. ERR=%s\n"),
+ mdb->cmd, sql_strerror(mdb));
+ Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg);
+ ar->PathId = 0;
+ stat = 0;
+ } else {
+ ar->PathId = sql_insert_id(mdb, NT_("Path"));
+ stat = 1;
+ }
+
+ /* Cache path */
+ if (stat && ar->PathId != mdb->cached_path_id) {
+ mdb->cached_path_id = ar->PathId;
+ mdb->cached_path_len = mdb->pnl;
+ pm_strcpy(mdb->cached_path, mdb->path);
+ }
+ return stat;
+}
/*
* Create a Unique record for the counter -- no duplicates
return stat;
}
-/* Create a Unique record for the Path -- no duplicates */
-static int db_create_path_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
-{
- SQL_ROW row;
- int stat;
-
- mdb->esc_name = check_pool_memory_size(mdb->esc_name, 2*mdb->pnl+2);
- db_escape_string(jcr, mdb, mdb->esc_name, mdb->path, mdb->pnl);
-
- if (mdb->cached_path_id != 0 && mdb->cached_path_len == mdb->pnl &&
- strcmp(mdb->cached_path, mdb->path) == 0) {
- ar->PathId = mdb->cached_path_id;
- return 1;
- }
-
- Mmsg(mdb->cmd, "SELECT PathId FROM Path WHERE Path='%s'", mdb->esc_name);
-
- if (QUERY_DB(jcr, mdb, mdb->cmd)) {
- mdb->num_rows = sql_num_rows(mdb);
- if (mdb->num_rows > 1) {
- char ed1[30];
- Mmsg2(&mdb->errmsg, _("More than one Path!: %s for path: %s\n"),
- edit_uint64(mdb->num_rows, ed1), mdb->path);
- Jmsg(jcr, M_WARNING, 0, "%s", mdb->errmsg);
- }
- /* Even if there are multiple paths, take the first one */
- if (mdb->num_rows >= 1) {
- if ((row = sql_fetch_row(mdb)) == NULL) {
- Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
- Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
- sql_free_result(mdb);
- ar->PathId = 0;
- ASSERT(ar->PathId);
- return 0;
- }
- ar->PathId = str_to_int64(row[0]);
- sql_free_result(mdb);
- /* Cache path */
- if (ar->PathId != mdb->cached_path_id) {
- mdb->cached_path_id = ar->PathId;
- mdb->cached_path_len = mdb->pnl;
- pm_strcpy(mdb->cached_path, mdb->path);
- }
- ASSERT(ar->PathId);
- return 1;
- }
- sql_free_result(mdb);
- }
-
- Mmsg(mdb->cmd, "INSERT INTO Path (Path) VALUES ('%s')", mdb->esc_name);
-
- if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
- Mmsg2(&mdb->errmsg, _("Create db Path record %s failed. ERR=%s\n"),
- mdb->cmd, sql_strerror(mdb));
- Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg);
- ar->PathId = 0;
- stat = 0;
- } else {
- ar->PathId = sql_insert_id(mdb, NT_("Path"));
- stat = 1;
- }
-
- /* Cache path */
- if (stat && ar->PathId != mdb->cached_path_id) {
- mdb->cached_path_id = ar->PathId;
- mdb->cached_path_len = mdb->pnl;
- pm_strcpy(mdb->cached_path, mdb->path);
- }
- return stat;
-}
-
/* Create a Unique record for the filename -- no duplicates */
static int db_create_filename_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
{
/* Forward referenced functions */
static int db_get_file_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr, FILE_DBR *fdbr);
static int db_get_filename_record(JCR *jcr, B_DB *mdb);
-static int db_get_path_record(JCR *jcr, B_DB *mdb);
/*
*
* DO NOT use Jmsg in this routine (see notes for get_file_record)
*/
-static int db_get_path_record(JCR *jcr, B_DB *mdb)
+int db_get_path_record(JCR *jcr, B_DB *mdb)
{
SQL_ROW row;
uint32_t PathId = 0;
RUN *find_next_run(RUN *run, JOB *job, utime_t &runtime, int ndays);
/* ua_restore.c */
-int get_next_jobid_from_list(char **p, JobId_t *JobId);
void find_storage_resource(UAContext *ua, RESTORE_CTX &rx, char *Storage, char *MediaType);
/* ua_server.c */
return ok;
}
-
-/*
- * Return next JobId from comma separated list
- *
- * Returns:
- * 1 if next JobId returned
- * 0 if no more JobIds are in list
- * -1 there is an error
- */
-int get_next_jobid_from_list(char **p, JobId_t *JobId)
-{
- const int maxlen = 30;
- char jobid[maxlen+1];
- char *q = *p;
-
- jobid[0] = 0;
- for (int i=0; i<maxlen; i++) {
- if (*q == 0) {
- break;
- } else if (*q == ',') {
- q++;
- break;
- }
- jobid[i] = *q++;
- jobid[i+1] = 0;
- }
- if (jobid[0] == 0) {
- return 0;
- } else if (!is_a_number(jobid)) {
- return -1; /* error */
- }
- *p = q;
- *JobId = str_to_int64(jobid);
- return 1;
-}
-
static int restore_count_handler(void *ctx, int num_fields, char **row)
{
RESTORE_CTX *rx = (RESTORE_CTX *)ctx;
/* The following routines are found in lib/jcr.c */
+extern int get_next_jobid_from_list(char **p, uint32_t *JobId);
extern bool init_jcr_subsystem(void);
extern JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr);
extern JCR *get_jcr_by_id(uint32_t JobId);
Dmsg0(dbglvl, "Finished JCR timeout checks\n");
}
+/*
+ * Return next JobId from comma separated list
+ *
+ * Returns:
+ * 1 if next JobId returned
+ * 0 if no more JobIds are in list
+ * -1 there is an error
+ */
+int get_next_jobid_from_list(char **p, uint32_t *JobId)
+{
+ const int maxlen = 30;
+ char jobid[maxlen+1];
+ char *q = *p;
+
+ jobid[0] = 0;
+ for (int i=0; i<maxlen; i++) {
+ if (*q == 0) {
+ break;
+ } else if (*q == ',') {
+ q++;
+ break;
+ }
+ jobid[i] = *q++;
+ jobid[i+1] = 0;
+ }
+ if (jobid[0] == 0) {
+ return 0;
+ } else if (!is_a_number(jobid)) {
+ return -1; /* error */
+ }
+ *p = q;
+ *JobId = str_to_int64(jobid);
+ return 1;
+}
+
/*
* Timeout signal comes here
*/
DIRCONFOBJS = ../dird/dird_conf.o ../dird/run_conf.o ../dird/inc_conf.o
NODIRTOOLS = bsmtp
-DIRTOOLS = bsmtp dbcheck drivetype fstype testfind testls bregex bwild bbatch bregtest
+DIRTOOLS = bsmtp dbcheck drivetype fstype testfind testls bregex bwild bbatch bregtest bvfs_test
TOOLS = $(@DIR_TOOLS@)
INSNODIRTOOLS = bsmtp
$(LIBTOOL_LINK) $(CXX) -g $(LDFLAGS) -L../cats -L. -L../lib -o $@ bbatch.o \
-lbacsql -lbac -lm $(DB_LIBS) $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS)
+bvfs_test: Makefile ../lib/libbac$(DEFAULT_ARCHIVE_TYPE) ../cats/libbacsql$(DEFAULT_ARCHIVE_TYPE) bvfs_test.o
+ $(LIBTOOL_LINK) $(CXX) -g $(LDFLAGS) -L../cats -L. -L../lib -o $@ bvfs_test.o \
+ -lbacsql -lbac -lm $(DB_LIBS) $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS)
+
gigaslam.o: gigaslam.c
$(CC) -c $<
General:
06Aug09
+ebl Add a new Bvfs class that implements brestore instant navigation
+ cache inside Bacula. Works for Mysql, Postgresql and Sqlite3
kes bat: fix compiler warning for unreferenced argument
04Aug09
ebl bat: Go to the media info panel when double-click on job page or media list