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

Commit 740a194

Browse files
committed
Fix some bugs in part_removed(
1 parent 428745d commit 740a194

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

shard.sql

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,12 @@ BEGIN
264264
RAISE DEBUG '[SHMN] part_removed trigger called for part %, owner %',
265265
OLD.part_name, OLD.owner;
266266

267+
ASSERT (OLD.prv IS NULL OR OLD.nxt IS NULL), 'We currently do not support redundancy level > 2';
268+
267269
IF OLD.prv IS NOT NULL THEN
268270
prev_src_lname := shardman.get_data_lname(OLD.part_name, OLD.prv, OLD.owner);
269271
ELSE
272+
-- Primaty is moved
270273
select * from shardman.partitions where owner=OLD.nxt and part_name=OLD.part_name into new_primary;
271274
END IF;
272275
IF OLD.nxt IS NOT NULL THEN
@@ -292,30 +295,30 @@ BEGIN
292295
PERFORM shardman.remove_sync_standby(src_next_lname);
293296
END IF;
294297
-- Drop old table anyway
295-
-- ???? Can we really do it now? We will have FDW pointing to removed table...
296298
EXECUTE format('DROP TABLE IF EXISTS %I', OLD.part_name);
297299
ELSEIF me = OLD.prv THEN -- node with prev replica
298300
-- Wait sometime to let other node first remove subscription
299301
PERFORM pg_sleep(drop_slot_delay);
300302
-- Drop pub for old channel prev -> src
301303
PERFORM shardman.drop_repslot_and_pub(prev_src_lname);
302304
PERFORM shardman.remove_sync_standby(prev_src_lname);
305+
-- Update L2-list (TODO: change replication model from chain to star)
303306
PERFORM update shardman.partitions set nxt=OLD.nxt where owner=me and part_name=OLD.part_name;
304307
ELSEIF me = OLD.nxt THEN -- node with next replica
305308
-- Drop sub for old channel src -> next
306309
PERFORM shardman.eliminate_sub(src_next_lname);
310+
-- Update L2-list (TODO: change replication model from chain to star)
307311
PERFORM update shardman.partitions set prv=OLD.prv where owner=me and part_name=OLD.part_name;
308-
-- This replica is promoted to primary node, so drop trigger disabling writes to the table
312+
-- This replica is promoted to primary node, so drop trigger disabling writes to the table
309313
PERFORM readonly_replica_off(part_name);
310-
-- and replace FDW with local partition
311-
PERFORM shardman.replace_usual_part_with_foreign(new_primary);
314+
-- Replace FDW with local partition
315+
PERFORM shardman.replace_foreign_part_with_usual(new_primary);
312316
END IF;
313317

314318
-- If primary was moved
315319
IF OLD.prv IS NULL THEN
316-
-- And update fdw almost everywhere
320+
-- then update fdw almost everywhere
317321
PERFORM shardman.update_fdw_server(new_primary);
318-
PERFORM shardman.replace_foreign_part_with_usual(NEW);
319322
END IF;
320323

321324
RETURN NULL;

0 commit comments

Comments
 (0)