Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds additional alter database propagation support #7253

Merged
merged 316 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
316 commits
Select commit Hold shift + click to select a range
f896238
Adds expected test result
gurkanindibay Oct 12, 2023
4087d19
Fixes review comments
gurkanindibay Oct 12, 2023
e5a6b78
Adds If exists statement for drop database
gurkanindibay Oct 12, 2023
bc0a283
Fixes distributed_object management
gurkanindibay Oct 13, 2023
06050a1
Adds EnableCreateDatabasePropagation check
gurkanindibay Oct 13, 2023
0fdb338
Adds EnableCreateDatabasePropagation for drop db
gurkanindibay Oct 13, 2023
0d5c2f9
Adds first commit
gurkanindibay Sep 22, 2023
39cb797
Fixes additional compile errors
gurkanindibay Sep 23, 2023
bd398a6
Fixes compile errors
gurkanindibay Sep 23, 2023
ca36833
Fix for Pg16 compile error
gurkanindibay Sep 23, 2023
eb1f093
Fixes runtime and compile errors
gurkanindibay Oct 4, 2023
40893e6
Removes unnecessary files
gurkanindibay Oct 4, 2023
1e7c18c
Removes unnecessary code
gurkanindibay Oct 4, 2023
cef9ac7
Fixes indentation
gurkanindibay Oct 4, 2023
3735bef
Fixes sql comments
gurkanindibay Oct 4, 2023
5c50d58
Changes EnableCreateDatabasePropagation to false
gurkanindibay Oct 4, 2023
8c98369
Fixes affected tests
gurkanindibay Oct 4, 2023
a5e0b94
Adds tests for create and drop database
gurkanindibay Oct 4, 2023
25488af
Changes encoding
gurkanindibay Oct 4, 2023
d0bd20c
Fixes tests
gurkanindibay Oct 5, 2023
b01c9ff
Removes unnecessary fileds from selects
gurkanindibay Oct 5, 2023
4c79788
Fixes tablespace error
gurkanindibay Oct 5, 2023
aa47ca8
Fixes tablespace results
gurkanindibay Oct 5, 2023
29093e0
Removes pg15 changes to test unusal failures
gurkanindibay Oct 5, 2023
1461887
Tests error cause
gurkanindibay Oct 5, 2023
c7304ab
Fixes pg15 file
gurkanindibay Oct 5, 2023
acece98
Rollbacks pg_regress_multi
gurkanindibay Oct 5, 2023
5eb8783
Rollbacks last test
gurkanindibay Oct 5, 2023
1d9c02f
Changes schedule location
gurkanindibay Oct 5, 2023
c3d773a
Changes test order
gurkanindibay Oct 5, 2023
51d1560
Adds OID to see the error cause
gurkanindibay Oct 5, 2023
1f57879
Fixes pg_dist_object delete problem
gurkanindibay Oct 6, 2023
94abb07
Fixes indentation
gurkanindibay Oct 6, 2023
6913496
Fixes tests
gurkanindibay Oct 6, 2023
a7112fb
Adds tablespace to test tablespace statement
gurkanindibay Oct 6, 2023
6f36556
Revert "Removes pg15 changes to test unusal failures"
gurkanindibay Oct 6, 2023
214ebc4
Fixes encodings for pg16
gurkanindibay Oct 6, 2023
3050b0e
Fixes pg15 tests
gurkanindibay Oct 6, 2023
576264c
Fixes UTF error
gurkanindibay Oct 6, 2023
031b648
Fixes locale
gurkanindibay Oct 6, 2023
da46878
Fixes Locale
gurkanindibay Oct 6, 2023
ddea1c8
Removes iculocale
gurkanindibay Oct 6, 2023
32d74d9
Fixes collate and ctype
gurkanindibay Oct 6, 2023
d55ecc2
Updates test results
gurkanindibay Oct 6, 2023
7bccf93
Fixes icu locale
gurkanindibay Oct 6, 2023
09d201d
Fixes pg15 output
gurkanindibay Oct 6, 2023
0bf1c2c
Refactors the code to make more managable
gurkanindibay Oct 9, 2023
82358fb
Fixes indentation
gurkanindibay Oct 9, 2023
e7f8058
Removes T_Boolean since it breaks pg14 compile
gurkanindibay Oct 9, 2023
6096a0e
Adds missing types
gurkanindibay Oct 9, 2023
134ec8f
Fixes compile error for PG 14
gurkanindibay Oct 9, 2023
df715a0
Fixes indent
gurkanindibay Oct 9, 2023
d46a839
Fixes compile error
gurkanindibay Oct 9, 2023
d778bb1
Adds PG_VERSION_15 constant
gurkanindibay Oct 9, 2023
480c22a
Fixes the comment
gurkanindibay Oct 9, 2023
d0ef13d
Fixes review comments
gurkanindibay Oct 9, 2023
d88a1e7
Fixes compile error
gurkanindibay Oct 9, 2023
fb6dd41
Fixes PostprocessCreateDatabaseStmt comment
gurkanindibay Oct 9, 2023
7bdeb2f
Fixes indentation
gurkanindibay Oct 9, 2023
f2092d2
Clarifies the code
gurkanindibay Oct 9, 2023
875f347
Fixes indentation
gurkanindibay Oct 9, 2023
8cc6792
Fixes review comments
gurkanindibay Oct 12, 2023
a274ffc
Adds If exists statement for drop database
gurkanindibay Oct 12, 2023
c31479d
Fixes review notes
gurkanindibay Oct 13, 2023
333f77a
Fixes distributed_object management
gurkanindibay Oct 13, 2023
abf9dd9
Adds EnableCreateDatabasePropagation check
gurkanindibay Oct 13, 2023
ca5e234
Adds EnableCreateDatabasePropagation for drop db
gurkanindibay Oct 13, 2023
ef920b0
Fixes compile errors
gurkanindibay Oct 13, 2023
81766e4
Merge branch 'main' into create_alter_database
gurkanindibay Oct 13, 2023
761fb13
Fixes review notes
gurkanindibay Oct 13, 2023
ba31234
Fixes review notes
gurkanindibay Oct 13, 2023
30bbfe4
Fixes review notes
gurkanindibay Oct 13, 2023
3a6fdad
Changes if to switch statements
gurkanindibay Oct 14, 2023
c38e856
Merge branch 'create_alter_database' into alter_database_additional_o…
gurkanindibay Oct 14, 2023
cd4ffd1
Fixes merge errors
gurkanindibay Oct 13, 2023
674fd32
Sets enable_create_database_propagation true
gurkanindibay Oct 14, 2023
c6d1ef9
Rollbacks enable_create_database_propagation
gurkanindibay Oct 14, 2023
a497a78
Fixes review comments
gurkanindibay Oct 14, 2023
1e91b14
Fixed review issues
gurkanindibay Oct 14, 2023
c3a9a37
Merge branch 'create_alter_database' into alter_database_additional_o…
gurkanindibay Oct 16, 2023
7ab86cf
Fixes indentation
gurkanindibay Oct 13, 2023
dad8104
Adds undistribute sql
gurkanindibay Oct 23, 2023
ea0a908
Fixes pg_dist_objects record in coordinators
gurkanindibay Oct 23, 2023
690276c
Fixes indentation
gurkanindibay Oct 23, 2023
c9dae26
tests db as role
gurkanindibay Oct 24, 2023
2d009d4
Fixes worker pg_dist_object removal issue
gurkanindibay Oct 24, 2023
73f0db2
Fixes create and drop database transaction use
gurkanindibay Oct 24, 2023
87f694e
Merge branch 'drop_db_as_role' into create_alter_database
gurkanindibay Oct 24, 2023
e9e64a6
Fixes indentation
gurkanindibay Oct 24, 2023
fb9f75b
Removes unnecessary logs
gurkanindibay Oct 24, 2023
1dcee37
Fixes create_drop_database_test
gurkanindibay Oct 24, 2023
f779947
Removes unnecessary logs
gurkanindibay Oct 24, 2023
b5cbc04
Fixes missing ok issue
gurkanindibay Oct 24, 2023
3a0a5ae
Fixes missin ok issue
gurkanindibay Oct 24, 2023
2f52fbd
Fixes missing ok issue
gurkanindibay Oct 24, 2023
c7b040c
Fixes indentation
gurkanindibay Oct 24, 2023
c5c7705
Merge branch 'main' into create_alter_database
gurkanindibay Oct 24, 2023
c7da2cd
Fixes cannotBeExecutedInTransction
gurkanindibay Oct 24, 2023
48d749e
Fixes message for non-transaction-safe commands
gurkanindibay Oct 24, 2023
c437850
Beatufies error message
gurkanindibay Oct 24, 2023
c8fcf08
Fixes out files for transaction message
gurkanindibay Oct 24, 2023
641e413
Adds metadatasync for create database
gurkanindibay Oct 26, 2023
473f6cb
Fixes metadata sync
gurkanindibay Oct 27, 2023
a797584
Fixes tests
gurkanindibay Oct 27, 2023
72874a8
Merge remote-tracking branch 'origin/main' into create_alter_database
gurkanindibay Oct 27, 2023
569f4db
Fixes pg 14 compile warnings
gurkanindibay Oct 27, 2023
fe26aeb
Fixes useless declarations
gurkanindibay Oct 27, 2023
2a6c40d
Fixes flaky tests
gurkanindibay Oct 27, 2023
8811d91
Fixes pg 14 compile errors
gurkanindibay Oct 27, 2023
b41fead
Fixes indent
gurkanindibay Oct 27, 2023
b28210c
Adds shard selects to debug
gurkanindibay Oct 27, 2023
3cb5cab
Fixes test problem
gurkanindibay Oct 27, 2023
b4dec6e
Fixes test
gurkanindibay Oct 27, 2023
66b4333
Moves pg15 tests to fix errors
gurkanindibay Oct 27, 2023
93dab80
Moves pg15 tests
gurkanindibay Oct 27, 2023
d323ab8
Fixes pg15 sql
gurkanindibay Oct 27, 2023
7368944
Fixes pg15 tests
gurkanindibay Oct 27, 2023
a0da426
Fixes tests
gurkanindibay Oct 27, 2023
8519e7d
Adds a dummy file for pg14
gurkanindibay Oct 27, 2023
6eeeddd
Fixes pg14 tests
gurkanindibay Oct 27, 2023
8c29444
Fixes pg14 tests
gurkanindibay Oct 27, 2023
2b3a556
Fixes pg14 tests
gurkanindibay Oct 27, 2023
cf7efca
Fixes single_node for pg14
gurkanindibay Oct 27, 2023
5381aa8
Fixes flaky tests
gurkanindibay Oct 27, 2023
dcae4c3
Fixes python code format
gurkanindibay Oct 27, 2023
89e2d63
Adds pg15 create drop to minimal tests
gurkanindibay Oct 27, 2023
fe13688
Changes pg15 test files
gurkanindibay Oct 27, 2023
693eeed
Fixes pg15 test name
gurkanindibay Oct 27, 2023
d99737e
Merge branch 'main' into create_alter_database
gurkanindibay Oct 30, 2023
d8639d5
Adds locale restrictions
gurkanindibay Oct 31, 2023
2d9181a
Fixes indents
gurkanindibay Oct 31, 2023
75f1e69
Merge branch 'create_alter_database' into alter_database_additional_o…
gurkanindibay Oct 31, 2023
328e349
Fixes review notes
gurkanindibay Oct 31, 2023
c72f535
Fix PG16 assertion
JelteF Oct 31, 2023
595d078
Merge branch 'main' into create_alter_database
gurkanindibay Nov 1, 2023
65660db
Fixes review items
gurkanindibay Nov 7, 2023
ba377ec
Fixes tests
gurkanindibay Nov 8, 2023
5f8f1d3
Fixes message errors
gurkanindibay Nov 8, 2023
75589d1
Apply suggestions from code review
gurkanindibay Nov 8, 2023
afa6055
Fixes review comments
gurkanindibay Nov 8, 2023
4c9863c
Fixes review comments
gurkanindibay Nov 8, 2023
32c6796
Merge branch 'main' into create_alter_database
gurkanindibay Nov 9, 2023
5f4092d
Adds validation for template
gurkanindibay Nov 9, 2023
3ab91c9
Fixes review comments
gurkanindibay Nov 10, 2023
b45543f
Merge remote-tracking branch 'origin/create_alter_database' into alte…
gurkanindibay Nov 10, 2023
b5424db
Fixes compilation errors
gurkanindibay Nov 10, 2023
e31ca6e
Merge remote-tracking branch 'origin/create_alter_database' into alte…
gurkanindibay Nov 10, 2023
2ebeea3
Fixes compilation warnings
gurkanindibay Nov 10, 2023
1b9a8ea
Fixes indentation
gurkanindibay Nov 10, 2023
7a6afb0
Fixes review comments
gurkanindibay Nov 10, 2023
0a73cb3
Merge branch 'main' into create_alter_database
gurkanindibay Nov 10, 2023
8df30a2
Fixes EnsureCitusInitiatedOperation name change
gurkanindibay Nov 10, 2023
3067d1e
Apply suggestions from code review
gurkanindibay Nov 10, 2023
f8b3f32
Fixed review items
gurkanindibay Nov 10, 2023
fe24227
Improve tests for PG <= 14
onurctirtir Nov 10, 2023
5b446b1
make tests passing
onurctirtir Nov 13, 2023
30e1a85
Removes oid support
gurkanindibay Nov 13, 2023
974e628
Merge branch 'create_alter_database' of https://github.com/citusdata/…
gurkanindibay Nov 13, 2023
2ca6e2c
indent
onurctirtir Nov 13, 2023
f5a3f4d
Merge remote-tracking branch 'origin/create_alter_database' into crea…
onurctirtir Nov 13, 2023
a35cae0
Fixes review issues
gurkanindibay Nov 13, 2023
6921767
allow wal_log option only if it's set to default
onurctirtir Nov 13, 2023
ffa1fa0
Improve tests for >= pg15 & pg >= 16
onurctirtir Nov 13, 2023
1a80181
indent
onurctirtir Nov 13, 2023
3731c45
Fixes drop force option
gurkanindibay Nov 13, 2023
712fd8e
Fixes comments
gurkanindibay Nov 13, 2023
8728871
Apply suggestions from code review
gurkanindibay Nov 13, 2023
52c9e92
Adds IsAnyObjectDistributed check for db
gurkanindibay Nov 13, 2023
a9977e8
Moves validation to preprocess for createdb
gurkanindibay Nov 13, 2023
fcdea98
Removes drop in citus_internal_db_command udf
gurkanindibay Nov 13, 2023
b5388dd
Adds icu_rules in meta_data sync
gurkanindibay Nov 13, 2023
7e15939
Update src/backend/distributed/commands/database.c
gurkanindibay Nov 13, 2023
c1dce6f
commit
onurctirtir Nov 13, 2023
05d8d44
Merge branch 'create_alter_database' of https://github.com/citusdata/…
gurkanindibay Nov 13, 2023
32df331
Update src/backend/distributed/metadata/metadata_sync.c
gurkanindibay Nov 13, 2023
a956786
Update src/backend/distributed/deparser/deparse_database_stmts.c
gurkanindibay Nov 13, 2023
1e044a2
Update src/backend/distributed/deparser/deparse_database_stmts.c
gurkanindibay Nov 13, 2023
7780101
Update src/backend/distributed/commands/database.c
gurkanindibay Nov 13, 2023
c1e9335
Adds distributed check in metadata syncing
gurkanindibay Nov 14, 2023
cf019b8
Adds static declarations
gurkanindibay Nov 14, 2023
9a558bd
Adds datacl propagation
gurkanindibay Nov 15, 2023
eb46d93
Fixes warning on compile
gurkanindibay Nov 15, 2023
6f838e6
Fixes indentation
gurkanindibay Nov 15, 2023
931514b
Fixes indentation
gurkanindibay Nov 15, 2023
bb76a9b
Merge branch 'main' into create_alter_database
gurkanindibay Nov 15, 2023
37681ea
Fixes comment on code
gurkanindibay Nov 15, 2023
7939267
Fixes flakiness of test
gurkanindibay Nov 15, 2023
deee8e5
Adds grant to public
gurkanindibay Nov 15, 2023
dc48833
Adds tests for non-distributed database
gurkanindibay Nov 15, 2023
0f1273f
Updates test output
gurkanindibay Nov 15, 2023
11e7c94
Removes extra line in test
gurkanindibay Nov 15, 2023
144ede3
Adds GUC check for db grant sync
gurkanindibay Nov 15, 2023
e18c440
Removes unnecessary logs
gurkanindibay Nov 15, 2023
cd40380
resets enable_create_database_propagation
gurkanindibay Nov 15, 2023
9b6511a
Fixes indentation
gurkanindibay Nov 15, 2023
feb6098
Fixes flag name
gurkanindibay Nov 15, 2023
772a13d
Removes SendDatabaseGrantSyncCommands
gurkanindibay Nov 15, 2023
a685873
Fixes indentation
gurkanindibay Nov 15, 2023
bb2b7ae
Adds logs for test
gurkanindibay Nov 15, 2023
b474d98
Removes log
gurkanindibay Nov 15, 2023
95572c5
Adds EnableCreateDatabasePropagation flag check
gurkanindibay Nov 15, 2023
8443ae3
Fixes indentation
gurkanindibay Nov 15, 2023
ed9021c
Merge branch 'main' of https://github.com/citusdata/citus into create…
gurkanindibay Nov 16, 2023
56bc813
Adds check_database_on_all_nodes
gurkanindibay Nov 16, 2023
a6e1625
Removes extra line
gurkanindibay Nov 16, 2023
ef2a47e
Fixes function after merge
gurkanindibay Nov 16, 2023
a948358
Fixes multi_test_helpers
gurkanindibay Nov 16, 2023
e56a113
Adds missing line
gurkanindibay Nov 16, 2023
1cdae74
Fixes review notes
gurkanindibay Nov 16, 2023
c63f124
Fixes indentation
gurkanindibay Nov 16, 2023
58bb165
Removes unnecessary comments
gurkanindibay Nov 16, 2023
3a6bf7e
Merge branch 'main' into create_alter_database
gurkanindibay Nov 17, 2023
da72cd3
Fixes quotes for db columns
gurkanindibay Nov 16, 2023
73db50d
Removes database rename for each node
gurkanindibay Nov 19, 2023
c123fc3
Fixes indentation
gurkanindibay Nov 19, 2023
022b626
Merge branch 'main' into create_alter_database
gurkanindibay Nov 20, 2023
7794aab
Merge branch 'create_alter_database' into alter_database_additional_o…
gurkanindibay Nov 20, 2023
2207846
Fixes warning
gurkanindibay Nov 19, 2023
dc93ca8
Update src/backend/distributed/commands/database.c
gurkanindibay Nov 21, 2023
a1ab60f
Merge branch 'main' into alter_database_additional_options
gurkanindibay Nov 20, 2023
3dd4735
Fixes runtime errors
gurkanindibay Nov 21, 2023
d528ec2
Fixes merge errors
gurkanindibay Nov 21, 2023
752c2ee
Fixes indentation
gurkanindibay Nov 21, 2023
a747699
Removes duplicated includes
gurkanindibay Nov 21, 2023
ed3ebf2
Removes unnecessary comment change
gurkanindibay Nov 21, 2023
9d7e601
Fixes review notes
gurkanindibay Nov 21, 2023
5f263c1
Fixes review notes
gurkanindibay Nov 21, 2023
5aae80f
Fixes review notes
gurkanindibay Nov 21, 2023
49b1f9a
Fixes create_drop_propagation test error
gurkanindibay Nov 21, 2023
63e3738
Fixes pre review check results
gurkanindibay Nov 22, 2023
1900c8e
Fixes codecov issue
gurkanindibay Nov 22, 2023
cd8e4e6
Fixes indentation
gurkanindibay Nov 22, 2023
455620c
Details coment for AppendBasicAlterDatabaseOptions
gurkanindibay Nov 22, 2023
9301531
Apply suggestions from code review
gurkanindibay Nov 27, 2023
0c25b72
Fixes review notes
gurkanindibay Nov 27, 2023
0526033
Apply suggestions from code review
gurkanindibay Nov 27, 2023
2fd191a
Merge branch 'alter_database_additional_options' of https://github.co…
gurkanindibay Nov 27, 2023
2608d94
Fixes review comments
gurkanindibay Nov 27, 2023
2e00d37
Fixes review comments
gurkanindibay Nov 27, 2023
81de9bb
Merge branch 'main' into alter_database_additional_options
gurkanindibay Nov 27, 2023
c750388
Merge branch 'alter_database_additional_options' of https://github.co…
gurkanindibay Nov 27, 2023
ab19f4a
Fixes multiple includes
gurkanindibay Nov 27, 2023
18a8783
Removes empty lines from sql
gurkanindibay Nov 27, 2023
dd41c72
Adds distributed check for rename and alter db
gurkanindibay Nov 28, 2023
5971549
Fixes review comments
gurkanindibay Dec 17, 2023
ea7c5f2
Merge branch 'main' into alter_database_additional_options
gurkanindibay Dec 20, 2023
775c78c
Fixes comments
gurkanindibay Dec 17, 2023
09a7a33
Fixes review comments
gurkanindibay Dec 25, 2023
ce32be6
Merge branch 'main' into alter_database_additional_options
gurkanindibay Dec 26, 2023
0975f7b
Fixed review notes
gurkanindibay Dec 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 70 additions & 5 deletions src/backend/distributed/commands/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,25 @@ PreprocessGrantOnDatabaseStmt(Node *node, const char *queryString,
}


