forked from greenplum-db/diskquota-archive
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Invalidate diskquota.table_size entries during startup (#27)
Diskquota calculates sizes and stores information in the diskquota.table_size table periodically with a pause in diskquota.naptime, 2 seconds by default. If we restart the cluster during this pause, then diskquota will lose all changes that have occurred since the last save to the diskquota.table_size table. We could create temporary tables, wait when it will be flushed to diskquota.table_size table, restart the cluster, and diskquota would remember the information about the temporary tables. Or we could delete the tables, restart the cluster, and again diskquota will remember information about the deleted tables. This happens because at the start of the cluster, diskquota remembers all the information written to the diskquota.table_size table, but does not check that some tables may have already been deleted. As a solution, we invalidate diskquota.table_size during diskquota worker start in addition to pg_class validation.
- Loading branch information
Showing
8 changed files
with
182 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
-- Ensure diskquota does not save information about dropped table during restart cluster by invalidates it at startup | ||
|
||
1: CREATE SCHEMA dropped_schema; | ||
CREATE | ||
1: SET search_path TO dropped_schema; | ||
SET | ||
1: SELECT diskquota.set_schema_quota('dropped_schema', '1 MB'); | ||
set_schema_quota | ||
------------------ | ||
|
||
(1 row) | ||
1: SELECT diskquota.wait_for_worker_new_epoch(); | ||
wait_for_worker_new_epoch | ||
--------------------------- | ||
t | ||
(1 row) | ||
1: CREATE TABLE dropped_table(id int) DISTRIBUTED BY (id); | ||
CREATE | ||
1: INSERT INTO dropped_table SELECT generate_series(1, 100000); | ||
INSERT 100000 | ||
-- Wait for the diskquota bgworker refreshing the size of 'dropped_table'. | ||
1: SELECT diskquota.wait_for_worker_new_epoch(); | ||
wait_for_worker_new_epoch | ||
--------------------------- | ||
t | ||
(1 row) | ||
1: DROP TABLE dropped_table; | ||
DROP | ||
1q: ... <quitting> | ||
|
||
-- Restart cluster fastly | ||
!\retcode gpstop -afr; | ||
-- start_ignore | ||
-- end_ignore | ||
(exited with code 0) | ||
|
||
-- Indicates that there is no dropped table in pg_catalog.pg_class | ||
1: SELECT oid FROM pg_catalog.pg_class WHERE relname = 'dropped_table'; | ||
oid | ||
----- | ||
(0 rows) | ||
-- Indicates that there are no entries in diskquota.table_size that are not present in pg_catalog.pg_class | ||
1: SELECT tableid FROM diskquota.table_size WHERE NOT EXISTS (SELECT 1 FROM pg_catalog.pg_class WHERE tableid = oid) AND segid = -1; | ||
tableid | ||
--------- | ||
(0 rows) | ||
1: DROP SCHEMA dropped_schema CASCADE; | ||
DROP | ||
1q: ... <quitting> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
-- Ensure diskquota does not save information about temporary table during restart cluster by invalidates it at startup | ||
|
||
1: CREATE SCHEMA temporary_schema; | ||
CREATE | ||
1: SET search_path TO temporary_schema; | ||
SET | ||
1: SELECT diskquota.set_schema_quota('temporary_schema', '1 MB'); | ||
set_schema_quota | ||
------------------ | ||
|
||
(1 row) | ||
1: SELECT diskquota.wait_for_worker_new_epoch(); | ||
wait_for_worker_new_epoch | ||
--------------------------- | ||
t | ||
(1 row) | ||
1: CREATE TEMPORARY TABLE temporary_table(id int) DISTRIBUTED BY (id); | ||
CREATE | ||
1: INSERT INTO temporary_table SELECT generate_series(1, 100000); | ||
INSERT 100000 | ||
-- Wait for the diskquota bgworker refreshing the size of 'temporary_table'. | ||
1: SELECT diskquota.wait_for_worker_new_epoch(); | ||
wait_for_worker_new_epoch | ||
--------------------------- | ||
t | ||
(1 row) | ||
1q: ... <quitting> | ||
|
||
-- Restart cluster fastly | ||
!\retcode gpstop -afr; | ||
-- start_ignore | ||
-- end_ignore | ||
(exited with code 0) | ||
|
||
-- Indicates that there is no temporary table in pg_catalog.pg_class | ||
1: SELECT oid FROM pg_catalog.pg_class WHERE relname = 'temporary_table'; | ||
oid | ||
----- | ||
(0 rows) | ||
-- Indicates that there are no entries in diskquota.table_size that are not present in pg_catalog.pg_class | ||
1: SELECT tableid FROM diskquota.table_size WHERE NOT EXISTS (SELECT 1 FROM pg_catalog.pg_class WHERE tableid = oid) AND segid = -1; | ||
tableid | ||
--------- | ||
(0 rows) | ||
1: DROP SCHEMA temporary_schema CASCADE; | ||
DROP | ||
1q: ... <quitting> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- Ensure diskquota does not save information about dropped table during restart cluster by invalidates it at startup | ||
|
||
1: CREATE SCHEMA dropped_schema; | ||
1: SET search_path TO dropped_schema; | ||
1: SELECT diskquota.set_schema_quota('dropped_schema', '1 MB'); | ||
1: SELECT diskquota.wait_for_worker_new_epoch(); | ||
1: CREATE TABLE dropped_table(id int) DISTRIBUTED BY (id); | ||
1: INSERT INTO dropped_table SELECT generate_series(1, 100000); | ||
-- Wait for the diskquota bgworker refreshing the size of 'dropped_table'. | ||
1: SELECT diskquota.wait_for_worker_new_epoch(); | ||
1: DROP TABLE dropped_table; | ||
1q: | ||
|
||
-- Restart cluster fastly | ||
!\retcode gpstop -afr; | ||
|
||
-- Indicates that there is no dropped table in pg_catalog.pg_class | ||
1: SELECT oid FROM pg_catalog.pg_class WHERE relname = 'dropped_table'; | ||
-- Indicates that there are no entries in diskquota.table_size that are not present in pg_catalog.pg_class | ||
1: SELECT tableid FROM diskquota.table_size WHERE NOT EXISTS (SELECT 1 FROM pg_catalog.pg_class WHERE tableid = oid) AND segid = -1; | ||
1: DROP SCHEMA dropped_schema CASCADE; | ||
1q: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- Ensure diskquota does not save information about temporary table during restart cluster by invalidates it at startup | ||
|
||
1: CREATE SCHEMA temporary_schema; | ||
1: SET search_path TO temporary_schema; | ||
1: SELECT diskquota.set_schema_quota('temporary_schema', '1 MB'); | ||
1: SELECT diskquota.wait_for_worker_new_epoch(); | ||
1: CREATE TEMPORARY TABLE temporary_table(id int) DISTRIBUTED BY (id); | ||
1: INSERT INTO temporary_table SELECT generate_series(1, 100000); | ||
-- Wait for the diskquota bgworker refreshing the size of 'temporary_table'. | ||
1: SELECT diskquota.wait_for_worker_new_epoch(); | ||
1q: | ||
|
||
-- Restart cluster fastly | ||
!\retcode gpstop -afr; | ||
|
||
-- Indicates that there is no temporary table in pg_catalog.pg_class | ||
1: SELECT oid FROM pg_catalog.pg_class WHERE relname = 'temporary_table'; | ||
-- Indicates that there are no entries in diskquota.table_size that are not present in pg_catalog.pg_class | ||
1: SELECT tableid FROM diskquota.table_size WHERE NOT EXISTS (SELECT 1 FROM pg_catalog.pg_class WHERE tableid = oid) AND segid = -1; | ||
1: DROP SCHEMA temporary_schema CASCADE; | ||
1q: |