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

Commit 2ca66a9

Browse files
committed
Fixed hanging during DROP EXTENSION.
Now we SET LOCAL synchronous_commit TO local to avoid hangup. Also, not used trigger on replica creation code removed.
1 parent 03c6819 commit 2ca66a9

File tree

4 files changed

+23
-31
lines changed

4 files changed

+23
-31
lines changed

bin/shardman_start.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ script_dir=`dirname "$(readlink -f "$0")"`
44
source "${script_dir}/common.sh"
55

66
cd "${script_dir}/.."
7-
make clean
87

98
> $logfile
109

@@ -14,8 +13,10 @@ for port in "${worker_ports[@]}" $master_port; do
1413
psql -p $port -c "drop extension if exists pg_shardman cascade;"
1514
done
1615

17-
restart_nodes
16+
make clean
1817
make install
18+
19+
restart_nodes
1920
for port in $master_port "${worker_ports[@]}"; do
2021
psql -p $port -c "create extension pg_shardman cascade;"
2122
done

init.sql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ DECLARE
262262
sub record;
263263
rs record;
264264
BEGIN
265+
RAISE DEBUG '[SHARDMAN %] pg_shardman is dropping, cleaning up', shardman.my_id();
266+
265267
FOR pub IN SELECT pubname FROM pg_publication WHERE pubname LIKE 'shardman_%' LOOP
266268
EXECUTE format('DROP PUBLICATION %I', pub.pubname);
267269
END LOOP;
@@ -274,8 +276,10 @@ BEGIN
274276
WHERE slot_name LIKE 'shardman_%' AND slot_type = 'logical' LOOP
275277
PERFORM shardman.drop_repslot(rs.slot_name, true);
276278
END LOOP;
277-
-- TODO: remove only shardman's standbys
278279
IF shardman.my_id() IS NOT NULL THEN
280+
-- otherwise we will hang
281+
SET LOCAL synchronous_commit TO local;
282+
-- TODO: remove only shardman's standbys
279283
PERFORM shardman.set_sync_standbys('');
280284
END IF;
281285

@@ -285,5 +289,5 @@ $$ LANGUAGE plpgsql;
285289
CREATE FUNCTION pg_shardman_cleanup_c() RETURNS event_trigger
286290
AS 'pg_shardman' LANGUAGE C;
287291
CREATE EVENT TRIGGER cleanup_lr_trigger ON ddl_command_start
288-
WHEN TAG in ('DROP EXTENSION')
292+
WHEN TAG IN ('DROP EXTENSION')
289293
EXECUTE PROCEDURE pg_shardman_cleanup_c();

shard.sql

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -287,23 +287,6 @@ BEGIN
287287
lname, oldtail_connstr, lname, lname);
288288
END $$ LANGUAGE plpgsql;
289289

290-
-- TODO
291-
-- Update fdw according to new replica creation. We update it on newtail node --
292-
-- its connstring to this part should include only primary and newtail itself,
293-
-- and on all other nodes except oldtail, so they learn about new replica.
294-
-- CREATE FUNCTION replica_created_update_fdw() RETURNS TRIGGER AS $$
295-
-- BEGIN
296-
-- RAISE DEBUG '[SHARDMAN] replica_created_update_fdw trigger called';
297-
-- IF shardman.my_id() != NEW.prv THEN -- don't update on oldtail node
298-
-- PERFORM shardman.update_fdw_server(NEW);
299-
-- END IF;
300-
-- RETURN NULL;
301-
-- END $$ LANGUAGE plpgsql;
302-
-- CREATE TRIGGER replica_created AFTER INSERT ON shardman.partitions
303-
-- FOR EACH ROW WHEN (NEW.prv IS NOT NULL) EXECUTE PROCEDURE replica_created();
304-
-- fire trigger only on worker nodes
305-
-- ALTER TABLE shardman.partitions ENABLE REPLICA TRIGGER replica_created;
306-
307290
-- Otherwise partitioned tables on worker nodes not will be dropped properly,
308291
-- see pathman's docs.
309292
ALTER EVENT TRIGGER pathman_ddl_trigger ENABLE ALWAYS;
@@ -656,7 +639,7 @@ BEGIN
656639
END $$ LANGUAGE plpgsql STRICT;
657640

