diff --git a/sql/ddl_api.sql b/sql/ddl_api.sql index 4587932c6..39c4034af 100644 --- a/sql/ddl_api.sql +++ b/sql/ddl_api.sql @@ -209,3 +209,10 @@ AS '@MODULE_PATHNAME@', 'ts_data_node_allow_new_chunks' LANGUAGE C VOLATILE; -- to execute the query on every data node CREATE OR REPLACE FUNCTION distributed_exec(query TEXT, node_list name[] = NULL) RETURNS VOID AS '@MODULE_PATHNAME@', 'ts_distributed_exec' LANGUAGE C VOLATILE; + +-- Sets new replication factor for distributed hypertable +CREATE OR REPLACE FUNCTION set_replication_factor( + main_table REGCLASS, + replication_factor INTEGER +) RETURNS VOID +AS '@MODULE_PATHNAME@', 'ts_hypertable_distributed_set_replication_factor' LANGUAGE C VOLATILE; diff --git a/src/cross_module_fn.c b/src/cross_module_fn.c index 9ba99145f..cc787e293 100644 --- a/src/cross_module_fn.c +++ b/src/cross_module_fn.c @@ -65,6 +65,7 @@ TS_FUNCTION_INFO_V1(ts_dist_set_peer_id); TS_FUNCTION_INFO_V1(ts_dist_remote_hypertable_info); TS_FUNCTION_INFO_V1(ts_dist_validate_as_data_node); TS_FUNCTION_INFO_V1(ts_distributed_exec); +TS_FUNCTION_INFO_V1(ts_hypertable_distributed_set_replication_factor); Datum ts_add_drop_chunks_policy(PG_FUNCTION_ARGS) @@ -249,6 +250,12 @@ ts_distributed_exec(PG_FUNCTION_ARGS) PG_RETURN_VOID(); } +Datum +ts_hypertable_distributed_set_replication_factor(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(ts_cm_functions->set_replication_factor(fcinfo)); +} + /* * stub function to trigger aggregate util functions. */ @@ -660,6 +667,7 @@ TSDLLEXPORT CrossModuleFunctions ts_cm_functions_default = { .func_call_on_data_nodes = func_call_on_data_nodes_default, .get_chunk_relstats = error_no_default_fn_pg_community, .get_chunk_colstats = error_no_default_fn_pg_community, + .set_replication_factor = error_no_default_fn_pg_community, }; TSDLLEXPORT CrossModuleFunctions *ts_cm_functions = &ts_cm_functions_default; diff --git a/src/cross_module_fn.h b/src/cross_module_fn.h index 08fe1c4cf..c71ed7c9f 100644 --- a/src/cross_module_fn.h +++ b/src/cross_module_fn.h @@ -145,6 +145,7 @@ typedef struct CrossModuleFunctions PGFunction distributed_exec; PGFunction get_chunk_relstats; PGFunction get_chunk_colstats; + PGFunction set_replication_factor; } CrossModuleFunctions; extern TSDLLEXPORT CrossModuleFunctions *ts_cm_functions; diff --git a/src/hypertable.c b/src/hypertable.c index 3c340638f..cc0d6d9c1 100644 --- a/src/hypertable.c +++ b/src/hypertable.c @@ -1714,8 +1714,8 @@ ts_hypertable_check_partitioning(Hypertable *ht, int32 id_of_updated_dimension) } } -static int16 -validate_replication_factor(int32 replication_factor, bool is_null, bool is_dist_call) +extern int16 +ts_validate_replication_factor(int32 replication_factor, bool is_null, bool is_dist_call) { bool valid = replication_factor >= 1 && replication_factor <= PG_INT16_MAX; @@ -1750,7 +1750,7 @@ validate_replication_factor(int32 replication_factor, bool is_null, bool is_dist if (!valid) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("invalid replication_factor"), + errmsg("invalid replication factor"), errhint("A hypertable's replication factor must be between 1 and %d.", PG_INT16_MAX))); @@ -1847,9 +1847,9 @@ ts_hypertable_create_internal(PG_FUNCTION_ARGS, bool is_dist_call) * Ensure replication factor is a valid value and convert it to * catalog table format */ - replication_factor = validate_replication_factor(replication_factor_in, - replication_factor_is_null, - is_dist_call); + replication_factor = ts_validate_replication_factor(replication_factor_in, + replication_factor_is_null, + is_dist_call); /* Validate data nodes and check permissions on them if this is a * distributed hypertable. */ @@ -2183,7 +2183,7 @@ ts_hypertable_create_from_info(Oid table_relid, int32 hypertable_id, uint32 flag else if (list_length(data_node_names) > 0) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("invalid replication_factor for non-empty data node list"), + errmsg("invalid replication factor for non-empty data node list"), errhint("The replication_factor should be 1 or greater with a non-empty data node " "list"))); diff --git a/src/hypertable.h b/src/hypertable.h index 4297c9a8d..0d27cc83c 100644 --- a/src/hypertable.h +++ b/src/hypertable.h @@ -118,7 +118,7 @@ extern int ts_hypertable_scan_with_memory_context(const char *schema, const char MemoryContext mctx); extern TM_Result ts_hypertable_lock_tuple(Oid table_relid); extern bool ts_hypertable_lock_tuple_simple(Oid table_relid); -extern int ts_hypertable_update(Hypertable *ht); +extern TSDLLEXPORT int ts_hypertable_update(Hypertable *ht); extern int ts_hypertable_set_name(Hypertable *ht, const char *newname); extern int ts_hypertable_set_schema(Hypertable *ht, const char *newname); extern int ts_hypertable_set_num_dimensions(Hypertable *ht, int16 num_dimensions); @@ -162,6 +162,8 @@ extern TSDLLEXPORT List *ts_hypertable_get_available_data_node_server_oids(Hyper extern TSDLLEXPORT HypertableType ts_hypertable_get_type(Hypertable *ht); extern TSDLLEXPORT void ts_hypertable_func_call_on_data_nodes(Hypertable *ht, FunctionCallInfo fcinfo); +extern TSDLLEXPORT int16 ts_validate_replication_factor(int32 replication_factor, bool is_null, + bool is_dist_call); #define hypertable_scan(schema, table, tuple_found, data, lockmode, tuplock) \ ts_hypertable_scan_with_memory_context(schema, \ diff --git a/test/expected/extension.out b/test/expected/extension.out index bc115010a..3105115ad 100644 --- a/test/expected/extension.out +++ b/test/expected/extension.out @@ -58,6 +58,7 @@ ORDER BY proname; set_chunk_time_interval set_integer_now_func set_number_partitions + set_replication_factor show_chunks show_tablespaces time_bucket @@ -66,5 +67,5 @@ ORDER BY proname; timescaledb_fdw_validator timescaledb_post_restore timescaledb_pre_restore -(52 rows) +(53 rows) diff --git a/tsl/src/hypertable.c b/tsl/src/hypertable.c index dd99d9d39..10daef55f 100644 --- a/tsl/src/hypertable.c +++ b/tsl/src/hypertable.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include #include @@ -22,6 +24,8 @@ #include "license.h" #include "utils.h" #include "hypertable_cache.h" +#include "chunk.h" +#include "chunk_data_node.h" #if PG_VERSION_SUPPORTS_MULTINODE #include @@ -200,4 +204,69 @@ hypertable_make_distributed(Hypertable *ht, List *data_node_names) hypertable_assign_data_nodes(ht->fd.id, data_node_names); } +static bool +hypertable_is_underreplicated(Hypertable *const ht, const int16 replication_factor) +{ + ListCell *lc; + List *chunks = find_inheritance_children(ht->main_table_relid, NoLock); + + Assert(hypertable_is_distributed(ht)); + + foreach (lc, chunks) + { + Oid chunk_oid = lfirst_oid(lc); + Chunk *chunk = ts_chunk_get_by_relid(chunk_oid, true); + List *replicas = ts_chunk_data_node_scan_by_chunk_id(chunk->fd.id, CurrentMemoryContext); + + Assert(get_rel_relkind(chunk_oid) == RELKIND_FOREIGN_TABLE); + + if (list_length(replicas) < replication_factor) + return true; + } + return false; +} + +static void +update_replication_factor(Hypertable *const ht, const int32 replication_factor_in) +{ + const int16 replication_factor = + ts_validate_replication_factor(replication_factor_in, false, true); + + ht->fd.replication_factor = replication_factor; + ts_hypertable_update(ht); + if (hypertable_is_underreplicated(ht, replication_factor)) + ereport(WARNING, + (errcode(ERRCODE_WARNING), + errmsg("hypertable \"%s\" is under-replicated", NameStr(ht->fd.table_name)), + errdetail("Some chunks have less than %d replicas.", replication_factor))); +} + +Datum +hypertable_set_replication_factor(PG_FUNCTION_ARGS) +{ + const Oid table_relid = PG_ARGISNULL(0) ? InvalidOid : PG_GETARG_OID(0); + const int32 replication_factor_in = PG_ARGISNULL(1) ? 0 : PG_GETARG_INT32(1); + Cache *hcache; + Hypertable *ht; + + if (!OidIsValid(table_relid)) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("invalid hypertable: cannot be NULL"))); + + hcache = ts_hypertable_cache_pin(); + ht = ts_hypertable_cache_get_entry(hcache, table_relid, CACHE_FLAG_NONE); + + if (!hypertable_is_distributed(ht)) + ereport(ERROR, + (errcode(ERRCODE_TS_HYPERTABLE_NOT_DISTRIBUTED), + errmsg("hypertable \"%s\" is not distributed", get_rel_name(table_relid)))); + + update_replication_factor(ht, replication_factor_in); + + ts_cache_release(hcache); + + PG_RETURN_VOID(); +} + #endif /* PG_VERSION_SUPPORTS_MULTINODE */ diff --git a/tsl/src/hypertable.h b/tsl/src/hypertable.h index fa1069c09..950bbb6cc 100644 --- a/tsl/src/hypertable.h +++ b/tsl/src/hypertable.h @@ -22,6 +22,7 @@ extern Datum hypertable_valid_ts_interval(PG_FUNCTION_ARGS); extern void hypertable_make_distributed(Hypertable *ht, List *data_node_names); extern List *hypertable_assign_data_nodes(int32 hypertable_id, List *nodes); extern List *hypertable_get_and_validate_data_nodes(ArrayType *nodearr); +extern Datum hypertable_set_replication_factor(PG_FUNCTION_ARGS); #endif /* PG_VERSION_SUPPORTS_MULTINODE */ #endif /* TIMESCALEDB_TSL_HYPERTABLE_H */ diff --git a/tsl/src/init.c b/tsl/src/init.c index 72cf28e35..ec1efd6db 100644 --- a/tsl/src/init.c +++ b/tsl/src/init.c @@ -260,6 +260,7 @@ CrossModuleFunctions tsl_cm_functions = { .func_call_on_data_nodes = error_func_call_on_data_nodes_not_supported, .get_chunk_relstats = error_not_supported_default_fn, .get_chunk_colstats = error_not_supported_default_fn, + .set_replication_factor = error_not_supported_default_fn, #else .add_data_node = data_node_add, .delete_data_node = data_node_delete, @@ -295,6 +296,7 @@ CrossModuleFunctions tsl_cm_functions = { .func_call_on_data_nodes = ts_dist_cmd_func_call_on_data_nodes, .get_chunk_relstats = chunk_api_get_chunk_relstats, .get_chunk_colstats = chunk_api_get_chunk_colstats, + .set_replication_factor = hypertable_set_replication_factor, #endif .cache_syscache_invalidate = cache_syscache_invalidate, }; diff --git a/tsl/test/expected/data_node.out b/tsl/test/expected/data_node.out index b7d26526f..869ecb80a 100644 --- a/tsl/test/expected/data_node.out +++ b/tsl/test/expected/data_node.out @@ -337,13 +337,13 @@ ERROR: table "disttable" is not a hypertable -- Test some bad create_hypertable() parameter values for distributed hypertables -- Bad replication factor SELECT * FROM create_distributed_hypertable('disttable', 'time', 'device', replication_factor => 0, data_nodes => '{ "data_node_2", "data_node_4" }'); -ERROR: invalid replication_factor +ERROR: invalid replication factor SELECT * FROM create_distributed_hypertable('disttable', 'time', 'device', replication_factor => 32768); -ERROR: invalid replication_factor +ERROR: invalid replication factor SELECT * FROM create_hypertable('disttable', 'time', replication_factor => -1); -ERROR: invalid replication_factor +ERROR: invalid replication factor SELECT * FROM create_distributed_hypertable('disttable', 'time', 'device', replication_factor => -1); -ERROR: invalid replication_factor +ERROR: invalid replication factor -- Non-existing data node SELECT * FROM create_distributed_hypertable('disttable', 'time', 'device', replication_factor => 2, data_nodes => '{ "data_node_4" }'); ERROR: server "data_node_4" does not exist diff --git a/tsl/test/expected/dist_ddl.out b/tsl/test/expected/dist_ddl.out index 560321ebc..47580aa7b 100644 --- a/tsl/test/expected/dist_ddl.out +++ b/tsl/test/expected/dist_ddl.out @@ -445,6 +445,15 @@ TRUNCATE non_disttable1, non_disttable2; TRUNCATE disttable; -- Test unsupported operations on distributed hypertable \set ON_ERROR_STOP 0 +-- test set_replication_factor on non-hypertable +SELECT * FROM set_replication_factor('non_disttable1', 1); +ERROR: table "non_disttable1" is not a hypertable +-- test set_replication_factor on non-distributed +SELECT * FROM set_replication_factor('non_disttable2', 1); +ERROR: hypertable "non_disttable2" is not distributed +-- test set_replication_factor on NULL hypertable +SELECT * FROM set_replication_factor(NULL, 1); +ERROR: invalid hypertable: cannot be NULL -- Combining one distributed hypertable with any other tables should -- be blocked since not all nodes might have all tables and we -- currently don't rewrite the command. @@ -1666,6 +1675,61 @@ NOTICE: adding not-null constraint to column "time" (1 row) CREATE INDEX disttable_device_idx ON disttable (device); +-- Test alter replication factor on empty table +SELECT replication_factor FROM _timescaledb_catalog.hypertable ORDER BY id; + replication_factor +-------------------- + 3 +(1 row) + +SELECT * FROM set_replication_factor('disttable', 1); + set_replication_factor +------------------------ + +(1 row) + +SELECT replication_factor FROM _timescaledb_catalog.hypertable ORDER BY id; + replication_factor +-------------------- + 1 +(1 row) + +SELECT * FROM set_replication_factor('disttable', 1); + set_replication_factor +------------------------ + +(1 row) + +SELECT replication_factor FROM _timescaledb_catalog.hypertable ORDER BY id; + replication_factor +-------------------- + 1 +(1 row) + +SELECT * FROM set_replication_factor('disttable', 2); + set_replication_factor +------------------------ + +(1 row) + +SELECT replication_factor FROM _timescaledb_catalog.hypertable ORDER BY id; + replication_factor +-------------------- + 2 +(1 row) + +\set ON_ERROR_STOP 0 +SELECT * FROM set_replication_factor('disttable', 0); +ERROR: invalid replication factor +SELECT * FROM set_replication_factor('disttable', NULL); +ERROR: invalid replication factor +\set ON_ERROR_STOP 1 +SELECT replication_factor FROM _timescaledb_catalog.hypertable ORDER BY id; + replication_factor +-------------------- + 2 +(1 row) + \c data_node_1 SELECT schemaname, tablename FROM pg_tables WHERE tablename = 'disttable'; schemaname | tablename @@ -1681,6 +1745,9 @@ SELECT * FROM test.show_indexes('disttable'); (2 rows) \set ON_ERROR_STOP 0 +-- fail to alter replication factor for the table on data node +SELECT * FROM set_replication_factor('disttable', 1); +ERROR: hypertable "disttable" is not distributed -- Test TRUNCATE blocked on data node TRUNCATE disttable; ERROR: operation is blocked on a distributed hypertable member diff --git a/tsl/test/expected/dist_hypertable-11.out b/tsl/test/expected/dist_hypertable-11.out index 9bf9408c4..8d067b262 100644 --- a/tsl/test/expected/dist_hypertable-11.out +++ b/tsl/test/expected/dist_hypertable-11.out @@ -1639,7 +1639,7 @@ ERROR: [data_node_3]: relation "remotetable" already exists -- Test distributed_hypertable creation fails with replication factor 0 CREATE TABLE remotetable2(time timestamptz PRIMARY KEY, device int CHECK (device > 0), color int, temp float); SELECT * FROM create_distributed_hypertable('remotetable2', 'time', replication_factor => 0); -ERROR: invalid replication_factor +ERROR: invalid replication factor \set ON_ERROR_STOP 1 SELECT * FROM timescaledb_information.hypertable ORDER BY table_schema, table_name; @@ -3424,3 +3424,269 @@ INSERT INTO devices VALUES (6, 'E999'); INSERT INTO hyper VALUES ('2017-01-01 06:01', 6, 1.1); ERROR: [data_node_1]: insert or update on table "_hyper_17_45_dist_chunk" violates foreign key constraint "28_17_hyper_device_fkey" \set ON_ERROR_STOP 1 +-- Test alter replication factor with data +SELECT * FROM test.remote_exec('{ data_node_1, data_node_2, data_node_3 }',$$ + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper'); +$$); +NOTICE: [data_node_1]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_1]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 28| 16|_timescaledb_internal|_hyper_17_45_dist_chunk|r |{"time": [1483272000000000, 1483336800000000], "device": [-9223372036854775808, 715827882]} + 29| 16|_timescaledb_internal|_hyper_17_46_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [-9223372036854775808, 715827882]} + 30| 16|_timescaledb_internal|_hyper_17_49_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [-9223372036854775808, 715827882]} +(3 rows) + + +NOTICE: [data_node_2]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_2]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+--------------------------------------------------------------------------------- + 23| 15|_timescaledb_internal|_hyper_17_47_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [715827882, 1431655764]} + 24| 15|_timescaledb_internal|_hyper_17_50_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [715827882, 1431655764]} +(2 rows) + + +NOTICE: [data_node_3]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_3]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 21| 14|_timescaledb_internal|_hyper_17_48_dist_chunk|r |{"time": [1483401600000000, 1483466400000000], "device": [1431655764, 9223372036854775807]} + 22| 14|_timescaledb_internal|_hyper_17_51_dist_chunk|r |{"time": [1515866400000000, 1515931200000000], "device": [1431655764, 9223372036854775807]} +(2 rows) + + + remote_exec +------------- + +(1 row) + +SELECT * FROM set_replication_factor('hyper', 3); +WARNING: hypertable "hyper" is under-replicated + set_replication_factor +------------------------ + +(1 row) + +INSERT INTO hyper VALUES ('2017-01-02 07:11', 1, 1.7); +SELECT * FROM test.remote_exec('{ data_node_1, data_node_2, data_node_3 }',$$ + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper'); +$$); +NOTICE: [data_node_1]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_1]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 28| 16|_timescaledb_internal|_hyper_17_45_dist_chunk|r |{"time": [1483272000000000, 1483336800000000], "device": [-9223372036854775808, 715827882]} + 29| 16|_timescaledb_internal|_hyper_17_46_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [-9223372036854775808, 715827882]} + 30| 16|_timescaledb_internal|_hyper_17_49_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [-9223372036854775808, 715827882]} +(3 rows) + + +NOTICE: [data_node_2]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_2]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+--------------------------------------------------------------------------------- + 23| 15|_timescaledb_internal|_hyper_17_47_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [715827882, 1431655764]} + 24| 15|_timescaledb_internal|_hyper_17_50_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [715827882, 1431655764]} +(2 rows) + + +NOTICE: [data_node_3]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_3]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 21| 14|_timescaledb_internal|_hyper_17_48_dist_chunk|r |{"time": [1483401600000000, 1483466400000000], "device": [1431655764, 9223372036854775807]} + 22| 14|_timescaledb_internal|_hyper_17_51_dist_chunk|r |{"time": [1515866400000000, 1515931200000000], "device": [1431655764, 9223372036854775807]} +(2 rows) + + + remote_exec +------------- + +(1 row) + +INSERT INTO hyper VALUES ('2017-02-01 06:01', 1, 5.1); +SELECT * FROM test.remote_exec('{ data_node_1, data_node_2, data_node_3 }',$$ + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper'); +$$); +NOTICE: [data_node_1]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_1]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 28| 16|_timescaledb_internal|_hyper_17_45_dist_chunk|r |{"time": [1483272000000000, 1483336800000000], "device": [-9223372036854775808, 715827882]} + 29| 16|_timescaledb_internal|_hyper_17_46_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [-9223372036854775808, 715827882]} + 30| 16|_timescaledb_internal|_hyper_17_49_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [-9223372036854775808, 715827882]} + 31| 16|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} +(4 rows) + + +NOTICE: [data_node_2]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_2]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 23| 15|_timescaledb_internal|_hyper_17_47_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [715827882, 1431655764]} + 24| 15|_timescaledb_internal|_hyper_17_50_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [715827882, 1431655764]} + 25| 15|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} +(3 rows) + + +NOTICE: [data_node_3]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_3]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 21| 14|_timescaledb_internal|_hyper_17_48_dist_chunk|r |{"time": [1483401600000000, 1483466400000000], "device": [1431655764, 9223372036854775807]} + 22| 14|_timescaledb_internal|_hyper_17_51_dist_chunk|r |{"time": [1515866400000000, 1515931200000000], "device": [1431655764, 9223372036854775807]} + 23| 14|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} +(3 rows) + + + remote_exec +------------- + +(1 row) + +SELECT * FROM set_replication_factor('hyper', 2); +WARNING: hypertable "hyper" is under-replicated + set_replication_factor +------------------------ + +(1 row) + +INSERT INTO hyper VALUES ('2017-03-01 06:01', 1, 15.1); +SELECT * FROM test.remote_exec('{ data_node_1, data_node_2, data_node_3 }',$$ + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper'); +$$); +NOTICE: [data_node_1]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_1]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 28| 16|_timescaledb_internal|_hyper_17_45_dist_chunk|r |{"time": [1483272000000000, 1483336800000000], "device": [-9223372036854775808, 715827882]} + 29| 16|_timescaledb_internal|_hyper_17_46_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [-9223372036854775808, 715827882]} + 30| 16|_timescaledb_internal|_hyper_17_49_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [-9223372036854775808, 715827882]} + 31| 16|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} + 32| 16|_timescaledb_internal|_hyper_17_53_dist_chunk|r |{"time": [1488326400000000, 1488391200000000], "device": [-9223372036854775808, 715827882]} +(5 rows) + + +NOTICE: [data_node_2]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_2]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 23| 15|_timescaledb_internal|_hyper_17_47_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [715827882, 1431655764]} + 24| 15|_timescaledb_internal|_hyper_17_50_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [715827882, 1431655764]} + 25| 15|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} + 26| 15|_timescaledb_internal|_hyper_17_53_dist_chunk|r |{"time": [1488326400000000, 1488391200000000], "device": [-9223372036854775808, 715827882]} +(4 rows) + + +NOTICE: [data_node_3]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_3]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 21| 14|_timescaledb_internal|_hyper_17_48_dist_chunk|r |{"time": [1483401600000000, 1483466400000000], "device": [1431655764, 9223372036854775807]} + 22| 14|_timescaledb_internal|_hyper_17_51_dist_chunk|r |{"time": [1515866400000000, 1515931200000000], "device": [1431655764, 9223372036854775807]} + 23| 14|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} +(3 rows) + + + remote_exec +------------- + +(1 row) + +SELECT * FROM set_replication_factor('hyper', replication_factor => 2); +WARNING: hypertable "hyper" is under-replicated + set_replication_factor +------------------------ + +(1 row) + +INSERT INTO hyper VALUES ('2017-04-01 06:01', 2, 45.1); +SELECT * FROM test.remote_exec('{ data_node_1, data_node_2, data_node_3 }',$$ + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper'); +$$); +NOTICE: [data_node_1]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_1]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 28| 16|_timescaledb_internal|_hyper_17_45_dist_chunk|r |{"time": [1483272000000000, 1483336800000000], "device": [-9223372036854775808, 715827882]} + 29| 16|_timescaledb_internal|_hyper_17_46_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [-9223372036854775808, 715827882]} + 30| 16|_timescaledb_internal|_hyper_17_49_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [-9223372036854775808, 715827882]} + 31| 16|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} + 32| 16|_timescaledb_internal|_hyper_17_53_dist_chunk|r |{"time": [1488326400000000, 1488391200000000], "device": [-9223372036854775808, 715827882]} +(5 rows) + + +NOTICE: [data_node_2]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_2]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 23| 15|_timescaledb_internal|_hyper_17_47_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [715827882, 1431655764]} + 24| 15|_timescaledb_internal|_hyper_17_50_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [715827882, 1431655764]} + 25| 15|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} + 26| 15|_timescaledb_internal|_hyper_17_53_dist_chunk|r |{"time": [1488326400000000, 1488391200000000], "device": [-9223372036854775808, 715827882]} + 27| 15|_timescaledb_internal|_hyper_17_54_dist_chunk|r |{"time": [1491048000000000, 1491112800000000], "device": [715827882, 1431655764]} +(5 rows) + + +NOTICE: [data_node_3]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_3]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 21| 14|_timescaledb_internal|_hyper_17_48_dist_chunk|r |{"time": [1483401600000000, 1483466400000000], "device": [1431655764, 9223372036854775807]} + 22| 14|_timescaledb_internal|_hyper_17_51_dist_chunk|r |{"time": [1515866400000000, 1515931200000000], "device": [1431655764, 9223372036854775807]} + 23| 14|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} + 24| 14|_timescaledb_internal|_hyper_17_54_dist_chunk|r |{"time": [1491048000000000, 1491112800000000], "device": [715827882, 1431655764]} +(4 rows) + + + remote_exec +------------- + +(1 row) + +DROP TABLE hyper; +SELECT * FROM distributed_exec($$ + DROP TABLE devices; +$$); + distributed_exec +------------------ + +(1 row) + +DROP TABLE devices; diff --git a/tsl/test/expected/dist_hypertable-12.out b/tsl/test/expected/dist_hypertable-12.out index 58b11ae67..65c72da7d 100644 --- a/tsl/test/expected/dist_hypertable-12.out +++ b/tsl/test/expected/dist_hypertable-12.out @@ -1639,7 +1639,7 @@ ERROR: [data_node_3]: relation "remotetable" already exists -- Test distributed_hypertable creation fails with replication factor 0 CREATE TABLE remotetable2(time timestamptz PRIMARY KEY, device int CHECK (device > 0), color int, temp float); SELECT * FROM create_distributed_hypertable('remotetable2', 'time', replication_factor => 0); -ERROR: invalid replication_factor +ERROR: invalid replication factor \set ON_ERROR_STOP 1 SELECT * FROM timescaledb_information.hypertable ORDER BY table_schema, table_name; @@ -3417,3 +3417,269 @@ INSERT INTO devices VALUES (6, 'E999'); INSERT INTO hyper VALUES ('2017-01-01 06:01', 6, 1.1); ERROR: [data_node_1]: insert or update on table "_hyper_17_45_dist_chunk" violates foreign key constraint "28_17_hyper_device_fkey" \set ON_ERROR_STOP 1 +-- Test alter replication factor with data +SELECT * FROM test.remote_exec('{ data_node_1, data_node_2, data_node_3 }',$$ + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper'); +$$); +NOTICE: [data_node_1]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_1]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 28| 16|_timescaledb_internal|_hyper_17_45_dist_chunk|r |{"time": [1483272000000000, 1483336800000000], "device": [-9223372036854775808, 715827882]} + 29| 16|_timescaledb_internal|_hyper_17_46_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [-9223372036854775808, 715827882]} + 30| 16|_timescaledb_internal|_hyper_17_49_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [-9223372036854775808, 715827882]} +(3 rows) + + +NOTICE: [data_node_2]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_2]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+--------------------------------------------------------------------------------- + 23| 15|_timescaledb_internal|_hyper_17_47_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [715827882, 1431655764]} + 24| 15|_timescaledb_internal|_hyper_17_50_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [715827882, 1431655764]} +(2 rows) + + +NOTICE: [data_node_3]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_3]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 21| 14|_timescaledb_internal|_hyper_17_48_dist_chunk|r |{"time": [1483401600000000, 1483466400000000], "device": [1431655764, 9223372036854775807]} + 22| 14|_timescaledb_internal|_hyper_17_51_dist_chunk|r |{"time": [1515866400000000, 1515931200000000], "device": [1431655764, 9223372036854775807]} +(2 rows) + + + remote_exec +------------- + +(1 row) + +SELECT * FROM set_replication_factor('hyper', 3); +WARNING: hypertable "hyper" is under-replicated + set_replication_factor +------------------------ + +(1 row) + +INSERT INTO hyper VALUES ('2017-01-02 07:11', 1, 1.7); +SELECT * FROM test.remote_exec('{ data_node_1, data_node_2, data_node_3 }',$$ + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper'); +$$); +NOTICE: [data_node_1]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_1]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 28| 16|_timescaledb_internal|_hyper_17_45_dist_chunk|r |{"time": [1483272000000000, 1483336800000000], "device": [-9223372036854775808, 715827882]} + 29| 16|_timescaledb_internal|_hyper_17_46_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [-9223372036854775808, 715827882]} + 30| 16|_timescaledb_internal|_hyper_17_49_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [-9223372036854775808, 715827882]} +(3 rows) + + +NOTICE: [data_node_2]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_2]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+--------------------------------------------------------------------------------- + 23| 15|_timescaledb_internal|_hyper_17_47_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [715827882, 1431655764]} + 24| 15|_timescaledb_internal|_hyper_17_50_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [715827882, 1431655764]} +(2 rows) + + +NOTICE: [data_node_3]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_3]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 21| 14|_timescaledb_internal|_hyper_17_48_dist_chunk|r |{"time": [1483401600000000, 1483466400000000], "device": [1431655764, 9223372036854775807]} + 22| 14|_timescaledb_internal|_hyper_17_51_dist_chunk|r |{"time": [1515866400000000, 1515931200000000], "device": [1431655764, 9223372036854775807]} +(2 rows) + + + remote_exec +------------- + +(1 row) + +INSERT INTO hyper VALUES ('2017-02-01 06:01', 1, 5.1); +SELECT * FROM test.remote_exec('{ data_node_1, data_node_2, data_node_3 }',$$ + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper'); +$$); +NOTICE: [data_node_1]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_1]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 28| 16|_timescaledb_internal|_hyper_17_45_dist_chunk|r |{"time": [1483272000000000, 1483336800000000], "device": [-9223372036854775808, 715827882]} + 29| 16|_timescaledb_internal|_hyper_17_46_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [-9223372036854775808, 715827882]} + 30| 16|_timescaledb_internal|_hyper_17_49_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [-9223372036854775808, 715827882]} + 31| 16|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} +(4 rows) + + +NOTICE: [data_node_2]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_2]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 23| 15|_timescaledb_internal|_hyper_17_47_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [715827882, 1431655764]} + 24| 15|_timescaledb_internal|_hyper_17_50_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [715827882, 1431655764]} + 25| 15|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} +(3 rows) + + +NOTICE: [data_node_3]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_3]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 21| 14|_timescaledb_internal|_hyper_17_48_dist_chunk|r |{"time": [1483401600000000, 1483466400000000], "device": [1431655764, 9223372036854775807]} + 22| 14|_timescaledb_internal|_hyper_17_51_dist_chunk|r |{"time": [1515866400000000, 1515931200000000], "device": [1431655764, 9223372036854775807]} + 23| 14|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} +(3 rows) + + + remote_exec +------------- + +(1 row) + +SELECT * FROM set_replication_factor('hyper', 2); +WARNING: hypertable "hyper" is under-replicated + set_replication_factor +------------------------ + +(1 row) + +INSERT INTO hyper VALUES ('2017-03-01 06:01', 1, 15.1); +SELECT * FROM test.remote_exec('{ data_node_1, data_node_2, data_node_3 }',$$ + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper'); +$$); +NOTICE: [data_node_1]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_1]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 28| 16|_timescaledb_internal|_hyper_17_45_dist_chunk|r |{"time": [1483272000000000, 1483336800000000], "device": [-9223372036854775808, 715827882]} + 29| 16|_timescaledb_internal|_hyper_17_46_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [-9223372036854775808, 715827882]} + 30| 16|_timescaledb_internal|_hyper_17_49_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [-9223372036854775808, 715827882]} + 31| 16|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} + 32| 16|_timescaledb_internal|_hyper_17_53_dist_chunk|r |{"time": [1488326400000000, 1488391200000000], "device": [-9223372036854775808, 715827882]} +(5 rows) + + +NOTICE: [data_node_2]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_2]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 23| 15|_timescaledb_internal|_hyper_17_47_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [715827882, 1431655764]} + 24| 15|_timescaledb_internal|_hyper_17_50_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [715827882, 1431655764]} + 25| 15|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} + 26| 15|_timescaledb_internal|_hyper_17_53_dist_chunk|r |{"time": [1488326400000000, 1488391200000000], "device": [-9223372036854775808, 715827882]} +(4 rows) + + +NOTICE: [data_node_3]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_3]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 21| 14|_timescaledb_internal|_hyper_17_48_dist_chunk|r |{"time": [1483401600000000, 1483466400000000], "device": [1431655764, 9223372036854775807]} + 22| 14|_timescaledb_internal|_hyper_17_51_dist_chunk|r |{"time": [1515866400000000, 1515931200000000], "device": [1431655764, 9223372036854775807]} + 23| 14|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} +(3 rows) + + + remote_exec +------------- + +(1 row) + +SELECT * FROM set_replication_factor('hyper', replication_factor => 2); +WARNING: hypertable "hyper" is under-replicated + set_replication_factor +------------------------ + +(1 row) + +INSERT INTO hyper VALUES ('2017-04-01 06:01', 2, 45.1); +SELECT * FROM test.remote_exec('{ data_node_1, data_node_2, data_node_3 }',$$ + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper'); +$$); +NOTICE: [data_node_1]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_1]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 28| 16|_timescaledb_internal|_hyper_17_45_dist_chunk|r |{"time": [1483272000000000, 1483336800000000], "device": [-9223372036854775808, 715827882]} + 29| 16|_timescaledb_internal|_hyper_17_46_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [-9223372036854775808, 715827882]} + 30| 16|_timescaledb_internal|_hyper_17_49_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [-9223372036854775808, 715827882]} + 31| 16|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} + 32| 16|_timescaledb_internal|_hyper_17_53_dist_chunk|r |{"time": [1488326400000000, 1488391200000000], "device": [-9223372036854775808, 715827882]} +(5 rows) + + +NOTICE: [data_node_2]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_2]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 23| 15|_timescaledb_internal|_hyper_17_47_dist_chunk|r |{"time": [1483336800000000, 1483401600000000], "device": [715827882, 1431655764]} + 24| 15|_timescaledb_internal|_hyper_17_50_dist_chunk|r |{"time": [1515801600000000, 1515866400000000], "device": [715827882, 1431655764]} + 25| 15|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} + 26| 15|_timescaledb_internal|_hyper_17_53_dist_chunk|r |{"time": [1488326400000000, 1488391200000000], "device": [-9223372036854775808, 715827882]} + 27| 15|_timescaledb_internal|_hyper_17_54_dist_chunk|r |{"time": [1491048000000000, 1491112800000000], "device": [715827882, 1431655764]} +(5 rows) + + +NOTICE: [data_node_3]: + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper') +NOTICE: [data_node_3]: +chunk_id|hypertable_id|schema_name |table_name |relkind|slices +--------+-------------+---------------------+-----------------------+-------+------------------------------------------------------------------------------------------- + 21| 14|_timescaledb_internal|_hyper_17_48_dist_chunk|r |{"time": [1483401600000000, 1483466400000000], "device": [1431655764, 9223372036854775807]} + 22| 14|_timescaledb_internal|_hyper_17_51_dist_chunk|r |{"time": [1515866400000000, 1515931200000000], "device": [1431655764, 9223372036854775807]} + 23| 14|_timescaledb_internal|_hyper_17_52_dist_chunk|r |{"time": [1485928800000000, 1485993600000000], "device": [-9223372036854775808, 715827882]} + 24| 14|_timescaledb_internal|_hyper_17_54_dist_chunk|r |{"time": [1491048000000000, 1491112800000000], "device": [715827882, 1431655764]} +(4 rows) + + + remote_exec +------------- + +(1 row) + +DROP TABLE hyper; +SELECT * FROM distributed_exec($$ + DROP TABLE devices; +$$); + distributed_exec +------------------ + +(1 row) + +DROP TABLE devices; diff --git a/tsl/test/sql/dist_ddl.sql b/tsl/test/sql/dist_ddl.sql index 9145aa447..c1ddb96e2 100644 --- a/tsl/test/sql/dist_ddl.sql +++ b/tsl/test/sql/dist_ddl.sql @@ -106,6 +106,13 @@ TRUNCATE disttable; -- Test unsupported operations on distributed hypertable \set ON_ERROR_STOP 0 +-- test set_replication_factor on non-hypertable +SELECT * FROM set_replication_factor('non_disttable1', 1); +-- test set_replication_factor on non-distributed +SELECT * FROM set_replication_factor('non_disttable2', 1); +-- test set_replication_factor on NULL hypertable +SELECT * FROM set_replication_factor(NULL, 1); + -- Combining one distributed hypertable with any other tables should -- be blocked since not all nodes might have all tables and we -- currently don't rewrite the command. @@ -412,12 +419,29 @@ CREATE TABLE disttable(time timestamptz, device int); SELECT * FROM create_hypertable('disttable', 'time', replication_factor => 3); CREATE INDEX disttable_device_idx ON disttable (device); +-- Test alter replication factor on empty table +SELECT replication_factor FROM _timescaledb_catalog.hypertable ORDER BY id; +SELECT * FROM set_replication_factor('disttable', 1); +SELECT replication_factor FROM _timescaledb_catalog.hypertable ORDER BY id; +SELECT * FROM set_replication_factor('disttable', 1); +SELECT replication_factor FROM _timescaledb_catalog.hypertable ORDER BY id; +SELECT * FROM set_replication_factor('disttable', 2); +SELECT replication_factor FROM _timescaledb_catalog.hypertable ORDER BY id; +\set ON_ERROR_STOP 0 +SELECT * FROM set_replication_factor('disttable', 0); +SELECT * FROM set_replication_factor('disttable', NULL); +\set ON_ERROR_STOP 1 +SELECT replication_factor FROM _timescaledb_catalog.hypertable ORDER BY id; + \c data_node_1 SELECT schemaname, tablename FROM pg_tables WHERE tablename = 'disttable'; SELECT * FROM test.show_indexes('disttable'); \set ON_ERROR_STOP 0 +-- fail to alter replication factor for the table on data node +SELECT * FROM set_replication_factor('disttable', 1); + -- Test TRUNCATE blocked on data node TRUNCATE disttable; diff --git a/tsl/test/sql/dist_hypertable.sql.in b/tsl/test/sql/dist_hypertable.sql.in index 9ec9712df..d434b72a2 100644 --- a/tsl/test/sql/dist_hypertable.sql.in +++ b/tsl/test/sql/dist_hypertable.sql.in @@ -1073,3 +1073,49 @@ INSERT INTO devices VALUES (6, 'E999'); \set ON_ERROR_STOP 0 INSERT INTO hyper VALUES ('2017-01-01 06:01', 6, 1.1); \set ON_ERROR_STOP 1 + +-- Test alter replication factor with data + +SELECT * FROM test.remote_exec('{ data_node_1, data_node_2, data_node_3 }',$$ + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper'); +$$); + +SELECT * FROM set_replication_factor('hyper', 3); +INSERT INTO hyper VALUES ('2017-01-02 07:11', 1, 1.7); + +SELECT * FROM test.remote_exec('{ data_node_1, data_node_2, data_node_3 }',$$ + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper'); +$$); + +INSERT INTO hyper VALUES ('2017-02-01 06:01', 1, 5.1); + +SELECT * FROM test.remote_exec('{ data_node_1, data_node_2, data_node_3 }',$$ + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper'); +$$); + +SELECT * FROM set_replication_factor('hyper', 2); + +INSERT INTO hyper VALUES ('2017-03-01 06:01', 1, 15.1); + +SELECT * FROM test.remote_exec('{ data_node_1, data_node_2, data_node_3 }',$$ + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper'); +$$); + +SELECT * FROM set_replication_factor('hyper', replication_factor => 2); + +INSERT INTO hyper VALUES ('2017-04-01 06:01', 2, 45.1); + +SELECT * FROM test.remote_exec('{ data_node_1, data_node_2, data_node_3 }',$$ + SELECT (_timescaledb_internal.show_chunk(show_chunks)).* + FROM show_chunks('hyper'); +$$); + +DROP TABLE hyper; +SELECT * FROM distributed_exec($$ + DROP TABLE devices; +$$); +DROP TABLE devices;