Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADBDEV-4648: Limit diskquota hash table's size according initial request #28

Merged
merged 34 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d0b41d6
Merge remote-tracking branch 'origin/2.3.0-sync2' into 2.3.0-sync
red1452 Nov 23, 2023
f7b0ca1
Limit diskquota hash table's size according initial request
KnightMurloc Nov 27, 2023
705d2ca
using functions to work with time from gpdb instead of libc. add flag…
KnightMurloc Nov 28, 2023
2e1eed7
Revert "using functions to work with time from gpdb instead of libc. …
KnightMurloc Nov 29, 2023
645fd60
using functions to work with time from gpdb instead of libc
KnightMurloc Nov 29, 2023
1e3f233
unified logic for adding elements to hash tables in shared memory for…
KnightMurloc Nov 30, 2023
7158307
few fixes
KnightMurloc Nov 30, 2023
800adc1
remake shm_hash_enter
KnightMurloc Nov 30, 2023
7ff7717
use TimestampTz instead of time_t
KnightMurloc Nov 30, 2023
1d4a647
Merge branch 'gpdb' into ADBDEV-4648
KnightMurloc Dec 5, 2023
bcae9e1
fix formating
KnightMurloc Dec 5, 2023
9844e59
fix formating
KnightMurloc Dec 5, 2023
8af2777
make tests more stable
KnightMurloc Dec 5, 2023
edbda84
change guc description. fix warning message
KnightMurloc Dec 6, 2023
a94fd92
rework
KnightMurloc Dec 13, 2023
cdc9414
fix format
KnightMurloc Dec 13, 2023
db86b9b
change warning messages
KnightMurloc Dec 14, 2023
652c111
change macro names
KnightMurloc Dec 14, 2023
785fecd
use an external table to check warnings in the test.
KnightMurloc Dec 21, 2023
cb4e1bf
rename waribles. remove GUC value from warning messages.
KnightMurloc Dec 22, 2023
b8bbfc8
Add guc diskquota.max_reject_entries that control size of
KnightMurloc Dec 25, 2023
f650b93
fix format
KnightMurloc Dec 25, 2023
77e6caa
change default value of table_size_map_last_overflow_report from 0 to…
KnightMurloc Dec 25, 2023
a03e278
add comment.
KnightMurloc Dec 25, 2023
f65bddd
fix format
KnightMurloc Dec 25, 2023
58acb43
fix test
KnightMurloc Dec 26, 2023
a26964f
move quota_info_map_last_overflow_report size adding to diskquota_wor…
KnightMurloc Dec 26, 2023
a84787d
change warning messages. move size adding of quota_info_map to diskqu…
KnightMurloc Dec 26, 2023
2a2ed36
make tests more stable
KnightMurloc Dec 26, 2023
df6ef6f
add comment to tests. add new line at the end of new test
KnightMurloc Dec 27, 2023
e6e4033
Merge branch 'gpdb' into ADBDEV-4648
andr-sokolov Dec 28, 2023
4508501
change macro to const varibles.
KnightMurloc Dec 29, 2023
7f66cd5
make warning constats static
KnightMurloc Dec 29, 2023
7139176
add static to altered_reloid_cache_warning
KnightMurloc Dec 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,11 @@ install(PROGRAMS "cmake/install_gpdb_component" DESTINATION ".")
install(FILES ${diskquota_DDL} DESTINATION "share/postgresql/extension/")
install(TARGETS diskquota DESTINATION "lib/postgresql/")
install(FILES ${build_info_PATH} DESTINATION ".")

file(GLOB sql_files RELATIVE ${DISKQUOTA_DDL_DIR} "${DISKQUOTA_DDL_DIR}/diskquota--2.*.sql")
list(FILTER sql_files EXCLUDE REGEX ".*--.*--.*")
list(FILTER sql_files EXCLUDE REGEX ".*diskquota--${DISKQUOTA_MAJOR_VERSION}.${DISKQUOTA_MINOR_VERSION}.*")
foreach(so IN LISTS sql_files)
string(REGEX REPLACE "^diskquota--([0-9]+)\.([0-9]+).sql$" "diskquota-\\1.\\2.so" so ${so})
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${DISKQUOTA_BINARY_NAME}.so \"\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/lib/postgresql/${so}\")")
endforeach()
8 changes: 8 additions & 0 deletions control/ddl/diskquota--1.0--1.0.3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
\echo use "alter extension diskquota update to '1.0.3'" to load this file. \quit

