@@ -264,9 +264,12 @@ BEGIN
264
264
RAISE DEBUG ' [SHMN] part_removed trigger called for part %, owner %' ,
265
265
OLD .part_name , OLD .owner ;
266
266
267
+ ASSERT (OLD .prv IS NULL OR OLD .nxt IS NULL ), ' We currently do not support redundancy level > 2' ;
268
+
267
269
IF OLD .prv IS NOT NULL THEN
268
270
prev_src_lname := shardman .get_data_lname (OLD .part_name , OLD .prv , OLD .owner );
269
271
ELSE
272
+ -- Primaty is moved
270
273
select * from shardman .partitions where owner= OLD .nxt and part_name= OLD .part_name into new_primary;
271
274
END IF;
272
275
IF OLD .nxt IS NOT NULL THEN
@@ -292,30 +295,30 @@ BEGIN
292
295
PERFORM shardman .remove_sync_standby (src_next_lname);
293
296
END IF;
294
297
-- Drop old table anyway
295
- -- ???? Can we really do it now? We will have FDW pointing to removed table...
296
298
EXECUTE format(' DROP TABLE IF EXISTS %I' , OLD .part_name );
297
299
ELSEIF me = OLD .prv THEN -- node with prev replica
298
300
-- Wait sometime to let other node first remove subscription
299
301
PERFORM pg_sleep(drop_slot_delay);
300
302
-- Drop pub for old channel prev -> src
301
303
PERFORM shardman .drop_repslot_and_pub (prev_src_lname);
302
304
PERFORM shardman .remove_sync_standby (prev_src_lname);
305
+ -- Update L2-list (TODO: change replication model from chain to star)
303
306
PERFORM update shardman .partitions set nxt= OLD .nxt where owner= me and part_name= OLD .part_name ;
304
307
ELSEIF me = OLD .nxt THEN -- node with next replica
305
308
-- Drop sub for old channel src -> next
306
309
PERFORM shardman .eliminate_sub (src_next_lname);
310
+ -- Update L2-list (TODO: change replication model from chain to star)
307
311
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
309
313
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);
312
316
END IF;
313
317
314
318
-- If primary was moved
315
319
IF OLD .prv IS NULL THEN
316
- -- And update fdw almost everywhere
320
+ -- then update fdw almost everywhere
317
321
PERFORM shardman .update_fdw_server (new_primary);
318
- PERFORM shardman .replace_foreign_part_with_usual (NEW);
319
322
END IF;
320
323
321
324
RETURN NULL ;
0 commit comments