You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -886,40 +886,66 @@ CREATE FUNCTION is_shardlord()
886
886
RETURNS bool AS'pg_shardman' LANGUAGE C STRICT;
887
887
888
888
-- Wait completion of partition copy using LR
889
-
CREATEFUNCTIONwait_copy_completion(src_node_id int, part_name text) RETURNS void AS $$
889
+
CREATEFUNCTIONwait_copy_completion(src_node_id int, dst_node_id int, part_name text) RETURNS void AS $$
890
890
DECLARE
891
891
slot text= format('copy_%s', part_name);
892
892
lag bigint;
893
893
response text;
894
894
caughtup_threshold bigint=1024*1024;
895
895
timeout_sec int=1;
896
896
locked bool = false;
897
+
synced bool = false;
898
+
wal_lsn text;
897
899
BEGIN
898
900
LOOP
899
-
response :=shardman.broadcast(format('%s:SELECT confirmed_flush_lsn - pg_current_wal_lsn() FROM pg_replication_slots WHERE slot_name=%L;', src_node_id, slot));
900
-
lag := response::bigint;
901
-
902
-
RAISE DEBUG 'Replication lag %', lag;
903
-
IF locked THEN
904
-
IF lag <=0 THEN
905
-
RETURN;
901
+
IF NOT synced
902
+
THEN
903
+
response :=shardman.broadcast(format(
904
+
'%s:SELECT srsubstate FROM pg_subscription_rel srel
905
+
JOIN pg_subscription s on srel.srsubid = s.oid where subname=%L;',
906
+
dst_node_id, slot));
907
+
IF response='r' THEN
908
+
synced := true;
909
+
RAISE DEBUG 'Table % sync completed', part_name;
910
+
CONTINUE;
911
+
END IF;
912
+
ELSE
913
+
IF NOT locked THEN
914
+
response :=shardman.broadcast(format('%s:SELECT pg_current_wal_lsn() - confirmed_flush_lsn FROM pg_replication_slots WHERE slot_name=%L;', src_node_id, slot));
915
+
ELSE
916
+
response :=shardman.broadcast(format('%s:SELECT %L - confirmed_flush_lsn FROM pg_replication_slots WHERE slot_name=%L;', src_node_id, wal_lsn, slot));
917
+
END IF;
918
+
lag := response::bigint;
919
+
920
+
RAISE DEBUG 'Replication lag %', lag;
921
+
IF locked THEN
922
+
IF lag<=0 THEN
923
+
RETURN;
924
+
END IF;
925
+
ELSIF lag < caughtup_threshold THEN
926
+
PERFORM shardman.broadcast(format('%s:CREATE TRIGGER write_protection BEFORE INSERT OR UPDATE OR DELETE ON %I FOR EACH STATEMENT EXECUTE PROCEDURE shardman.deny_access();',
927
+
src_node_id, part_name));
928
+
SELECTshardman.broadcast(format('%s:SELECT pg_current_wal_lsn();', src_node_id)) INTO wal_lsn;
929
+
locked := true;
930
+
CONTINUE;
906
931
END IF;
907
-
ELSIF lag < caughtup_threshold THEN
908
-
PERFORM shardman.broadcast(format('%s:REVOKE SELECT,INSERT,UPDATE,DELETE ON %I FROM PUBLIC;',
909
-
src_node_id, part_name));
910
-
locked := true;
911
-
CONTINUE;
912
932
END IF;
913
933
PERFORM pg_sleep(timeout_sec);
914
934
END LOOP;
915
935
END
916
936
$$ LANGUAGE plpgsql;
917
937
918
-
CREATEFUNCTIONcomplete_partition_move(src_node_id int, part_name text) RETURNS void AS $$
938
+
CREATEFUNCTIONcomplete_partition_move(src_node_id int, dst_node_id int, part_name text) RETURNS void AS $$
0 commit comments