CHANGELOG: Allow REINDEX to change the tablespace of the new index

pull/5209/head
Sait Talha Nisanci 2021-08-26 13:11:12 +03:00
parent 4e85d9ffce
commit 35a3f7240d
12 changed files with 230 additions and 8 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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';

View File

@ -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';

View File

@ -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

View File

@ -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

View File

@ -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';

View File

@ -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;

View File

@ -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';