/*
* IsSetTablespaceStatement returns true if the statement is a SET TABLESPACE statement,
* false otherwise.
*/
static bool
IsSetTablespaceStatement(AlterDatabaseStmt *stmt)
{
DefElem *def = NULL;
foreach_ptr(def, stmt->options)
{
if (strcmp(def->defname, "tablespace") == 0)
{
return true;
}
}
return false;
}


/*
* PreprocessAlterDatabaseStmt is executed before the statement is applied to the local
* postgres instance.
Expand All @@ -203,22 +222,38 @@ List *
PreprocessAlterDatabaseStmt(Node *node, const char *queryString,
ProcessUtilityContext processUtilityContext)
{
if (!ShouldPropagate())
bool missingOk = false;
AlterDatabaseStmt *stmt = castNode(AlterDatabaseStmt, node);
ObjectAddress *dbAddress = GetDatabaseAddressFromDatabaseName(stmt->dbname,
missingOk);

if (!ShouldPropagate() || !IsAnyObjectDistributed(list_make1(dbAddress)))
{
return NIL;
}

onurctirtir marked this conversation as resolved.
Show resolved Hide resolved
AlterDatabaseStmt *stmt = castNode(AlterDatabaseStmt, node);

EnsureCoordinator();
onurctirtir marked this conversation as resolved.
Show resolved Hide resolved

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

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

return NodeDDLTaskList(NON_COORDINATOR_NODES, commands);
if (IsSetTablespaceStatement(stmt))
{
/*
* Set tablespace does not work inside a transaction.Therefore, we need to use
* NontransactionalNodeDDLTask to run the command on the workers outside
* the transaction block.
*/

