Skip to content

Commit 59778f5

Browse files
author
Maksim Milyutin
committed
Add error propagation under creating new partition;
add test for the case of deleting callback function under existing the referencies to it on new partitions
1 parent 6057a16 commit 59778f5

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

expected/pathman_callbacks.out

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,39 @@ WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_2",
129129

130130
DROP TABLE abc CASCADE;
131131
NOTICE: drop cascades to 2 other objects
132+
/* test the temprary deletion of callback function */
133+
CREATE TABLE abc(a serial, b int);
134+
SELECT set_init_callback('abc',
135+
'callbacks.abc_on_part_created_callback');
136+
set_init_callback
137+
-------------------
138+
139+
(1 row)
140+
141+
SELECT create_range_partitions('abc', 'a', 1, 100, 2);
142+
WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_1", "range_max": "101", "range_min": "1", "parent_schema": "public", "partition_schema": "public"}
143+
WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_2", "range_max": "201", "range_min": "101", "parent_schema": "public", "partition_schema": "public"}
144+
create_range_partitions
145+
-------------------------
146+
2
147+
(1 row)
148+
149+
INSERT INTO abc VALUES (201, 0);
150+
WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_3", "range_max": "301", "range_min": "201", "parent_schema": "public", "partition_schema": "public"}
151+
DROP FUNCTION callbacks.abc_on_part_created_callback(jsonb);
152+
INSERT INTO abc VALUES (301, 0);
153+
ERROR: create_partitions_internal(): callback function "]callbacks.abc_on_part_created_callback(jsonb)" doesn't exist
154+
CREATE OR REPLACE FUNCTION callbacks.abc_on_part_created_callback(
155+
args JSONB)
156+
RETURNS VOID AS $$
157+
BEGIN
158+
RAISE WARNING 'callback arg: %', args::TEXT;
159+
END
160+
$$ language plpgsql;
161+
INSERT INTO abc VALUES (301, 0);
162+
WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_5", "range_max": "401", "range_min": "301", "parent_schema": "public", "partition_schema": "public"}
163+
DROP TABLE abc CASCADE;
164+
NOTICE: drop cascades to 4 other objects
132165
DROP SCHEMA callbacks CASCADE;
133166
NOTICE: drop cascades to 2 other objects
134167
DROP EXTENSION pg_pathman CASCADE;

sql/pathman_callbacks.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,26 @@ SELECT create_range_partitions('abc', 'a', 1, 100, 2);
5353

5454
DROP TABLE abc CASCADE;
5555

56+
/* test the temprary deletion of callback function */
57+
CREATE TABLE abc(a serial, b int);
58+
SELECT set_init_callback('abc',
59+
'callbacks.abc_on_part_created_callback');
60+
SELECT create_range_partitions('abc', 'a', 1, 100, 2);
61+
62+
INSERT INTO abc VALUES (201, 0);
63+
DROP FUNCTION callbacks.abc_on_part_created_callback(jsonb);
64+
INSERT INTO abc VALUES (301, 0);
65+
CREATE OR REPLACE FUNCTION callbacks.abc_on_part_created_callback(
66+
args JSONB)
67+
RETURNS VOID AS $$
68+
BEGIN
69+
RAISE WARNING 'callback arg: %', args::TEXT;
70+
END
71+
$$ language plpgsql;
72+
INSERT INTO abc VALUES (301, 0);
73+
74+
DROP TABLE abc CASCADE;
75+
76+
5677
DROP SCHEMA callbacks CASCADE;
5778
DROP EXTENSION pg_pathman CASCADE;

src/partition_creation.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,14 @@ create_partitions_for_value_internal(Oid relid, Datum value, Oid value_type)
405405
edata = CopyErrorData();
406406
FlushErrorState();
407407

408-
elog(LOG, "create_partitions_internal(): %s [%u]",
409-
edata->message, MyProcPid);
408+
if (IsBackgroundWorker)
409+
ereport(LOG,
410+
(errmsg("create_partitions_internal(): %s [%u]", edata->message, MyProcPid),
411+
(edata->detail) ? errdetail("%s", edata->detail) : 0));
412+
else
413+
ereport(ERROR,
414+
(errmsg("create_partitions_internal(): %s", edata->message),
415+
(edata->detail) ? errdetail("%s", edata->detail) : 0));
410416

411417
FreeErrorData(edata);
412418

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy