Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbeb3471

Browse files
committed
improve regression tests, fix rare crash in create_partitions_for_value_internal()
1 parentfcfd134 commitbeb3471

File tree

5 files changed

+93
-37
lines changed

5 files changed

+93
-37
lines changed

‎expected/pathman_bgw.out

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,43 @@ SELECT * FROM pathman_partition_list ORDER BY partition; /* should contain 3 par
105105

106106
DROP TABLE test_bgw.test_4 CASCADE;
107107
NOTICE: drop cascades to 4 other objects
108+
/* test error handling in BGW */
109+
CREATE TABLE test_bgw.test_5(val INT4 NOT NULL);
110+
SELECT create_range_partitions('test_bgw.test_5', 'val', 1, 10, 2);
111+
create_range_partitions
112+
-------------------------
113+
2
114+
(1 row)
115+
116+
CREATE OR REPLACE FUNCTION test_bgw.abort_xact(args JSONB)
117+
RETURNS VOID AS $$
118+
BEGIN
119+
RAISE EXCEPTION 'aborting xact!';
120+
END
121+
$$ language plpgsql;
122+
SELECT set_spawn_using_bgw('test_bgw.test_5', true);
123+
set_spawn_using_bgw
124+
---------------------
125+
126+
(1 row)
127+
128+
SELECT set_init_callback('test_bgw.test_5', 'test_bgw.abort_xact(jsonb)');
129+
set_init_callback
130+
-------------------
131+
132+
(1 row)
133+
134+
INSERT INTO test_bgw.test_5 VALUES (-100);
135+
ERROR: Attempt to spawn new partitions of relation "test_5" failed
136+
SELECT * FROM pathman_partition_list ORDER BY partition; /* should contain 3 partitions */
137+
parent | partition | parttype | expr | range_min | range_max
138+
-----------------+-------------------+----------+------+-----------+-----------
139+
test_bgw.test_5 | test_bgw.test_5_1 | 2 | val | 1 | 11
140+
test_bgw.test_5 | test_bgw.test_5_2 | 2 | val | 11 | 21
141+
(2 rows)
142+
143+
DROP FUNCTION test_bgw.abort_xact(args JSONB);
144+
DROP TABLE test_bgw.test_5 CASCADE;
145+
NOTICE: drop cascades to 3 other objects
108146
DROP SCHEMA test_bgw CASCADE;
109147
DROP EXTENSION pg_pathman;

‎expected/pathman_callbacks.out

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
\set VERBOSITY terse
22
CREATE EXTENSION pg_pathman;
33
CREATE SCHEMA callbacks;
4-
/*Check callbacks */
4+
/*callback #1 */
55
CREATE OR REPLACE FUNCTION callbacks.abc_on_part_created_callback(args JSONB)
66
RETURNS VOID AS $$
77
BEGIN
88
RAISE WARNING 'callback arg: %', args::TEXT;
99
END
1010
$$ language plpgsql;
11-
/* callbackis in public namespace, must be schema-qualified */
11+
/* callback#2 */
1212
CREATE OR REPLACE FUNCTION public.dummy_cb(args JSONB)
1313
RETURNS VOID AS $$
1414
BEGIN
@@ -184,15 +184,11 @@ WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_2",
184184

