*/
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,"
"Name blob,"
"LStat tinyblob,"
"MD5 tinyblob)",NULL, NULL);
- db_unlock(mdb);
- if (!ok) {
- bmicrosleep(1, 0);
- }
- }
+ db_unlock(mdb);
return ok;
}
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,
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);
}
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;
* 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
*/
/* 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];
*/
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 */
/* 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 == ' ') {