From ee964dde3df6ee9a6fe794a64a0a66e421274a4a Mon Sep 17 00:00:00 2001 From: Nils Dijk Date: Fri, 7 Feb 2020 01:21:37 +0100 Subject: [PATCH] extract extension DistributeObjectOps --- .../commands/distribute_object_ops.c | 47 -------- src/backend/distributed/commands/extension.c | 105 ++++++++++++++++-- .../distributed/deparser/objectaddress.c | 32 ------ src/include/distributed/commands.h | 15 --- 4 files changed, 97 insertions(+), 102 deletions(-) diff --git a/src/backend/distributed/commands/distribute_object_ops.c b/src/backend/distributed/commands/distribute_object_ops.c index deaccd2fe..dfa7b0f75 100644 --- a/src/backend/distributed/commands/distribute_object_ops.c +++ b/src/backend/distributed/commands/distribute_object_ops.c @@ -23,24 +23,6 @@ static DistributeObjectOps NoDistributeOps = { .address = NULL, }; -static DistributeObjectOps Any_AlterExtension = { - .deparse = DeparseAlterExtensionStmt, - .qualify = NULL, - .preprocess = PreprocessAlterExtensionUpdateStmt, - .postprocess = NULL, - .address = AlterExtensionUpdateStmtObjectAddress, -}; -REGISTER_DISTRIBUTED_OPERATION(AlterExtensionStmt, Any_AlterExtension); - -static DistributeObjectOps Any_AlterExtensionContents = { - .deparse = NULL, - .qualify = NULL, - .preprocess = PreprocessAlterExtensionContentsStmt, - .postprocess = NULL, - .address = NULL, -}; -REGISTER_DISTRIBUTED_OPERATION(AlterExtensionContentsStmt, Any_AlterExtensionContents); - static DistributeObjectOps Any_AlterFunction = { .deparse = DeparseAlterFunctionStmt, .qualify = QualifyAlterFunctionStmt, @@ -86,15 +68,6 @@ static DistributeObjectOps Any_Cluster = { }; REGISTER_DISTRIBUTED_OPERATION(ClusterStmt, Any_Cluster); -static DistributeObjectOps Any_CreateExtension = { - .deparse = DeparseCreateExtensionStmt, - .qualify = NULL, - .preprocess = NULL, - .postprocess = PostprocessCreateExtensionStmt, - .address = CreateExtensionStmtObjectAddress, -}; -REGISTER_DISTRIBUTED_OPERATION(CreateExtensionStmt, Any_CreateExtension); - static DistributeObjectOps Any_CreateFunction = { .deparse = NULL, .qualify = NULL, @@ -207,26 +180,6 @@ static DistributeObjectOps Collation_Rename = { REGISTER_DISTRIBUTED_OPERATION_NESTED(RenameStmt, renameType, OBJECT_COLLATION, Collation_Rename); -static DistributeObjectOps Extension_AlterObjectSchema = { - .deparse = DeparseAlterExtensionSchemaStmt, - .qualify = NULL, - .preprocess = PreprocessAlterExtensionSchemaStmt, - .postprocess = PostprocessAlterExtensionSchemaStmt, - .address = AlterExtensionSchemaStmtObjectAddress, -}; -REGISTER_DISTRIBUTED_OPERATION_NESTED(AlterObjectSchemaStmt, objectType, OBJECT_EXTENSION, - Extension_AlterObjectSchema); - -static DistributeObjectOps Extension_Drop = { - .deparse = DeparseDropExtensionStmt, - .qualify = NULL, - .preprocess = PreprocessDropExtensionStmt, - .postprocess = NULL, - .address = NULL, -}; -REGISTER_DISTRIBUTED_OPERATION_NESTED(DropStmt, removeType, OBJECT_EXTENSION, - Extension_Drop); - static DistributeObjectOps ForeignTable_AlterTable = { .deparse = NULL, .qualify = NULL, diff --git a/src/backend/distributed/commands/extension.c b/src/backend/distributed/commands/extension.c index 5add3f147..7cab07eec 100644 --- a/src/backend/distributed/commands/extension.c +++ b/src/backend/distributed/commands/extension.c @@ -39,6 +39,63 @@ static bool IsAlterExtensionSetSchemaCitus(Node *parseTree); static Node * RecreateExtensionStmt(Oid extensionOid); +/* DistributeObjectOps */ +static List * PreprocessAlterExtensionUpdateStmt(Node *node, const char *queryString); +static ObjectAddress AlterExtensionUpdateStmtObjectAddress(Node *node, bool missing_ok); +static DistributeObjectOps Any_AlterExtension = { + .deparse = DeparseAlterExtensionStmt, + .qualify = NULL, + .preprocess = PreprocessAlterExtensionUpdateStmt, + .postprocess = NULL, + .address = AlterExtensionUpdateStmtObjectAddress, +}; +REGISTER_DISTRIBUTED_OPERATION(AlterExtensionStmt, Any_AlterExtension); + +static List * PreprocessAlterExtensionContentsStmt(Node *node, const char *queryString); +static DistributeObjectOps Any_AlterExtensionContents = { + .deparse = NULL, + .qualify = NULL, + .preprocess = PreprocessAlterExtensionContentsStmt, + .postprocess = NULL, + .address = NULL, +}; +REGISTER_DISTRIBUTED_OPERATION(AlterExtensionContentsStmt, Any_AlterExtensionContents); + +static List * PostprocessCreateExtensionStmt(Node *node, const char *queryString); +static ObjectAddress CreateExtensionStmtObjectAddress(Node *node, bool missing_ok); +static DistributeObjectOps Any_CreateExtension = { + .deparse = DeparseCreateExtensionStmt, + .qualify = NULL, + .preprocess = NULL, + .postprocess = PostprocessCreateExtensionStmt, + .address = CreateExtensionStmtObjectAddress, +}; +REGISTER_DISTRIBUTED_OPERATION(CreateExtensionStmt, Any_CreateExtension); + +static List * PreprocessAlterExtensionSchemaStmt(Node *node, const char *queryString); +static List * PostprocessAlterExtensionSchemaStmt(Node *node, const char *queryString); +static ObjectAddress AlterExtensionSchemaStmtObjectAddress(Node *node, bool missing_ok); +static DistributeObjectOps Extension_AlterObjectSchema = { + .deparse = DeparseAlterExtensionSchemaStmt, + .qualify = NULL, + .preprocess = PreprocessAlterExtensionSchemaStmt, + .postprocess = PostprocessAlterExtensionSchemaStmt, + .address = AlterExtensionSchemaStmtObjectAddress, +}; +REGISTER_DISTRIBUTED_OPERATION_NESTED(AlterObjectSchemaStmt, objectType, OBJECT_EXTENSION, + Extension_AlterObjectSchema); + +static List * PreprocessDropExtensionStmt(Node *node, const char *queryString); +static DistributeObjectOps Extension_Drop = { + .deparse = DeparseDropExtensionStmt, + .qualify = NULL, + .preprocess = PreprocessDropExtensionStmt, + .postprocess = NULL, + .address = NULL, +}; +REGISTER_DISTRIBUTED_OPERATION_NESTED(DropStmt, removeType, OBJECT_EXTENSION, + Extension_Drop); + /* * ErrorIfUnstableCreateOrAlterExtensionStmt compares CITUS_EXTENSIONVERSION * and version given CREATE/ALTER EXTENSION statement will create/update to. If @@ -124,7 +181,7 @@ ExtractNewExtensionVersion(Node *parseTree) * created, we can mark it as distributed to make sure that its * dependencies exist on all nodes. */ -List * +static List * PostprocessCreateExtensionStmt(Node *node, const char *queryString) { CreateExtensionStmt *stmt = castNode(CreateExtensionStmt, node); @@ -232,7 +289,7 @@ AddSchemaFieldIfMissing(CreateExtensionStmt *createExtensionStmt) * If no extensions in the drop list are distributed, then no calls will * be made to the workers. */ -List * +static List * PreprocessDropExtensionStmt(Node *node, const char *queryString) { DropStmt *stmt = castNode(DropStmt, node); @@ -384,7 +441,7 @@ ExtensionNameListToObjectAddressList(List *extensionObjectList) /* * PreprocessAlterExtensionSchemaStmt is invoked for alter extension set schema statements. */ -List * +static List * PreprocessAlterExtensionSchemaStmt(Node *node, const char *queryString) { if (!ShouldPropagateExtensionCommand(node)) @@ -429,7 +486,7 @@ PreprocessAlterExtensionSchemaStmt(Node *node, const char *queryString) * locally, we can now use the new dependencies (schema) of the extension to ensure * all its dependencies exist on the workers before we apply the commands remotely. */ -List * +static List * PostprocessAlterExtensionSchemaStmt(Node *node, const char *queryString) { ObjectAddress extensionAddress = GetObjectAddressFromParseTree(node, false); @@ -449,7 +506,7 @@ PostprocessAlterExtensionSchemaStmt(Node *node, const char *queryString) /* * PreprocessAlterExtensionUpdateStmt is invoked for alter extension update statements. */ -List * +static List * PreprocessAlterExtensionUpdateStmt(Node *node, const char *queryString) { AlterExtensionStmt *alterExtensionStmt = castNode(AlterExtensionStmt, node); @@ -494,7 +551,7 @@ PreprocessAlterExtensionUpdateStmt(Node *node, const char *queryString) /* * PreprocessAlterExtensionContentsStmt issues a notice. It does not propagate. */ -List * +static List * PreprocessAlterExtensionContentsStmt(Node *node, const char *queryString) { ereport(NOTICE, (errmsg( @@ -741,7 +798,7 @@ RecreateExtensionStmt(Oid extensionOid) * AlterExtensionSchemaStmtObjectAddress returns the ObjectAddress of the extension that is * the subject of the AlterObjectSchemaStmt. Errors if missing_ok is false. */ -ObjectAddress +static ObjectAddress AlterExtensionSchemaStmtObjectAddress(Node *node, bool missing_ok) { AlterObjectSchemaStmt *stmt = castNode(AlterObjectSchemaStmt, node); @@ -769,7 +826,7 @@ AlterExtensionSchemaStmtObjectAddress(Node *node, bool missing_ok) * AlterExtensionUpdateStmtObjectAddress returns the ObjectAddress of the extension that is * the subject of the AlterExtensionStmt. Errors if missing_ok is false. */ -ObjectAddress +static ObjectAddress AlterExtensionUpdateStmtObjectAddress(Node *node, bool missing_ok) { AlterExtensionStmt *stmt = castNode(AlterExtensionStmt, node); @@ -789,3 +846,35 @@ AlterExtensionUpdateStmtObjectAddress(Node *node, bool missing_ok) return address; } + + +/* + * CreateExtensionStmtObjectAddress finds the ObjectAddress for the extension described + * by the CreateExtensionStmt. If missing_ok is false, then this function throws an + * error if the extension does not exist. + * + * Never returns NULL, but the objid in the address could be invalid if missing_ok was set + * to true. + */ +static ObjectAddress +CreateExtensionStmtObjectAddress(Node *node, bool missing_ok) +{ + CreateExtensionStmt *stmt = castNode(CreateExtensionStmt, node); + ObjectAddress address = { 0 }; + + const char *extensionName = stmt->extname; + + Oid extensionoid = get_extension_oid(extensionName, missing_ok); + + /* if we couldn't find the extension, error if missing_ok is false */ + if (!missing_ok && extensionoid == InvalidOid) + { + ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("extension \"%s\" does not exist", + extensionName))); + } + + ObjectAddressSet(address, ExtensionRelationId, extensionoid); + + return address; +} diff --git a/src/backend/distributed/deparser/objectaddress.c b/src/backend/distributed/deparser/objectaddress.c index a1ef82b0b..3f245ca24 100644 --- a/src/backend/distributed/deparser/objectaddress.c +++ b/src/backend/distributed/deparser/objectaddress.c @@ -59,38 +59,6 @@ RenameAttributeStmtObjectAddress(Node *node, bool missing_ok) } -/* - * CreateExtensionStmtObjectAddress finds the ObjectAddress for the extension described - * by the CreateExtensionStmt. If missing_ok is false, then this function throws an - * error if the extension does not exist. - * - * Never returns NULL, but the objid in the address could be invalid if missing_ok was set - * to true. - */ -ObjectAddress -CreateExtensionStmtObjectAddress(Node *node, bool missing_ok) -{ - CreateExtensionStmt *stmt = castNode(CreateExtensionStmt, node); - ObjectAddress address = { 0 }; - - const char *extensionName = stmt->extname; - - Oid extensionoid = get_extension_oid(extensionName, missing_ok); - - /* if we couldn't find the extension, error if missing_ok is false */ - if (!missing_ok && extensionoid == InvalidOid) - { - ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), - errmsg("extension \"%s\" does not exist", - extensionName))); - } - - ObjectAddressSet(address, ExtensionRelationId, extensionoid); - - return address; -} - - /* * AlterExtensionStmtObjectAddress finds the ObjectAddress for the extension described * by the AlterExtensionStmt. If missing_ok is false, then this function throws an diff --git a/src/include/distributed/commands.h b/src/include/distributed/commands.h index a21d28809..8a0ed4a8a 100644 --- a/src/include/distributed/commands.h +++ b/src/include/distributed/commands.h @@ -148,21 +148,7 @@ extern List * PostprocessDefineCollationStmt(Node *stmt, const char *queryString /* extension.c - forward declarations */ extern bool IsCreateAlterExtensionUpdateCitusStmt(Node *parsetree); extern void ErrorIfUnstableCreateOrAlterExtensionStmt(Node *parsetree); -extern List * PostprocessCreateExtensionStmt(Node *stmt, const char *queryString); -extern List * PreprocessDropExtensionStmt(Node *stmt, const char *queryString); -extern List * PreprocessAlterExtensionSchemaStmt(Node *stmt, - const char *queryString); -extern List * PostprocessAlterExtensionSchemaStmt(Node *stmt, - const char *queryString); -extern List * PreprocessAlterExtensionUpdateStmt(Node *stmt, - const char *queryString); -extern List * PreprocessAlterExtensionContentsStmt(Node *node, - const char *queryString); extern List * CreateExtensionDDLCommand(const ObjectAddress *extensionAddress); -extern ObjectAddress AlterExtensionSchemaStmtObjectAddress(Node *stmt, - bool missing_ok); -extern ObjectAddress AlterExtensionUpdateStmtObjectAddress(Node *stmt, - bool missing_ok); /* foreign_constraint.c - forward declarations */ @@ -204,7 +190,6 @@ extern List * PostprocessIndexStmt(Node *node, extern void ErrorIfUnsupportedAlterIndexStmt(AlterTableStmt *alterTableStatement); /* objectaddress.c - forward declarations */ -extern ObjectAddress CreateExtensionStmtObjectAddress(Node *stmt, bool missing_ok); extern ObjectAddress AlterExtensionStmtObjectAddress(Node *stmt, bool missing_ok);