mirror of https://github.com/citusdata/citus.git
Handling failure with subtransaction
parent
789ff7b162
commit
28dceecfff
|
@ -169,10 +169,24 @@ TryDropOrphanedShards(bool waitForLocks)
|
||||||
{
|
{
|
||||||
int droppedShardCount = 0;
|
int droppedShardCount = 0;
|
||||||
MemoryContext savedContext = CurrentMemoryContext;
|
MemoryContext savedContext = CurrentMemoryContext;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start a subtransaction so we can rollback database's state to it in case
|
||||||
|
* of error.
|
||||||
|
*/
|
||||||
|
BeginInternalSubTransaction(NULL);
|
||||||
|
|
||||||
PG_TRY();
|
PG_TRY();
|
||||||
{
|
{
|
||||||
droppedShardCount = DropOrphanedShardsForMove(waitForLocks);
|
droppedShardCount = DropOrphanedShardsForMove(waitForLocks);
|
||||||
droppedShardCount += DropOrphanedShardsForCleanup();
|
droppedShardCount += DropOrphanedShardsForCleanup();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Releasing a subtransaction doesn't free its memory context, since the
|
||||||
|
* data it contains will be needed at upper commit. See the comments for
|
||||||
|
* AtSubCommit_Memory() at postgres/src/backend/access/transam/xact.c.
|
||||||
|
*/
|
||||||
|
ReleaseCurrentSubTransaction();
|
||||||
}
|
}
|
||||||
PG_CATCH();
|
PG_CATCH();
|
||||||
{
|
{
|
||||||
|
@ -180,6 +194,8 @@ TryDropOrphanedShards(bool waitForLocks)
|
||||||
ErrorData *edata = CopyErrorData();
|
ErrorData *edata = CopyErrorData();
|
||||||
FlushErrorState();
|
FlushErrorState();
|
||||||
|
|
||||||
|
RollbackAndReleaseCurrentSubTransaction();
|
||||||
|
|
||||||
/* rethrow as WARNING */
|
/* rethrow as WARNING */
|
||||||
edata->elevel = WARNING;
|
edata->elevel = WARNING;
|
||||||
ThrowErrorData(edata);
|
ThrowErrorData(edata);
|
||||||
|
|
Loading…
Reference in New Issue