!3493 创建数据库时校验表空间大小,并限制创建段页式表时不支持指定表空间大小

Merge pull request !3493 from 申正/createdb_change_max_size
This commit is contained in:
opengauss-bot
2023-06-05 13:46:30 +00:00
committed by Gitee
5 changed files with 32 additions and 2 deletions

View File

@ -253,6 +253,11 @@ static int64 calculate_database_size(Oid dbOid)
return totalsize;
}
int64 pg_cal_database_size_oid(Oid dbOid)
{
return (int64)(calculate_database_size(dbOid));
}
/*
* @Description: calculate the compress ratio of the column-partition relation.
* @in onerel: the relation.

View File

@ -50,6 +50,7 @@
#include "commands/comment.h"
#include "commands/dbcommands.h"
#include "commands/tablecmds.h"
#include "commands/tablespace.h"
#include "replication/slot.h"
#include "commands/sec_rls_cmds.h"
#include "commands/seclabel.h"
@ -437,6 +438,17 @@ Oid createdb(const CreatedbStmt* stmt)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("pg_global cannot be used as default tablespace")));
Oid defDbtemplate = get_database_oid(dbtemplate, false);
uint64 currSize = (uint64)pg_cal_database_size_oid(defDbtemplate);
uint64 tablespaceMaxSize = 0;
bool isLimit = TableSpaceUsageManager::IsLimited(dst_deftablespace, &tablespaceMaxSize);
if (isLimit && (tablespaceMaxSize < currSize)) {
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_RESOURCES),
errmsg("default database size %lu is bigger than max_size %lu set in tablespace \"%s\".",
currSize, tablespaceMaxSize, tablespacename)));
}
/*
* If we are trying to change the default tablespace of the template,
* we require that the template not have any files in the new default

View File

@ -2902,6 +2902,18 @@ ObjectAddress DefineRelation(CreateStmt* stmt, char relkind, Oid ownerId, Object
errmsg("The table %s do not support segment storage", stmt->relation->relname)));
}
if (storage_type == SEGMENT_PAGE) {
Oid tbspcId = (tablespaceId == InvalidOid) ? u_sess->proc_cxt.MyDatabaseTableSpace : tablespaceId;
uint64 tablespaceMaxSize = 0;
bool isLimit = TableSpaceUsageManager::IsLimited(tbspcId, &tablespaceMaxSize);
if (isLimit) {
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmodule(MOD_SEGMENT_PAGE),
errmsg("The table %s do not support segment-page storage", stmt->relation->relname),
errdetail("Segment-page storage doest not support limited tablespace \"%s\"", get_tablespace_name(tbspcId)),
errhint("use default or unlimited user defined tablespace before using segment-page storage.")));
}
}
if (ENABLE_DMS && !u_sess->attr.attr_common.IsInplaceUpgrade) {
if ((relkind == RELKIND_RELATION && storage_type != SEGMENT_PAGE) ||
relkind == RELKIND_MATVIEW ||

View File

@ -59,6 +59,7 @@ extern ObjectAddress AlterDatabaseOwner(const char* dbname, Oid newOwnerId);
extern void AlterDatabasePermissionCheck(Oid dboid, const char* dbname);
extern Oid get_database_oid(const char* dbname, bool missingok);
extern char* get_database_name(Oid dbid);
extern int64 pg_cal_database_size_oid(Oid dbOid);
extern char* get_and_check_db_name(Oid dbid, bool is_ereport = false);
extern bool have_createdb_privilege(void);

View File

@ -55,9 +55,9 @@ public:
static int ShmemSize(void);
static void Init(void);
static void IsExceedMaxsize(Oid tableSpaceOid, uint64 requestSize, bool segment);
private:
static bool IsLimited(Oid tableSpaceOid, uint64* maxSize);
private:
static inline int GetBucketIndex(Oid tableSpaceOid);
static inline void ResetUsageSlot(TableSpaceUsageSlot* info);
static inline void ResetBucket(TableSpaceUsageBucket* bucket);