return NontransactionalNodeDDLTaskList(NON_COORDINATOR_NODES, commands);
}
else
{
return NodeDDLTaskList(NON_COORDINATOR_NODES, commands);
}
}


Expand Down Expand Up @@ -256,6 +291,36 @@ PreprocessAlterDatabaseRefreshCollStmt(Node *node, const char *queryString,

#endif

/*
* PreprocessAlterDatabaseRenameStmt is executed before the statement is applied to the local
* postgres instance. In this stage we prepare ALTER DATABASE RENAME statement to be run on
* all workers.
*/
List *
PostprocessAlterDatabaseRenameStmt(Node *node, const char *queryString)
{
bool missingOk = false;
RenameStmt *stmt = castNode(RenameStmt, node);
ObjectAddress *dbAddress = GetDatabaseAddressFromDatabaseName(stmt->newname,
missingOk);

if (!ShouldPropagate() || !IsAnyObjectDistributed(list_make1(dbAddress)))
{
return NIL;
}

EnsureCoordinator();
onurctirtir marked this conversation as resolved.
Show resolved Hide resolved
onurctirtir marked this conversation as resolved.
Show resolved Hide resolved

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

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

return NodeDDLTaskList(NON_COORDINATOR_NODES, commands);
}


/*
* PreprocessAlterDatabaseSetStmt is executed before the statement is applied to the local
* postgres instance.
Expand Down
15 changes: 15 additions & 0 deletions src/backend/distributed/commands/distribute_object_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,16 @@ static DistributeObjectOps Database_Set = {
.markDistributed = false,
};

static DistributeObjectOps Database_Rename = {
.deparse = DeparseAlterDatabaseRenameStmt,
.qualify = NULL,
.preprocess = NULL,
.postprocess = PostprocessAlterDatabaseRenameStmt,
.objectType = OBJECT_DATABASE,
.operationType = DIST_OPS_ALTER,
.address = NULL,
.markDistributed = false,
};

static DistributeObjectOps Domain_Alter = {
.deparse = DeparseAlterDomainStmt,
Expand Down Expand Up @@ -2087,6 +2097,11 @@ GetDistributeObjectOps(Node *node)
return &Collation_Rename;
}

case OBJECT_DATABASE:
{
return &Database_Rename;
}

case OBJECT_DOMAIN:
{
return &Domain_Rename;
Expand Down
113 changes: 77 additions & 36 deletions src/backend/distributed/deparser/deparse_database_stmts.c
onurctirtir marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
static void AppendAlterDatabaseOwnerStmt(StringInfo buf, AlterOwnerStmt *stmt);
static void AppendAlterDatabaseSetStmt(StringInfo buf, AlterDatabaseSetStmt *stmt);
static void AppendAlterDatabaseStmt(StringInfo buf, AlterDatabaseStmt *stmt);
static void AppendDefElemConnLimit(StringInfo buf, DefElem *def);
static void AppendCreateDatabaseStmt(StringInfo buf, CreatedbStmt *stmt);
static void AppendDropDatabaseStmt(StringInfo buf, DropdbStmt *stmt);
static void AppendGrantOnDatabaseStmt(StringInfo buf, GrantStmt *stmt);
static void AppendBasicAlterDatabaseOptions(StringInfo buf, AlterDatabaseStmt *stmt);
static void AppendGrantDatabases(StringInfo buf, GrantStmt *stmt);
static void AppendAlterDatabaseSetTablespace(StringInfo buf, DefElem *def, char *dbname);

const DefElemOptionFormat create_database_option_formats[] = {
const DefElemOptionFormat createDatabaseOptionFormats[] = {
{ "owner", " OWNER %s", OPTION_FORMAT_STRING },
{ "template", " TEMPLATE %s", OPTION_FORMAT_STRING },
{ "encoding", " ENCODING %s", OPTION_FORMAT_LITERAL_CSTR },
Expand All @@ -53,6 +55,14 @@
{ "is_template", " IS_TEMPLATE %s", OPTION_FORMAT_BOOLEAN }
};


const DefElemOptionFormat alterDatabaseOptionFormats[] = {
onurctirtir marked this conversation as resolved.
Show resolved Hide resolved
{ "is_template", " IS_TEMPLATE %s", OPTION_FORMAT_BOOLEAN },
{ "allow_connections", " ALLOW_CONNECTIONS %s", OPTION_FORMAT_BOOLEAN },
{ "connection_limit", " CONNECTION LIMIT %d", OPTION_FORMAT_INTEGER },
};


char *
DeparseAlterDatabaseOwnerStmt(Node *node)
{
Expand Down Expand Up @@ -111,52 +121,67 @@
}


static void
AppendDefElemConnLimit(StringInfo buf, DefElem *def)
{
appendStringInfo(buf, " CONNECTION LIMIT %ld", (long int) defGetNumeric(def));
}


static void
AppendAlterDatabaseStmt(StringInfo buf, AlterDatabaseStmt *stmt)
{
appendStringInfo(buf, "ALTER DATABASE %s ", quote_identifier(stmt->dbname));
if (list_length(stmt->options) == 0)
{
elog(ERROR, "got unexpected number of options for ALTER DATABASE");

Check warning on line 129 in src/backend/distributed/deparser/deparse_database_stmts.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/deparser/deparse_database_stmts.c#L129

Added line #L129 was not covered by tests
}

if (stmt->options)
{
ListCell *cell = NULL;
appendStringInfo(buf, "WITH ");
foreach(cell, stmt->options)
DefElem *firstOption = linitial(stmt->options);
if (strcmp(firstOption->defname, "tablespace") == 0)
{
DefElem *def = castNode(DefElem, lfirst(cell));
if (strcmp(def->defname, "is_template") == 0)
{
appendStringInfo(buf, "IS_TEMPLATE %s",
quote_literal_cstr(strVal(def->arg)));
}
else if (strcmp(def->defname, "connection_limit") == 0)
{
AppendDefElemConnLimit(buf, def);
}
else if (strcmp(def->defname, "allow_connections") == 0)
{
ereport(ERROR,
errmsg("ALLOW_CONNECTIONS is not supported"));
}
else
{
ereport(ERROR,
errmsg("unrecognized ALTER DATABASE option: %s",
def->defname));
}
AppendAlterDatabaseSetTablespace(buf, firstOption, stmt->dbname);

/* SET tablespace cannot be combined with other options */
return;
}


