From 72d7d926114dad988bf05360e9b569222188dd1e Mon Sep 17 00:00:00 2001 From: Onder Kalaci Date: Fri, 4 Feb 2022 10:52:40 +0100 Subject: [PATCH] Apply code review feedback --- src/backend/distributed/commands/truncate.c | 6 +++++- src/backend/distributed/operations/repair_shards.c | 6 +++++- .../isolation_replicate_reference_tables_to_coordinator.out | 4 ++-- src/test/regress/isolation_schedule | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/backend/distributed/commands/truncate.c b/src/backend/distributed/commands/truncate.c index 109a1d941..815a90f93 100644 --- a/src/backend/distributed/commands/truncate.c +++ b/src/backend/distributed/commands/truncate.c @@ -437,8 +437,12 @@ AcquireDistributedLockOnRelations(List *relationIdList, LOCKMODE lockMode) /* * We only acquire distributed lock on relation if * the relation is sync'ed between mx nodes. + * + * Even if users disable metadata sync, we cannot + * allow them not to acquire the remote locks. + * Hence, we have !IsCoordinator() check. */ - if (ShouldSyncTableMetadata(relationId)) + if (ShouldSyncTableMetadata(relationId) || !IsCoordinator()) { char *qualifiedRelationName = generate_qualified_relation_name(relationId); StringInfo lockRelationCommand = makeStringInfo(); diff --git a/src/backend/distributed/operations/repair_shards.c b/src/backend/distributed/operations/repair_shards.c index 734d97450..1efec3193 100644 --- a/src/backend/distributed/operations/repair_shards.c +++ b/src/backend/distributed/operations/repair_shards.c @@ -556,8 +556,12 @@ BlockWritesToShardList(List *shardList) Oid firstDistributedTableId = firstShardInterval->relationId; bool shouldSyncMetadata = ShouldSyncTableMetadata(firstDistributedTableId); - if (shouldSyncMetadata) + if (shouldSyncMetadata || !IsCoordinator()) { + /* + * Even if users disable metadata sync, we cannot allow them not to + * acquire the remote locks. Hence, we have !IsCoordinator() check. + */ LockShardListMetadataOnWorkers(ExclusiveLock, shardList); } } diff --git a/src/test/regress/expected/isolation_replicate_reference_tables_to_coordinator.out b/src/test/regress/expected/isolation_replicate_reference_tables_to_coordinator.out index c012ef156..d28a6b714 100644 --- a/src/test/regress/expected/isolation_replicate_reference_tables_to_coordinator.out +++ b/src/test/regress/expected/isolation_replicate_reference_tables_to_coordinator.out @@ -103,8 +103,8 @@ step s2-view-worker: query |query_hostname |query_hostport|distributed_query_host_name|distributed_query_host_port|state |wait_event_type|wait_event|usename |datname --------------------------------------------------------------------- -UPDATE public.ref_table_1500803 ref_table SET a = (a OPERATOR(pg_catalog.+) 1)|localhost | 57638|coordinator_host | 57636|idle in transaction|Client |ClientRead|postgres|regression -UPDATE public.ref_table_1500803 ref_table SET a = (a OPERATOR(pg_catalog.+) 1)|localhost | 57637|coordinator_host | 57636|idle in transaction|Client |ClientRead|postgres|regression +UPDATE public.ref_table_1500767 ref_table SET a = (a OPERATOR(pg_catalog.+) 1)|localhost | 57638|coordinator_host | 57636|idle in transaction|Client |ClientRead|postgres|regression +UPDATE public.ref_table_1500767 ref_table SET a = (a OPERATOR(pg_catalog.+) 1)|localhost | 57637|coordinator_host | 57636|idle in transaction|Client |ClientRead|postgres|regression (2 rows) step s2-end: diff --git a/src/test/regress/isolation_schedule b/src/test/regress/isolation_schedule index 6108d3542..f0700c734 100644 --- a/src/test/regress/isolation_schedule +++ b/src/test/regress/isolation_schedule @@ -89,11 +89,11 @@ test: isolation_ref_update_delete_upsert_vs_all_on_mx test: isolation_dis2ref_foreign_keys_on_mx test: isolation_metadata_sync_deadlock test: isolation_replicated_dist_on_mx +test: isolation_replicate_reference_tables_to_coordinator test: isolation_multiuser_locking # MXless tests test: isolation_check_mx -test: isolation_replicate_reference_tables_to_coordinator test: isolation_turn_mx_off test: isolation_reference_copy_vs_all test: isolation_ref2ref_foreign_keys