SELECT gp_segment_id, pg_catalog.pg_extension_config_dump('diskquota.quota_config', '') from gp_dist_random('gp_id');

CREATE FUNCTION diskquota.update_diskquota_db_list(oid, int4)
RETURNS void STRICT
AS 'MODULE_PATHNAME'
LANGUAGE C;
6 changes: 3 additions & 3 deletions control/ddl/diskquota--1.0--2.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ CREATE TABLE diskquota.target (
primaryOid oid,
tablespaceOid oid, -- REFERENCES pg_tablespace.oid,
PRIMARY KEY (primaryOid, tablespaceOid, quotatype)
);
) WITH (appendonly=false);
-- TODO ALTER TABLE diskquota.target SET DEPENDS ON EXTENSION diskquota;

ALTER TABLE diskquota.table_size ADD COLUMN segid smallint DEFAULT -1; -- segid = coordinator means table size in cluster level
ALTER TABLE diskquota.table_size DROP CONSTRAINT table_size_pkey;
ALTER TABLE diskquota.table_size ADD PRIMARY KEY (tableid, segid);
ALTER TABLE diskquota.table_size SET WITH (REORGANIZE=true) DISTRIBUTED BY (tableid, segid);

-- TODO SELECT pg_catalog.pg_extension_config_dump('diskquota.target', '');
-- TODO SELECT gp_segment_id, pg_catalog.pg_extension_config_dump('diskquota.target', '') FROM gp_dist_random('gp_id');
SELECT pg_catalog.pg_extension_config_dump('diskquota.target', '');
SELECT gp_segment_id, pg_catalog.pg_extension_config_dump('diskquota.target', '') FROM gp_dist_random('gp_id');
-- table part end

-- type define
Expand Down
284 changes: 284 additions & 0 deletions control/ddl/diskquota--1.0.3--2.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
-- TODO check if worker should not refresh, current lib should be diskquota-2.0.so

-- table part
ALTER TABLE diskquota.quota_config ADD COLUMN segratio float4 DEFAULT 0;

CREATE TABLE diskquota.target (
rowId serial,
quotatype int, -- REFERENCES disquota.quota_config.quotatype,
primaryOid oid,
tablespaceOid oid, -- REFERENCES pg_tablespace.oid,
PRIMARY KEY (primaryOid, tablespaceOid, quotatype)
) WITH (appendonly=false);
-- TODO ALTER TABLE diskquota.target SET DEPENDS ON EXTENSION diskquota;

ALTER TABLE diskquota.table_size ADD COLUMN segid smallint DEFAULT -1; -- segid = coordinator means table size in cluster level
ALTER TABLE diskquota.table_size DROP CONSTRAINT table_size_pkey;
ALTER TABLE diskquota.table_size ADD PRIMARY KEY (tableid, segid);
ALTER TABLE diskquota.table_size SET WITH (REORGANIZE=true) DISTRIBUTED BY (tableid, segid);

SELECT pg_catalog.pg_extension_config_dump('diskquota.target', '');
SELECT gp_segment_id, pg_catalog.pg_extension_config_dump('diskquota.target', '') FROM gp_dist_random('gp_id');
-- table part end

-- type define
ALTER TYPE diskquota.diskquota_active_table_type ADD ATTRIBUTE "GP_SEGMENT_ID" smallint;

CREATE TYPE diskquota.rejectmap_entry AS (
target_oid oid,
database_oid oid,
tablespace_oid oid,
target_type integer,
seg_exceeded boolean
);

CREATE TYPE diskquota.rejectmap_entry_detail AS (
target_type text,
target_oid oid,
database_oid oid,
tablespace_oid oid,
seg_exceeded boolean,
dbnode oid,
spcnode oid,
relnode oid,
segid int
);

