Skip to content

Commit

Permalink
Rename server to data node
Browse files Browse the repository at this point in the history
The timescale clustering code so far has been written referring to the
remote databases as 'servers'.  This terminology is a bit overloaded,
and in particular we don't enforce any network topology limitations
that the term 'server' would suggest.  In light of this we've decided
to change to use the term 'node' when referring to the different
databases in a distributed database.  Specifically we refer to the
frontend as an 'access node' and to the backends as 'data nodes',
though we may omit the access or data qualifier where it's unambiguous.

As the vast bulk of the code so far has been written for the case where
there was a single access node, almost all instances of 'server' were
references to data nodes.  This change has updated the code to rename
those instances.
  • Loading branch information
Brian Rowe authored and erimatnor committed May 27, 2020
1 parent dd3847a commit 79fb464
Show file tree
Hide file tree
Showing 113 changed files with 4,251 additions and 4,223 deletions.
12 changes: 6 additions & 6 deletions sql/data_node.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.

-- Check if server is up
CREATE FUNCTION _timescaledb_internal.server_ping(server_name NAME) RETURNS BOOLEAN
AS '@MODULE_PATHNAME@', 'ts_server_ping' LANGUAGE C VOLATILE;
-- Check if a data node is up
CREATE FUNCTION _timescaledb_internal.ping_data_node(node_name NAME) RETURNS BOOLEAN
AS '@MODULE_PATHNAME@', 'ts_data_node_ping' LANGUAGE C VOLATILE;

