|
6 | 6 | namespace NKikimr { |
7 | 7 | namespace NSchemeShard { |
8 | 8 |
|
9 | | -inline bool CheckStorageQuotasKinds(const Ydb::Cms::DatabaseQuotas& quotas, |
10 | | - const TVector<TStoragePool>& pools, |
11 | | - const TString& path, |
12 | | - TString& error |
| 9 | +inline bool CheckStoragePoolsInQuotas(const Ydb::Cms::DatabaseQuotas& quotas, |
| 10 | + const TVector<TStoragePool>& pools, |
| 11 | + const TString& path, |
| 12 | + TString& error |
13 | 13 | ) { |
14 | 14 | TVector<TString> quotedKinds; |
| 15 | + quotedKinds.reserve(quotas.storage_quotas_size()); |
15 | 16 | for (const auto& storageQuota : quotas.storage_quotas()) { |
16 | 17 | quotedKinds.emplace_back(storageQuota.unit_kind()); |
17 | 18 | } |
18 | 19 | Sort(quotedKinds); |
19 | | - const auto uniqueEnd = Unique(quotedKinds.begin(), quotedKinds.end()); |
20 | | - if (uniqueEnd != quotedKinds.end()) { |
| 20 | + if (const auto equalKinds = AdjacentFind(quotedKinds); |
| 21 | + equalKinds != quotedKinds.end() |
| 22 | + ) { |
21 | 23 | error = TStringBuilder() |
22 | | - << "Malformed subdomain request: storage quotas' unit kinds must be unique, but " |
23 | | - << *uniqueEnd << " appears twice in the storage quotas definition of the " << path << " subdomain."; |
| 24 | + << "Malformed subdomain request: storage kinds in DatabaseQuotas must be unique, but " |
| 25 | + << *equalKinds << " appears twice in the quotas definition of the " << path << " subdomain."; |
24 | 26 | return false; |
25 | 27 | } |
26 | 28 |
|
27 | | - for (const auto& quotedKind : quotedKinds) { |
28 | | - if (!AnyOf(pools, ["edKind](const TStoragePool& pool) { |
29 | | - return pool.GetKind() == quotedKind; |
30 | | - })) { |
31 | | - error = TStringBuilder() |
32 | | - << "Malformed subdomain request: cannot set a " << quotedKind << " storage quota, " |
33 | | - << "because no storage pool in the subdomain " << path << " has the specified kind."; |
34 | | - return false; |
35 | | - } |
| 29 | + TVector<TString> existingKinds; |
| 30 | + existingKinds.reserve(pools.size()); |
| 31 | + for (const auto& pool : pools) { |
| 32 | + existingKinds.emplace_back(pool.GetKind()); |
| 33 | + } |
| 34 | + Sort(existingKinds); |
| 35 | + TVector<TString> unknownKinds; |
| 36 | + SetDifference(quotedKinds.begin(), quotedKinds.end(), |
| 37 | + existingKinds.begin(), existingKinds.end(), |
| 38 | + std::back_inserter(unknownKinds) |
| 39 | + ); |
| 40 | + if (!unknownKinds.empty()) { |
| 41 | + error = TStringBuilder() |
| 42 | + << "Malformed subdomain request: cannot set storage quotas of the following kinds: " << JoinSeq(", ", unknownKinds) |
| 43 | + << ", because no storage pool in the subdomain " << path << " has the specified kinds. " |
| 44 | + << "Existing storage kinds are: " << JoinSeq(", ", existingKinds); |
| 45 | + return false; |
36 | 46 | } |
37 | 47 | return true; |
38 | 48 | } |
|
0 commit comments