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

Commit81de353

Browse files
committed
Merge branch 'rel_future_beta' into rel_future_copy_fallback_2
2 parentsb2793a7 +63dccb6 commit81de353

11 files changed

+266
-198
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ pg_pathman--*.sql
1313
tags
1414
cscope*
1515
Dockerfile
16+
testgres

‎Dockerfile.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ RUN if [ "${CHECK_CODE}" = "cppcheck" ] ; then \
1414
RUN if [ "${CHECK_CODE}" = "false" ] ; then \
1515
echo 'http://dl-3.alpinelinux.org/alpine/edge/main' > /etc/apk/repositories; \
1616
apk --no-cache add curl python3 gcc make musl-dev cmocka-dev;\
17-
pip3 installtestgres;\
17+
pip3 installvirtualenv;\
1818
fi
1919

2020
RUN mkdir -p /pg/data && \

‎README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,25 @@ drop_partitions(parent REGCLASS,
251251
```
252252
Drop partitions of the`parent` table (both foreign and local relations). If`delete_data` is`false`, the data is copied to the parent table first. Default is`false`.
253253

254+
To remove partitioned table along with all partitions fully, use conventional
255+
`DROP TABLE relation CASCADE`. However, care should be taken in somewhat rare
256+
case when you are running logical replication and`DROP` was executed by
257+
replication apply worker, e.g. via trigger on replicated table.`pg_pathman`
258+
uses`pathman_ddl_trigger` event trigger to remove the record about dropped
259+
table from`pathman_config`, and this trigger by default won't fire on replica,
260+
leading to inconsistent state when`pg_pathman` thinks that the table still
261+
exists, but in fact it doesn't. If this is the case, configure this trigger to
262+
fire on replica too:
263+
264+
```plpgsql
265+
ALTER EVENT TRIGGER pathman_ddl_trigger ENABLE ALWAYS;
266+
```
267+
268+
Physical replication doesn't have this problem since DDL as well as
269+
`pathman_config` table is replicated too; master and slave PostgreSQL instances
270+
are basically identical, and it is only harmful to keep this trigger in`ALWAYS`
271+
mode.
272+
254273

255274
###Additional parameters
256275

‎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

‎make_images.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22

33
importsubprocess
4+
importgetpass
45

56
DOCKER_ID='pathman'
67
pg_versions= ['9.5','9.6','10']
@@ -17,11 +18,12 @@
1718
}
1819
}
1920

20-
password=input("Enter password for `docker login` for user `%s`: "%DOCKER_ID)
21+
user=input("Enter username for `docker login`: ")
22+
password=getpass.getpass()
2123
subprocess.check_output([
2224
'docker',
2325
'login',
24-
'-u',DOCKER_ID,
26+
'-u',user,
2527
'-p',password])
2628

2729
travis_conf_line='- DOCKER_IMAGE=%s'

‎run_tests.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ elif [ "$CHECK_CODE" = "cppcheck" ]; then
3535
exit$status
3636
fi
3737

38+
# we need testgres for pathman tests
39+
virtualenv env
40+
export VIRTUAL_ENV_DISABLE_PROMPT=1
41+
source env/bin/activate
42+
pip3 install testgres
43+
pip3 freeze| grep testgres
44+
3845
# don't forget to "make clean"
3946
make USE_PGXS=1 clean
4047

‎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
@@ -450,11 +450,10 @@ create_partitions_for_value_internal(Oid relid, Datum value, Oid value_type,
450450
FlushErrorState();
451451

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

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp