Skip to content

Commit

Permalink
Fixes indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
gurkanindibay committed Oct 4, 2023
1 parent c1aca5e commit 90ead5d
Show file tree
Hide file tree
Showing 7 changed files with 479 additions and 414 deletions.
91 changes: 51 additions & 40 deletions src/backend/distributed/commands/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,33 @@
#include "distributed/adaptive_executor.h"

/* macros to add DefElems to a list */
#define DEFELEM_ADD_STRING(options, key, value) \
{ \
DefElem *elem = makeDefElem(key, (Node *)makeString(value), -1); \
options = lappend(options, elem); \
#define DEFELEM_ADD_STRING(options, key, value) \
{ \
DefElem *elem = makeDefElem(key, (Node *) makeString(value), -1); \
options = lappend(options, elem); \
}

#define DEFELEM_ADD_BOOL(options, key, value) \
{ \
DefElem *elem = makeDefElem(key, (Node *)makeBoolean(value), -1); \
options = lappend(options, elem); \
#define DEFELEM_ADD_BOOL(options, key, value) \
{ \
DefElem *elem = makeDefElem(key, (Node *) makeBoolean(value), -1); \
options = lappend(options, elem); \
}

#define DEFELEM_ADD_INT(options, key, value) \
{ \
DefElem *elem = makeDefElem(key, (Node *)makeInteger(value), -1); \
options = lappend(options, elem); \
#define DEFELEM_ADD_INT(options, key, value) \
{ \
DefElem *elem = makeDefElem(key, (Node *) makeInteger(value), -1); \
options = lappend(options, elem); \
}

static AlterOwnerStmt *RecreateAlterDatabaseOwnerStmt(Oid databaseOid);
static AlterOwnerStmt * RecreateAlterDatabaseOwnerStmt(Oid databaseOid);

static List *CreateDDLTaskList(char *command, List *workerNodeList,
bool outsideTransaction);
static List * CreateDDLTaskList(char *command, List *workerNodeList,
bool outsideTransaction);

PG_FUNCTION_INFO_V1(citus_internal_database_command);
static Oid get_database_owner(Oid db_oid);
List *PreprocessGrantOnDatabaseStmt(Node *node, const char *queryString,
ProcessUtilityContext processUtilityContext);
List * PreprocessGrantOnDatabaseStmt(Node *node, const char *queryString,
ProcessUtilityContext processUtilityContext);

/* controlled via GUC */
bool EnableCreateDatabasePropagation = true;
Expand All @@ -79,13 +79,14 @@ AlterDatabaseOwnerObjectAddress(Node *node, bool missing_ok, bool isPostprocess)
AlterOwnerStmt *stmt = castNode(AlterOwnerStmt, node);
Assert(stmt->objectType == OBJECT_DATABASE);

Oid databaseOid = get_database_oid(strVal((String *)stmt->object), missing_ok);
Oid databaseOid = get_database_oid(strVal((String *) stmt->object), missing_ok);
ObjectAddress *address = palloc0(sizeof(ObjectAddress));
ObjectAddressSet(*address, DatabaseRelationId, databaseOid);

return list_make1(address);
}


/*
* DatabaseOwnerDDLCommands returns a list of sql statements to idempotently apply a
* change of the database owner on the workers so that the database is owned by the same
Expand All @@ -94,10 +95,11 @@ AlterDatabaseOwnerObjectAddress(Node *node, bool missing_ok, bool isPostprocess)
List *
DatabaseOwnerDDLCommands(const ObjectAddress *address)
{
Node *stmt = (Node *)RecreateAlterDatabaseOwnerStmt(address->objectId);
Node *stmt = (Node *) RecreateAlterDatabaseOwnerStmt(address->objectId);
return list_make1(DeparseTreeNode(stmt));
}


/*
* RecreateAlterDatabaseOwnerStmt creates an AlterOwnerStmt that represents the operation
* of changing the owner of the database to its current owner.
Expand All @@ -108,7 +110,7 @@ RecreateAlterDatabaseOwnerStmt(Oid databaseOid)
AlterOwnerStmt *stmt = makeNode(AlterOwnerStmt);

stmt->objectType = OBJECT_DATABASE;
stmt->object = (Node *)makeString(get_database_name(databaseOid));
stmt->object = (Node *) makeString(get_database_name(databaseOid));

Oid ownerOid = get_database_owner(databaseOid);
stmt->newowner = makeNode(RoleSpec);
Expand All @@ -118,6 +120,7 @@ RecreateAlterDatabaseOwnerStmt(Oid databaseOid)
return stmt;
}


/*
* get_database_owner returns the Oid of the role owning the database
*/
Expand All @@ -131,13 +134,14 @@ get_database_owner(Oid db_oid)
errmsg("database with OID %u does not exist", db_oid)));
}

