From 172bb457e66c792b17777f39c437b06076f23355 Mon Sep 17 00:00:00 2001 From: Marco Slot Date: Tue, 25 Oct 2016 15:14:30 +0200 Subject: [PATCH] Take shard metadata lock in master_append_table_to_shard --- .../distributed/master/master_stage_protocol.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/backend/distributed/master/master_stage_protocol.c b/src/backend/distributed/master/master_stage_protocol.c index 7ea07d47d..97b65b485 100644 --- a/src/backend/distributed/master/master_stage_protocol.c +++ b/src/backend/distributed/master/master_stage_protocol.c @@ -226,12 +226,11 @@ master_append_table_to_shard(PG_FUNCTION_ARGS) "in hash-partitioned tables"))); } - /* - * We lock on the shardId, but do not unlock. When the function returns, and - * the transaction for this function commits, this lock will automatically - * be released. This ensures appends to a shard happen in a serial manner. - */ - LockShardResource(shardId, AccessExclusiveLock); + /* ensure that the shard placement metadata does not change during the append */ + LockShardDistributionMetadata(shardId, ShareLock); + + /* serialize appends to the same shard */ + LockShardResource(shardId, ExclusiveLock); /* get schame name of the target shard */ shardSchemaOid = get_rel_namespace(relationId);