From: Kern Sibbald Date: Mon, 17 Apr 2006 12:23:40 +0000 (+0000) Subject: Get migration working again X-Git-Tag: Release-2.0.0~946 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1ee04fe845f4a4a5cbb2c1895e2e069c5ca07ac4;p=bacula%2Fbacula Get migration working again git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2934 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/dird/migrate.c b/bacula/src/dird/migrate.c index 4bc1d60678..46adb0c1a7 100644 --- a/bacula/src/dird/migrate.c +++ b/bacula/src/dird/migrate.c @@ -49,6 +49,7 @@ bool do_migration_init(JCR *jcr) { POOL_DBR pr; + /* If we find a job to migrate it is previous_jr.JobId */ if (!get_job_to_migrate(jcr)) { return false; } @@ -122,15 +123,16 @@ bool do_migration(JCR *jcr) POOL *pool; char ed1[100]; BSOCK *sd; - JOB *job, *tjob; - JCR *tjcr; + JOB *job, *prev_job; + JCR *prev_jcr; if (jcr->previous_jr.JobId == 0) { jcr->JobStatus = JS_Terminated; migration_cleanup(jcr, jcr->JobStatus); return true; /* no work */ } - Dmsg4(000, "Target: Name=%s JobId=%d Type=%c Level=%c\n", + + Dmsg4(000, "Previous:: Name=%s JobId=%d Type=%c Level=%c\n", jcr->previous_jr.Name, jcr->previous_jr.JobId, jcr->previous_jr.JobType, jcr->previous_jr.JobLevel); @@ -140,37 +142,37 @@ bool do_migration(JCR *jcr) LockRes(); job = (JOB *)GetResWithName(R_JOB, jcr->jr.Name); - tjob = (JOB *)GetResWithName(R_JOB, jcr->previous_jr.Name); + prev_job = (JOB *)GetResWithName(R_JOB, jcr->previous_jr.Name); UnlockRes(); - if (!job || !tjob) { + if (!job || !prev_job) { return false; } /* - * Target jcr is the new Job that corresponds to the original - * target job. It "runs" at the same time as the current + * prev_jcr is the new Job that corresponds to the original + * job. It "runs" at the same time as the current * migration job and becomes a new backup job that replaces * the original backup job. Most operations on the current - * migration jcr are also done on the target jcr. + * migration jcr are also done on the prev_jcr. */ - tjcr = jcr->previous_jcr = new_jcr(sizeof(JCR), dird_free_jcr); - memcpy(&tjcr->previous_jr, &jcr->previous_jr, sizeof(tjcr->previous_jr)); + prev_jcr = jcr->previous_jcr = new_jcr(sizeof(JCR), dird_free_jcr); + memcpy(&prev_jcr->previous_jr, &jcr->previous_jr, sizeof(prev_jcr->previous_jr)); - /* Turn the tjcr into a "real" job */ - set_jcr_defaults(tjcr, tjob); - if (!setup_job(tjcr)) { + /* Turn the prev_jcr into a "real" job */ + set_jcr_defaults(prev_jcr, prev_job); + if (!setup_job(prev_jcr)) { return false; } /* Set output PoolId and FileSetId. */ - tjcr->jr.PoolId = jcr->jr.PoolId; - tjcr->jr.FileSetId = jcr->jr.FileSetId; + prev_jcr->jr.PoolId = jcr->jr.PoolId; + prev_jcr->jr.FileSetId = jcr->jr.FileSetId; /* * Get the PoolId used with the original job. Then * find the pool name from the database record. */ memset(&pr, 0, sizeof(pr)); - pr.PoolId = tjcr->previous_jr.PoolId; + pr.PoolId = prev_jcr->previous_jr.PoolId; if (!db_get_pool_record(jcr, jcr->db, &pr)) { Jmsg(jcr, M_FATAL, 0, _("Pool for JobId %s not in database. ERR=%s\n"), edit_int64(pr.PoolId, ed1), db_strerror(jcr->db)); @@ -187,7 +189,7 @@ bool do_migration(JCR *jcr) /* ***FIXME*** */ /* If pool storage specified, use it for restore */ - copy_storage(tjcr, pool->storage); + copy_storage(prev_jcr, pool->storage); /* If the original backup pool has a NextPool, make sure a * record exists in the database. @@ -210,8 +212,8 @@ bool do_migration(JCR *jcr) * put the "NextPool" resource pointer in our jcr so that we * can pull the Storage reference from it. */ - tjcr->pool = jcr->pool = pool->NextPool; - tjcr->jr.PoolId = jcr->jr.PoolId = pr.PoolId; + prev_jcr->pool = jcr->pool = pool->NextPool; + prev_jcr->jr.PoolId = jcr->jr.PoolId = pr.PoolId; } /* If pool storage specified, use it instead of job storage for backup */ @@ -222,15 +224,15 @@ bool do_migration(JCR *jcr) edit_uint64(jcr->JobId, ed1), jcr->Job); set_jcr_job_status(jcr, JS_Running); - set_jcr_job_status(tjcr, JS_Running); + set_jcr_job_status(prev_jcr, JS_Running); Dmsg2(000, "JobId=%d JobLevel=%c\n", jcr->jr.JobId, jcr->jr.JobLevel); if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) { Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db)); return false; } - if (!db_update_job_start_record(tjcr, tjcr->db, &tjcr->jr)) { - Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(tjcr->db)); + if (!db_update_job_start_record(prev_jcr, prev_jcr->db, &prev_jcr->jr)) { + Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(prev_jcr->db)); return false; } @@ -243,7 +245,7 @@ bool do_migration(JCR *jcr) */ Dmsg0(110, "Open connection with storage daemon\n"); set_jcr_job_status(jcr, JS_WaitSD); - set_jcr_job_status(tjcr, JS_WaitSD); + set_jcr_job_status(prev_jcr, JS_WaitSD); /* * Start conversation with Storage daemon */ @@ -255,9 +257,9 @@ bool do_migration(JCR *jcr) * Now start a job with the Storage daemon */ Dmsg2(000, "Read store=%s, write store=%s\n", - ((STORE *)tjcr->storage->first())->hdr.name, + ((STORE *)prev_jcr->storage->first())->hdr.name, ((STORE *)jcr->storage->first())->hdr.name); - if (!start_storage_daemon_job(jcr, tjcr->storage, jcr->storage)) { + if (!start_storage_daemon_job(jcr, prev_jcr->storage, jcr->storage)) { return false; } Dmsg0(150, "Storage daemon connection OK\n"); @@ -279,7 +281,7 @@ bool do_migration(JCR *jcr) } set_jcr_job_status(jcr, JS_Running); - set_jcr_job_status(tjcr, JS_Running); + set_jcr_job_status(prev_jcr, JS_Running); /* Pickup Job termination data */ /* Note, the SD stores in jcr->JobFiles/ReadBytes/JobBytes/Errors */ @@ -379,7 +381,7 @@ const char *sql_job = const char *sql_jobids_from_job = "SELECT DISTINCT Job.JobId FROM Job,Pool" - " WHERE Job.Name=%s AND Pool.Name='%s' AND Job.PoolId=Pool.PoolId" + " WHERE Job.Name='%s' AND Pool.Name='%s' AND Job.PoolId=Pool.PoolId" " ORDER by Job.StartTime"; @@ -470,7 +472,6 @@ static bool get_job_to_migrate(JCR *jcr) * that have been matched by the regex, so now we need * to look up their jobids. */ - JobIds = get_pool_memory(PM_MESSAGE); JobIds[0] = 0; foreach_dlist(item, item_chain) { Dmsg1(000, "Got Job: %s\n", item->item); @@ -486,12 +487,10 @@ static bool get_job_to_migrate(JCR *jcr) goto ok_out; } Dmsg1(000, "Job Jobids=%s\n", JobIds); - free_pool_memory(JobIds); delete item_chain; break; case MT_SMALLEST_VOL: Mmsg(query, sql_smallest_vol, jcr->pool->hdr.name); - JobIds = get_pool_memory(PM_MESSAGE); JobIds[0] = 0; if (!db_sql_query(jcr->db, query.c_str(), jobid_handler, (void *)JobIds)) { Jmsg(jcr, M_FATAL, 0, @@ -514,7 +513,6 @@ static bool get_job_to_migrate(JCR *jcr) break; case MT_OLDEST_VOL: Mmsg(query, sql_oldest_vol, jcr->pool->hdr.name); - JobIds = get_pool_memory(PM_MESSAGE); JobIds[0] = 0; if (!db_sql_query(jcr->db, query.c_str(), jobid_handler, (void *)JobIds)) { Jmsg(jcr, M_FATAL, 0, @@ -536,7 +534,6 @@ static bool get_job_to_migrate(JCR *jcr) break; case MT_POOL_OCCUPANCY: Mmsg(query, sql_pool_bytes, jcr->pool->hdr.name); - JobIds = get_pool_memory(PM_MESSAGE); JobIds[0] = 0; if (!db_sql_query(jcr->db, query.c_str(), jobid_handler, (void *)JobIds)) { Jmsg(jcr, M_FATAL, 0, @@ -710,7 +707,6 @@ void migration_cleanup(JCR *jcr, int TermCode) set_jcr_job_status(prev_jcr, TermCode); - update_job_end_record(prev_jcr); Mmsg(query, "UPDATE Job SET StartTime='%s',EndTime='%s'," @@ -789,7 +785,7 @@ void migration_cleanup(JCR *jcr, int TermCode) if (RunTime <= 0) { kbps = 0; } else { - kbps = (double)jcr->jr.JobBytes / (1000 * RunTime); + kbps = (double)jcr->SDJobBytes / (1000 * RunTime); } @@ -837,7 +833,7 @@ void migration_cleanup(JCR *jcr, int TermCode) jcr->JobPriority, edit_uint64_with_commas(jcr->SDJobFiles, ec1), edit_uint64_with_commas(jcr->SDJobBytes, ec2), - edit_uint64_with_suffix(jcr->jr.JobBytes, ec3), + edit_uint64_with_suffix(jcr->SDJobBytes, ec3), (float)kbps, prev_jcr ? prev_jcr->VolumeName : "", jcr->VolSessionId, @@ -848,8 +844,10 @@ void migration_cleanup(JCR *jcr, int TermCode) sd_term_msg, term_code); - Dmsg1(100, "Leave migrate_cleanup() previous_jcr=0x%x\n", jcr->previous_jcr); + Dmsg1(000, "migrate_cleanup() previous_jcr=0x%x\n", jcr->previous_jcr); if (jcr->previous_jcr) { - free_jcr(jcr->previous_jcr); +// free_jcr(jcr->previous_jcr); +// jcr->previous_jcr = NULL; } + Dmsg0(000, "Leave migrate_cleanup()\n"); } diff --git a/bacula/src/lib/mem_pool.c b/bacula/src/lib/mem_pool.c index b43c60c621..61dc1bf52d 100644 --- a/bacula/src/lib/mem_pool.c +++ b/bacula/src/lib/mem_pool.c @@ -103,7 +103,7 @@ POOLMEM *sm_get_pool_memory(const char *fname, int lineno, int pool) pool_ctl[pool].max_used = pool_ctl[pool].in_use; } V(mutex); - Dmsg3(1800, "sm_get_pool_memory reuse %x to %s:%d\n", buf, fname, lineno); + Dmsg3(1800, "sm_get_pool_memory reuse %p to %s:%d\n", buf, fname, lineno); sm_new_owner(fname, lineno, (char *)buf); return (POOLMEM *)((char *)buf+HEAD_SIZE); } @@ -119,7 +119,7 @@ POOLMEM *sm_get_pool_memory(const char *fname, int lineno, int pool) pool_ctl[pool].max_used = pool_ctl[pool].in_use; } V(mutex); - Dmsg3(1800, "sm_get_pool_memory give %x to %s:%d\n", buf, fname, lineno); + Dmsg3(1800, "sm_get_pool_memory give %p to %s:%d\n", buf, fname, lineno); return (POOLMEM *)((char *)buf+HEAD_SIZE); } @@ -204,7 +204,8 @@ void sm_free_pool_memory(const char *fname, int lineno, POOLMEM *obuf) /* Don't let him free the same buffer twice */ for (next=pool_ctl[pool].free_buf; next; next=next->next) { if (next == buf) { - Dmsg4(1800, "bad free_pool_memory %x pool=%d from %s:%d\n", buf, pool, fname, lineno); + Dmsg4(1800, "free_pool_memory %p pool=%d from %s:%d\n", buf, pool, fname, lineno); + Dmsg4(1800, "bad free_pool_memory %p pool=%d from %s:%d\n", buf, pool, fname, lineno); V(mutex); /* unblock the pool */ ASSERT(next != buf); /* attempt to free twice */ } @@ -213,7 +214,7 @@ void sm_free_pool_memory(const char *fname, int lineno, POOLMEM *obuf) buf->next = pool_ctl[pool].free_buf; pool_ctl[pool].free_buf = buf; } - Dmsg4(1800, "free_pool_memory %x pool=%d from %s:%d\n", buf, pool, fname, lineno); + Dmsg4(1800, "free_pool_memory %p pool=%d from %s:%d\n", buf, pool, fname, lineno); V(mutex); } @@ -342,7 +343,7 @@ void free_pool_memory(POOLMEM *obuf) buf->next = pool_ctl[pool].free_buf; pool_ctl[pool].free_buf = buf; } - Dmsg2(1800, "free_pool_memory %x pool=%d\n", buf, pool); + Dmsg2(1800, "free_pool_memory %p pool=%d\n", buf, pool); V(mutex); } @@ -549,7 +550,7 @@ void POOL_MEM::realloc_pm(int32_t size) V(mutex); Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), size); } - Dmsg2(900, "Old buf=0x%x new buf=0x%x\n", cp, buf); + Dmsg2(900, "Old buf=%p new buf=%p\n", cp, buf); ((struct abufhead *)buf)->ablen = size; pool = ((struct abufhead *)buf)->pool; if (size > pool_ctl[pool].max_allocated) { @@ -557,7 +558,7 @@ void POOL_MEM::realloc_pm(int32_t size) } mem = buf+HEAD_SIZE; V(mutex); - Dmsg3(900, "Old buf=0x%x new buf=0x%x mem=0x%x\n", cp, buf, mem); + Dmsg3(900, "Old buf=%p new buf=%p mem=%p\n", cp, buf, mem); } int POOL_MEM::strcat(const char *str) diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index b5d5990b05..724015463e 100755 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -197,7 +197,7 @@ init_msg(JCR *jcr, MSGS *msg) add_msg_dest(daemon_msgs, MD_STDOUT, i, NULL, NULL); } #endif - Dmsg1(050, "Create daemon global message resource 0x%x\n", daemon_msgs); + Dmsg1(050, "Create daemon global message resource %p\n", daemon_msgs); return; } @@ -235,7 +235,7 @@ init_msg(JCR *jcr, MSGS *msg) daemon_msgs->dest_chain = temp_chain; memcpy(daemon_msgs->send_msg, msg->send_msg, sizeof(msg->send_msg)); } - Dmsg2(250, "Copy message resource 0x%x to 0x%x\n", msg, temp_chain); + Dmsg2(250, "Copy message resource %p to %p\n", msg, temp_chain); } @@ -289,7 +289,7 @@ void add_msg_dest(MSGS *msg, int dest_code, int msg_type, char *where, char *mai for (d=msg->dest_chain; d; d=d->next) { if (dest_code == d->dest_code && ((where == NULL && d->where == NULL) || (strcmp(where, d->where) == 0))) { - Dmsg4(850, "Add to existing d=%x msgtype=%d destcode=%d where=%s\n", + Dmsg4(850, "Add to existing d=%p msgtype=%d destcode=%d where=%s\n", d, msg_type, dest_code, NPRT(where)); set_bit(msg_type, d->msg_types); set_bit(msg_type, msg->send_msg); /* set msg_type bit in our local */ @@ -309,7 +309,7 @@ void add_msg_dest(MSGS *msg, int dest_code, int msg_type, char *where, char *mai if (mail_cmd) { d->mail_cmd = bstrdup(mail_cmd); } - Dmsg5(850, "add new d=%x msgtype=%d destcode=%d where=%s mailcmd=%s\n", + Dmsg5(850, "add new d=%p msgtype=%d destcode=%d where=%s mailcmd=%s\n", d, msg_type, dest_code, NPRT(where), NPRT(d->mail_cmd)); msg->dest_chain = d; } @@ -324,11 +324,11 @@ void rem_msg_dest(MSGS *msg, int dest_code, int msg_type, char *where) DEST *d; for (d=msg->dest_chain; d; d=d->next) { - Dmsg2(850, "Remove_msg_dest d=%x where=%s\n", d, NPRT(d->where)); + Dmsg2(850, "Remove_msg_dest d=%p where=%s\n", d, NPRT(d->where)); if (bit_is_set(msg_type, d->msg_types) && (dest_code == d->dest_code) && ((where == NULL && d->where == NULL) || (strcmp(where, d->where) == 0))) { - Dmsg3(850, "Found for remove d=%x msgtype=%d destcode=%d\n", + Dmsg3(850, "Found for remove d=%p msgtype=%d destcode=%d\n", d, msg_type, dest_code); clear_bit(msg_type, d->msg_types); Dmsg0(850, "Return rem_msg_dest\n"); @@ -393,7 +393,7 @@ void close_msg(JCR *jcr) POOLMEM *cmd, *line; int len, stat; - Dmsg1(850, "Close_msg jcr=0x%x\n", jcr); + Dmsg1(580, "Close_msg jcr=%p\n", jcr); if (jcr == NULL) { /* NULL -> global chain */ msgs = daemon_msgs; @@ -405,7 +405,7 @@ void close_msg(JCR *jcr) if (msgs == NULL) { return; } - Dmsg1(850, "===Begin close msg resource at 0x%x\n", msgs); + Dmsg1(850, "===Begin close msg resource at %p\n", msgs); cmd = get_pool_memory(PM_MESSAGE); for (d=msgs->dest_chain; d; ) { if (d->fd) { @@ -1253,7 +1253,6 @@ void Qmsg(JCR *jcr, int type, time_t mtime, const char *fmt,...) P(msg_queue_mutex); jcr->msg_queue->append(item); V(msg_queue_mutex); -// Dmsg1(000, "queue item=%lu\n", (long unsigned)item); } free_memory(pool_buf); } @@ -1267,7 +1266,6 @@ void dequeue_messages(JCR *jcr) P(msg_queue_mutex); jcr->dequeuing = true; foreach_dlist(item, jcr->msg_queue) { -// Dmsg1(000, "dequeue item=%lu\n", (long unsigned)item); Jmsg(jcr, item->type, item->mtime, "%s", item->msg); } jcr->msg_queue->destroy();