Skip to content

Commit

Permalink
Merge branch 'main', remote-tracking branch 'origin' into circleci-gh…
Browse files Browse the repository at this point in the history
…a-migration
  • Loading branch information
gokhangulbiz committed Aug 28, 2023
3 parents b46ac3f + d5d1684 + 291924f commit c272bb5
Show file tree
Hide file tree
Showing 32 changed files with 2,336 additions and 596 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/packaging-test-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:

workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

get_postgres_versions_from_file:
Expand Down Expand Up @@ -119,7 +123,6 @@ jobs:
- debian-buster-all
- debian-bookworm-all
- debian-bullseye-all
- ubuntu-bionic-all
- ubuntu-focal-all
- ubuntu-jammy-all
- ubuntu-kinetic-all
Expand Down
16 changes: 4 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ endif

include Makefile.global

all: extension pg_send_cancellation
all: extension


# build columnar only
Expand Down Expand Up @@ -40,22 +40,14 @@ clean-full:

install-downgrades:
$(MAKE) -C src/backend/distributed/ install-downgrades
install-all: install-headers install-pg_send_cancellation
install-all: install-headers
$(MAKE) -C src/backend/columnar/ install-all
$(MAKE) -C src/backend/distributed/ install-all

# build citus_send_cancellation binary
pg_send_cancellation:
$(MAKE) -C src/bin/pg_send_cancellation/ all
install-pg_send_cancellation: pg_send_cancellation
$(MAKE) -C src/bin/pg_send_cancellation/ install
clean-pg_send_cancellation:
$(MAKE) -C src/bin/pg_send_cancellation/ clean
.PHONY: pg_send_cancellation install-pg_send_cancellation clean-pg_send_cancellation

# Add to generic targets
install: install-extension install-headers install-pg_send_cancellation
clean: clean-extension clean-pg_send_cancellation
install: install-extension install-headers
clean: clean-extension

# apply or check style
reindent:
Expand Down
40 changes: 40 additions & 0 deletions src/backend/distributed/commands/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

static AlterOwnerStmt * RecreateAlterDatabaseOwnerStmt(Oid databaseOid);
static Oid get_database_owner(Oid db_oid);
List * PreprocessGrantOnDatabaseStmt(Node *node, const char *queryString,
ProcessUtilityContext processUtilityContext);

/* controlled via GUC */
bool EnableAlterDatabaseOwner = true;
Expand Down Expand Up @@ -107,3 +109,41 @@ get_database_owner(Oid db_oid)

return dba;
}


/*
* PreprocessGrantOnDatabaseStmt is executed before the statement is applied to the local
* postgres instance.
*
* In this stage we can prepare the commands that need to be run on all workers to grant
* on databases.
*/
List *
PreprocessGrantOnDatabaseStmt(Node *node, const char *queryString,
ProcessUtilityContext processUtilityContext)
{
if (!ShouldPropagate())
{
return NIL;
}

GrantStmt *stmt = castNode(GrantStmt, node);
Assert(stmt->objtype == OBJECT_DATABASE);

List *databaseList = stmt->objects;

if (list_length(databaseList) == 0)
{
return NIL;
}

EnsureCoordinator();

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

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

return NodeDDLTaskList(NON_COORDINATOR_NODES, commands);
}
17 changes: 17 additions & 0 deletions src/backend/distributed/commands/distribute_object_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,18 @@ static DistributeObjectOps Database_AlterOwner = {
.address = AlterDatabaseOwnerObjectAddress,
.markDistributed = false,
};

static DistributeObjectOps Database_Grant = {
.deparse = DeparseGrantOnDatabaseStmt,
.qualify = NULL,
.preprocess = PreprocessGrantOnDatabaseStmt,
.postprocess = NULL,
.objectType = OBJECT_DATABASE,
.operationType = DIST_OPS_ALTER,
.address = NULL,
.markDistributed = false,
};

static DistributeObjectOps Domain_Alter = {
.deparse = DeparseAlterDomainStmt,
.qualify = QualifyAlterDomainStmt,
Expand Down Expand Up @@ -1911,6 +1923,11 @@ GetDistributeObjectOps(Node *node)
return &Routine_Grant;
}

case OBJECT_DATABASE:
{
return &Database_Grant;
}