-- change default server for a chunk
CREATE OR REPLACE FUNCTION _timescaledb_internal.set_chunk_default_server(schema_name NAME, chunk_table_name NAME, server_name NAME) RETURNS BOOLEAN
AS '@MODULE_PATHNAME@', 'ts_set_chunk_default_server' LANGUAGE C VOLATILE;
-- Change the default data node for a chunk
CREATE OR REPLACE FUNCTION _timescaledb_internal.set_chunk_default_data_node(schema_name NAME, chunk_table_name NAME, node_name NAME) RETURNS BOOLEAN
AS '@MODULE_PATHNAME@', 'ts_set_chunk_default_data_node' LANGUAGE C VOLATILE;
60 changes: 31 additions & 29 deletions sql/ddl_api.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
-- chunk_sizing_func - (Optional) A function to calculate the chunk time interval for new chunks
-- time_partitioning_func - (Optional) The partitioning function to use for "time" partitioning
-- replication_factor - (Optional) A value of 1 or greater makes this hypertable distributed
-- servers - (Optional) The specific servers to distribute this hypertable across
-- data_nodes - (Optional) The specific data nodes to distribute this hypertable across
CREATE OR REPLACE FUNCTION create_hypertable(
main_table REGCLASS,
time_column_name NAME,
Expand All @@ -38,7 +38,7 @@ CREATE OR REPLACE FUNCTION create_hypertable(
chunk_sizing_func REGPROC = '_timescaledb_internal.calculate_chunk_interval'::regproc,
time_partitioning_func REGPROC = NULL,
replication_factor INTEGER = NULL,
servers NAME[] = NULL
data_nodes NAME[] = NULL
) RETURNS TABLE(hypertable_id INT, schema_name NAME, table_name NAME, created BOOL) AS '@MODULE_PATHNAME@', 'ts_hypertable_create' LANGUAGE C VOLATILE;

-- Same functionality as create_hypertable, only must have a replication factor > 0 (defaults to 1)
Expand All @@ -58,7 +58,7 @@ CREATE OR REPLACE FUNCTION create_distributed_hypertable(
chunk_sizing_func REGPROC = '_timescaledb_internal.calculate_chunk_interval'::regproc,
time_partitioning_func REGPROC = NULL,
replication_factor INTEGER = 1,
servers NAME[] = NULL
data_nodes NAME[] = NULL
) RETURNS TABLE(hypertable_id INT, schema_name NAME, table_name NAME, created BOOL) AS '@MODULE_PATHNAME@', 'ts_hypertable_distributed_create' LANGUAGE C VOLATILE;

-- Set adaptive chunking. To disable, set chunk_target_size => 'off'.
Expand Down Expand Up @@ -157,10 +157,10 @@ AS '@MODULE_PATHNAME@', 'ts_tablespace_detach_all_from_hypertable' LANGUAGE C VO
CREATE OR REPLACE FUNCTION show_tablespaces(hypertable REGCLASS) RETURNS SETOF NAME
AS '@MODULE_PATHNAME@', 'ts_tablespace_show' LANGUAGE C VOLATILE STRICT;

-- Add a server to a TimescaleDB cluster. This also add a
-- Add a data node to a TimescaleDB distributed database. This also add a
-- corresponding user mapping, if one does not already exist.
CREATE OR REPLACE FUNCTION add_server(
server_name NAME,
CREATE OR REPLACE FUNCTION add_data_node(
node_name NAME,
host TEXT = 'localhost',
database NAME = current_database(),
port INTEGER = inet_server_port(),
Expand All @@ -171,33 +171,35 @@ CREATE OR REPLACE FUNCTION add_server(
bootstrap_database NAME = 'postgres',
bootstrap_user NAME = NULL,
bootstrap_password TEXT = NULL
) RETURNS TABLE(server_name NAME, host TEXT, port INTEGER, database NAME, username NAME, server_username NAME, created BOOL)
AS '@MODULE_PATHNAME@', 'ts_server_add' LANGUAGE C VOLATILE;
) RETURNS TABLE(node_name NAME, host TEXT, port INTEGER, database NAME, username NAME, node_username NAME, created BOOL)
AS '@MODULE_PATHNAME@', 'ts_data_node_add' LANGUAGE C VOLATILE;

-- Delete a server from a TimescaleDB cluster
CREATE OR REPLACE FUNCTION delete_server(
server_name NAME,
-- Delete a data node from the distributed database
CREATE OR REPLACE FUNCTION delete_data_node(
node_name NAME,
if_exists BOOLEAN = FALSE,
cascade BOOLEAN = FALSE,
force BOOLEAN = FALSE
) RETURNS BOOLEAN AS '@MODULE_PATHNAME@', 'ts_server_delete' LANGUAGE C VOLATILE;
) RETURNS BOOLEAN AS '@MODULE_PATHNAME@', 'ts_data_node_delete' LANGUAGE C VOLATILE;

-- Attach a server to a hypertable
CREATE OR REPLACE FUNCTION attach_server(
-- Attach a data node to a distributed hypertable
CREATE OR REPLACE FUNCTION attach_data_node(
hypertable REGCLASS,
server_name NAME,
node_name NAME,
if_not_attached BOOLEAN = FALSE
) RETURNS TABLE(hypertable_id INTEGER, server_hypertable_id INTEGER, server_name NAME)
AS '@MODULE_PATHNAME@', 'ts_server_attach' LANGUAGE C VOLATILE;

-- Detach a server from a hypertable. NULL hypertable means it will do detach for all
CREATE OR REPLACE FUNCTION detach_server(server_name NAME, hypertable REGCLASS = NULL, force BOOLEAN = FALSE) RETURNS INTEGER
AS '@MODULE_PATHNAME@', 'ts_server_detach' LANGUAGE C VOLATILE;

-- Block new chunks on a server. NULL hypertable means it will block chunks for all hypertables
CREATE OR REPLACE FUNCTION block_new_chunks_on_server(server_name NAME, hypertable REGCLASS = NULL, force BOOLEAN = FALSE) RETURNS INTEGER
AS '@MODULE_PATHNAME@', 'ts_server_block_new_chunks' LANGUAGE C VOLATILE;

-- Allow new chunks on a server. NULL hypertable means it will allow chunks for all hypertables
CREATE OR REPLACE FUNCTION allow_new_chunks_on_server(server_name NAME, hypertable REGCLASS = NULL) RETURNS INTEGER
AS '@MODULE_PATHNAME@', 'ts_server_allow_new_chunks' LANGUAGE C VOLATILE;
) RETURNS TABLE(hypertable_id INTEGER, node_hypertable_id INTEGER, node_name NAME)
AS '@MODULE_PATHNAME@', 'ts_data_node_attach' LANGUAGE C VOLATILE;

-- Detach a data node from a distributed hypertable. NULL hypertable means it will detach from all distributed hypertables
CREATE OR REPLACE FUNCTION detach_data_node(node_name NAME, hypertable REGCLASS = NULL, force BOOLEAN = FALSE) RETURNS INTEGER
AS '@MODULE_PATHNAME@', 'ts_data_node_detach' LANGUAGE C VOLATILE;

-- Block new chunk creation on a data node for a distributed hypertable. NULL hypertable means it will block
-- chunks for all distributed hypertables
CREATE OR REPLACE FUNCTION block_new_chunks(data_node_name NAME, hypertable REGCLASS = NULL, force BOOLEAN = FALSE) RETURNS INTEGER
AS '@MODULE_PATHNAME@', 'ts_data_node_block_new_chunks' LANGUAGE C VOLATILE;

-- Reallow chunk creations on a blocked data node for a distributed hypertable. NULL hypertable means it will
-- allow chunks for all distributed hypertables
CREATE OR REPLACE FUNCTION allow_new_chunks(data_node_name NAME, hypertable REGCLASS = NULL) RETURNS INTEGER
AS '@MODULE_PATHNAME@', 'ts_data_node_allow_new_chunks' LANGUAGE C VOLATILE;
4 changes: 2 additions & 2 deletions sql/dist_internal.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ AS '@MODULE_PATHNAME@', 'ts_dist_remove_id' LANGUAGE C VOLATILE STRICT;
CREATE OR REPLACE FUNCTION _timescaledb_internal.set_peer_dist_id(dist_id UUID) RETURNS BOOL
AS '@MODULE_PATHNAME@', 'ts_dist_set_peer_id' LANGUAGE C VOLATILE STRICT;

CREATE OR REPLACE FUNCTION server_hypertable_info(
server_name NAME
CREATE OR REPLACE FUNCTION data_node_hypertable_info(
node_name NAME
)
RETURNS TABLE (id int,
table_schema name,
Expand Down
32 changes: 16 additions & 16 deletions sql/pre_install/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ CREATE TABLE IF NOT EXISTS _timescaledb_catalog.hypertable (
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.hypertable', '');
SELECT pg_catalog.pg_extension_config_dump(pg_get_serial_sequence('_timescaledb_catalog.hypertable','id'), '');

CREATE TABLE IF NOT EXISTS _timescaledb_catalog.hypertable_server (
CREATE TABLE IF NOT EXISTS _timescaledb_catalog.hypertable_data_node (
hypertable_id INTEGER NOT NULL REFERENCES _timescaledb_catalog.hypertable(id),
server_hypertable_id INTEGER NULL,
server_name NAME NOT NULL,
node_hypertable_id INTEGER NULL,
node_name NAME NOT NULL,
block_chunks BOOLEAN NOT NULL,
UNIQUE (server_hypertable_id, server_name),
UNIQUE (hypertable_id, server_name)
UNIQUE (node_hypertable_id, node_name),
UNIQUE (hypertable_id, node_name)
);
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.hypertable_server', '');
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.hypertable_data_node', '');

-- The tablespace table maps tablespaces to hypertables.
-- This allows spreading a hypertable's chunks across multiple disks.
Expand Down Expand Up @@ -173,14 +173,14 @@ CREATE INDEX IF NOT EXISTS chunk_index_hypertable_id_hypertable_index_name_idx
ON _timescaledb_catalog.chunk_index(hypertable_id, hypertable_index_name);
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.chunk_index', '');

CREATE TABLE IF NOT EXISTS _timescaledb_catalog.chunk_server (
CREATE TABLE IF NOT EXISTS _timescaledb_catalog.chunk_data_node (
chunk_id INTEGER NOT NULL REFERENCES _timescaledb_catalog.chunk(id),
server_chunk_id INTEGER NOT NULL,
server_name NAME NOT NULL,
UNIQUE (server_chunk_id, server_name),
UNIQUE (chunk_id, server_name)
node_chunk_id INTEGER NOT NULL,
node_name NAME NOT NULL,
UNIQUE (node_chunk_id, node_name),
UNIQUE (chunk_id, node_name)
);
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.chunk_server', '');
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.chunk_data_node', '');

-- Default jobs are given the id space [1,1000). User-installed jobs and any jobs created inside tests
-- are given the id space [1000, INT_MAX). That way, we do not pg_dump jobs that are always default-installed
Expand Down Expand Up @@ -373,17 +373,17 @@ CREATE TABLE IF NOT EXISTS _timescaledb_config.bgw_policy_compress_chunks(
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_config.bgw_policy_compress_chunks', '');

--This stores commit decisions for 2pc remote txns. Abort decisions are never stored.
--If a PREPARE TRANSACTION fails for any server then the entire
--If a PREPARE TRANSACTION fails for any data node then the entire
--frontend transaction will be rolled back and no rows will be stored.
--the frontend_transaction_id represents the entire distributed transaction
--each datanode will have a unique remote_transaction_id.
CREATE TABLE _timescaledb_catalog.remote_txn (
server_name NAME, --this is really only to allow us to cleanup stuff on a per-server basis.
data_node_name NAME, --this is really only to allow us to cleanup stuff on a per-node basis.
remote_transaction_id TEXT CHECK (remote_transaction_id::rxid is not null),
PRIMARY KEY (remote_transaction_id)
);
CREATE INDEX IF NOT EXISTS remote_txn_server_name_idx
ON _timescaledb_catalog.remote_txn(server_name);
CREATE INDEX IF NOT EXISTS remote_txn_data_node_name_idx
ON _timescaledb_catalog.remote_txn(data_node_name);
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.remote_txn', '');

-- Set table permissions
Expand Down
4 changes: 2 additions & 2 deletions sql/remote_txn.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.

CREATE FUNCTION _timescaledb_internal.remote_txn_heal_server(foreign_server_oid oid)
CREATE FUNCTION _timescaledb_internal.remote_txn_heal_data_node(foreign_server_oid oid)
RETURNS INT
AS '@MODULE_PATHNAME@', 'ts_remote_txn_heal_server'
AS '@MODULE_PATHNAME@', 'ts_remote_txn_heal_data_node'
LANGUAGE C STRICT;
40 changes: 20 additions & 20 deletions sql/size_utils.sql
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ BEGIN
sum(entry.total_bytes)::bigint AS total_bytes
FROM (
SELECT
s.server_name,
_timescaledb_internal.server_ping (server_name) AS server_up
s.node_name,
_timescaledb_internal.ping_data_node (node_name) AS node_up
FROM
_timescaledb_catalog.hypertable AS ht,
_timescaledb_catalog.hypertable_server AS s
_timescaledb_catalog.hypertable_data_node AS s
WHERE
ht.schema_name = schema_name_in
AND ht.table_name = table_name_in
AND s.hypertable_id = ht.id
) AS srv
LEFT OUTER JOIN LATERAL @extschema@.server_hypertable_info(
CASE WHEN srv.server_up THEN
srv.server_name
LEFT OUTER JOIN LATERAL @extschema@.data_node_hypertable_info(
CASE WHEN srv.node_up THEN
srv.node_name
ELSE
NULL
END) entry ON TRUE
Expand Down Expand Up @@ -215,24 +215,24 @@ END;
$BODY$;


-- Get the per-server relation size of a distributed hypertable across all servers in a distributed database
-- Get the per-node relation size of a distributed hypertable across all nodes in a distributed database
-- like pg_relation_size(hypertable)
-- (https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADMIN-DBSIZE)
--
-- main_table - hypertable to get size of
--
-- Returns:
-- server_name - Server hosting part of the table
-- num_chunks - Number of chunks hosted on the server
-- table_size - Pretty output of table_bytes for the server
-- index_bytes - Pretty output of index_bytes for the server
-- toast_bytes - Pretty output of toast_bytes for the server
-- total_size - Pretty output of total_bytes for the server

CREATE OR REPLACE FUNCTION hypertable_server_relation_size(
-- node_name - Data node hosting part of the table
-- num_chunks - Number of chunks hosted on the data node
-- table_size - Pretty output of table_bytes for the data node
-- index_bytes - Pretty output of index_bytes for the data node
-- toast_bytes - Pretty output of toast_bytes for the data node
-- total_size - Pretty output of total_bytes for the data node

CREATE OR REPLACE FUNCTION hypertable_data_node_relation_size(
main_table REGCLASS
)
RETURNS TABLE (server_name NAME,
RETURNS TABLE (node_name NAME,
num_chunks BIGINT,
table_size TEXT,
index_size TEXT,
Expand All @@ -251,19 +251,19 @@ BEGIN
WHERE c.OID = main_table;

IF NOT (SELECT distributed FROM timescaledb_information.hypertable ht WHERE ht.table_name = local_table_name AND ht.table_schema = local_schema_name)
THEN RAISE NOTICE 'calling hypertable_server_relation_size on a non-distributed hypertable';
THEN RAISE NOTICE 'calling hypertable_data_node_relation_size on a non-distributed hypertable';
END IF;

RETURN QUERY EXECUTE format(
$$
SELECT s.server_name as server,
SELECT s.node_name as node,
size.num_chunks as chunks,
pg_size_pretty(table_bytes) as table,
pg_size_pretty(index_bytes) as index,
pg_size_pretty(toast_bytes) as toast,
pg_size_pretty(total_bytes) as total
FROM timescaledb_information.server s
LEFT OUTER JOIN LATERAL @extschema@.server_hypertable_info(s.server_name) size ON TRUE
FROM timescaledb_information.data_node s
LEFT OUTER JOIN LATERAL @extschema@.data_node_hypertable_info(s.node_name) size ON TRUE
WHERE size.table_schema = %L
AND size.table_name = %L;
$$,
Expand Down
38 changes: 19 additions & 19 deletions sql/updates/latest-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ DROP FUNCTION IF EXISTS create_hypertable(regclass,name,name,integer,name,name,a

ALTER TABLE _timescaledb_catalog.hypertable ADD COLUMN replication_factor SMALLINT NULL CHECK (replication_factor > 0);

-- Table for hypertable -> servers mappings
CREATE TABLE IF NOT EXISTS _timescaledb_catalog.hypertable_server (
-- Table for hypertable -> node mappings
CREATE TABLE IF NOT EXISTS _timescaledb_catalog.hypertable_data_node (
hypertable_id INTEGER NOT NULL REFERENCES _timescaledb_catalog.hypertable(id),
server_hypertable_id INTEGER NULL,
server_name NAME NOT NULL,
node_hypertable_id INTEGER NULL,
node_name NAME NOT NULL,
block_chunks BOOLEAN NOT NULL,
UNIQUE(server_hypertable_id, server_name),
UNIQUE(hypertable_id, server_name)
UNIQUE(node_hypertable_id, node_name),
UNIQUE(hypertable_id, node_name)
);
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.hypertable_server', '');
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.hypertable_data_node', '');

GRANT SELECT ON _timescaledb_catalog.hypertable_server TO PUBLIC;
GRANT SELECT ON _timescaledb_catalog.hypertable_data_node TO PUBLIC;

-- Table for chunk -> servers mappings
CREATE TABLE IF NOT EXISTS _timescaledb_catalog.chunk_server (
-- Table for chunk -> nodes mappings
CREATE TABLE IF NOT EXISTS _timescaledb_catalog.chunk_data_node (
chunk_id INTEGER NOT NULL REFERENCES _timescaledb_catalog.chunk(id),
server_chunk_id INTEGER NOT NULL,
server_name NAME NOT NULL,
UNIQUE(server_chunk_id, server_name),
UNIQUE(chunk_id, server_name)
node_chunk_id INTEGER NOT NULL,
node_name NAME NOT NULL,
UNIQUE(node_chunk_id, node_name),
UNIQUE(chunk_id, node_name)
);
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.chunk_server', '');
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.chunk_data_node', '');

GRANT SELECT ON _timescaledb_catalog.chunk_server TO PUBLIC;
GRANT SELECT ON _timescaledb_catalog.chunk_data_node TO PUBLIC;

--placeholder to allow creation of functions below
CREATE TYPE rxid;
Expand All @@ -44,12 +44,12 @@ CREATE TYPE rxid (
);

CREATE TABLE _timescaledb_catalog.remote_txn (
server_name NAME, --this is really only to allow us to cleanup stuff on a per-server basis.
data_node_name NAME, --this is really only to allow us to cleanup stuff on a per-node basis.
remote_transaction_id TEXT CHECK (remote_transaction_id::rxid is not null),
PRIMARY KEY (remote_transaction_id)
);
CREATE INDEX IF NOT EXISTS remote_txn_server_name_idx
ON _timescaledb_catalog.remote_txn(server_name);
CREATE INDEX IF NOT EXISTS remote_txn_data_node_name_idx
ON _timescaledb_catalog.remote_txn(data_node_name);
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.remote_txn', '');


Expand Down
12 changes: 6 additions & 6 deletions sql/views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,17 @@ AS
where map.chunk_id = srcch.id and srcht.id = srcch.hypertable_id
group by srcht.id;

CREATE OR REPLACE VIEW timescaledb_information.server AS
SELECT s.server_name, s.owner, s.options, s.server_up,
COUNT(s.server_name) AS num_dist_tables,
CREATE OR REPLACE VIEW timescaledb_information.data_node AS
SELECT s.node_name, s.owner, s.options, s.node_up,
COUNT(s.node_name) AS num_dist_tables,
SUM(size.num_chunks) AS num_dist_chunks,
pg_size_pretty(SUM(size.total_bytes)) AS total_dist_size
FROM (SELECT srvname AS server_name, srvowner::regrole::name AS owner, srvoptions AS options, _timescaledb_internal.server_ping(srvname) AS server_up
FROM (SELECT srvname AS node_name, srvowner::regrole::name AS owner, srvoptions AS options, _timescaledb_internal.ping_data_node(srvname) AS node_up
FROM pg_catalog.pg_foreign_server AS srv, pg_catalog.pg_foreign_data_wrapper AS fdw
WHERE srv.srvfdw = fdw.oid
AND fdw.fdwname = 'timescaledb_fdw') AS s
LEFT OUTER JOIN LATERAL @extschema@.server_hypertable_info(CASE WHEN s.server_up THEN s.server_name ELSE NULL END) size ON TRUE
GROUP BY s.server_name, s.server_up, s.owner, s.options;
LEFT OUTER JOIN LATERAL @extschema@.data_node_hypertable_info(CASE WHEN s.node_up THEN s.node_name ELSE NULL END) size ON TRUE
GROUP BY s.node_name, s.node_up, s.owner, s.options;

GRANT USAGE ON SCHEMA timescaledb_information TO PUBLIC;
GRANT SELECT ON ALL TABLES IN SCHEMA timescaledb_information TO PUBLIC;
Loading

0 comments on commit 79fb464

Please sign in to comment.