From: Eric Bollengier Date: Tue, 25 Jan 2011 14:19:16 +0000 (+0100) Subject: Adapt bbatch and cats_test tool to new cats X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=03ba7cc3756452b28258d9f8dd1eb9aeb1749bb4;p=bacula%2Fbacula Adapt bbatch and cats_test tool to new cats --- diff --git a/bacula/src/tools/Makefile.in b/bacula/src/tools/Makefile.in index 24d94a03ec..9eed229a54 100644 --- a/bacula/src/tools/Makefile.in +++ b/bacula/src/tools/Makefile.in @@ -119,13 +119,13 @@ ing_test: Makefile ../findlib/libbacfind$(DEFAULT_ARCHIVE_TYPE) ../lib/libbac$(D $(LIBTOOL_LINK) $(CXX) -g $(LDFLAGS) -L../cats -L. -L../lib -L../findlib -o $@ ing_test.o \ -lbacsql -lbaccats -lbacfind -lbac -lm $(DB_LIBS) $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS) -cats_test.o: cats_test.o +cats_test.o: cats_test.c echo "Compiling $<" $(NO_ECHO)$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) $(PYTHON_INC) $(SQL_INC) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $< cats_test: Makefile ../findlib/libbacfind$(DEFAULT_ARCHIVE_TYPE) ../lib/libbac$(DEFAULT_ARCHIVE_TYPE) ../cats/libbacsql$(DEFAULT_ARCHIVE_TYPE) cats_test.o $(LIBTOOL_LINK) $(CXX) -g $(LDFLAGS) -L../cats -L. -L../lib -L../findlib -o $@ cats_test.o \ - -lbacsql -lbacfind -lbac -lm $(DB_LIBS) $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS) + -lbacsql -lbaccats -lbacfind -lbac -lm $(DB_LIBS) $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS) gigaslam.o: gigaslam.c $(CXX) $(CFLAGS) -c $< diff --git a/bacula/src/tools/bbatch.c b/bacula/src/tools/bbatch.c index 088455e5fb..189da9deb7 100644 --- a/bacula/src/tools/bbatch.c +++ b/bacula/src/tools/bbatch.c @@ -81,6 +81,8 @@ PROG_COPYRIGHT " will start 3 thread and load dat1, dat and datx in your catalog\n" "See bbatch.c to generate datafile\n\n" "Usage: bbatch [ options ] -w working/dir -f datafile\n" +" -b with batch mode\n" +" -B without batch mode\n" " -d set debug level to \n" " -dt print timestamp in debug output\n" " -n specify the database name (default bacula)\n" @@ -108,6 +110,7 @@ static int list_handler(void *ctx, int num_fields, char **row) int main (int argc, char *argv[]) { int ch; + bool use_batch = true; char *restore_list=NULL; setlocale(LC_ALL, ""); bindtextdomain("bacula", LOCALEDIR); @@ -122,12 +125,17 @@ int main (int argc, char *argv[]) OSDependentInit(); - while ((ch = getopt(argc, argv, "h:c:d:n:P:Su:vf:w:r:?")) != -1) { + while ((ch = getopt(argc, argv, "bBh:c:d:n:P:Su:vf:w:r:?")) != -1) { switch (ch) { case 'r': restore_list=bstrdup(optarg); break; - + case 'B': + use_batch = false; + break; + case 'b': + use_batch = true; + break; case 'd': /* debug level */ if (*optarg == 't') { dbg_timestamp = true; @@ -189,7 +197,7 @@ int main (int argc, char *argv[]) /* To use the -r option, the catalog should already contains records */ if ((db = db_init_database(NULL, NULL, db_name, db_user, db_password, - db_host, 0, NULL, false, false)) == NULL) { + db_host, 0, NULL, false, use_batch)) == NULL) { Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n")); } if (!db_open_database(NULL, db)) { @@ -207,11 +215,12 @@ int main (int argc, char *argv[]) return 0; } -#ifdef HAVE_BATCH_FILE_INSERT - printf("With new Batch mode\n"); -#else - printf("Without new Batch mode\n"); -#endif + if (use_batch) { + printf("With new Batch mode\n"); + } else { + printf("Without new Batch mode\n"); + } + i = nb; while (--i >= 0) { pthread_t thid; @@ -312,7 +321,7 @@ static void *do_batch(void *jcr) printf("\r%i", lineno); } fill_attr(&ar, data); - if (!db_create_file_attributes_record(bjcr, bjcr->db, &ar)) { + if (!db_create_attributes_record(bjcr, bjcr->db, &ar)) { Emsg0(M_ERROR_TERM, 0, _("Error while inserting file\n")); } } diff --git a/bacula/src/tools/cats_test.c b/bacula/src/tools/cats_test.c index c59d66672d..c134b7cc2c 100644 --- a/bacula/src/tools/cats_test.c +++ b/bacula/src/tools/cats_test.c @@ -30,11 +30,12 @@ * * */ -#define __SQL_C -#define BUILDING_CATS +#define _BDB_PRIV_INTERFACE_ #include "bacula.h" #include "cats/cats.h" +#include "cats/bdb_priv.h" +#include "cats/sql_glue.h" #include "cats/bvfs.h" #include "findlib/find.h" @@ -201,6 +202,7 @@ static int list_files(void *ctx, int nb_col, char **row) { uint32_t *k = (uint32_t*) ctx; (*k)++; + ok(nb_col > 4, "Check result columns"); ok(!strcmp(row[0], aPATH aPATH aPATH aPATH "/"), "Check path"); ok(!strcmp(row[1], aFILE aFILE ".txt"), "Check filename"); ok(str_to_int64(row[2]) == 10, "Check FileIndex"); @@ -344,11 +346,11 @@ int main (int argc, char *argv[]) Pmsg1(0, PLINE "Test DB connection \"%s\"" PLINE, db_name); if (full_test) { - db = db_init(jcr /* JCR */, + db = db_init_database(jcr /* JCR */, NULL /* dbi driver */, db_name, db_user, db_password, db_address, db_port + 100, NULL /* db_socket */, - 0 /* mult_db_connections */); + 0 /* mult_db_connections */, false); ok(db != NULL, "Test bad connection"); if (!db) { report(); @@ -358,11 +360,11 @@ int main (int argc, char *argv[]) db_close_database(jcr, db); } - db = db_init(jcr /* JCR */, + db = db_init_database(jcr /* JCR */, NULL /* dbi driver */, db_name, db_user, db_password, db_address, db_port, NULL /* db_socket */, - 0 /* mult_db_connections */); + false /* mult_db_connections */, false); ok(db != NULL, "Test db connection"); if (!db) { @@ -378,10 +380,11 @@ int main (int argc, char *argv[]) report(); exit (1); } - dbtype = db_type; + dbtype = db_get_type_index(db); + /* Check if the SQL library is thread-safe */ - db_check_backend_thread_safe(); + //db_check_backend_thread_safe(); ok(check_tables_version(jcr, db), "Check table version"); ok(db_sql_query(db, "SELECT VersionId FROM Version", db_int_handler, &j), "SELECT VersionId"); @@ -525,7 +528,7 @@ int main (int argc, char *argv[]) ar.FileType = FT_REG; jcr->JobId = ar.JobId = jr.JobId; jcr->JobStatus = JS_Running; - ok(db_create_file_attributes_record(jcr, db, &ar), "Inserting Filename"); + ok(db_create_attributes_record(jcr, db, &ar), "Inserting Filename"); ok(db_write_batch_file_records(jcr), "Commit batch session"); Mmsg(buf, "SELECT FileIndex FROM File WHERE JobId=%lld",(int64_t)jcr->JobId); ok(db_sql_query(db, buf, db_int_handler, &j), "Get Inserted record");