185185
INSERT INTO callbacks.abc VALUES (201, 0); /* +1 new partition */
186186
WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_3", "range_max": "301", "range_min": "201", "parent_schema": "callbacks", "partition_schema": "callbacks"}
187+
BEGIN;
187188
DROP FUNCTION callbacks.abc_on_part_created_callback(jsonb);
188189
INSERT INTO callbacks.abc VALUES (301, 0); /* +0 new partitions (ERROR) */
189190
ERROR: callback function "callbacks.abc_on_part_created_callback(jsonb)" does not exist
190-
CREATE OR REPLACE FUNCTION callbacks.abc_on_part_created_callback(args JSONB)
191-
RETURNS VOID AS $$
192-
BEGIN
193-
RAISE WARNING 'callback arg: %', args::TEXT;
194-
END
195-
$$ language plpgsql;
191+
ROLLBACK;
196192
INSERT INTO callbacks.abc VALUES (301, 0); /* +1 new partition */
197193
WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_5", "range_max": "401", "range_min": "301", "parent_schema": "callbacks", "partition_schema": "callbacks"}
198194
DROP TABLE callbacks.abc CASCADE;
@@ -211,22 +207,22 @@ CREATE OR REPLACE FUNCTION callbacks.rotation_callback(params jsonb)
211207
RETURNS VOID AS
212208
$$
213209
DECLARE
214-
relationregclass;
210+
relationregclass;
215211
parent_relregclass;
216212
BEGIN
217213
parent_rel := concat(params->>'partition_schema', '.', params->>'parent')::regclass;
218214

