Make sure spinlock is not left unreleased when an exception is thrown

A spinlock is not released when an exception is thrown after
spinlock is acquired. This has caused infinite wait and eventual
crash in maintenance daemon.

This work moves the code than can fail to the outside of spinlock
scope so that in the case of failure spinlock is not left locked
since it was not locked in the first place.
release-8.0
Murat Tuncer 2018-12-21 15:27:15 +03:00 committed by Hanefi Onaldi
parent 1e3969cae1
commit c5371965f6
No known key found for this signature in database
GPG Key ID: 95177DABDC09D1F5
1 changed files with 7 additions and 1 deletions

View File

@ -805,9 +805,15 @@ AssignDistributedTransactionId(void)
void
MarkCitusInitiatedCoordinatorBackend(void)
{
/*
* GetLocalGroupId may throw exception which can cause leaving spin lock
* unreleased. Calling GetLocalGroupId function before the lock to avoid this.
*/
int localGroupId = GetLocalGroupId();
SpinLockAcquire(&MyBackendData->mutex);
MyBackendData->citusBackend.initiatorNodeIdentifier = GetLocalGroupId();
MyBackendData->citusBackend.initiatorNodeIdentifier = localGroupId;
MyBackendData->citusBackend.transactionOriginator = true;
SpinLockRelease(&MyBackendData->mutex);