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

Commit a9da45b

Browse files
committed
shard.sql refactored, interface for create_replica
1 parent ae3cc6c commit a9da45b

File tree

5 files changed

+211
-146
lines changed

5 files changed

+211
-146
lines changed

init.sql

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $$;
2424

2525
-- available commands
2626
CREATE TYPE cmd AS ENUM ('add_node', 'rm_node', 'create_hash_partitions',
27-
'move_primary');
27+
'move_primary', 'create_replica');
2828
-- command status
2929
CREATE TYPE cmd_status AS ENUM ('waiting', 'canceled', 'failed', 'in progress',
3030
'success');
@@ -110,6 +110,20 @@ BEGIN
110110
RETURN c_id;
111111
END $$ LANGUAGE plpgsql;
112112

113+
-- Create replica partition. Params:
114+
-- 'part_name' is name of the partition to replicate
115+
-- 'dest' is id of the node on which part will be created
116+
CREATE FUNCTION create_replica(part_name text, dest int) RETURNS int AS $$
117+
DECLARE
118+
c_id int;
119+
BEGIN
120+
INSERT INTO @extschema@.cmd_log VALUES (DEFAULT, 'create_replica')
121+
RETURNING id INTO c_id;
122+
INSERT INTO @extschema@.cmd_opts VALUES (DEFAULT, c_id, part_name);
123+
INSERT INTO @extschema@.cmd_opts VALUES (DEFAULT, c_id, dest);
124+
RETURN c_id;
125+
END $$ LANGUAGE plpgsql;
126+
113127
-- Internal functions
114128

115129
-- Called on shardmaster bgw start. Add itself to nodes table, set id, create

0 commit comments

Comments
 (0)