219-
-- drop "old" partitions
220-
FOR relation IN (SELECT partition FROM
215+
-- drop "old" partitions
216+
FOR relation IN (SELECT partition FROM
221217
(SELECT partition, range_min::INT4 FROM pathman_partition_list
222218
WHERE parent = parent_rel
223219
ORDER BY range_min::INT4 DESC
224220
OFFSET 4) t -- remain 4 last partitions
225221
ORDER BY range_min)
226-
LOOP
227-
RAISE NOTICE 'dropping partition %', relation;
228-
PERFORM drop_range_partition(relation);
229-
END LOOP;
222+
LOOP
223+
RAISE NOTICE 'dropping partition %', relation;
224+
PERFORM drop_range_partition(relation);
225+
END LOOP;
230226
END
231227
$$ LANGUAGE plpgsql;
232228
SELECT * FROM pathman_partition_list

‎sql/pathman_bgw.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,26 @@ SELECT * FROM pathman_partition_list ORDER BY partition; /* should contain 3 par
5353
DROPTABLEtest_bgw.test_4 CASCADE;
5454

5555

56+
/* test error handling in BGW*/
57+
CREATETABLEtest_bgw.test_5(val INT4NOT NULL);
58+
SELECT create_range_partitions('test_bgw.test_5','val',1,10,2);
59+
60+
CREATE OR REPLACEFUNCTIONtest_bgw.abort_xact(args JSONB)
61+
RETURNS VOIDAS $$
62+
BEGIN
63+
RAISE EXCEPTION'aborting xact!';
64+
END
65+
$$ language plpgsql;
66+
67+
SELECT set_spawn_using_bgw('test_bgw.test_5', true);
68+
SELECT set_init_callback('test_bgw.test_5','test_bgw.abort_xact(jsonb)');
69+
INSERT INTOtest_bgw.test_5VALUES (-100);
70+
SELECT*FROM pathman_partition_listORDER BY partition;/* should contain 3 partitions*/
71+
72+
DROPFUNCTIONtest_bgw.abort_xact(args JSONB);
73+
DROPTABLEtest_bgw.test_5 CASCADE;
74+
75+
5676

5777
DROPSCHEMA test_bgw CASCADE;
5878
DROP EXTENSION pg_pathman;

‎sql/pathman_callbacks.sql

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,25 @@
33
CREATE EXTENSION pg_pathman;
44
CREATESCHEMAcallbacks;
55

6-
/* Check callbacks*/
76

7+
8+
/* callback #1*/
89
CREATE OR REPLACEFUNCTIONcallbacks.abc_on_part_created_callback(args JSONB)
910
RETURNS VOIDAS $$
1011
BEGIN
1112
RAISE WARNING'callback arg: %', args::TEXT;
1213
END
1314
$$ language plpgsql;
1415

15-
16-
17-
/* callback is in public namespace, must be schema-qualified*/
16+
/* callback #2*/
1817
CREATE OR REPLACEFUNCTIONpublic.dummy_cb(args JSONB)
1918
RETURNS VOIDAS $$
2019
BEGIN
2120
END
2221
$$ language plpgsql;
2322

23+
24+
2425
CREATETABLEcallbacks.abc(aserial, bint);
2526
SELECT create_range_partitions('callbacks.abc','a',1,100,2);
2627

@@ -78,25 +79,25 @@ SELECT create_hash_partitions('callbacks.abc', 'a', 5);
7879

7980
DROPTABLEcallbacks.abc CASCADE;
8081

82+
8183
/* test the temprary deletion of callback function*/
8284
CREATETABLEcallbacks.abc(aserial, bint);
8385
SELECT set_init_callback('callbacks.abc',
8486
'callbacks.abc_on_part_created_callback(jsonb)');
8587
SELECT create_range_partitions('callbacks.abc','a',1,100,2);
8688

8789
INSERT INTOcallbacks.abcVALUES (201,0);/* +1 new partition*/
90+
91+
BEGIN;
8892
DROPFUNCTIONcallbacks.abc_on_part_created_callback(jsonb);
8993
INSERT INTOcallbacks.abcVALUES (301,0);/* +0 new partitions (ERROR)*/
90-
CREATE OR REPLACEFUNCTIONcallbacks.abc_on_part_created_callback(args JSONB)
91-
RETURNS VOIDAS $$
92-
BEGIN
93-
RAISE WARNING'callback arg: %', args::TEXT;
94-
END
95-
$$ language plpgsql;
94+
ROLLBACK;
95+
9696
INSERT INTOcallbacks.abcVALUES (301,0);/* +1 new partition*/
9797

9898
DROPTABLEcallbacks.abc CASCADE;
9999

100+
100101
/* more complex test using rotation of tables*/
101102
CREATETABLEcallbacks.abc(a INT4NOT NULL);
102103
INSERT INTOcallbacks.abc
@@ -107,22 +108,22 @@ CREATE OR REPLACE FUNCTION callbacks.rotation_callback(params jsonb)
107108
RETURNS VOIDAS
108109
$$
109110
DECLARE
110-
relationregclass;
111+
relationregclass;
111112
parent_relregclass;
112113
BEGIN
113114
parent_rel := concat(params->>'partition_schema','.', params->>'parent')::regclass;
114115

115-
-- drop "old" partitions
116-
FOR relationIN (SELECT partitionFROM
116+
-- drop "old" partitions
117+
FOR relationIN (SELECT partitionFROM
117118
(SELECT partition, range_min::INT4FROM pathman_partition_list
118119
WHERE parent= parent_rel
119120
ORDER BY range_min::INT4DESC
120121
OFFSET4) t-- remain 4 last partitions
121122
ORDER BY range_min)
122-
LOOP
123-
RAISE NOTICE'dropping partition %', relation;
124-
PERFORM drop_range_partition(relation);
125-
END LOOP;
123+
LOOP
124+
RAISE NOTICE'dropping partition %', relation;
125+
PERFORM drop_range_partition(relation);
126+
END LOOP;
126127
END
127128
$$ LANGUAGE plpgsql;
128129

@@ -140,6 +141,8 @@ SELECT * FROM pathman_partition_list
140141
WHERE parent='callbacks.abc'::REGCLASS
141142
ORDER BY range_min::INT4;
142143

144+
145+
143146
DROPTABLEcallbacks.abc CASCADE;
144147
DROPSCHEMA callbacks CASCADE;
145148
DROP EXTENSION pg_pathman CASCADE;

‎src/partition_creation.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,10 @@ create_partitions_for_value_internal(Oid relid, Datum value, Oid value_type,
451451
FlushErrorState();
452452

453453
/* Produce log message if we're in BGW */
454-
error->elevel=LOG;
455-
error->message=psprintf(CppAsString(create_partitions_for_value_internal)
456-
": %s [%u]",error->message,MyProcPid);
457-
458-
ReThrowError(error);
454+
elog(LOG,
455+
CppAsString(create_partitions_for_value_internal)": %s [%u]",
456+
error->message,
457+
MyProcPid);
459458

460459
/* Reset 'partid' in case of error */
461460
partid=InvalidOid;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp