Redesigns code with callbacks

non-main-redesign-suggest
gurkanindibay 2024-03-01 09:16:52 +03:00
parent c4d4b42d8b
commit 5bcb166316
1 changed files with 137 additions and 87 deletions

View File

@ -177,6 +177,15 @@ static void MarkObjectDistributedGloballyOnMainDbs(
MarkDistributedGloballyParams *markDistributedParams); MarkDistributedGloballyParams *markDistributedParams);
static void UnmarkObjectsDistributedOnLocalMainDb(List *unmarkDistributedParamsList); static void UnmarkObjectsDistributedOnLocalMainDb(List *unmarkDistributedParamsList);
const NonMainDbDistributeObjectOps * HandleCreateRoleStmt(Node *parsetree);
const NonMainDbDistributeObjectOps * HandleDropRoleStmt(Node *parsetree);
const NonMainDbDistributeObjectOps * HandleAlterRoleStmt(Node *parsetree);
const NonMainDbDistributeObjectOps * HandleGrantRoleStmt(Node *parsetree);
const NonMainDbDistributeObjectOps * HandleCreatedbStmt(Node *parsetree);
const NonMainDbDistributeObjectOps * HandleDropdbStmt(Node *parsetree);
const NonMainDbDistributeObjectOps * HandleGrantStmt(Node *parsetree);
const NonMainDbDistributeObjectOps * HandleSecLabelStmt(Node *parsetree);
/* /*
* RunPreprocessNonMainDBCommand runs the necessary commands for a query, in main * RunPreprocessNonMainDBCommand runs the necessary commands for a query, in main
@ -265,38 +274,37 @@ RunPostprocessNonMainDBCommand(Node *parsetree)
} }
/*
* GetNonMainDbDistributeObjectOps returns the NonMainDbDistributeObjectOps for given
* command if it's node-wide object management command that's supported from non-main
* databases.
*/
const NonMainDbDistributeObjectOps * const NonMainDbDistributeObjectOps *
GetNonMainDbDistributeObjectOps(Node *parsetree) HandleCreateRoleStmt(Node *parsetree)
{ {
switch (nodeTag(parsetree))
{
case T_CreateRoleStmt:
{
return &Any_CreateRole; return &Any_CreateRole;
} }
case T_DropRoleStmt:
{ const NonMainDbDistributeObjectOps *
HandleDropRoleStmt(Node *parsetree)
{
return &Any_DropRole; return &Any_DropRole;
} }
case T_AlterRoleStmt:
{ const NonMainDbDistributeObjectOps *
HandleAlterRoleStmt(Node *parsetree)
{
return &Any_AlterRole; return &Any_AlterRole;
} }
case T_GrantRoleStmt:
{ const NonMainDbDistributeObjectOps *
HandleGrantRoleStmt(Node *parsetree)
{
return &Any_GrantRole; return &Any_GrantRole;
} }
case T_CreatedbStmt:
{ const NonMainDbDistributeObjectOps *
HandleCreatedbStmt(Node *parsetree)
{
CreatedbStmt *stmt = castNode(CreatedbStmt, parsetree); CreatedbStmt *stmt = castNode(CreatedbStmt, parsetree);
/* /*
@ -310,10 +318,12 @@ GetNonMainDbDistributeObjectOps(Node *parsetree)
} }
return NULL; return NULL;
} }
case T_DropdbStmt:
{ const NonMainDbDistributeObjectOps *
HandleDropdbStmt(Node *parsetree)
{
DropdbStmt *stmt = castNode(DropdbStmt, parsetree); DropdbStmt *stmt = castNode(DropdbStmt, parsetree);
/* /*
@ -327,10 +337,12 @@ GetNonMainDbDistributeObjectOps(Node *parsetree)
} }
return NULL; return NULL;
} }
case T_GrantStmt:
{ const NonMainDbDistributeObjectOps *
HandleGrantStmt(Node *parsetree)
{
GrantStmt *stmt = castNode(GrantStmt, parsetree); GrantStmt *stmt = castNode(GrantStmt, parsetree);
switch (stmt->objtype) switch (stmt->objtype)
@ -343,10 +355,12 @@ GetNonMainDbDistributeObjectOps(Node *parsetree)
default: default:
return NULL; return NULL;
} }
} }
case T_SecLabelStmt:
{ const NonMainDbDistributeObjectOps *
HandleSecLabelStmt(Node *parsetree)
{
SecLabelStmt *stmt = castNode(SecLabelStmt, parsetree); SecLabelStmt *stmt = castNode(SecLabelStmt, parsetree);
switch (stmt->objtype) switch (stmt->objtype)
@ -359,11 +373,47 @@ GetNonMainDbDistributeObjectOps(Node *parsetree)
default: default:
return NULL; return NULL;
} }
}
typedef const NonMainDbDistributeObjectOps *(*HandlerFunc)(Node *);
static const struct
{
NodeTag tag;
HandlerFunc handler;
}
handlers[] = {
{ T_CreateRoleStmt, HandleCreateRoleStmt },
{ T_DropRoleStmt, HandleDropRoleStmt },
{ T_AlterRoleStmt, HandleAlterRoleStmt },
{ T_GrantRoleStmt, HandleGrantRoleStmt },
{ T_CreatedbStmt, HandleCreatedbStmt },
{ T_DropdbStmt, HandleDropdbStmt },
{ T_GrantStmt, HandleGrantStmt },
{ T_SecLabelStmt, HandleSecLabelStmt },
};
/*
* GetNonMainDbDistributeObjectOps returns the NonMainDbDistributeObjectOps for given
* command if it's node-wide object management command that's supported from non-main
* databases.
*/
const NonMainDbDistributeObjectOps *
GetNonMainDbDistributeObjectOps(Node *parsetree)
{
NodeTag tag = nodeTag(parsetree);
for (int i = 0; i < sizeof(handlers) / sizeof(handlers[0]); i++)
{
if (handlers[i].tag == tag)
{
return handlers[i].handler(parsetree);
}
} }
default:
return NULL; return NULL;
}
} }