appendStringInfo(buf, "ALTER DATABASE %s WITH",
quote_identifier(stmt->dbname));

AppendBasicAlterDatabaseOptions(buf, stmt);
}

appendStringInfo(buf, ";");
}


static void
AppendAlterDatabaseSetTablespace(StringInfo buf, DefElem *def, char *dbname)
{
appendStringInfo(buf,
"ALTER DATABASE %s SET TABLESPACE %s",
quote_identifier(dbname), quote_identifier(defGetString(def)));
}


/*
* AppendBasicAlterDatabaseOptions appends basic ALTER DATABASE options to a string buffer.
* Basic options are those that can be appended to the ALTER DATABASE statement
* after the "WITH" keyword.(i.e. ALLOW_CONNECTIONS, CONNECTION LIMIT, IS_TEMPLATE)
* For example, the tablespace option is not a basic option since it is defined via SET keyword.
*
* This function takes a string buffer and an AlterDatabaseStmt as input.
* It appends the basic options to the string buffer.
*
*/
static void
AppendBasicAlterDatabaseOptions(StringInfo buf, AlterDatabaseStmt *stmt)
onurctirtir marked this conversation as resolved.
Show resolved Hide resolved
{
DefElem *def = NULL;
foreach_ptr(def, stmt->options)
{
DefElemOptionToStatement(buf, def, alterDatabaseOptionFormats, lengthof(
alterDatabaseOptionFormats));
}
}


