2016-10-11 23:52:11 +08:00
|
|
|
-- Read configuration parameter analysis_quota_factor, making it
|
|
|
|
-- accessible to regular users (which don't have access to cdb_conf)
|
2019-05-31 21:29:28 +08:00
|
|
|
CREATE OR REPLACE FUNCTION @extschema@._CDB_GetConfAnalysisQuotaFactor()
|
2016-10-11 23:52:11 +08:00
|
|
|
RETURNS float8 AS
|
|
|
|
$$
|
|
|
|
BEGIN
|
2019-05-31 21:29:28 +08:00
|
|
|
RETURN @extschema@.CDB_Conf_GetConf('analysis_quota_factor')::text::float8;
|
2016-10-11 23:52:11 +08:00
|
|
|
END;
|
2019-10-03 23:37:11 +08:00
|
|
|
$$ LANGUAGE 'plpgsql'
|
|
|
|
STABLE
|
|
|
|
PARALLEL SAFE
|
|
|
|
SECURITY DEFINER
|
|
|
|
SET search_path = pg_temp;
|
2016-10-11 23:52:11 +08:00
|
|
|
|
|
|
|
|
2016-10-11 21:14:44 +08:00
|
|
|
-- Get the factor (fraction of the quota) for Camshaft cached analysis tables
|
2019-05-31 21:29:28 +08:00
|
|
|
CREATE OR REPLACE FUNCTION @extschema@._CDB_AnalysisQuotaFactor()
|
2016-10-11 21:14:44 +08:00
|
|
|
RETURNS float8 AS
|
|
|
|
$$
|
|
|
|
DECLARE
|
|
|
|
factor float8;
|
|
|
|
BEGIN
|
|
|
|
-- We use a floating point cdb_conf parameter
|
2019-05-31 21:29:28 +08:00
|
|
|
factor := @extschema@._CDB_GetConfAnalysisQuotaFactor();
|
2016-10-11 21:14:44 +08:00
|
|
|
-- With a default value
|
|
|
|
IF factor IS NULL THEN
|
2016-10-19 18:36:55 +08:00
|
|
|
factor := 2;
|
2016-10-11 21:14:44 +08:00
|
|
|
END IF;
|
|
|
|
RETURN factor;
|
|
|
|
END;
|
|
|
|
$$
|
2017-10-24 20:16:56 +08:00
|
|
|
LANGUAGE 'plpgsql' STABLE PARALLEL SAFE;
|
2016-10-11 21:14:44 +08:00
|
|
|
|
|
|
|
-- This checks the space used up by Camshaft cached analysis tables.
|
|
|
|
-- An exception will be raised if the limits are exceeded.
|
|
|
|
-- The name of an analysis table is passed; this, in addition to the
|
|
|
|
-- db role that executes this function is used to determined which
|
|
|
|
-- analysis tables will be considered.
|
2019-05-31 21:29:28 +08:00
|
|
|
CREATE OR REPLACE FUNCTION @extschema@.CDB_CheckAnalysisQuota(table_name TEXT)
|
2016-10-11 21:14:44 +08:00
|
|
|
RETURNS void AS
|
|
|
|
$$
|
|
|
|
DECLARE
|
|
|
|
schema_name TEXT;
|
|
|
|
user_name TEXT;
|
2016-10-19 18:41:18 +08:00
|
|
|
nominal_quota int8;
|
2016-10-11 21:14:44 +08:00
|
|
|
cache_size float8;
|
|
|
|
BEGIN
|
|
|
|
-- We rely on the search_path to determine the user's schema and
|
|
|
|
-- check for all analysis tables in that schema.
|
|
|
|
-- An alternative would be to use cdb_analysis_catalog to
|
|
|
|
-- select analysis tables (cache_tables) from the same user, analysis or node.
|
|
|
|
-- For example:
|
|
|
|
-- SELECT unnest(cache_tables) FROM cdb_analysis_catalog
|
|
|
|
-- WHERE username IN (SELECT username FROM cdb_analysis_catalog
|
|
|
|
-- WHERE table_name::regclass = ANY (cache_tables));
|
|
|
|
-- At the moment we're not using the provided table_name.
|
|
|
|
|
|
|
|
SELECT current_schema() INTO schema_name;
|
2016-10-19 18:41:18 +08:00
|
|
|
EXECUTE FORMAT('SELECT %I._CDB_UserQuotaInBytes();', schema_name) INTO nominal_quota;
|
2019-05-31 21:29:28 +08:00
|
|
|
IF nominal_quota * @extschema@._CDB_AnalysisQuotaFactor() < @extschema@._CDB_AnalysisDataSize(schema_name) THEN
|
2016-10-11 21:14:44 +08:00
|
|
|
-- The limit is defined by a factor applied to the total space quota for the user
|
|
|
|
RAISE EXCEPTION 'Analysis cache space limits exceeded';
|
|
|
|
END IF;
|
|
|
|
END;
|
2017-10-24 20:16:56 +08:00
|
|
|
$$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
|