X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Ftools%2Fbbatch.c;h=b793dd32088fea46483beaa84d8b04667825633b;hb=a2bbe5fe90fa7b488146142f1c56af3e4da56867;hp=24d3c52d2530fa087aa96fe40850df1c80e37a5b;hpb=cbf620c59f4993ca823131bdacc603ccf3e0af04;p=bacula%2Fbacula diff --git a/bacula/src/tools/bbatch.c b/bacula/src/tools/bbatch.c index 24d3c52d25..b793dd3208 100644 --- a/bacula/src/tools/bbatch.c +++ b/bacula/src/tools/bbatch.c @@ -49,39 +49,36 @@ find / | while read a; do j=$(($j+1)) echo "$j;$a;xxxLSTATxxxx;xxxxxxxMD5xxxxxx" - done + done > dat1 */ #include "bacula.h" -#include "stored.h" +#include "stored/stored.h" #include "findlib/find.h" #include "cats/cats.h" /* Forward referenced functions */ -static void do_batch(); +static void *do_batch(void *); /* Local variables */ static B_DB *db; -static time_t lasttime = 0; - static const char *db_name = "bacula"; static const char *db_user = "bacula"; static const char *db_password = ""; static const char *db_host = NULL; -static bool list_records = false; -static int ignored_msgs = 0; - -static JCR *bjcr; -char *datafile=NULL; +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static void usage() { fprintf(stderr, _( PROG_COPYRIGHT -"\nVersion: %s (%s)\n\n" +"\nVersion: %s (%s)\n" +"Example : bbatch -w /path/to/workdir -h localhost -f dat1 -f dat -f datx\n" +" 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" " -d set debug level to nn\n" " -n specify the database name (default bacula)\n" @@ -95,21 +92,25 @@ PROG_COPYRIGHT exit(1); } +/* number of thread started */ +int nb=0; + int main (int argc, char *argv[]) { int ch; - struct stat stat_buf; setlocale(LC_ALL, ""); bindtextdomain("bacula", LOCALEDIR); textdomain("bacula"); init_stack_dump(); - + + char **files = (char **) malloc (10 * sizeof(char *)); + int i; my_name_is(argc, argv, "bbatch"); init_msg(NULL, NULL); OSDependentInit(); - while ((ch = getopt(argc, argv, "c:d:n:P:Su:vf:w:?")) != -1) { + while ((ch = getopt(argc, argv, "h:c:d:n:P:Su:vf:w:?")) != -1) { switch (ch) { case 'd': /* debug level */ debug_level = atoi(optarg); @@ -142,7 +143,9 @@ int main (int argc, char *argv[]) break; case 'f': - datafile = optarg; + if (nb < 10 ) { + files[nb++] = optarg; + } break; case '?': @@ -159,53 +162,55 @@ int main (int argc, char *argv[]) usage(); } - if (!datafile) { - Pmsg0(0, _("You must specified a data file\n")); - usage(); - } - #ifdef HAVE_BATCH_FILE_INSERT printf("With new Batch mode\n"); #else printf("Without new Batch mode\n"); #endif + i = nb; + while (--i >= 0) { + pthread_t thid; + JCR *bjcr = new_jcr(sizeof(JCR), NULL); + bjcr->bsr = NULL; + bjcr->VolSessionId = 1; + bjcr->VolSessionTime = (uint32_t)time(NULL); + bjcr->NumReadVolumes = 0; + bjcr->NumWriteVolumes = 0; + bjcr->JobId = getpid(); + bjcr->JobType = JT_CONSOLE; + bjcr->JobLevel = L_FULL; + bjcr->JobStatus = JS_Running; + bjcr->where = bstrdup(files[i]); + bjcr->job_name = get_pool_memory(PM_FNAME); + pm_strcpy(bjcr->job_name, "Dummy.Job.Name"); + bjcr->client_name = get_pool_memory(PM_FNAME); + pm_strcpy(bjcr->client_name, "Dummy.Client.Name"); + bstrncpy(bjcr->Job, "bbatch", sizeof(bjcr->Job)); + bjcr->fileset_name = get_pool_memory(PM_FNAME); + pm_strcpy(bjcr->fileset_name, "Dummy.fileset.name"); + bjcr->fileset_md5 = get_pool_memory(PM_FNAME); + pm_strcpy(bjcr->fileset_md5, "Dummy.fileset.md5"); + + if ((db=db_init_database(NULL, db_name, db_user, db_password, + db_host, 0, NULL, 0)) == NULL) { + Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n")); + } + if (!db_open_database(NULL, db)) { + Emsg0(M_ERROR_TERM, 0, db_strerror(db)); + } + Dmsg0(200, "Database opened\n"); + if (verbose) { + Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user); + } + + bjcr->db = db; - bjcr = new_jcr(sizeof(JCR), NULL); - bjcr->bsr = NULL; - bjcr->VolSessionId = 1; - bjcr->VolSessionTime = (uint32_t)time(NULL); - bjcr->NumReadVolumes = 0; - bjcr->NumWriteVolumes = 0; - bjcr->JobId = getpid(); - bjcr->JobType = JT_CONSOLE; - bjcr->JobLevel = L_FULL; - bjcr->JobStatus = JS_Running; - bjcr->where = bstrdup(""); - bjcr->job_name = get_pool_memory(PM_FNAME); - pm_strcpy(bjcr->job_name, "Dummy.Job.Name"); - bjcr->client_name = get_pool_memory(PM_FNAME); - pm_strcpy(bjcr->client_name, "Dummy.Client.Name"); - bstrncpy(bjcr->Job, "bbatch", sizeof(bjcr->Job)); - bjcr->fileset_name = get_pool_memory(PM_FNAME); - pm_strcpy(bjcr->fileset_name, "Dummy.fileset.name"); - bjcr->fileset_md5 = get_pool_memory(PM_FNAME); - pm_strcpy(bjcr->fileset_md5, "Dummy.fileset.md5"); - - if ((db=db_init_database(NULL, db_name, db_user, db_password, - db_host, 0, NULL, 0)) == NULL) { - Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n")); - } - if (!db_open_database(NULL, db)) { - Emsg0(M_ERROR_TERM, 0, db_strerror(db)); - } - Dmsg0(200, "Database opened\n"); - if (verbose) { - Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user); + pthread_create(&thid, NULL, do_batch, bjcr); } - bjcr->db = db; - - do_batch(); + while (nb > 0) { + bmicrosleep(1,0); + } return 0; } @@ -236,18 +241,20 @@ static void fill_attr(ATTR_DBR *ar, char *data) break; } index++; - p++; + b = ++p; } } } -static void do_batch() +static void *do_batch(void *jcr) { + JCR *bjcr = (JCR *)jcr; char data[1024]; int lineno = 0; struct ATTR_DBR ar; memset(&ar, 0, sizeof(ar)); btime_t begin = get_current_btime(); + char *datafile = bjcr->where; FILE *fd = fopen(datafile, "r"); if (!fd) { @@ -268,9 +275,14 @@ static void do_batch() db_write_batch_file_records(bjcr); btime_t end = get_current_btime(); + P(mutex); char ed1[200], ed2[200]; printf("\rbegin = %s, end = %s\n", edit_int64(begin, ed1),edit_int64(end, ed2)); - printf("Insert time = %ims\n", (end - begin) / 10000); - printf("Create %i files at %.2f/s\n", lineno, + printf("Insert time = %llims\n", (end - begin) / 10000); + printf("Create %u files at %.2f/s\n", lineno, (lineno / ((float)((end - begin) / 1000000)))); + nb--; + V(mutex); + pthread_exit(NULL); + return NULL; }