Oid dba = ((Form_pg_database)GETSTRUCT(tuple))->datdba;
Oid dba = ((Form_pg_database) GETSTRUCT(tuple))->datdba;

ReleaseSysCache(tuple);

return dba;
}


/*
* PreprocessGrantOnDatabaseStmt is executed before the statement is applied to the local
* postgres instance.
Expand Down Expand Up @@ -166,15 +170,16 @@ PreprocessGrantOnDatabaseStmt(Node *node, const char *queryString,

EnsureCoordinator();

char *sql = DeparseTreeNode((Node *)stmt);
char *sql = DeparseTreeNode((Node *) stmt);

List *commands = list_make3(DISABLE_DDL_PROPAGATION,
(void *)sql,
(void *) sql,
ENABLE_DDL_PROPAGATION);

return NodeDDLTaskList(NON_COORDINATOR_NODES, commands);
}


/*
* PreprocessAlterDatabaseStmt is executed before the statement is applied to the local
* postgres instance.
Expand All @@ -195,15 +200,16 @@ PreprocessAlterDatabaseStmt(Node *node, const char *queryString,

EnsureCoordinator();

char *sql = DeparseTreeNode((Node *)stmt);
char *sql = DeparseTreeNode((Node *) stmt);

List *commands = list_make3(DISABLE_DDL_PROPAGATION,
(void *)sql,
(void *) sql,
ENABLE_DDL_PROPAGATION);

return NodeDDLTaskList(NON_COORDINATOR_NODES, commands);
}


#if PG_VERSION_NUM >= PG_VERSION_15

/*
Expand All @@ -226,15 +232,16 @@ PreprocessAlterDatabaseRefreshCollStmt(Node *node, const char *queryString,

EnsureCoordinator();

char *sql = DeparseTreeNode((Node *)stmt);
char *sql = DeparseTreeNode((Node *) stmt);

List *commands = list_make3(DISABLE_DDL_PROPAGATION,
(void *)sql,
(void *) sql,
ENABLE_DDL_PROPAGATION);

return NodeDDLTaskList(NON_COORDINATOR_NODES, commands);
}


#endif

/*
Expand Down Expand Up @@ -320,7 +327,8 @@ PostprocessCreateDatabaseStmt(Node *node, const char *queryString)
*
* We do not do this right now because of the AssignDatabaseToShard at the end.
*/
List *workerNodes = TargetWorkerSetNodeList(NON_COORDINATOR_METADATA_NODES, RowShareLock);
List *workerNodes = TargetWorkerSetNodeList(NON_COORDINATOR_METADATA_NODES,
RowShareLock);
if (list_length(workerNodes) > 0)
{
char *createDatabaseCommand = DeparseTreeNode(node);
Expand All @@ -345,29 +353,30 @@ PostprocessCreateDatabaseStmt(Node *node, const char *queryString)
}

/* synchronize pg_dist_object records */
ObjectAddress dbAddress = {0};
ObjectAddress dbAddress = { 0 };
ObjectAddressSet(dbAddress, DatabaseRelationId, databaseOid);
MarkObjectDistributed(&dbAddress);



return NIL;
}


