From 2489c59c15d69ee92f4b02425c49af5dcdc872cc Mon Sep 17 00:00:00 2001 From: Burak Yucesoy Date: Wed, 18 Jan 2017 12:01:28 +0200 Subject: [PATCH] In case of failed transactions update shard state only if it is FILE_FINALIZED Before this change, when a transaction failed, we update related placements shard states to FILE_INACTIVE during XACT_EVENT_PRE_COMMIT. However that means if another code block changed shard state to something else (e.g. FILE_TO_DELETE) before XACT_EVENT_PRE_COMMIT we overwrite that. To prevent that problem, in case of failure we started to change shard state, only if its current shard state is FILE_FINALIZED. --- .../distributed/connection/placement_connection.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/backend/distributed/connection/placement_connection.c b/src/backend/distributed/connection/placement_connection.c index 5dcbab9c3..7df453945 100644 --- a/src/backend/distributed/connection/placement_connection.c +++ b/src/backend/distributed/connection/placement_connection.c @@ -837,7 +837,18 @@ CheckShardPlacements(ConnectionShardHashEntry *shardEntry, if (placementEntry->failed) { - UpdateShardPlacementState(placementEntry->key.placementId, FILE_INACTIVE); + uint64 shardId = shardEntry->key.shardId; + uint64 placementId = placementEntry->key.placementId; + ShardPlacement *shardPlacement = LoadShardPlacement(shardId, placementId); + + /* + * We only set shard state if its current state is FILE_FINALIZED, which + * prevents overwriting shard state if it is already set at somewhere else. + */ + if (shardPlacement->shardState == FILE_FINALIZED) + { + UpdateShardPlacementState(placementEntry->key.placementId, FILE_INACTIVE); + } } }