mirror of https://github.com/citusdata/citus.git
refactor inner loop of background worker thing
parent
5a2ec73475
commit
80e2edf1a5
|
@ -912,28 +912,35 @@ RebalanceJobsBackgroundWorkerMain(Datum arg)
|
|||
RebalanceJob *job = GetRunableRebalanceJob();
|
||||
MemoryContextSwitchTo(oldContext);
|
||||
|
||||
if (job)
|
||||
if (!job)
|
||||
{
|
||||
ereport(LOG, (errmsg("found job with jobid: %ld", job->jobid)));
|
||||
MemoryContext savedContext = CurrentMemoryContext;
|
||||
|
||||
UpdateJobStatus(job, REBALANCE_JOB_STATUS_RUNNING);
|
||||
PopActiveSnapshot();
|
||||
CommitTransactionCommand();
|
||||
|
||||
StartTransactionCommand();
|
||||
PushActiveSnapshot(GetTransactionSnapshot());
|
||||
hasJobs = false;
|
||||
break;
|
||||
}
|
||||
|
||||
BeginInternalSubTransaction(NULL);
|
||||
ereport(LOG, (errmsg("found job with jobid: %ld", job->jobid)));
|
||||
|
||||
/* Update job status to indicate it is running */
|
||||
UpdateJobStatus(job, REBALANCE_JOB_STATUS_RUNNING);
|
||||
|
||||
PopActiveSnapshot();
|
||||
CommitTransactionCommand();
|
||||
|
||||
MemoryContext savedContext = CurrentMemoryContext;
|
||||
PG_TRY();
|
||||
{
|
||||
StartTransactionCommand();
|
||||
PushActiveSnapshot(GetTransactionSnapshot());
|
||||
if (ExecuteRebalanceJob(job))
|
||||
{
|
||||
UpdateJobStatus(job, REBALANCE_JOB_STATUS_DONE);
|
||||
}
|
||||
|
||||
ReleaseCurrentSubTransaction();
|
||||
PopActiveSnapshot();
|
||||
CommitTransactionCommand();
|
||||
}
|
||||
}
|
||||
PG_CATCH();
|
||||
{
|
||||
|
@ -942,10 +949,14 @@ RebalanceJobsBackgroundWorkerMain(Datum arg)
|
|||
ErrorData *edata = CopyErrorData();
|
||||
FlushErrorState();
|
||||
|
||||
RollbackAndReleaseCurrentSubTransaction();
|
||||
StartTransactionCommand();
|
||||
PushActiveSnapshot(GetTransactionSnapshot());
|
||||
|
||||
UpdateJobError(job, edata);
|
||||
|
||||
PopActiveSnapshot();
|
||||
CommitTransactionCommand();
|
||||
|
||||
FreeErrorData(edata);
|
||||
edata = NULL;
|
||||
|
||||
|
@ -953,16 +964,8 @@ RebalanceJobsBackgroundWorkerMain(Datum arg)
|
|||
}
|
||||
PG_END_TRY();
|
||||
}
|
||||
else
|
||||
{
|
||||
hasJobs = false;
|
||||
}
|
||||
}
|
||||
|
||||
PopActiveSnapshot();
|
||||
CommitTransactionCommand();
|
||||
ProcessCompletedNotifies();
|
||||
}
|
||||
MemoryContextSwitchTo(oldContextPerJob);
|
||||
MemoryContextDelete(perJobContext);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue