You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "Cpaulyz (via GitHub)" <gi...@apache.org> on 2023/03/27 08:50:19 UTC
[GitHub] [iotdb] Cpaulyz commented on a diff in pull request #9430: [To rel/1.1][IOTDB-5719] Cluster-Wide Time Series Limit Control
Cpaulyz commented on code in PR #9430:
URL: https://github.com/apache/iotdb/pull/9430#discussion_r1148991752
##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaQuotaManager.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.confignode.manager.schema;
+
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId;
+import org.apache.iotdb.commons.schema.ClusterSchemaQuotaLevel;
+import org.apache.iotdb.confignode.conf.ConfigNodeDescriptor;
+import org.apache.iotdb.mpp.rpc.thrift.TSchemaQuotaLevel;
+import org.apache.iotdb.mpp.rpc.thrift.TSchemaQuotaReq;
+import org.apache.iotdb.mpp.rpc.thrift.TSchemaQuotaResp;
+
+import javax.validation.constraints.NotNull;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class ClusterSchemaQuotaManager {
+
+ private final Map<TConsensusGroupId, Long> countMap = new ConcurrentHashMap<>();
+ private ClusterSchemaQuotaLevel level =
+ ClusterSchemaQuotaLevel.valueOf(
+ ConfigNodeDescriptor.getInstance().getConf().getClusterSchemaLimitLevel());
+ private long limit = ConfigNodeDescriptor.getInstance().getConf().getClusterMaxSchemaCount();
+
+ public void updateCount(@NotNull TSchemaQuotaResp resp, List<TConsensusGroupId> leaderGroupIds) {
+ for (TConsensusGroupId groupId : leaderGroupIds) {
+ if (resp.regionIdCountMap.containsKey(groupId)) {
+ countMap.put(groupId, resp.regionIdCountMap.get(groupId));
+ }
+ }
+ }
+
+ public TSchemaQuotaReq generateReq() {
+ if (limit == -1) {
+ return null;
+ } else {
+ return new TSchemaQuotaReq(
+ level == ClusterSchemaQuotaLevel.MEASUREMENT
+ ? TSchemaQuotaLevel.MEASUREMENT
+ : TSchemaQuotaLevel.DEVICE,
+ countMap.values().stream().mapToLong(i -> i).sum(),
+ limit);
+ }
+ }
+
+ public void invalidateSchemaRegion(Set<TConsensusGroupId> consensusGroupIdSet) {
+ for (TConsensusGroupId consensusGroupId : consensusGroupIdSet) {
+ countMap.remove(consensusGroupId);
+ }
+ }
+
+ public void setLevel(ClusterSchemaQuotaLevel level) {
+ this.level = level;
+ }
+
+ public void setLimit(long limit) {
+ this.limit = limit;
+ }
+
+ private ClusterSchemaQuotaManager() {}
+
+ public static ClusterSchemaQuotaManager getInstance() {
+ return ClusterSchemaQuotaManager.ClusterSchemaQuotaManagerHolder.INSTANCE;
+ }
+
+ private static class ClusterSchemaQuotaManagerHolder {
+ private static final ClusterSchemaQuotaManager INSTANCE = new ClusterSchemaQuotaManager();
+
+ private ClusterSchemaQuotaManagerHolder() {
+ // empty constructor
+ }
+ }
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org