/*
* citus_internal_database_command is an internal UDF to
* create/drop a database in an idempotent maner without
* transaction block restrictions.
*/
Datum citus_internal_database_command(PG_FUNCTION_ARGS)
Datum
citus_internal_database_command(PG_FUNCTION_ARGS)
{
int saveNestLevel = NewGUCNestLevel();
text *commandText = PG_GETARG_TEXT_P(0);
char *command = text_to_cstring(commandText);
Node *parseTree = ParseTreeNode(command);

ereport(NOTICE, (errmsg("test internal pre"),
errhint("test pre hint")));
errhint("test pre hint")));

set_config_option("citus.enable_ddl_propagation", "off",
(superuser() ? PGC_SUSET : PGC_USERSET), PGC_S_SESSION,
Expand All @@ -386,7 +395,7 @@ Datum citus_internal_database_command(PG_FUNCTION_ARGS)

if (!OidIsValid(databaseOid))
{
createdb(NULL, (CreatedbStmt *)parseTree);
createdb(NULL, (CreatedbStmt *) parseTree);
}
else
{
Expand All @@ -407,18 +416,18 @@ Datum citus_internal_database_command(PG_FUNCTION_ARGS)
else
{
/* remove database from pg_dist_object */
ObjectAddress dbAddress = {0};
ObjectAddress dbAddress = { 0 };
ObjectAddressSet(dbAddress, DatabaseRelationId, databaseOid);

if (IsObjectDistributed(&dbAddress))
{
UnmarkObjectDistributed(&dbAddress);
}

// /* remove database from database shards */
// DeleteDatabaseShardByDatabaseIdLocally(databaseOid);
/* / * remove database from database shards * / */
/* DeleteDatabaseShardByDatabaseIdLocally(databaseOid); */

DropDatabase(NULL, (DropdbStmt *)parseTree);
DropDatabase(NULL, (DropdbStmt *) parseTree);
}
}
else
Expand All @@ -431,6 +440,7 @@ Datum citus_internal_database_command(PG_FUNCTION_ARGS)
PG_RETURN_VOID();
}


List *
PreprocessDropDatabaseStmt(Node *node, const char *queryString,
ProcessUtilityContext processUtilityContext)
Expand All @@ -440,7 +450,7 @@ PreprocessDropDatabaseStmt(Node *node, const char *queryString,
return NIL;
}

DropdbStmt *stmt = (DropdbStmt *)node;
DropdbStmt *stmt = (DropdbStmt *) node;
char *databaseName = stmt->dbname;
bool missingOk = true;
Oid databaseOid = get_database_oid(databaseName, missingOk);
Expand All @@ -450,14 +460,15 @@ PreprocessDropDatabaseStmt(Node *node, const char *queryString,
return NIL;
}

ObjectAddress dbAddress = {0};
ObjectAddress dbAddress = { 0 };
ObjectAddressSet(dbAddress, DatabaseRelationId, databaseOid);
if (!IsObjectDistributed(&dbAddress))
{
return NIL;
}

List *workerNodes = TargetWorkerSetNodeList(NON_COORDINATOR_METADATA_NODES, RowShareLock);
List *workerNodes = TargetWorkerSetNodeList(NON_COORDINATOR_METADATA_NODES,
RowShareLock);
if (list_length(workerNodes) == 0)
{
return NIL;
Expand Down
1 change: 1 addition & 0 deletions src/backend/distributed/commands/distribute_object_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,7 @@ GetDistributeObjectOps(Node *node)
{
return &Database_Alter;
}

case T_CreatedbStmt:
{
return &Database_Create;
Expand Down
2 changes: 1 addition & 1 deletion src/backend/distributed/commands/utility_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ ProcessUtilityInternal(PlannedStmt *pstmt,
}

/* inform the user about potential caveats */
if (IsA(parsetree, CreatedbStmt) &&!EnableCreateDatabasePropagation)
if (IsA(parsetree, CreatedbStmt) && !EnableCreateDatabasePropagation)
{
if (EnableUnsupportedFeatureMessages)
{
Expand Down
Loading

0 comments on commit 90ead5d

Please sign in to comment.