Implement altering replication factor

Implements SQL function set_replication_factor, which changes
replication factor of a distributed hypertable. The change of the
replication factor doesn't affect existing chunks. Newly created
chunks are replicated according to new replication factor.
This commit is contained in:
Ruslan Fomkin 2020-01-15 10:58:58 +01:00 committed by Erik Nordström
parent d49e9a5739
commit c44a202576
15 changed files with 775 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,6 +7,8 @@
#include <postgres.h>
#include <catalog/pg_type.h>
#include <catalog/pg_proc.h>
#include <catalog/pg_inherits.h>
#include <funcapi.h>
#include <utils/builtins.h>
#include <utils/lsyscache.h>
#include <utils/syscache.h>
@ -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 <foreign/foreign.h>
@ -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 */

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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