diff --git a/src/backend/distributed/commands/extension.c b/src/backend/distributed/commands/extension.c index e7be51992..6f01be54c 100644 --- a/src/backend/distributed/commands/extension.c +++ b/src/backend/distributed/commands/extension.c @@ -653,51 +653,6 @@ GetAllViews(void) } -/* - * ShouldMarkRelationDistributed is a helper function that - * decides whether the input relation should be marked as distributed - * during the upgrade. - */ -bool -ShouldMarkRelationDistributed(Oid relationId) -{ - if (!EnableMetadataSync) - { - /* - * Just in case anything goes wrong, we should still be able - * to continue to the version upgrade. - */ - return false; - } - - ObjectAddress relationAddress = { 0 }; - ObjectAddressSet(relationAddress, RelationRelationId, relationId); - - bool pgObject = (relationId < FirstNormalObjectId); - bool ownedByExtension = IsTableOwnedByExtension(relationId); - bool alreadyDistributed = IsObjectDistributed(&relationAddress); - bool hasUnsupportedDependency = - DeferErrorIfHasUnsupportedDependency(&relationAddress) != NULL; - bool hasCircularDependency = - DeferErrorIfCircularDependencyExists(&relationAddress) != NULL; - - /* - * pgObject: Citus never marks pg objects as distributed - * ownedByExtension: let extensions manage its own objects - * alreadyDistributed: most likely via earlier versions - * hasUnsupportedDependency: Citus doesn't know how to distribute its dependencies - * hasCircularDependency: Citus cannot handle circular dependencies - */ - if (pgObject || ownedByExtension || alreadyDistributed || - hasUnsupportedDependency || hasCircularDependency) - { - return false; - } - - return true; -} - - /* * PreprocessAlterExtensionContentsStmt issues a notice. It does not propagate. */ diff --git a/src/backend/distributed/metadata/distobject.c b/src/backend/distributed/metadata/distobject.c index 172691b7d..cd6ededdd 100644 --- a/src/backend/distributed/metadata/distobject.c +++ b/src/backend/distributed/metadata/distobject.c @@ -29,7 +29,9 @@ #include "citus_version.h" #include "commands/extension.h" #include "distributed/colocation_utils.h" +#include "distributed/commands.h" #include "distributed/commands/utility_hook.h" +#include "distributed/metadata/dependency.h" #include "distributed/metadata/distobject.h" #include "distributed/metadata/pg_dist_object.h" #include "distributed/metadata_cache.h" @@ -220,6 +222,56 @@ MarkObjectDistributedLocally(const ObjectAddress *distAddress) } +/* + * ShouldMarkRelationDistributed is a helper function that + * decides whether the input relation should be marked as distributed. + */ +bool +ShouldMarkRelationDistributed(Oid relationId) +{ + if (!EnableMetadataSync) + { + /* + * Just in case anything goes wrong, we should still be able + * to continue to the version upgrade. + */ + return false; + } + + ObjectAddress relationAddress = { 0 }; + ObjectAddressSet(relationAddress, RelationRelationId, relationId); + + /* check if the relation itself is supported or not */ + if (!SupportedDependencyByCitus(&relationAddress)) + { + return false; + } + + bool pgObject = (relationId < FirstNormalObjectId); + bool ownedByExtension = IsTableOwnedByExtension(relationId); + bool alreadyDistributed = IsObjectDistributed(&relationAddress); + bool hasUnsupportedDependency = + DeferErrorIfHasUnsupportedDependency(&relationAddress) != NULL; + bool hasCircularDependency = + DeferErrorIfCircularDependencyExists(&relationAddress) != NULL; + + /* + * pgObject: Citus never marks pg objects as distributed + * ownedByExtension: let extensions manage its own objects + * alreadyDistributed: most likely via earlier versions + * hasUnsupportedDependency: Citus doesn't know how to distribute its dependencies + * hasCircularDependency: Citus cannot handle circular dependencies + */ + if (pgObject || ownedByExtension || alreadyDistributed || + hasUnsupportedDependency || hasCircularDependency) + { + return false; + } + + return true; +} + + /* * CreatePgDistObjectEntryCommand creates command to insert pg_dist_object tuple * for the given object address. diff --git a/src/backend/distributed/metadata/metadata_sync.c b/src/backend/distributed/metadata/metadata_sync.c index 62f7e841c..bc5e37043 100644 --- a/src/backend/distributed/metadata/metadata_sync.c +++ b/src/backend/distributed/metadata/metadata_sync.c @@ -98,6 +98,7 @@ static char * SchemaOwnerName(Oid objectId); static bool HasMetadataWorkers(void); static void CreateShellTableOnWorkers(Oid relationId); static void CreateTableMetadataOnWorkers(Oid relationId); +static void CreateDependentViewsOnWorkers(Oid relationId); static NodeMetadataSyncResult SyncNodeMetadataToNodesOptional(void); static bool ShouldSyncTableMetadataInternal(bool hashDistributed, bool citusTableWithNoDistKey); @@ -303,7 +304,8 @@ SyncNodeMetadataToNode(const char *nodeNameString, int32 nodePort) * SyncCitusTableMetadata syncs citus table metadata to worker nodes with metadata. * Our definition of metadata includes the shell table and its inter relations with * other shell tables, corresponding pg_dist_object, pg_dist_partiton, pg_dist_shard - * and pg_dist_shard placement entries. + * and pg_dist_shard placement entries. This function also propagates the views that + * depend on the given relation, to the metadata workers. */ void SyncCitusTableMetadata(Oid relationId) @@ -327,7 +329,7 @@ SyncCitusTableMetadata(Oid relationId) * CreateDependentViewsOnWorkers takes a relationId and creates the views that depend on * that relation on workers with metadata. */ -void +static void CreateDependentViewsOnWorkers(Oid relationId) { List *views = GetDependingViews(relationId); diff --git a/src/include/distributed/metadata_sync.h b/src/include/distributed/metadata_sync.h index 7107194f8..e4cdf8830 100644 --- a/src/include/distributed/metadata_sync.h +++ b/src/include/distributed/metadata_sync.h @@ -32,7 +32,6 @@ typedef enum /* Functions declarations for metadata syncing */ extern void SyncNodeMetadataToNode(const char *nodeNameString, int32 nodePort); extern void SyncCitusTableMetadata(Oid relationId); -extern void CreateDependentViewsOnWorkers(Oid relationId); extern void EnsureSequentialModeMetadataOperations(void); extern bool ClusterHasKnownMetadataWorkers(void); extern char * LocalGroupIdUpdateCommand(int32 groupId);