CREATE TYPE diskquota.relation_cache_detail AS (
RELID oid,
PRIMARY_TABLE_OID oid,
AUXREL_NUM int,
OWNEROID oid,
NAMESPACEOID oid,
BACKENDID int,
SPCNODE oid,
DBNODE oid,
RELNODE oid,
RELSTORAGE "char",
AUXREL_OID oid[]
);
-- type define end

-- UDF
/* ALTER */ CREATE OR REPLACE FUNCTION diskquota.set_schema_quota(text, text) RETURNS void STRICT AS '$libdir/diskquota-2.0.so' LANGUAGE C;
/* ALTER */ CREATE OR REPLACE FUNCTION diskquota.set_role_quota(text, text) RETURNS void STRICT AS '$libdir/diskquota-2.0.so' LANGUAGE C;
/* ALTER */ CREATE OR REPLACE FUNCTION diskquota.init_table_size_table() RETURNS void STRICT AS '$libdir/diskquota-2.0.so' LANGUAGE C;
/* ALTER */ CREATE OR REPLACE FUNCTION diskquota.diskquota_fetch_table_stat(int4, oid[]) RETURNS setof diskquota.diskquota_active_table_type AS '$libdir/diskquota-2.0.so', 'diskquota_fetch_table_stat' LANGUAGE C VOLATILE;

-- TODO solve dependency DROP FUNCTION diskquota.update_diskquota_db_list(oid, int4);

CREATE FUNCTION diskquota.set_schema_tablespace_quota(text, text, text) RETURNS void STRICT AS '$libdir/diskquota-2.0.so' LANGUAGE C;
CREATE FUNCTION diskquota.set_role_tablespace_quota(text, text, text) RETURNS void STRICT AS '$libdir/diskquota-2.0.so' LANGUAGE C;
CREATE FUNCTION diskquota.set_per_segment_quota(text, float4) RETURNS void STRICT AS '$libdir/diskquota-2.0.so' LANGUAGE C;
CREATE FUNCTION diskquota.refresh_rejectmap(diskquota.rejectmap_entry[], oid[]) RETURNS void STRICT AS '$libdir/diskquota-2.0.so' LANGUAGE C;
CREATE FUNCTION diskquota.show_rejectmap() RETURNS setof diskquota.rejectmap_entry_detail AS '$libdir/diskquota-2.0.so', 'show_rejectmap' LANGUAGE C;
CREATE FUNCTION diskquota.pause() RETURNS void STRICT AS '$libdir/diskquota-2.0.so', 'diskquota_pause' LANGUAGE C;
CREATE FUNCTION diskquota.resume() RETURNS void STRICT AS '$libdir/diskquota-2.0.so', 'diskquota_resume' LANGUAGE C;
CREATE FUNCTION diskquota.show_worker_epoch() RETURNS bigint STRICT AS '$libdir/diskquota-2.0.so', 'show_worker_epoch' LANGUAGE C;
CREATE FUNCTION diskquota.wait_for_worker_new_epoch() RETURNS boolean STRICT AS '$libdir/diskquota-2.0.so', 'wait_for_worker_new_epoch' LANGUAGE C;
CREATE FUNCTION diskquota.status() RETURNS TABLE ("name" text, "status" text) STRICT AS '$libdir/diskquota-2.0.so', 'diskquota_status' LANGUAGE C;
CREATE FUNCTION diskquota.show_relation_cache() RETURNS setof diskquota.relation_cache_detail AS '$libdir/diskquota-2.0.so', 'show_relation_cache' LANGUAGE C;
CREATE FUNCTION diskquota.relation_size_local(
reltablespace oid,
relfilenode oid,
relpersistence "char",
relstorage "char")
RETURNS bigint STRICT AS '$libdir/diskquota-2.0.so', 'relation_size_local' LANGUAGE C;
CREATE FUNCTION diskquota.pull_all_table_size(OUT tableid oid, OUT size bigint, OUT segid smallint) RETURNS SETOF RECORD AS '$libdir/diskquota-2.0.so', 'pull_all_table_size' LANGUAGE C;
CREATE FUNCTION diskquota.relation_size(relation regclass) RETURNS bigint STRICT AS $$
SELECT SUM(size)::bigint FROM (
SELECT diskquota.relation_size_local(reltablespace, relfilenode, relpersistence, relstorage) AS size
FROM gp_dist_random('pg_class') WHERE oid = relation
UNION ALL
SELECT diskquota.relation_size_local(reltablespace, relfilenode, relpersistence, relstorage) AS size
FROM pg_class WHERE oid = relation
) AS t $$ LANGUAGE SQL;

