From: Kern Sibbald Date: Wed, 26 Sep 2007 19:30:32 +0000 (+0000) Subject: Allow starting 59 jobs a second. X-Git-Tag: Release-3.0.0~2445 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=0d68db46b120f0c8178fe4bffbb842d346f3b0a2;p=bacula%2Fbacula Allow starting 59 jobs a second. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5661 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index 928bc35796..c619146c4d 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -688,12 +688,10 @@ bool db_create_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr) */ bool my_batch_start(JCR *jcr, B_DB *mdb) { - bool ok = false; - int retry = 0; + bool ok; - while (!ok && retry++ < 10) { - db_lock(mdb); - ok = db_sql_query(mdb, + db_lock(mdb); + ok = db_sql_query(mdb, "CREATE TEMPORARY TABLE batch (" "FileIndex integer," "JobId integer," @@ -701,11 +699,7 @@ bool my_batch_start(JCR *jcr, B_DB *mdb) "Name blob," "LStat tinyblob," "MD5 tinyblob)",NULL, NULL); - db_unlock(mdb); - if (!ok) { - bmicrosleep(1, 0); - } - } + db_unlock(mdb); return ok; } @@ -845,8 +839,7 @@ bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) if (!jcr->db_batch) { Dmsg2(100, "Opendb attr. Stream=%d fname=%s\n", ar->Stream, ar->fname); - while (!jcr->db_batch && retry++ < 10) { - jcr->db_batch = db_init_database(jcr, + jcr->db_batch = db_init_database(jcr, mdb->db_name, mdb->db_user, mdb->db_password, @@ -854,10 +847,6 @@ bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) mdb->db_port, mdb->db_socket, 1 /* multi_db = true */); - if (!jcr->db_batch) { - bmicrosleep(1, 0); - } - } if (!jcr->db_batch) { Mmsg1(&mdb->errmsg, _("Could not init batch database: \"%s\".\n"), jcr->db->db_name); @@ -866,7 +855,7 @@ bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) } if (!db_open_database(jcr, jcr->db_batch)) { - Mmsg2(&mdb->errmsg, _("Could not open database \"%s\": ERR=%s.\n"), + Mmsg2(&mdb->errmsg, _("Could not open database \"%s\": ERR=%s\n"), jcr->db->db_name, db_strerror(jcr->db_batch)); Jmsg1(jcr, M_FATAL, 0, "%s", mdb->errmsg); return false; diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 406a43e3bb..68a0f0c09e 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -745,6 +745,10 @@ void update_job_end_record(JCR *jcr) * Takes base_name and appends (unique) current * date and time to form unique job name. * + * Note, the seconds are actually a sequence number. This + * permits us to start a maximum fo 59 unique jobs a second, which + * should be sufficient. + * * Returns: unique job name in jcr->Job * date/time in jcr->start_time */ @@ -753,6 +757,7 @@ void create_unique_job_name(JCR *jcr, const char *base_name) /* Job start mutex */ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static time_t last_start_time = 0; + static int seq = 0; time_t now; struct tm tm; char dt[MAX_TIME_LENGTH]; @@ -764,9 +769,13 @@ void create_unique_job_name(JCR *jcr, const char *base_name) */ P(mutex); /* lock creation of jobs */ now = time(NULL); - while (now == last_start_time) { - bmicrosleep(0, 500000); - now = time(NULL); + seq++; + if (seq > 59) { /* wrap as if it is seconds */ + seq = 0; + while (now == last_start_time) { + bmicrosleep(0, 500000); + now = time(NULL); + } } last_start_time = now; V(mutex); /* allow creation of jobs */ @@ -774,10 +783,10 @@ void create_unique_job_name(JCR *jcr, const char *base_name) /* Form Unique JobName */ (void)localtime_r(&now, &tm); /* Use only characters that are permitted in Windows filenames */ - strftime(dt, sizeof(dt), "%Y-%m-%d_%H.%M.%S", &tm); + strftime(dt, sizeof(dt), "%Y-%m-%d_%H.%M", &tm); bstrncpy(name, base_name, sizeof(name)); name[sizeof(name)-22] = 0; /* truncate if too long */ - bsnprintf(jcr->Job, sizeof(jcr->Job), "%s.%s", name, dt); /* add date & time */ + bsnprintf(jcr->Job, sizeof(jcr->Job), "%s.%s.%02d", name, dt, seq); /* add date & time */ /* Convert spaces into underscores */ for (p=jcr->Job; *p; p++) { if (*p == ' ') { diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index ef1cbc35ec..c64ba8795b 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -2,6 +2,7 @@ General: 26Sep07 +kes Allow starting 59 jobs a second. kes Make SD session key more random. kes Add retry for SQLite opening db if it fails. kes Suppress extra error messages during batch insert failure.