658641
CREATE FUNCTION get_data_lname(part_name text, pub_node int, sub_node int)
659-
RETURNS text AS 'pg_shardman' LANGUAGE C;
642+
RETURNS text AS 'pg_shardman' LANGUAGE C STRICT;
660643

661644
-- Make sure that standby_name is present in synchronous_standby_names. If not,
662645
-- add it via ALTER SYSTEM and SIGHUP postmaster to reread conf.
@@ -667,26 +650,30 @@ BEGIN
667650
IF newval IS NOT NULL THEN
668651
RAISE DEBUG '[SHARDMAN] Adding standby %, new value is %', standby, newval;
669652
PERFORM shardman.set_sync_standbys(newval);
670-
PERFORM pg_reload_conf();
671653
END IF;
672654
END $$ LANGUAGE plpgsql STRICT;
673655
CREATE FUNCTION ensure_sync_standby_c(standby text) RETURNS text
674-
AS 'pg_shardman' LANGUAGE C;
656+
AS 'pg_shardman' LANGUAGE C STRICT;
675657

676658
-- Remove 'standby' from synchronous_standby_names, if it is there, and SIGHUP
677659
-- postmaster.
678-
CREATE FUNCTION remove_sync_standby(standby text) RETURNS void as $$
660+
CREATE FUNCTION remove_sync_standby(standby text) RETURNS void AS $$
679661
DECLARE
680662
newval text := shardman.remove_sync_standby_c(standby);
681663
BEGIN
682664
IF newval IS NOT NULL THEN
683665
RAISE DEBUG '[SHARDMAN] Removing standby %, new value is %', standby, newval;
684666
PERFORM shardman.set_sync_standbys(newval);
685-
PERFORM pg_reload_conf();
686667
END IF;
687668
END $$ LANGUAGE plpgsql STRICT;
688669
CREATE FUNCTION remove_sync_standby_c(standby text) RETURNS text
689-
AS 'pg_shardman' LANGUAGE C;
670+
AS 'pg_shardman' LANGUAGE C STRICT;
690671

691-
CREATE FUNCTION set_sync_standbys(standby text) RETURNS void
692-
AS 'pg_shardman' LANGUAGE C;
672+
CREATE FUNCTION set_sync_standbys(standby text) RETURNS void AS $$
673+
BEGIN
674+
PERFORM pg_reload_conf();
675+
PERFORM shardman.set_sync_standbys_c(standby);
676+
RAISE DEBUG '[SHARDMAN] sync_standbys set to %', standby;
677+
END $$ LANGUAGE plpgsql STRICT;
678+
CREATE FUNCTION set_sync_standbys_c(standby text) RETURNS void
679+
AS 'pg_shardman' LANGUAGE C STRICT;

src/udf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,9 @@ remove_sync_standby_c(PG_FUNCTION_ARGS)
402402
* transaction, so we resort to another exquisite hack: we connect to
403403
* ourselves via libpq and perform the job.
404404
*/
405-
PG_FUNCTION_INFO_V1(set_sync_standbys);
405+
PG_FUNCTION_INFO_V1(set_sync_standbys_c);
406406
Datum
407-
set_sync_standbys(PG_FUNCTION_ARGS)
407+
set_sync_standbys_c(PG_FUNCTION_ARGS)
408408
{
409409
char *standbys = quote_literal_cstr(text_to_cstring(PG_GETARG_TEXT_PP(0)));
410410
char *cmd = psprintf("alter system set synchronous_standby_names to %s",

0 commit comments

Comments
 (0)