CREATE FUNCTION diskquota.show_relation_cache_all_seg() RETURNS setof diskquota.relation_cache_detail AS $$
WITH relation_cache AS (
SELECT diskquota.show_relation_cache() AS a
FROM gp_dist_random('gp_id')
)
SELECT (a).* FROM relation_cache; $$ LANGUAGE SQL;
-- UDF end

-- views
CREATE VIEW diskquota.rejectmap AS SELECT * FROM diskquota.show_rejectmap() AS BM;

/* ALTER */ CREATE OR REPLACE VIEW diskquota.show_fast_database_size_view AS
SELECT (
(SELECT SUM(pg_relation_size(oid)) FROM pg_class WHERE oid <= 16384)
+
(SELECT SUM(size) FROM diskquota.table_size WHERE segid = -1)
) AS dbsize;

/* ALTER */ CREATE OR REPLACE VIEW diskquota.show_fast_schema_quota_view AS
WITH
quota_usage AS (
SELECT
relnamespace,
SUM(size) AS total_size
FROM
diskquota.table_size,
pg_class
WHERE
tableid = pg_class.oid AND
segid = -1
GROUP BY
relnamespace
)
SELECT
nspname AS schema_name,
targetoid AS schema_oid,
quotalimitMB AS quota_in_mb,
COALESCE(total_size, 0) AS nspsize_in_bytes
FROM
diskquota.quota_config JOIN
pg_namespace ON targetoid = pg_namespace.oid LEFT OUTER JOIN
quota_usage ON pg_namespace.oid = relnamespace
WHERE
quotaType = 0; -- NAMESPACE_QUOTA

/* ALTER */ CREATE OR REPLACE VIEW diskquota.show_fast_role_quota_view AS
WITH
quota_usage AS (
SELECT
relowner,
SUM(size) AS total_size
FROM
diskquota.table_size,
pg_class
WHERE
tableid = pg_class.oid AND
segid = -1
GROUP BY
relowner
)
SELECT
rolname AS role_name,
targetoid AS role_oid,
quotalimitMB AS quota_in_mb,
COALESCE(total_size, 0) AS rolsize_in_bytes
FROM
diskquota.quota_config JOIN
pg_roles ON targetoid = pg_roles.oid LEFT OUTER JOIN
quota_usage ON pg_roles.oid = relowner
WHERE
quotaType = 1; -- ROLE_QUOTA

CREATE VIEW diskquota.show_fast_schema_tablespace_quota_view AS
WITH
default_tablespace AS (
SELECT dattablespace FROM pg_database
WHERE datname = current_database()
),
quota_usage AS (
SELECT
relnamespace,
CASE
WHEN reltablespace = 0 THEN dattablespace
ELSE reltablespace
END AS reltablespace,
SUM(size) AS total_size
FROM
diskquota.table_size,
pg_class,
default_tablespace
WHERE
tableid = pg_class.oid AND
segid = -1
GROUP BY
relnamespace,
reltablespace,
dattablespace
),
full_quota_config AS (
SELECT
primaryOid,
tablespaceoid,
quotalimitMB
FROM
diskquota.quota_config AS config,
diskquota.target AS target
WHERE
config.targetOid = target.rowId AND
config.quotaType = target.quotaType AND
config.quotaType = 2 -- NAMESPACE_TABLESPACE_QUOTA
)
SELECT
nspname AS schema_name,
primaryoid AS schema_oid,
spcname AS tablespace_name,
tablespaceoid AS tablespace_oid,
quotalimitMB AS quota_in_mb,
COALESCE(total_size, 0) AS nspsize_tablespace_in_bytes
FROM
full_quota_config JOIN
pg_namespace ON primaryoid = pg_namespace.oid JOIN
pg_tablespace ON tablespaceoid = pg_tablespace.oid LEFT OUTER JOIN
quota_usage ON pg_namespace.oid = relnamespace AND pg_tablespace.oid = reltablespace;

