Skip to content

Commit 472db76

Browse files
committed
Fix Some commands forgot to mark meta track.
Issue #504 It will make unstable cases failed as: ERROR: duplicate key value violates unique constraint "pg_statlastop_classid_objid_staactionname_index" Call MetaTrackDropObject in functions: RemoveSchemaById RemovePublicationById RemovePolicyById Authored-by: Zhang Mingli avamingli@gmail.com
1 parent d4decf9 commit 472db76

File tree

6 files changed

+114
-0
lines changed

6 files changed

+114
-0
lines changed

src/backend/commands/policy.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,13 @@ RemovePolicyById(Oid policy_id)
391391

392392
systable_endscan(sscan);
393393

394+
/*
395+
* CBDB GITHUB ISSUE:
396+
* https://github.com/cloudberrydb/cloudberrydb/issues/504
397+
*/
398+
if (Gp_role == GP_ROLE_DISPATCH)
399+
MetaTrackDropObject(PolicyRelationId, policy_id);
400+
394401
/*
395402
* Note that, unlike some of the other flags in pg_class, relrowsecurity
396403
* is not just an indication of if policies exist. When relrowsecurity is

src/backend/commands/publicationcmds.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,13 @@ RemovePublicationById(Oid pubid)
573573
if (pubform->puballtables)
574574
CacheInvalidateRelcacheAll();
575575

576+
/*
577+
* CBDB GITHUB ISSUE:
578+
* https://github.com/cloudberrydb/cloudberrydb/issues/504
579+
*/
580+
if (Gp_role == GP_ROLE_DISPATCH)
581+
MetaTrackDropObject(PublicationRelationId, pubid);
582+
576583
CatalogTupleDelete(rel, &tup->t_self);
577584

578585
ReleaseSysCache(tup);

src/backend/commands/schemacmds.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,13 @@ RemoveSchemaById(Oid schemaOid)
325325

326326
CatalogTupleDelete(relation, &tup->t_self);
327327

328+
/*
329+
* CBDB GITHUB ISSUE:
330+
* https://github.com/cloudberrydb/cloudberrydb/issues/504
331+
*/
332+
if (Gp_role == GP_ROLE_DISPATCH)
333+
MetaTrackDropObject(NamespaceRelationId, schemaOid);
334+
328335
ReleaseSysCache(tup);
329336

330337
table_close(relation, RowExclusiveLock);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
--
2+
--CBDB GITHUB ISSUE:
3+
--https://github.com/cloudberrydb/cloudberrydb/issues/504
4+
--
5+
create schema bfv_meta_track;
6+
set search_path to bfv_meta_track;
7+
select count(*) from pg_stat_last_operation join
8+
pg_namespace on pg_namespace.oid = pg_stat_last_operation.objid
9+
where pg_namespace.nspname = 'bfv_meta_track';
10+
count
11+
-------
12+
1
13+
(1 row)
14+
15+
-- test drop popicy
16+
create table t1(a int);
17+
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Cloudberry Database data distribution key for this table.
18+
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
19+
create policy p1 on t1 using (a % 2 = 0);
20+
select count(*) from pg_stat_last_operation a join pg_policy b on b.oid = a.objid where b.polname = 'p1' and b.polrelid ='t1'::regclass::oid;
21+
count
22+
-------
23+
1
24+
(1 row)
25+
26+
drop policy p1 on t1;
27+
select count(*) from pg_stat_last_operation a join pg_policy b on b.oid = a.objid where b.polname = 'p1' and b.polrelid ='t1'::regclass::oid;
28+
count
29+
-------
30+
0
31+
(1 row)
32+
33+
--test drop publication
34+
-- start_ignore
35+
create publication pub1;
36+
-- end_ignore
37+
select count(*) from pg_stat_last_operation a join pg_publication b on b.oid = a.objid where b.pubname = 'pub1';
38+
count
39+
-------
40+
1
41+
(1 row)
42+
43+
drop publication pub1;
44+
select count(*) from pg_stat_last_operation a join pg_publication b on b.oid = a.objid where b.pubname = 'pub1';
45+
count
46+
-------
47+
0
48+
(1 row)
49+
50+
drop schema bfv_meta_track cascade;
51+
NOTICE: drop cascades to table t1
52+
-- test drop schema
53+
select count(*) from pg_stat_last_operation join
54+
pg_namespace on pg_namespace.oid = pg_stat_last_operation.objid
55+
where pg_namespace.nspname = 'bfv_meta_track';
56+
count
57+
-------
58+
0
59+
(1 row)
60+

src/test/regress/greenplum_schedule

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,6 @@ test: motion_socket
327327
# subtransaction overflow test
328328
test: subtrx_overflow
329329

330+
test: bfv_meta_track
331+
330332
# end of tests
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--
2+
--CBDB GITHUB ISSUE:
3+
--https://github.com/cloudberrydb/cloudberrydb/issues/504
4+
--
5+
6+
create schema bfv_meta_track;
7+
set search_path to bfv_meta_track;
8+
select count(*) from pg_stat_last_operation join
9+
pg_namespace on pg_namespace.oid = pg_stat_last_operation.objid
10+
where pg_namespace.nspname = 'bfv_meta_track';
11+
12+
-- test drop popicy
13+
create table t1(a int);
14+
create policy p1 on t1 using (a % 2 = 0);
15+
select count(*) from pg_stat_last_operation a join pg_policy b on b.oid = a.objid where b.polname = 'p1' and b.polrelid ='t1'::regclass::oid;
16+
drop policy p1 on t1;
17+
select count(*) from pg_stat_last_operation a join pg_policy b on b.oid = a.objid where b.polname = 'p1' and b.polrelid ='t1'::regclass::oid;
18+
19+
--test drop publication
20+
-- start_ignore
21+
create publication pub1;
22+
-- end_ignore
23+
select count(*) from pg_stat_last_operation a join pg_publication b on b.oid = a.objid where b.pubname = 'pub1';
24+
drop publication pub1;
25+
select count(*) from pg_stat_last_operation a join pg_publication b on b.oid = a.objid where b.pubname = 'pub1';
26+
27+
drop schema bfv_meta_track cascade;
28+
-- test drop schema
29+
select count(*) from pg_stat_last_operation join
30+
pg_namespace on pg_namespace.oid = pg_stat_last_operation.objid
31+
where pg_namespace.nspname = 'bfv_meta_track';

0 commit comments

Comments
 (0)