diff --git a/src/backend/distributed/deparser/citus_ruleutils.c b/src/backend/distributed/deparser/citus_ruleutils.c index 70bacd204..86584245b 100644 --- a/src/backend/distributed/deparser/citus_ruleutils.c +++ b/src/backend/distributed/deparser/citus_ruleutils.c @@ -78,6 +78,7 @@ static void AppendStorageParametersToString(StringInfo stringBuffer, List *optionList); static void simple_quote_literal(StringInfo buf, const char *val); static char * flatten_reloptions(Oid relid); +static void AddVacuumParams(ReindexStmt *reindexStmt, StringInfo buffer); /* @@ -755,11 +756,7 @@ deparse_shard_reindex_statement(ReindexStmt *origStmt, Oid distrelid, int64 shar } appendStringInfoString(buffer, "REINDEX "); - - if (IsReindexWithParam_compat(reindexStmt, "verbose")) - { - appendStringInfoString(buffer, "(VERBOSE) "); - } + AddVacuumParams(reindexStmt, buffer); switch (reindexStmt->kind) { @@ -829,6 +826,49 @@ bool IsReindexWithParam_compat(ReindexStmt* reindexStmt, char* param) { } +/* + * AddVacuumParams adds vacuum params to the given buffer. + */ +static void +AddVacuumParams(ReindexStmt *reindexStmt, StringInfo buffer) +{ + StringInfo temp = makeStringInfo(); + if (IsReindexWithParam_compat(reindexStmt, "verbose")) + { + appendStringInfoString(temp, "VERBOSE"); + } +#if PG_VERSION_NUM >= PG_VERSION_14 + char *tableSpaceName = NULL; + DefElem *opt = NULL; + foreach_ptr(opt, reindexStmt->params) + { + if (strcmp(opt->defname, "tablespace") == 0) + { + tableSpaceName = defGetString(opt); + break; + } + } + + if (tableSpaceName) + { + if (temp->len > 0) + { + appendStringInfo(temp, ", TABLESPACE %s", tableSpaceName); + } + else + { + appendStringInfo(temp, "TABLESPACE %s", tableSpaceName); + } + } +#endif + + if (temp->len > 0) + { + appendStringInfo(buffer, "(%s) ", temp->data); + } +} + + /* deparse_index_columns appends index or include parameters to the provided buffer */ static void deparse_index_columns(StringInfo buffer, List *indexParameterList, List *deparseContext) diff --git a/src/test/regress/Makefile b/src/test/regress/Makefile index 39f82df62..670ca4d79 100644 --- a/src/test/regress/Makefile +++ b/src/test/regress/Makefile @@ -52,12 +52,19 @@ ISOLATION_BUILDDIR=build/specs # ex: make print-generated_isolation_files print-% : ; @echo $* = $($*) -.PHONY: create-symbolic-link +.PHONY: create-symbolic-link create-tablespaces create-symbolic-link: mkdir -p $(citus_abs_srcdir)/build ln -fsn $(citus_abs_srcdir)/expected $(citus_abs_srcdir)/build/ +create-tablespaces: + rm -rf $(citus_abs_srcdir)/tmp_check/ts1 + mkdir -p $(citus_abs_srcdir)/tmp_check/ts1 + rm -rf $(citus_abs_srcdir)/tmp_check/ts0 + mkdir -p $(citus_abs_srcdir)/tmp_check/ts0 + rm -rf $(citus_abs_srcdir)/tmp_check/ts2 + mkdir -p $(citus_abs_srcdir)/tmp_check/ts2 # How this target works: # cpp is used before running isolation tests to preprocess spec files. @@ -106,7 +113,7 @@ check-base: all -- $(MULTI_REGRESS_OPTS) --schedule=$(citus_abs_srcdir)/base_schedule $(EXTRA_TESTS) # check-minimal only sets up the cluster -check-minimal: all +check-minimal: all create-tablespaces $(pg_regress_multi_check) --load-extension=citus \ -- $(MULTI_REGRESS_OPTS) --schedule=$(citus_abs_srcdir)/minimal_schedule $(EXTRA_TESTS) @@ -235,3 +242,5 @@ clean-upgrade-artifacts: clean distclean maintainer-clean: rm -f $(output_files) $(input_files) rm -rf tmp_check/ + +all: create-tablespaces \ No newline at end of file diff --git a/src/test/regress/base_schedule b/src/test/regress/base_schedule index 34e770b5a..e3ea4de24 100644 --- a/src/test/regress/base_schedule +++ b/src/test/regress/base_schedule @@ -6,4 +6,4 @@ test: multi_test_helpers multi_test_helpers_superuser multi_create_fdw columnar_ test: multi_test_catalog_views test: multi_create_table multi_behavioral_analytics_create_table test: multi_create_table_superuser multi_behavioral_analytics_create_table_superuser -test: multi_load_data multi_load_data_superuser +test: multi_load_data multi_load_data_superuser tablespace diff --git a/src/test/regress/bin/normalize.sed b/src/test/regress/bin/normalize.sed index ae4b63ac7..468d81810 100644 --- a/src/test/regress/bin/normalize.sed +++ b/src/test/regress/bin/normalize.sed @@ -241,3 +241,6 @@ s/ERROR: ROLLBACK is not allowed in an SQL function/ERROR: ROLLBACK is not all /Parent-Relationship/d s/function array_cat_agg\(anycompatiblearray\)/function array_cat_agg\(anyarray\)/g s/TRIM\(BOTH FROM value\)/btrim\(value\)/g +s/pg14\.idx.*/pg14\.xxxxx/g + +s/CREATE TABLESPACE test_tablespace LOCATION.*/CREATE TABLESPACE test_tablespace LOCATION XXXX/g diff --git a/src/test/regress/expected/pg14.out b/src/test/regress/expected/pg14.out index 35b3a5676..6e42f4fbc 100644 --- a/src/test/regress/expected/pg14.out +++ b/src/test/regress/expected/pg14.out @@ -5,3 +5,125 @@ SELECT substring(:'server_version', '\d+')::int > 13 AS server_version_above_thi \else \q \endif +create schema pg14; +set search_path to pg14; +create table dist(a int, b int); +select create_distributed_table('dist','a'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +create index idx on dist(a); +set citus.log_remote_commands to on; +-- make sure that we send the tablespace option +SET citus.multi_shard_commit_protocol TO '1pc'; +SET citus.multi_shard_modify_mode TO 'sequential'; +reindex(TABLESPACE test_tablespace) index idx; +NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing COMMIT +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing COMMIT +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +reindex(TABLESPACE test_tablespace, verbose) index idx; +INFO: index "idx" was reindexed +NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (VERBOSE, TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (VERBOSE, TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (VERBOSE, TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (VERBOSE, TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (VERBOSE, TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (VERBOSE, TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (VERBOSE, TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (VERBOSE, TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing COMMIT +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing COMMIT +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +reindex(TABLESPACE test_tablespace, verbose false) index idx ; +NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing COMMIT +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing COMMIT +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +reindex(verbose, TABLESPACE test_tablespace) index idx ; +INFO: index "idx" was reindexed +NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx'); +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (VERBOSE, TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (VERBOSE, TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (VERBOSE, TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (VERBOSE, TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (VERBOSE, TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (VERBOSE, TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (VERBOSE, TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing REINDEX (VERBOSE, TABLESPACE test_tablespace) INDEX pg14.xxxxx +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing COMMIT +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing COMMIT +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +-- should error saying table space doesn't exist +reindex(TABLESPACE test_tablespace1) index idx; +ERROR: tablespace "test_tablespace1" does not exist +set citus.log_remote_commands to off; +set client_min_messages to error; +drop schema pg14 cascade; diff --git a/src/test/regress/expected/tablespace.out b/src/test/regress/expected/tablespace.out new file mode 100644 index 000000000..2aba6ffdd --- /dev/null +++ b/src/test/regress/expected/tablespace.out @@ -0,0 +1,5 @@ +CREATE TABLESPACE test_tablespace LOCATION '/home/talha/citus/src/test/regress/data/ts0'; +\c - - - :worker_1_port +CREATE TABLESPACE test_tablespace LOCATION '/home/talha/citus/src/test/regress/data/ts1'; +\c - - - :worker_2_port +CREATE TABLESPACE test_tablespace LOCATION '/home/talha/citus/src/test/regress/data/ts2'; diff --git a/src/test/regress/input/tablespace.source b/src/test/regress/input/tablespace.source new file mode 100644 index 000000000..653c0dba0 --- /dev/null +++ b/src/test/regress/input/tablespace.source @@ -0,0 +1,5 @@ +CREATE TABLESPACE test_tablespace LOCATION '@abs_srcdir@/tmp_check/ts0'; +\c - - - :worker_1_port +CREATE TABLESPACE test_tablespace LOCATION '@abs_srcdir@/tmp_check/ts1'; +\c - - - :worker_2_port +CREATE TABLESPACE test_tablespace LOCATION '@abs_srcdir@/tmp_check/ts2'; diff --git a/src/test/regress/minimal_schedule b/src/test/regress/minimal_schedule index 982059e75..c5d15ff52 100644 --- a/src/test/regress/minimal_schedule +++ b/src/test/regress/minimal_schedule @@ -1,3 +1,4 @@ test: multi_cluster_management test: multi_test_helpers multi_test_helpers_superuser columnar_test_helpers test: multi_test_catalog_views +test: tablespace diff --git a/src/test/regress/multi_schedule b/src/test/regress/multi_schedule index 6b31d2673..405089a70 100644 --- a/src/test/regress/multi_schedule +++ b/src/test/regress/multi_schedule @@ -15,6 +15,7 @@ test: insert_select_repartition window_functions dml_recursive multi_insert_sele test: multi_insert_select_conflict citus_table_triggers test: multi_row_insert insert_select_into_local_table multi_create_table_new_features test: multi_agg_approximate_distinct +test: tablespace # following should not run in parallel because it relies on connection counts to workers test: insert_select_connection_leak diff --git a/src/test/regress/output/tablespace.source b/src/test/regress/output/tablespace.source new file mode 100644 index 000000000..653c0dba0 --- /dev/null +++ b/src/test/regress/output/tablespace.source @@ -0,0 +1,5 @@ +CREATE TABLESPACE test_tablespace LOCATION '@abs_srcdir@/tmp_check/ts0'; +\c - - - :worker_1_port +CREATE TABLESPACE test_tablespace LOCATION '@abs_srcdir@/tmp_check/ts1'; +\c - - - :worker_2_port +CREATE TABLESPACE test_tablespace LOCATION '@abs_srcdir@/tmp_check/ts2'; diff --git a/src/test/regress/sql/pg14.sql b/src/test/regress/sql/pg14.sql index 35b3a5676..84107791a 100644 --- a/src/test/regress/sql/pg14.sql +++ b/src/test/regress/sql/pg14.sql @@ -5,3 +5,29 @@ SELECT substring(:'server_version', '\d+')::int > 13 AS server_version_above_thi \else \q \endif + +create schema pg14; +set search_path to pg14; + +create table dist(a int, b int); +select create_distributed_table('dist','a'); +create index idx on dist(a); + +set citus.log_remote_commands to on; +-- make sure that we send the tablespace option +SET citus.multi_shard_commit_protocol TO '1pc'; +SET citus.multi_shard_modify_mode TO 'sequential'; +reindex(TABLESPACE test_tablespace) index idx; +reindex(TABLESPACE test_tablespace, verbose) index idx; +reindex(TABLESPACE test_tablespace, verbose false) index idx ; +reindex(verbose, TABLESPACE test_tablespace) index idx ; +-- should error saying table space doesn't exist +reindex(TABLESPACE test_tablespace1) index idx; +set citus.log_remote_commands to off; + +set client_min_messages to error; +drop schema pg14 cascade; + + + + diff --git a/src/test/regress/sql/tablespace.sql b/src/test/regress/sql/tablespace.sql new file mode 100644 index 000000000..427039892 --- /dev/null +++ b/src/test/regress/sql/tablespace.sql @@ -0,0 +1,5 @@ +CREATE TABLESPACE test_tablespace LOCATION '/home/talha/citus/src/test/regress/data/ts0'; +\c - - - :worker_1_port +CREATE TABLESPACE test_tablespace LOCATION '/home/talha/citus/src/test/regress/data/ts1'; +\c - - - :worker_2_port +CREATE TABLESPACE test_tablespace LOCATION '/home/talha/citus/src/test/regress/data/ts2'; \ No newline at end of file