Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 12fb77b

Browse files
committed
Removed unnecessary 'worker' field from shardman.nodes.
1 parent 0894b10 commit 12fb77b

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

init.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,15 @@ BEGIN
179179
SELECT pg_settings.setting INTO lord_connstring FROM pg_settings
180180
WHERE NAME = 'shardman.shardlord_connstring';
181181
EXECUTE format(
182-
'INSERT INTO @extschema@.nodes VALUES (DEFAULT, %L, NULL, false, true)
182+
'INSERT INTO shardman.nodes VALUES (DEFAULT, %L, NULL, true)
183183
RETURNING id', lord_connstring) INTO lord_id;
184184
PERFORM shardman.set_node_id(lord_id);
185185
init_lord := true;
186186
ELSE
187-
EXECUTE 'SELECT NOT (SELECT lord FROM shardman.nodes WHERE id = $1)'
187+
EXECUTE 'SELECT NOT (SELECT shardlord FROM shardman.nodes WHERE id = $1)'
188188
INTO init_lord USING lord_id;
189-
EXECUTE 'UPDATE shardman.nodes SET lord = true WHERE id = $1' USING lord_id;
189+
EXECUTE 'UPDATE shardman.nodes SET shardlord = true WHERE id = $1'
190+
USING lord_id;
190191
END IF;
191192
IF init_lord THEN
192193
-- TODO: set up lr channels

membership.sql

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,25 @@
66
* ------------------------------------------------------------------------
77
*/
88

9-
-- active is the normal mode, others needed only for proper node add and removal
9+
-- active is the normal mode, removed means node removed, others needed only
10+
-- for proper node add and removal
1011
CREATE TYPE worker_node_status AS ENUM (
1112
'active', 'add_in_progress', 'rm_in_progress', 'removed');
1213

1314
-- list of nodes present in the cluster
1415
CREATE TABLE nodes (
1516
id serial PRIMARY KEY,
16-
connstring text NOT NULL UNIQUE,
17-
worker_status worker_node_status,
17+
connstring text NOT NULL,
1818
-- While currently we don't support lord and worker roles on one node,
19-
-- potentially node can be either worker, lord or both, so we need 2 bits.
20-
-- One bool with NULL might be fine, but it seems a bit counter-intuitive.
21-
worker bool NOT NULL DEFAULT true,
22-
lord bool NOT NULL DEFAULT false,
19+
-- potentially node can be either worker, lord or both.
20+
worker_status worker_node_status, -- NULL if this node is not a worker
21+
-- is this node shardlord?
22+
shardlord bool NOT NULL DEFAULT false,
2323
-- cmd by which node was added
2424
added_by bigint REFERENCES shardman.cmd_log(id)
2525
);
26+
CREATE UNIQUE INDEX unique_node_connstr ON shardman.nodes (connstring)
27+
WHERE (worker_status = 'active' OR shardlord);
2628

2729
-- Lord is removing us, so reset our state, removing all subscriptions. A bit
2830
-- tricky part: we can't DROP SUBSCRIPTION here, because that would mean
@@ -88,7 +90,7 @@ BEGIN
8890
INTO n_id;
8991
IF n_id IS NULL THEN
9092
INSERT INTO shardman.nodes
91-
VALUES (DEFAULT, connstring, 'add_in_progress', true, false, cmd_id)
93+
VALUES (DEFAULT, connstring, 'add_in_progress', false, cmd_id)
9294
RETURNING id INTO n_id;
9395
END IF;
9496
RETURN n_id;
@@ -110,7 +112,8 @@ END $$ LANGUAGE plpgsql;
110112
-- one.
111113
CREATE FUNCTION get_worker_node_connstr(node_id int) RETURNS text AS $$
112114
DECLARE
113-
connstr text := connstring FROM shardman.nodes WHERE id = node_id AND worker;
115+
connstr text := connstring FROM shardman.nodes WHERE id = node_id AND
116+
worker_status IS NOT NULL;
114117
BEGIN
115118
IF connstr IS NULL THEN
116119
RAISE EXCEPTION 'Worker node with id % not found', node_id;

readme.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,17 @@ Remove node from the cluster. Its shardman state will be reset. We don't delete
9191
tables with data and foreign tables though.
9292

9393
You can see all cluster nodes at any time by examining shardman.nodes table:
94-
-- active is the normal mode, others needed only for proper node add and removal
94+
-- active is the normal mode, removed means node removed, others needed only
95+
-- for proper node add and removal
9596
CREATE TYPE worker_node_status AS ENUM (
9697
'active', 'add_in_progress', 'rm_in_progress', 'removed');
9798
CREATE TABLE nodes (
9899
id serial PRIMARY KEY,
99100
connstring text NOT NULL UNIQUE,
100-
worker_status worker_node_status,
101101
-- While currently we don't support lord and worker roles on one node,
102-
-- potentially node can be either worker, lord or both, so we need 2 bits.
103-
-- One bool with NULL might be fine, but it seems a bit counter-intuitive.
104-
worker bool NOT NULL DEFAULT true,
102+
-- potentially node can be either worker, lord or both.
103+
worker_status worker_node_status, -- NULL if this node is not a worker
104+
-- is this node shardlord?
105105
lord bool NOT NULL DEFAULT false,
106106
-- cmd by which node was added
107107
added_by bigint REFERENCES shardman.cmd_log(id)

src/pg_shardman.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -634,14 +634,14 @@ insert_node(const char *connstr, int64 cmd_id)
634634
}
635635

636636
/*
637-
* Returns true, if node 'id' is in cluster and not in add_in_progress state
637+
* Returns true, if node 'id' is active node in cluster or rm in progress
638638
*/
639639
static bool
640640
node_in_cluster(int id)
641641
{
642642
char *sql = psprintf(
643-
"select id from shardman.nodes where id = %d and (shardlord OR"
644-
" worker_status != 'add_in_progress');",
643+
"select id from shardman.nodes where id = %d and (shardlord or"
644+
" worker_status = 'active' or worker_status = 'rm_in_progress');",
645645
id);
646646
bool res;
647647

@@ -695,7 +695,7 @@ rm_node(Cmd *cmd)
695695
* fixed.
696696
*/
697697
sql = psprintf(
698-
"select shardman.drop_repslot('shardman_meta_sub_%d');"
698+
"select shardman.drop_repslot('shardman_meta_sub_%d', true);"
699699
"update shardman.nodes set worker_status = 'removed' where id = %d;"
700700
"update shardman.cmd_log set status = 'success' where id = %ld;",
701701
node_id, node_id, cmd->id);
@@ -708,14 +708,14 @@ rm_node(Cmd *cmd)
708708

709709
/*
710710
* Get connstr of worker node with id node_id. Memory is palloc'ed.
711-
* NULL is returned, if there is no such node.
711+
* NULL is returned, if there is no such worker.
712712
*/
713713
char *
714714
get_worker_node_connstr(int32 node_id)
715715
{
716716
MemoryContext oldcxt = CurrentMemoryContext;
717717
char *sql = psprintf("select connstring from shardman.nodes where id = %d"
718-
" and worker", node_id);
718+
" and worker_status is not null", node_id);
719719
char *res;
720720

721721
SPI_PROLOG;

0 commit comments

Comments
 (0)