Skip to content

Commit

Permalink
PG16: Prohibit use of multi-node
Browse files Browse the repository at this point in the history
Since multi-node is not supported on PG16, add errors to multi-node
functions when run on this PostgreSQL version.
  • Loading branch information
fabriziomello committed Oct 13, 2023
1 parent f12ed00 commit 27ba58a
Show file tree
Hide file tree
Showing 89 changed files with 13,745 additions and 13,485 deletions.
32 changes: 32 additions & 0 deletions sql/updates/pre-update.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,35 @@ WHERE
)
;

-- ERROR if trying to update the extension on PG16 using Multi-Node
DO $$
DECLARE
data_nodes TEXT;
dist_hypertables TEXT;
BEGIN
IF current_setting('server_version_num')::int >= 160000 THEN
SELECT string_agg(format('%I.%I', hypertable_schema, hypertable_name), ', ')
INTO dist_hypertables
FROM timescaledb_information.hypertables
WHERE is_distributed IS TRUE;

IF dist_hypertables IS NOT NULL THEN
RAISE USING
ERRCODE = 'feature_not_supported',
MESSAGE = 'cannot upgrade because multi-node is not supported on PostgreSQL >= 16',
DETAIL = 'The following distributed hypertables should be migrated to regular: '||dist_hypertables;
END IF;

SELECT string_agg(format('%I', node_name), ', ')
INTO data_nodes
FROM timescaledb_information.data_nodes;

IF data_nodes IS NOT NULL THEN
RAISE USING
ERRCODE = 'feature_not_supported',
MESSAGE = 'cannot upgrade because multi-node is not supported on PostgreSQL >= 16',
DETAIL = 'The following data nodes should be removed: '||data_nodes;
END IF;
END IF;
END $$;

13 changes: 13 additions & 0 deletions src/hypertable.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include "debug_assert.h"
#include "osm_callbacks.h"
#include "error_utils.h"
#include "compat/compat.h"

Oid
ts_rel_get_owner(Oid relid)
Expand Down Expand Up @@ -2046,6 +2047,18 @@ ts_hypertable_create(PG_FUNCTION_ARGS)
Datum
ts_hypertable_distributed_create(PG_FUNCTION_ARGS)
{
#if PG16_GE
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("distributed hypertable is not supported"),
errdetail("Multi-node is not supported anymore on PostgreSQL >= 16."),
errhint("Use the \"create_hypertable\" to create a regular hypertable instead.")));
#else
ereport(WARNING,
(errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
errmsg("distributed hypertable is deprecated"),
errdetail("Multi-node is deprecated and will be removed in future releases.")));
#endif
return ts_hypertable_create_time_prev(fcinfo, true);
}

Expand Down
70 changes: 70 additions & 0 deletions tsl/src/data_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,18 +857,52 @@ data_node_add_internal(PG_FUNCTION_ARGS, bool set_distid)
Datum
data_node_add(PG_FUNCTION_ARGS)
{
#if PG16_GE
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("adding data node is not supported"),
errdetail("Multi-node is not supported anymore on PostgreSQL >= 16.")));
#else
ereport(WARNING,
(errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
errmsg("adding data node is deprecated"),
errdetail("Multi-node is deprecated and will be removed in future releases.")));
#endif
return data_node_add_internal(fcinfo, true);
}

Datum
data_node_add_without_dist_id(PG_FUNCTION_ARGS)
{
#if PG16_GE
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("adding data node is not supported"),
errdetail("Multi-node is not supported anymore on PostgreSQL >= 16.")));
#else
ereport(WARNING,
(errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
errmsg("adding data node is deprecated"),
errdetail("Multi-node is deprecated and will be removed in future releases.")));
#endif
return data_node_add_internal(fcinfo, false);
}

Datum
data_node_attach(PG_FUNCTION_ARGS)
{
#if PG16_GE
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("attaching data node is not supported"),
errdetail("Multi-node is not supported anymore on PostgreSQL >= 16.")));
#else
ereport(WARNING,
(errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
errmsg("attaching data node is deprecated"),
errdetail("Multi-node is deprecated and will be removed in future releases.")));
#endif

const char *node_name = PG_ARGISNULL(0) ? NULL : PG_GETARG_CSTRING(0);
Oid table_id = PG_GETARG_OID(1);
bool if_not_attached = PG_ARGISNULL(2) ? false : PG_GETARG_BOOL(2);
Expand Down Expand Up @@ -1404,6 +1438,18 @@ data_node_block_new_chunks(PG_FUNCTION_ARGS)
Datum
data_node_detach(PG_FUNCTION_ARGS)
{
#if PG16_GE
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("detaching data node is not supported"),
errdetail("Multi-node is not supported anymore on PostgreSQL >= 16.")));
#else
ereport(WARNING,
(errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
errmsg("detaching data node is deprecated"),
errdetail("Multi-node is deprecated and will be removed in future releases.")));
#endif

