[bugfix](policy) Forbid creating policy with same name with different resource name (#25025)

This commit is contained in:
AlexYue
2023-10-09 11:27:49 +08:00
committed by GitHub
parent febc5ed1a5
commit 0f59f49768
2 changed files with 58 additions and 1 deletions

View File

@ -120,7 +120,16 @@ public class PolicyMgr implements Writable {
Policy policy = Policy.fromCreateStmt(stmt);
writeLock();
try {
if (existPolicy(policy)) {
boolean storagePolicyExists = false;
if (PolicyTypeEnum.STORAGE == policy.getType()) {
// The name of the storage policy remains globally unique until it is renamed by user.
// So we could just compare the policy name to check if there are redundant ones.
// Otherwise two storage policy share one same name but with different resource name
// will not be filtered. See github #25025 for more details.
storagePolicyExists = getPoliciesByType(PolicyTypeEnum.STORAGE)
.stream().anyMatch(p -> p.getPolicyName().equals(policy.getPolicyName()));
}
if (storagePolicyExists || existPolicy(policy)) {
if (stmt.isIfNotExists()) {
return;
}