Skip to content

Commit

Permalink
Remove multinode functions from crossmodule struct
Browse files Browse the repository at this point in the history
This commit removes the multinode specific entries from the cross
module function struct. It also removes the function
set_chunk_default_data_node
  • Loading branch information
svenklemm committed Dec 14, 2023
1 parent 4b51b8c commit 06867af
Show file tree
Hide file tree
Showing 25 changed files with 61 additions and 2,002 deletions.
4 changes: 0 additions & 4 deletions sql/chunk.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ CREATE OR REPLACE FUNCTION _timescaledb_functions.create_chunk(
RETURNS TABLE(chunk_id INTEGER, hypertable_id INTEGER, schema_name NAME, table_name NAME, relkind "char", slices JSONB, created BOOLEAN)
AS '@MODULE_PATHNAME@', 'ts_chunk_create' LANGUAGE C VOLATILE;

-- change default data node for a chunk
CREATE OR REPLACE FUNCTION _timescaledb_functions.set_chunk_default_data_node(chunk REGCLASS, node_name NAME) RETURNS BOOLEAN
AS '@MODULE_PATHNAME@', 'ts_chunk_set_default_data_node' LANGUAGE C VOLATILE;

-- Get chunk stats.
CREATE OR REPLACE FUNCTION _timescaledb_functions.get_chunk_relstats(relid REGCLASS)
RETURNS TABLE(chunk_id INTEGER, hypertable_id INTEGER, num_pages INTEGER, num_tuples REAL, num_allvisible INTEGER)
Expand Down
10 changes: 0 additions & 10 deletions sql/compat.sql
Original file line number Diff line number Diff line change
Expand Up @@ -638,16 +638,6 @@ END$$
SET search_path TO pg_catalog,pg_temp;


CREATE OR REPLACE FUNCTION _timescaledb_internal.set_chunk_default_data_node(chunk regclass,node_name name) RETURNS boolean LANGUAGE PLPGSQL AS $$
BEGIN
IF current_setting('timescaledb.enable_deprecation_warnings', true)::bool THEN
RAISE WARNING 'function _timescaledb_internal.set_chunk_default_data_node(regclass,name) is deprecated and has been moved to _timescaledb_functions schema. this compatibility function will be removed in a future version.';
END IF;
RETURN _timescaledb_functions.set_chunk_default_data_node($1,$2);
END$$
SET search_path TO pg_catalog,pg_temp;


CREATE OR REPLACE FUNCTION _timescaledb_internal.show_chunk(chunk regclass) RETURNS TABLE(chunk_id INTEGER, hypertable_id INTEGER, schema_name NAME, table_name NAME, relkind "char", slices JSONB) LANGUAGE PLPGSQL AS $$
BEGIN
IF current_setting('timescaledb.enable_deprecation_warnings', true)::bool THEN
Expand Down
5 changes: 4 additions & 1 deletion sql/updates/2.10.1--2.10.2.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
DROP FUNCTION _timescaledb_internal.ping_data_node(NAME);

-- We only create stub here to not introduce shared library dependencies in update chains
-- the proper function definition will be created at end of update script when all functions
-- are recreated.
CREATE OR REPLACE FUNCTION _timescaledb_internal.ping_data_node(node_name NAME, timeout INTERVAL = NULL) RETURNS BOOLEAN
AS '@MODULE_PATHNAME@', 'ts_data_node_ping' LANGUAGE C VOLATILE;
AS $$SELECT false;$$ LANGUAGE SQL VOLATILE;

-- drop dependent views
DROP VIEW IF EXISTS timescaledb_information.job_errors;
Expand Down
3 changes: 2 additions & 1 deletion sql/updates/2.11.2--2.12.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ ALTER FUNCTION _timescaledb_internal.calculate_chunk_interval(int, bigint, bigin
ALTER FUNCTION _timescaledb_internal.chunks_in(record, integer[]) SET SCHEMA _timescaledb_functions;
ALTER FUNCTION _timescaledb_internal.chunk_id_from_relid(oid) SET SCHEMA _timescaledb_functions;
ALTER FUNCTION _timescaledb_internal.show_chunk(regclass) SET SCHEMA _timescaledb_functions;
ALTER FUNCTION _timescaledb_internal.set_chunk_default_data_node(regclass, name) SET SCHEMA _timescaledb_functions;
ALTER FUNCTION _timescaledb_internal.get_chunk_relstats(regclass) SET SCHEMA _timescaledb_functions;
ALTER FUNCTION _timescaledb_internal.get_chunk_colstats(regclass) SET SCHEMA _timescaledb_functions;

Expand Down Expand Up @@ -129,6 +128,8 @@ DECLARE
alter_job_set_hypertable_id,
set_chunk_default_data_node,
create_compressed_chunk, get_compressed_chunk_index_for_recompression, recompress_chunk_segmentwise,
chunk_drop_replica, chunk_index_clone, chunk_index_replace, create_chunk_replica_table, drop_stale_chunks,
chunk_constraint_add_table_constraint, hypertable_constraint_add_table_fk_constraint,
Expand Down
3 changes: 2 additions & 1 deletion sql/updates/2.5.2--2.6.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_aggs

DROP VIEW IF EXISTS timescaledb_information.continuous_aggregates;

-- create stub to not introduce shared library dependency
CREATE FUNCTION @[email protected]_data_node(
node_name NAME,
if_exists BOOLEAN = FALSE,
force BOOLEAN = FALSE,
repartition BOOLEAN = TRUE,
drop_database BOOLEAN = FALSE
) RETURNS BOOLEAN AS '@MODULE_PATHNAME@', 'ts_data_node_delete' LANGUAGE C VOLATILE;
) RETURNS BOOLEAN AS $$SELECT true;$$ LANGUAGE SQL VOLATILE;

CREATE FUNCTION @[email protected]_telemetry_report() RETURNS jsonb
AS '@MODULE_PATHNAME@', 'ts_telemetry_get_report_jsonb'
Expand Down
8 changes: 4 additions & 4 deletions sql/updates/2.8.1--2.9.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ GRANT SELECT ON _timescaledb_catalog.dimension TO PUBLIC;

-- end recreate _timescaledb_catalog.dimension table --

-- changes related to alter_data_node():
-- only creating stub here to not introduce shared library dependencies
CREATE INDEX chunk_data_node_node_name_idx ON _timescaledb_catalog.chunk_data_node (node_name);
CREATE FUNCTION @[email protected]_data_node(
node_name NAME,
Expand All @@ -389,7 +389,7 @@ CREATE FUNCTION @[email protected]_data_node(
port INTEGER = NULL,
available BOOLEAN = NULL
) RETURNS TABLE(node_name NAME, host TEXT, port INTEGER, database NAME, available BOOLEAN)
AS '@MODULE_PATHNAME@', 'ts_data_node_alter' LANGUAGE C VOLATILE;
AS $$ SELECT NULL::name,NULL::text,NULL::int,NULL::name,NULL::bool; $$ LANGUAGE SQL VOLATILE;

--
-- Rebuild the catalog table `_timescaledb_catalog.continuous_agg`
Expand Down Expand Up @@ -488,9 +488,9 @@ ALTER TABLE _timescaledb_catalog.continuous_agg_migrate_plan

ANALYZE _timescaledb_catalog.continuous_agg;

-- changes related to drop_stale_chunks()
-- only create stub here to not introduce shared library dependency
CREATE FUNCTION _timescaledb_internal.drop_stale_chunks(
node_name NAME,
chunks integer[] = NULL
) RETURNS VOID
AS '@MODULE_PATHNAME@', 'ts_chunks_drop_stale' LANGUAGE C VOLATILE;
AS '' LANGUAGE SQL VOLATILE;
3 changes: 3 additions & 0 deletions sql/updates/latest-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,6 @@ DROP PROCEDURE IF EXISTS timescaledb_experimental.move_chunk;
DROP PROCEDURE IF EXISTS timescaledb_experimental.copy_chunk;
DROP PROCEDURE IF EXISTS timescaledb_experimental.cleanup_copy_chunk_operation;

DROP FUNCTION IF EXISTS _timescaledb_functions.set_chunk_default_data_node;
DROP FUNCTION IF EXISTS _timescaledb_internal.set_chunk_default_data_node;

4 changes: 4 additions & 0 deletions sql/updates/reverse-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,7 @@ CREATE PROCEDURE timescaledb_experimental.cleanup_copy_chunk_operation(
operation_id NAME)
AS '@MODULE_PATHNAME@', 'ts_copy_chunk_cleanup_proc' LANGUAGE C;

CREATE FUNCTION _timescaledb_functions.set_chunk_default_data_node(chunk REGCLASS, node_name NAME) RETURNS BOOLEAN
AS '@MODULE_PATHNAME@', 'ts_chunk_set_default_data_node' LANGUAGE C VOLATILE;


43 changes: 0 additions & 43 deletions src/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,46 +806,6 @@ ts_chunk_create_table(const Chunk *chunk, const Hypertable *ht, const char *tabl
if (uid != saved_uid)
SetUserIdAndSecContext(saved_uid, sec_ctx);
}
else if (chunk->relkind == RELKIND_FOREIGN_TABLE)
{
ChunkDataNode *cdn;

if (list_length(chunk->data_nodes) == 0)
ereport(ERROR,
(errcode(ERRCODE_TS_INSUFFICIENT_NUM_DATA_NODES),
(errmsg("no data nodes associated with chunk \"%s\"",
get_rel_name(chunk->table_id)))));

/*
* Use the first chunk data node as the "primary" to put in the foreign
* table
*/
cdn = linitial(chunk->data_nodes);
stmt.base.type = T_CreateForeignServerStmt;
stmt.servername = NameStr(cdn->fd.node_name);

/* Create the foreign table catalog information */
CreateForeignTable(&stmt, objaddr.objectId);

/*
* Some options require being table owner to set for example statistics
* so we have to set them before restoring security context
*/
set_attoptions(rel, objaddr.objectId);

/*
* Need to restore security context to execute remote commands as the
* original user
*/
if (uid != saved_uid)
SetUserIdAndSecContext(saved_uid, sec_ctx);

/* Create the corresponding chunk replicas on the remote data nodes */
ts_cm_functions->create_chunk_on_data_nodes(chunk, ht, NULL, NIL);

/* Record the remote data node chunk ID mappings */
ts_chunk_data_node_insert_multi(chunk->data_nodes);
}
else
elog(ERROR, "invalid relkind \"%c\" when creating chunk", chunk->relkind);

Expand Down Expand Up @@ -4455,9 +4415,6 @@ ts_chunk_drop_chunks(PG_FUNCTION_ARGS)

MemoryContextSwitchTo(oldcontext);

if (data_node_oids != NIL)
ts_cm_functions->func_call_on_data_nodes(fcinfo, data_node_oids);

/* store data for multi function call */
funcctx->max_calls = list_length(dc_names);
funcctx->user_fctx = dc_names;
Expand Down
134 changes: 0 additions & 134 deletions src/cross_module_fn.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,51 +89,16 @@ CROSSMODULE_WRAPPER(invalidation_process_hypertable_log);
CROSSMODULE_WRAPPER(invalidation_process_cagg_log);
CROSSMODULE_WRAPPER(cagg_try_repair);

CROSSMODULE_WRAPPER(data_node_ping);
CROSSMODULE_WRAPPER(data_node_block_new_chunks);
CROSSMODULE_WRAPPER(data_node_allow_new_chunks);
CROSSMODULE_WRAPPER(data_node_add);
CROSSMODULE_WRAPPER(data_node_delete);
CROSSMODULE_WRAPPER(data_node_attach);
CROSSMODULE_WRAPPER(data_node_detach);
CROSSMODULE_WRAPPER(data_node_alter);
CROSSMODULE_WRAPPER(chunk_drop_replica);
CROSSMODULE_WRAPPER(chunk_freeze_chunk);
CROSSMODULE_WRAPPER(chunk_unfreeze_chunk);
CROSSMODULE_WRAPPER(chunks_drop_stale);

CROSSMODULE_WRAPPER(chunk_set_default_data_node);
CROSSMODULE_WRAPPER(chunk_get_relstats);
CROSSMODULE_WRAPPER(chunk_get_colstats);
CROSSMODULE_WRAPPER(chunk_create_empty_table);
CROSSMODULE_WRAPPER(chunk_create_replica_table);

CROSSMODULE_WRAPPER(recompress_chunk_segmentwise);
CROSSMODULE_WRAPPER(get_compressed_chunk_index_for_recompression);

TS_FUNCTION_INFO_V1(ts_dist_set_id);
Datum
ts_dist_set_id(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(ts_cm_functions->set_distributed_id(PG_GETARG_DATUM(0)));
}

TS_FUNCTION_INFO_V1(ts_dist_set_peer_id);
Datum
ts_dist_set_peer_id(PG_FUNCTION_ARGS)
{
ts_cm_functions->set_distributed_peer_id(PG_GETARG_DATUM(0));
PG_RETURN_VOID();
}

TS_FUNCTION_INFO_V1(ts_dist_validate_as_data_node);
Datum
ts_dist_validate_as_data_node(PG_FUNCTION_ARGS)
{
ts_cm_functions->validate_as_data_node();
PG_RETURN_VOID();
}

/*
* casting a function pointer to a pointer of another type is undefined
* behavior, so we need one of these for every function type we have
Expand Down Expand Up @@ -254,21 +219,6 @@ process_cagg_try_repair(PG_FUNCTION_ARGS)
pg_unreachable();
}

static void
hypertable_make_distributed_default_fn(Hypertable *ht, List *data_node_names)
{
error_no_default_fn_community();
}

static List *
get_and_validate_data_node_list_default_fn(ArrayType *nodearr)
{
error_no_default_fn_community();
pg_unreachable();

return NIL;
}

static void
cache_syscache_invalidate_default(Datum arg, int cacheid, uint32 hashvalue)
{
Expand Down Expand Up @@ -315,45 +265,6 @@ continuous_agg_call_invalidation_trigger_default(int32 hypertable_id, Relation c
pg_unreachable();
}

static Datum
empty_fn(PG_FUNCTION_ARGS)
{
PG_RETURN_VOID();
}

static void
create_chunk_on_data_nodes_default(const Chunk *chunk, const Hypertable *ht,
const char *remote_chunk_name, List *data_nodes)
{
error_no_default_fn_community();
}

static bool
set_distributed_id_default(Datum d)
{
return error_no_default_fn_bool_void_community();
}

static void
set_distributed_peer_id_default(Datum d)
{
error_no_default_fn_community();
}

static void
func_call_on_data_nodes_default(FunctionCallInfo finfo, List *data_node_oids)
{
error_no_default_fn_community();
pg_unreachable();
}

static void
dist_update_stale_chunk_metadata_default(Chunk *new_chunk, List *chunk_data_nodes)
{
error_no_default_fn_community();
pg_unreachable();
}

TS_FUNCTION_INFO_V1(ts_tsl_loaded);

PGDLLEXPORT Datum
Expand All @@ -362,13 +273,6 @@ ts_tsl_loaded(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(ts_cm_functions != &ts_cm_functions_default);
}

static void
mn_get_foreign_join_path_default_fn_pg_community(PlannerInfo *root, RelOptInfo *joinrel,
RelOptInfo *outerrel, RelOptInfo *innerrel,
JoinType jointype, JoinPathExtraData *extra)
{
}

/*
* Define cross-module functions' default values:
* If the submodule isn't activated, using one of the cm functions will throw an
Expand Down Expand Up @@ -441,9 +345,7 @@ TSDLLEXPORT CrossModuleFunctions ts_cm_functions_default = {
.continuous_agg_validate_query = error_no_default_fn_pg_community,
.invalidation_cagg_log_add_entry = error_no_default_fn_pg_community,
.invalidation_hyper_log_add_entry = error_no_default_fn_pg_community,
.remote_invalidation_log_delete = NULL,
.drop_dist_ht_invalidation_trigger = error_no_default_fn_pg_community,
.remote_drop_dist_ht_invalidation_trigger = NULL,
.invalidation_process_hypertable_log = error_no_default_fn_pg_community,
.invalidation_process_cagg_log = error_no_default_fn_pg_community,
.cagg_try_repair = process_cagg_try_repair,
Expand All @@ -468,52 +370,16 @@ TSDLLEXPORT CrossModuleFunctions ts_cm_functions_default = {
.array_compressor_append = error_no_default_fn_pg_community,
.array_compressor_finish = error_no_default_fn_pg_community,

.data_node_add = error_no_default_fn_pg_community,
.data_node_delete = error_no_default_fn_pg_community,
.data_node_attach = error_no_default_fn_pg_community,
.data_node_ping = error_no_default_fn_pg_community,
.data_node_detach = error_no_default_fn_pg_community,
.data_node_alter = error_no_default_fn_pg_community,
.data_node_allow_new_chunks = error_no_default_fn_pg_community,
.data_node_block_new_chunks = error_no_default_fn_pg_community,
.distributed_exec = error_no_default_fn_pg_community,
.create_distributed_restore_point = error_no_default_fn_pg_community,
.chunk_set_default_data_node = error_no_default_fn_pg_community,
.show_chunk = error_no_default_fn_pg_community,
.create_chunk = error_no_default_fn_pg_community,
.create_chunk_on_data_nodes = create_chunk_on_data_nodes_default,
.chunk_drop_replica = error_no_default_fn_pg_community,
.chunk_freeze_chunk = error_no_default_fn_pg_community,
.chunk_unfreeze_chunk = error_no_default_fn_pg_community,
.chunks_drop_stale = error_no_default_fn_pg_community,
.hypertable_make_distributed = hypertable_make_distributed_default_fn,
.get_and_validate_data_node_list = get_and_validate_data_node_list_default_fn,
.timescaledb_fdw_handler = error_no_default_fn_pg_community,
.timescaledb_fdw_validator = empty_fn,
.cache_syscache_invalidate = cache_syscache_invalidate_default,
.remote_txn_id_in = error_no_default_fn_pg_community,
.remote_txn_id_out = error_no_default_fn_pg_community,
.remote_txn_heal_data_node = error_no_default_fn_pg_community,
.remote_connection_cache_show = error_no_default_fn_pg_community,
.set_distributed_id = set_distributed_id_default,
.set_distributed_peer_id = set_distributed_peer_id_default,
.is_access_node_session = error_no_default_fn_bool_void_community,
.remove_from_distributed_db = error_no_default_fn_bool_void_community,
.dist_remote_hypertable_info = error_no_default_fn_pg_community,
.dist_remote_chunk_info = error_no_default_fn_pg_community,
.dist_remote_compressed_chunk_info = error_no_default_fn_pg_community,
.dist_remote_hypertable_index_info = error_no_default_fn_pg_community,
.dist_update_stale_chunk_metadata = dist_update_stale_chunk_metadata_default,
.validate_as_data_node = error_no_default_fn_community,
.func_call_on_data_nodes = func_call_on_data_nodes_default,
.chunk_get_relstats = error_no_default_fn_pg_community,
.chunk_get_colstats = error_no_default_fn_pg_community,
.chunk_create_empty_table = error_no_default_fn_pg_community,
.chunk_create_replica_table = error_no_default_fn_pg_community,
.hypertable_distributed_set_replication_factor = error_no_default_fn_pg_community,
.recompress_chunk_segmentwise = error_no_default_fn_pg_community,
.get_compressed_chunk_index_for_recompression = error_no_default_fn_pg_community,
.mn_get_foreign_join_paths = mn_get_foreign_join_path_default_fn_pg_community,
};

TSDLLEXPORT CrossModuleFunctions *ts_cm_functions = &ts_cm_functions_default;
Loading

0 comments on commit 06867af

Please sign in to comment.