default:
{
return &Any_Grant;
Expand Down
3 changes: 2 additions & 1 deletion src/backend/distributed/commands/multi_copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ EnsureCopyCanRunOnRelation(Oid relationId)
*/
if (RecoveryInProgress() && WritableStandbyCoordinator)
{
ereport(ERROR, (errmsg("COPY command to Citus tables is not allowed in "
ereport(ERROR, (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
errmsg("COPY command to Citus tables is not allowed in "
"read-only mode"),
errhint("All COPY commands to citus tables happen via 2PC, "
"and 2PC requires the database to be in a writable state."),
Expand Down
8 changes: 8 additions & 0 deletions src/backend/distributed/commands/statistics.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ PreprocessCreateStatisticsStmt(Node *node, const char *queryString,

EnsureCoordinator();

if (!(stmt->defnames))
{
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot create statistics without a name on a "
"Citus table"),
errhint("Consider specifying a name for the statistics")));
}

QualifyTreeNode((Node *) stmt);

Oid statsOid = get_statistics_object_oid(stmt->defnames, true);
Expand Down
76 changes: 76 additions & 0 deletions src/backend/distributed/deparser/deparse_database_stmts.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,79 @@ AppendAlterDatabaseOwnerStmt(StringInfo buf, AlterOwnerStmt *stmt)
quote_identifier(strVal((String *) stmt->object)),
RoleSpecString(stmt->newowner, true));
}


static void
AppendGrantDatabases(StringInfo buf, GrantStmt *stmt)
{
ListCell *cell = NULL;
appendStringInfo(buf, " ON DATABASE ");

foreach(cell, stmt->objects)
{
char *database = strVal(lfirst(cell));
appendStringInfoString(buf, quote_identifier(database));
if (cell != list_tail(stmt->objects))
{
appendStringInfo(buf, ", ");
}
}
}


static void
AppendGrantOnDatabaseStmt(StringInfo buf, GrantStmt *stmt)
{
Assert(stmt->objtype == OBJECT_DATABASE);

appendStringInfo(buf, "%s ", stmt->is_grant ? "GRANT" : "REVOKE");

if (!stmt->is_grant && stmt->grant_option)
{
appendStringInfo(buf, "GRANT OPTION FOR ");
}

AppendGrantPrivileges(buf, stmt);

AppendGrantDatabases(buf, stmt);

AppendGrantGrantees(buf, stmt);

if (stmt->is_grant && stmt->grant_option)
{
appendStringInfo(buf, " WITH GRANT OPTION");
}
if (!stmt->is_grant)
{
if (stmt->behavior == DROP_RESTRICT)
{
appendStringInfo(buf, " RESTRICT");
}
else if (stmt->behavior == DROP_CASCADE)
{
appendStringInfo(buf, " CASCADE");
}
}

if (stmt->grantor)
{
appendStringInfo(buf, " GRANTED BY %s", RoleSpecString(stmt->grantor, true));
}

appendStringInfo(buf, ";");
}


char *
DeparseGrantOnDatabaseStmt(Node *node)
{
GrantStmt *stmt = castNode(GrantStmt, node);
Assert(stmt->objtype == OBJECT_DATABASE);

StringInfoData str = { 0 };
initStringInfo(&str);

AppendGrantOnDatabaseStmt(&str, stmt);

return str.data;
}
6 changes: 4 additions & 2 deletions src/backend/distributed/metadata/metadata_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ EnsureModificationsCanRun(void)
{
if (RecoveryInProgress() && !WritableStandbyCoordinator)
{
ereport(ERROR, (errmsg("writing to worker nodes is not currently allowed"),
ereport(ERROR, (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
errmsg("writing to worker nodes is not currently allowed"),
errdetail("the database is read-only")));
}

Expand Down Expand Up @@ -415,7 +416,8 @@ EnsureModificationsCanRunOnRelation(Oid relationId)

if (modifiedTableReplicated)
{
ereport(ERROR, (errmsg("writing to worker nodes is not currently "
ereport(ERROR, (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
errmsg("writing to worker nodes is not currently "
"allowed for replicated tables such as reference "
"tables or hash distributed tables with replication "
"factor greater than 1."),
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions src/backend/distributed/planner/multi_explain.c
Original file line number Diff line number Diff line change
Expand Up @@ -992,12 +992,18 @@ BuildRemoteExplainQuery(char *queryString, ExplainState *es)
appendStringInfo(explainQuery,
"EXPLAIN (ANALYZE %s, VERBOSE %s, "
"COSTS %s, BUFFERS %s, WAL %s, "
#if PG_VERSION_NUM >= PG_VERSION_16
"GENERIC_PLAN %s, "
#endif
"TIMING %s, SUMMARY %s, FORMAT %s) %s",
es->analyze ? "TRUE" : "FALSE",
es->verbose ? "TRUE" : "FALSE",
es->costs ? "TRUE" : "FALSE",
es->buffers ? "TRUE" : "FALSE",
es->wal ? "TRUE" : "FALSE",
#if PG_VERSION_NUM >= PG_VERSION_16
es->generic ? "TRUE" : "FALSE",
#endif
es->timing ? "TRUE" : "FALSE",
es->summary ? "TRUE" : "FALSE",
formatStr,
Expand Down
70 changes: 0 additions & 70 deletions src/backend/distributed/test/pg_send_cancellation.c

This file was deleted.

1 change: 0 additions & 1 deletion src/bin/pg_send_cancellation/.gitignore

This file was deleted.

24 changes: 0 additions & 24 deletions src/bin/pg_send_cancellation/Makefile

This file was deleted.

Loading

0 comments on commit c272bb5

Please sign in to comment.