*/
bool my_batch_start(JCR *jcr, B_DB *mdb)
{
- return QUERY_DB(jcr, mdb,
+ return db_sql_query(mdb,
" CREATE TEMPORARY TABLE batch "
" (fileindex integer, "
" jobid integer, "
" path blob, "
" name blob, "
" lstat tinyblob, "
- " md5 tinyblob) ");
+ " md5 tinyblob) ",NULL, NULL);
}
/*
ar->FileIndex, edit_int64(ar->JobId,ed1), mdb->path,
mdb->fname, ar->attr, digest);
- return QUERY_DB(jcr, mdb, mdb->cmd);
+ return INSERT_DB(jcr, mdb, mdb->cmd);
}
/* set error to something to abort operation */
}
/* we have to lock tables */
- if (!QUERY_DB(jcr, jcr->db_batch, sql_batch_lock_path_query)) {
+ if (!db_sql_query(jcr->db_batch, sql_batch_lock_path_query, NULL, NULL)) {
Jmsg(jcr, M_FATAL, 0, "Can't lock Path table %s\n", jcr->db_batch->errmsg);
return false;
}
- if (!QUERY_DB(jcr, jcr->db_batch, sql_batch_fill_path_query)) {
+ if (!db_sql_query(jcr->db_batch, sql_batch_fill_path_query, NULL, NULL)) {
Jmsg(jcr, M_FATAL, 0, "Can't fill Path table %s\n",jcr->db_batch->errmsg);
- QUERY_DB(jcr, jcr->db_batch, sql_batch_unlock_tables_query);
+ db_sql_query(jcr->db_batch, sql_batch_unlock_tables_query, NULL, NULL);
return false;
}
- if (!QUERY_DB(jcr, jcr->db_batch, sql_batch_unlock_tables_query)) {
+ if (!db_sql_query(jcr->db_batch, sql_batch_unlock_tables_query,NULL,NULL)) {
Jmsg(jcr, M_FATAL, 0, "Can't unlock Path table %s\n", jcr->db_batch->errmsg);
return false;
}
/* we have to lock tables */
- if (!QUERY_DB(jcr, jcr->db_batch, sql_batch_lock_filename_query)) {
+ if (!db_sql_query(jcr->db_batch,sql_batch_lock_filename_query,NULL, NULL)) {
Jmsg(jcr, M_FATAL, 0, "Can't lock Filename table %s\n", jcr->db_batch->errmsg);
return false;
}
- if (!QUERY_DB(jcr, jcr->db_batch, sql_batch_fill_filename_query)) {
+ if (!db_sql_query(jcr->db_batch,sql_batch_fill_filename_query, NULL,NULL)) {
Jmsg(jcr,M_FATAL,0,"Can't fill Filename table %s\n",jcr->db_batch->errmsg);
QUERY_DB(jcr, jcr->db_batch, sql_batch_unlock_tables_query);
return false;
}
- if (!QUERY_DB(jcr, jcr->db_batch, sql_batch_unlock_tables_query)) {
+ if (!db_sql_query(jcr->db_batch, sql_batch_unlock_tables_query,NULL,NULL)) {
Jmsg(jcr, M_FATAL, 0, "Can't unlock Filename table %s\n", jcr->db_batch->errmsg);
return false;
}
- if (!QUERY_DB(jcr, jcr->db_batch,
+ if (!db_sql_query(jcr->db_batch,
" INSERT INTO File (FileIndex, JobId, PathId, FilenameId, LStat, MD5)"
" SELECT batch.FileIndex, batch.JobId, Path.PathId, "
" Filename.FilenameId,batch.LStat, batch.MD5 "
" FROM batch "
" JOIN Path ON (batch.Path = Path.Path) "
- " JOIN Filename ON (batch.Name = Filename.Name) "))
+ " JOIN Filename ON (batch.Name = Filename.Name) ",
+ NULL,NULL))
{
Jmsg(jcr, M_FATAL, 0, "Can't fill File table %s\n", jcr->db_batch->errmsg);
return false;
}
- QUERY_DB(jcr, jcr->db_batch, "DROP TABLE batch");
+ db_sql_query(jcr->db_batch, "DROP TABLE batch", NULL,NULL);
return true;
}
}
if (!sql_batch_start(jcr, jcr->db_batch)) {
- Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db_batch));
+ Jmsg(jcr, M_FATAL, 0,
+ "Can't start batch mode %s", db_strerror(jcr->db_batch));
return false;
}
}
if (jcr->changes > 100000) {
db_write_batch_file_records(jcr);
jcr->changes = 0;
+ sql_batch_start(jcr, jcr->db_batch);
}
*/
#include "cats/cats.h"
/* Forward referenced functions */
-static void do_batch();
+static void *do_batch(void *);
/* Local variables */
static const char *db_password = "";
static const char *db_host = NULL;
-static JCR *bjcr;
-
char *datafile=NULL;
static void usage()
exit(1);
}
+/* number of thread started */
+int nb=0;
+
int main (int argc, char *argv[])
{
int ch;
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);
break;
case 'f':
- datafile = optarg;
+ if (nb < 10 ) {
+ files[nb++] = optarg;
+ }
break;
case '?':
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));
+ pthread_create(&thid, NULL, do_batch, bjcr);
}
- Dmsg0(200, "Database opened\n");
- if (verbose) {
- Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user);
- }
-
- bjcr->db = db;
- do_batch();
+ while (nb > 0) {
+ bmicrosleep(1,0);
+ }
return 0;
}
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) {
printf("Insert time = %llims\n", (end - begin) / 10000);
printf("Create %u files at %.2f/s\n", lineno,
(lineno / ((float)((end - begin) / 1000000))));
+ nb--;
+ pthread_exit(NULL);
+ return NULL;
}