CREATE VIEW diskquota.show_fast_role_tablespace_quota_view AS
WITH
default_tablespace AS (
SELECT dattablespace FROM pg_database
WHERE datname = current_database()
),
quota_usage AS (
SELECT
relowner,
CASE
WHEN reltablespace = 0 THEN dattablespace
ELSE reltablespace
END AS reltablespace,
SUM(size) AS total_size
FROM
diskquota.table_size,
pg_class,
default_tablespace
WHERE
tableid = pg_class.oid AND
segid = -1
GROUP BY
relowner,
reltablespace,
dattablespace
),
full_quota_config AS (
SELECT
primaryOid,
tablespaceoid,
quotalimitMB
FROM
diskquota.quota_config AS config,
diskquota.target AS target
WHERE
config.targetOid = target.rowId AND
config.quotaType = target.quotaType AND
config.quotaType = 3 -- ROLE_TABLESPACE_QUOTA
)
SELECT
rolname AS role_name,
primaryoid AS role_oid,
spcname AS tablespace_name,
tablespaceoid AS tablespace_oid,
quotalimitMB AS quota_in_mb,
COALESCE(total_size, 0) AS rolsize_tablespace_in_bytes
FROM
full_quota_config JOIN
pg_roles ON primaryoid = pg_roles.oid JOIN
pg_tablespace ON tablespaceoid = pg_tablespace.oid LEFT OUTER JOIN
quota_usage ON pg_roles.oid = relowner AND pg_tablespace.oid = reltablespace;

CREATE VIEW diskquota.show_segment_ratio_quota_view AS
SELECT
spcname as tablespace_name,
pg_tablespace.oid as tablespace_oid,
segratio as per_seg_quota_ratio
FROM
diskquota.quota_config JOIN
pg_tablespace ON targetOid = pg_tablespace.oid
AND quotatype = 4;

-- views end

6 changes: 3 additions & 3 deletions control/ddl/diskquota--1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ CREATE TABLE diskquota.quota_config(
quotatype int,
quotalimitMB int8,
PRIMARY KEY(targetOid, quotatype)
);
) WITH (appendonly=false);

CREATE TABLE diskquota.table_size(
tableid oid,
size bigint,
PRIMARY KEY(tableid)
);
) WITH (appendonly=false);

CREATE TABLE diskquota.state(
state int,
PRIMARY KEY(state)
);
) WITH (appendonly=false);

-- only diskquota.quota_config is dump-able, other table can be generate on fly
SELECT pg_catalog.pg_extension_config_dump('diskquota.quota_config', '');
Expand Down
8 changes: 4 additions & 4 deletions control/ddl/diskquota--2.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ CREATE TABLE diskquota.quota_config(
quotalimitMB int8,
segratio float4 DEFAULT 0,
PRIMARY KEY(targetOid, quotatype)
) DISTRIBUTED BY (targetOid, quotatype);
) WITH (appendonly=false) DISTRIBUTED BY (targetOid, quotatype);

CREATE TABLE diskquota.target (
rowId serial,
quotatype int, --REFERENCES disquota.quota_config.quotatype,
primaryOid oid,
tablespaceOid oid, --REFERENCES pg_tablespace.oid,
PRIMARY KEY (primaryOid, tablespaceOid, quotatype)
);
) WITH (appendonly=false);

CREATE TABLE diskquota.table_size(
tableid oid,
size bigint,
segid smallint,
PRIMARY KEY(tableid, segid)
) DISTRIBUTED BY (tableid, segid);
) WITH (appendonly=false) DISTRIBUTED BY (tableid, segid);

CREATE TABLE diskquota.state(
state int,
PRIMARY KEY(state)
) DISTRIBUTED BY (state);
) WITH (appendonly=false) DISTRIBUTED BY (state);

-- diskquota.quota_config AND diskquota.target is dump-able, other table can be generate on fly
SELECT pg_catalog.pg_extension_config_dump('diskquota.quota_config', '');
Expand Down
Loading
Loading