char *
DeparseGrantOnDatabaseStmt(Node *node)
{
Expand Down Expand Up @@ -216,6 +241,22 @@
}


char *
DeparseAlterDatabaseRenameStmt(Node *node)
{
RenameStmt *stmt = (RenameStmt *) node;

StringInfoData str;
initStringInfo(&str);

appendStringInfo(&str, "ALTER DATABASE %s RENAME TO %s",
quote_identifier(stmt->subname),
quote_identifier(stmt->newname));

return str.data;
}


char *
DeparseAlterDatabaseSetStmt(Node *node)
{
Expand Down Expand Up @@ -246,8 +287,8 @@
DefElem *option = NULL;
foreach_ptr(option, stmt->options)
{
DefElemOptionToStatement(buf, option, create_database_option_formats,
lengthof(create_database_option_formats));
DefElemOptionToStatement(buf, option, createDatabaseOptionFormats,
lengthof(createDatabaseOptionFormats));
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/include/distributed/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ extern List * DropDatabaseStmtObjectAddress(Node *node, bool missingOk,
bool isPostprocess);
extern List * CreateDatabaseStmtObjectAddress(Node *node, bool missingOk,
bool isPostprocess);
extern List * GenerateGrantDatabaseCommandList(void);
extern List * PostprocessAlterDatabaseRenameStmt(Node *node, const char *queryString);
extern void EnsureSupportedCreateDatabaseCommand(CreatedbStmt *stmt);
extern char * CreateDatabaseDDLCommand(Oid dbId);

Expand Down
1 change: 1 addition & 0 deletions src/include/distributed/deparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ extern char * DeparseAlterDatabaseRefreshCollStmt(Node *node);
extern char * DeparseAlterDatabaseSetStmt(Node *node);
extern char * DeparseCreateDatabaseStmt(Node *node);
extern char * DeparseDropDatabaseStmt(Node *node);
extern char * DeparseAlterDatabaseRenameStmt(Node *node);


/* forward declaration for deparse_publication_stmts.c */
Expand Down
Loading