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

Commit 45847e8

Browse files
committed
Interesting race condition discovered.
1 parent 5ce4eb8 commit 45847e8

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

postgresql.conf.common.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ autovacuum = off
88

99
log_min_messages = DEBUG1
1010
# client_min_messages = NOTICE
11-
client_min_messages = INFO
11+
# client_min_messages = INFO
12+
client_min_messages = PANIC
1213

1314
wal_level = logical

shard.sql

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ DECLARE
2626
pname text;
2727
BEGIN
2828
IF NEW.initial_node != (SELECT shardman.get_node_id()) THEN
29+
RAISE DEBUG '[SHARDMAN] new table trig, pid %', (select pg_backend_pid());
2930
EXECUTE format('DROP TABLE IF EXISTS %I CASCADE;', NEW.relation);
3031
partition_names :=
3132
(SELECT ARRAY(SELECT part_name FROM shardman.gen_part_names(
@@ -198,6 +199,7 @@ BEGIN
198199
format('%I', part.relation))),
199200
part.part_name,
200201
part.part_name);
202+
RAISE DEBUG '[SHARDMAN] my id: %, new part: %', shardman.get_node_id(), part.part_name;
201203
-- replace local partition with foreign table
202204
EXECUTE format('SELECT replace_hash_partition(%L, %L)',
203205
part.part_name, fdw_part_name);
@@ -207,18 +209,21 @@ END $$ LANGUAGE plpgsql;
207209

208210
-- On adding new partition, create proper foreign server & foreign table and
209211
-- replace tmp (empty) partition with it.
210-
CREATE FUNCTION new_partition() RETURNS TRIGGER AS $$
212+
-- TODO: race condition between this trigger and new_table_worker_side
213+
-- definitely deserves attention.
214+
CREATE FUNCTION new_primary() RETURNS TRIGGER AS $$
211215
BEGIN
212216
IF NEW.owner != (SELECT shardman.get_node_id()) THEN
217+
RAISE DEBUG 'SHARDMAN new prim trigger, pid %', (select pg_backend_pid());
213218
PERFORM shardman.replace_usual_part_with_foreign(NEW);
214219
END IF;
215220
RETURN NULL;
216221
END
217222
$$ LANGUAGE plpgsql;
218-
CREATE TRIGGER new_partition AFTER INSERT ON shardman.partitions
219-
FOR EACH ROW EXECUTE PROCEDURE new_partition();
223+
CREATE TRIGGER new_primary AFTER INSERT ON shardman.partitions
224+
FOR EACH ROW WHEN (NEW.num = 0) EXECUTE PROCEDURE new_primary();
220225
-- fire trigger only on worker nodes
221-
ALTER TABLE shardman.partitions ENABLE REPLICA TRIGGER new_partition;
226+
ALTER TABLE shardman.partitions ENABLE REPLICA TRIGGER new_primary;
222227

223228
-- Replace foreign table-partition with local. The latter must exist!
224229
-- Foreign table will be dropped.

src/shardman_hooks.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ emit_log_hook_type log_hook_next;
1818
* Add [SHNODE x] where x is node id to each log message, if '%z' is in
1919
* log_line_prefix. Seems like there is no way to hook something into
2020
* prefix iself without touching core code.
21+
* TODO: In some, probably most interesting cases this hook is not called :(
2122
*/
2223
void
2324
shardman_log_hook(ErrorData *edata)

0 commit comments

Comments
 (0)