const char *node_name = PG_ARGISNULL(0) ? NULL : NameStr(*PG_GETARG_NAME(0));
Oid table_id = PG_ARGISNULL(1) ? InvalidOid : PG_GETARG_OID(1);
bool all_hypertables = PG_ARGISNULL(1);
Expand Down Expand Up @@ -1601,6 +1647,18 @@ append_data_node_option(List *new_options, List **current_options, const char *n
Datum
data_node_alter(PG_FUNCTION_ARGS)
{
#if PG16_GE
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("altering data node is not supported"),
errdetail("Multi-node is not supported anymore on PostgreSQL >= 16.")));
#else
ereport(WARNING,
(errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
errmsg("altering data node is deprecated"),
errdetail("Multi-node is deprecated and will be removed in future releases.")));
#endif

const char *node_name = PG_ARGISNULL(0) ? NULL : NameStr(*PG_GETARG_NAME(0));
const char *host = PG_ARGISNULL(1) ? NULL : TextDatumGetCString(PG_GETARG_DATUM(1));
const char *database = PG_ARGISNULL(2) ? NULL : NameStr(*PG_GETARG_NAME(2));
Expand Down Expand Up @@ -1826,6 +1884,18 @@ drop_data_node_database(const ForeignServer *server)
Datum
data_node_delete(PG_FUNCTION_ARGS)
{
#if PG16_GE
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("deleting data node is not supported"),
errdetail("Multi-node is not supported anymore on PostgreSQL >= 16.")));
#else
ereport(WARNING,
(errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
errmsg("deleting data node is deprecated"),
errdetail("Multi-node is deprecated and will be removed in future releases.")));
#endif

const char *node_name = PG_ARGISNULL(0) ? NULL : PG_GETARG_CSTRING(0);
bool if_exists = PG_ARGISNULL(1) ? false : PG_GETARG_BOOL(1);
bool force = PG_ARGISNULL(2) ? false : PG_GETARG_BOOL(2);
Expand Down
12 changes: 12 additions & 0 deletions tsl/src/dist_backup.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ create_restore_point_datum(TupleDesc tupdesc, const char *node_name, XLogRecPtr
Datum
create_distributed_restore_point(PG_FUNCTION_ARGS)
{
#if PG16_GE
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("creating distributed restore point is not supported"),
errdetail("Multi-node is not supported anymore on PostgreSQL >= 16.")));
#else
ereport(WARNING,
(errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
errmsg("creating distributed restore point is deprecated"),
errdetail("Multi-node is deprecated and will be removed in future releases.")));
#endif

const char *name = TextDatumGetCString(PG_GETARG_DATUM(0));
DistCmdResult *result_cmd;
FuncCallContext *funcctx;
Expand Down
7 changes: 7 additions & 0 deletions tsl/src/remote/dist_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,13 @@ ts_dist_cmd_close_prepared_command(PreparedDistCmd *command)
Datum
ts_dist_cmd_exec(PG_FUNCTION_ARGS)
{
#if PG16_GE
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("distributed command execution is not supported"),
errdetail("Multi-node is not supported anymore on PostgreSQL >= 16.")));
#endif

const char *query = PG_ARGISNULL(0) ? NULL : TextDatumGetCString(PG_GETARG_DATUM(0));
ArrayType *data_nodes = PG_ARGISNULL(1) ? NULL : PG_GETARG_ARRAYTYPE_P(1);
bool transactional = PG_ARGISNULL(2) ? true : PG_GETARG_BOOL(2);
Expand Down
5 changes: 5 additions & 0 deletions tsl/test/expected/cagg_bgw_dist_ht.out
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ FROM (
SELECT (add_data_node(name, host => 'localhost', DATABASE => name)).*
FROM (VALUES (:'DATA_NODE_1'), (:'DATA_NODE_2'), (:'DATA_NODE_3')) v(name)
) a;
WARNING: adding data node is deprecated
WARNING: adding data node is deprecated
WARNING: adding data node is deprecated
node_name | database | node_created | database_created | extension_created
-----------------------+-----------------------+--------------+------------------+-------------------
db_cagg_bgw_dist_ht_1 | db_cagg_bgw_dist_ht_1 | t | t | t
Expand Down Expand Up @@ -120,6 +123,7 @@ psql:include/cagg_bgw_common.sql:76: WARNING: no privileges were granted for "p
CREATE TABLE test_continuous_agg_table(time int, data int);
\if :IS_DISTRIBUTED
SELECT create_distributed_hypertable('test_continuous_agg_table', 'time', chunk_time_interval => 10, replication_factor => 2);
psql:include/cagg_bgw_common.sql:80: WARNING: distributed hypertable is deprecated
psql:include/cagg_bgw_common.sql:80: NOTICE: adding not-null constraint to column "time"
create_distributed_hypertable
----------------------------------------
Expand Down Expand Up @@ -610,6 +614,7 @@ SELECT ts_bgw_params_reset_time();
CREATE TABLE test_continuous_agg_table_w_grant(time int, data int);
\if :IS_DISTRIBUTED
SELECT create_distributed_hypertable('test_continuous_agg_table_w_grant', 'time', chunk_time_interval => 10, replication_factor => 2);
psql:include/cagg_bgw_common.sql:330: WARNING: distributed hypertable is deprecated
psql:include/cagg_bgw_common.sql:330: NOTICE: adding not-null constraint to column "time"
create_distributed_hypertable
------------------------------------------------
Expand Down
Loading

0 comments on commit 27ba58a

Please sign in to comment.