mirror of https://github.com/citusdata/citus.git
phase 2: remove the clutter in utiity_hook.c and some funct renaming
parent
0ba3a9bb5b
commit
fadee4e494
|
@ -143,25 +143,42 @@ IsCommandToCreateOrDropMainDB(Node *parsetree)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RunPreprocessMainDBCommand runs the necessary commands for a query, in main
|
* RunPreprocessNonMainDBCommand runs the necessary commands for a query, in main
|
||||||
* database before query is run on the local node with PrevProcessUtility
|
* database before query is run on the local node with PrevProcessUtility.
|
||||||
|
*
|
||||||
|
* Returns true if previous utility hook needs to be skipped after completing
|
||||||
|
* preprocess phase.
|
||||||
*/
|
*/
|
||||||
void
|
bool
|
||||||
RunPreprocessMainDBCommand(Node *parsetree)
|
RunPreprocessNonMainDBCommand(Node *parsetree)
|
||||||
{
|
{
|
||||||
if (!IsStatementSupportedFromNonMainDb(parsetree))
|
if (IsMainDB || !IsStatementSupportedFromNonMainDb(parsetree))
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsCommandToCreateOrDropMainDB(parsetree))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* We don't try to send the query to the main database if the CREATE/DROP DATABASE
|
||||||
|
* command is for the main database itself, this is a very rare case but it's
|
||||||
|
* exercised by our test suite.
|
||||||
|
*/
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *queryString = DeparseTreeNode(parsetree);
|
char *queryString = DeparseTreeNode(parsetree);
|
||||||
|
|
||||||
if (IsA(parsetree, CreatedbStmt) ||
|
if (IsA(parsetree, CreatedbStmt) || IsA(parsetree, DropdbStmt))
|
||||||
IsA(parsetree, DropdbStmt))
|
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* We always execute CREATE/DROP DATABASE from the main database. There are no
|
||||||
|
* transactional visibility issues, since these commands are non-transactional.
|
||||||
|
* And this way we only have to consider one codepath when creating databases.
|
||||||
|
*/
|
||||||
IsMainDBCommandInXact = false;
|
IsMainDBCommandInXact = false;
|
||||||
RunCitusMainDBQuery((char *) queryString);
|
RunCitusMainDBQuery((char *) queryString);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IsMainDBCommandInXact = true;
|
IsMainDBCommandInXact = true;
|
||||||
|
@ -184,18 +201,24 @@ RunPreprocessMainDBCommand(Node *parsetree)
|
||||||
List *unmarkParams = GetDistObjectOperationParams(parsetree);
|
List *unmarkParams = GetDistObjectOperationParams(parsetree);
|
||||||
UnMarkObjectDistributedLocallyFromNonMainDb(unmarkParams);
|
UnMarkObjectDistributedLocallyFromNonMainDb(unmarkParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RunPostprocessMainDBCommand runs the necessary commands for a query, in main
|
* RunPostprocessNonMainDBCommand runs the necessary commands for a query, in main
|
||||||
* database after query is run on the local node with PrevProcessUtility
|
* database after query is run on the local node with PrevProcessUtility.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
RunPostprocessMainDBCommand(Node *parsetree)
|
RunPostprocessNonMainDBCommand(Node *parsetree)
|
||||||
{
|
{
|
||||||
if (IsStatementSupportedFromNonMainDb(parsetree) &&
|
if (IsMainDB || !IsStatementSupportedFromNonMainDb(parsetree))
|
||||||
StatementRequiresMarkDistributedGloballyFromNonMainDb(parsetree))
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StatementRequiresMarkDistributedGloballyFromNonMainDb(parsetree))
|
||||||
{
|
{
|
||||||
MarkObjectDistributedGloballyFromNonMainDb(parsetree);
|
MarkObjectDistributedGloballyFromNonMainDb(parsetree);
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,37 +247,26 @@ citus_ProcessUtility(PlannedStmt *pstmt,
|
||||||
if (!CitusHasBeenLoaded())
|
if (!CitusHasBeenLoaded())
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* We always execute CREATE/DROP DATABASE from the main database. There are no
|
* Process the command via RunPreprocessNonMainDBCommand and
|
||||||
* transactional visibility issues, since these commands are non-transactional.
|
* RunPostprocessNonMainDBCommand hooks if we're in a non-main database
|
||||||
* And this way we only have to consider one codepath when creating databases.
|
* and if the command is a node-wide object management command that we
|
||||||
* We don't try to send the query to the main database if the CREATE/DROP DATABASE
|
* support from non-main databases.
|
||||||
* command is for the main database itself, this is a very rare case but it's
|
|
||||||
* exercised by our test suite.
|
|
||||||
*/
|
*/
|
||||||
if (!IsMainDB &&
|
|
||||||
!IsCommandToCreateOrDropMainDB(parsetree))
|
|
||||||
{
|
|
||||||
RunPreprocessMainDBCommand(parsetree);
|
|
||||||
|
|
||||||
if (IsA(parsetree, CreatedbStmt) ||
|
bool shouldSkipPrevUtilityHook = RunPreprocessNonMainDBCommand(parsetree);
|
||||||
IsA(parsetree, DropdbStmt))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!shouldSkipPrevUtilityHook)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* Ensure that utility commands do not behave any differently until CREATE
|
* Ensure that utility commands do not behave any differently until CREATE
|
||||||
* EXTENSION is invoked.
|
* EXTENSION is invoked.
|
||||||
*/
|
*/
|
||||||
PrevProcessUtility(pstmt, queryString, false, context,
|
PrevProcessUtility(pstmt, queryString, false, context,
|
||||||
params, queryEnv, dest, completionTag);
|
params, queryEnv, dest, completionTag);
|
||||||
|
|
||||||
if (!IsMainDB)
|
|
||||||
{
|
|
||||||
RunPostprocessMainDBCommand(parsetree);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RunPostprocessNonMainDBCommand(parsetree);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (IsA(parsetree, CallStmt))
|
else if (IsA(parsetree, CallStmt))
|
||||||
|
|
|
@ -106,8 +106,8 @@ const DistributeObjectOps * GetDistributeObjectOps(Node *node);
|
||||||
|
|
||||||
/* functions to support node-wide object management commands from non-main dbs */
|
/* functions to support node-wide object management commands from non-main dbs */
|
||||||
extern bool IsCommandToCreateOrDropMainDB(Node *parsetree);
|
extern bool IsCommandToCreateOrDropMainDB(Node *parsetree);
|
||||||
extern void RunPreprocessMainDBCommand(Node *parsetree);
|
extern bool RunPreprocessNonMainDBCommand(Node *parsetree);
|
||||||
extern void RunPostprocessMainDBCommand(Node *parsetree);
|
extern void RunPostprocessNonMainDBCommand(Node *parsetree);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Flags that can be passed to GetForeignKeyOids to indicate
|
* Flags that can be passed to GetForeignKeyOids to indicate
|
||||||
|
|
Loading…
Reference in New Issue