Skip to content

Commit

Permalink
Fix Some commands forgot to mark meta track.
Browse files Browse the repository at this point in the history
Issue apache#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
  • Loading branch information
avamingli committed Jul 9, 2024
1 parent c87fc6d commit 8b185f5
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/backend/commands/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,13 @@ RemovePolicyById(Oid policy_id)

systable_endscan(sscan);

/*
* CBDB GITHUB ISSUE:
* https://github.com/cloudberrydb/cloudberrydb/issues/504
*/
if (Gp_role == GP_ROLE_DISPATCH)
MetaTrackDropObject(PolicyRelationId, policy_id);

/*
* Note that, unlike some of the other flags in pg_class, relrowsecurity
* is not just an indication of if policies exist. When relrowsecurity is
Expand Down
7 changes: 7 additions & 0 deletions src/backend/commands/publicationcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,13 @@ RemovePublicationById(Oid pubid)
if (pubform->puballtables)
CacheInvalidateRelcacheAll();

/*
* CBDB GITHUB ISSUE:
* https://github.com/cloudberrydb/cloudberrydb/issues/504
*/
if (Gp_role == GP_ROLE_DISPATCH)
MetaTrackDropObject(PublicationRelationId, pubid);

CatalogTupleDelete(rel, &tup->t_self);

ReleaseSysCache(tup);
Expand Down
7 changes: 7 additions & 0 deletions src/backend/commands/schemacmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ RemoveSchemaById(Oid schemaOid)

CatalogTupleDelete(relation, &tup->t_self);

/*
* CBDB GITHUB ISSUE:
* https://github.com/cloudberrydb/cloudberrydb/issues/504
*/
if (Gp_role == GP_ROLE_DISPATCH)
MetaTrackDropObject(NamespaceRelationId, schemaOid);

ReleaseSysCache(tup);

table_close(relation, RowExclusiveLock);
Expand Down
60 changes: 60 additions & 0 deletions src/test/regress/expected/bfv_meta_track.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
--
--CBDB GITHUB ISSUE:
--https://github.com/cloudberrydb/cloudberrydb/issues/504
--
create schema bfv_meta_track;
set search_path to bfv_meta_track;
select count(*) from pg_stat_last_operation join
pg_namespace on pg_namespace.oid = pg_stat_last_operation.objid
where pg_namespace.nspname = 'bfv_meta_track';
count
-------
1
(1 row)

-- test drop popicy
create table t1(a int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Cloudberry Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
create policy p1 on t1 using (a % 2 = 0);
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;
count
-------
1
(1 row)

drop policy p1 on t1;
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;
count
-------
0
(1 row)

--test drop publication
-- start_ignore
create publication pub1;
-- end_ignore
select count(*) from pg_stat_last_operation a join pg_publication b on b.oid = a.objid where b.pubname = 'pub1';
count
-------
1
(1 row)

drop publication pub1;
select count(*) from pg_stat_last_operation a join pg_publication b on b.oid = a.objid where b.pubname = 'pub1';
count
-------
0
(1 row)

drop schema bfv_meta_track cascade;
NOTICE: drop cascades to table t1
-- test drop schema
select count(*) from pg_stat_last_operation join
pg_namespace on pg_namespace.oid = pg_stat_last_operation.objid
where pg_namespace.nspname = 'bfv_meta_track';
count
-------
0
(1 row)

2 changes: 2 additions & 0 deletions src/test/regress/greenplum_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,6 @@ test: motion_socket
# subtransaction overflow test
test: subtrx_overflow

test: bfv_meta_track

# end of tests
31 changes: 31 additions & 0 deletions src/test/regress/sql/bfv_meta_track.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--
--CBDB GITHUB ISSUE:
--https://github.com/cloudberrydb/cloudberrydb/issues/504
--

create schema bfv_meta_track;
set search_path to bfv_meta_track;
select count(*) from pg_stat_last_operation join
pg_namespace on pg_namespace.oid = pg_stat_last_operation.objid
where pg_namespace.nspname = 'bfv_meta_track';

-- test drop popicy
create table t1(a int);
create policy p1 on t1 using (a % 2 = 0);
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;
drop policy p1 on t1;
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;

--test drop publication
-- start_ignore
create publication pub1;
-- end_ignore
select count(*) from pg_stat_last_operation a join pg_publication b on b.oid = a.objid where b.pubname = 'pub1';
drop publication pub1;
select count(*) from pg_stat_last_operation a join pg_publication b on b.oid = a.objid where b.pubname = 'pub1';

drop schema bfv_meta_track cascade;
-- test drop schema
select count(*) from pg_stat_last_operation join
pg_namespace on pg_namespace.oid = pg_stat_last_operation.objid
where pg_namespace.nspname = 'bfv_meta_track';

0 comments on commit 8b185f5

Please sign in to comment.