You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2019/12/06 14:17:25 UTC

[GitHub] [incubator-doris] imay commented on a change in pull request #2367: [PROPOSAL]Support Dynamic Partition

imay commented on a change in pull request #2367: [PROPOSAL]Support Dynamic Partition
URL: https://github.com/apache/incubator-doris/pull/2367#discussion_r354849873
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/clone/DynamicPartitionScheduler.java
 ##########
 @@ -0,0 +1,206 @@
+// 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.doris.clone;
+
+import com.google.common.collect.Range;
+import org.apache.doris.analysis.AddPartitionClause;
+import org.apache.doris.analysis.DistributionDesc;
+import org.apache.doris.analysis.HashDistributionDesc;
+import org.apache.doris.analysis.PartitionKeyDesc;
+import org.apache.doris.analysis.PartitionValue;
+import org.apache.doris.analysis.SingleRangePartitionDesc;
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.HashDistributionInfo;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.PartitionInfo;
+import org.apache.doris.catalog.PartitionKey;
+import org.apache.doris.catalog.PartitionType;
+import org.apache.doris.catalog.RangePartitionInfo;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.TableProperty;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.Pair;
+import org.apache.doris.common.util.DynamicPartitionUtil;
+import org.apache.doris.common.util.MasterDaemon;
+import org.apache.doris.common.util.TimeUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * This class is used to periodically add or drop partition on an olapTable which specify dynamic partition properties
+ * Config.dynamic_partition_enable determine whether this feature is enable, Config.dynamic_partition_check_interval_seconds
+ * determine how often the task is performed
+ */
+public class DynamicPartitionScheduler extends MasterDaemon {
+    private static final Logger LOG = LogManager.getLogger(DynamicPartitionScheduler.class);
+
+    private final String defaultValue = "N/A";
+    public String lastSchedulerTime = defaultValue;
+    public String lastUpdateTime = defaultValue;
+    public State dynamicPartitionState = State.NORMAL;
+    public String msg = defaultValue;
+
+    public enum State {
+        NORMAL,
+        ERROR
+    }
+
+    private Set<Pair<Long, Long>> dynamicPartitionTableInfo = new HashSet<>();
+    private boolean initialize;
+
+    public DynamicPartitionScheduler(String name, long intervalMs) {
+        super(name, intervalMs);
+        this.initialize = false;
+    }
+    public synchronized void registerDynamicPartitionTable(Long dbId, Long tableId) {
+        dynamicPartitionTableInfo.add(new Pair<>(dbId, tableId));
+    }
+
+    public synchronized void removeDynamicPartitionTable(Long dbId, Long tableId) {
+        dynamicPartitionTableInfo.remove(new Pair<>(dbId, tableId));
+    }
+
+    private void dynamicAddPartition() {
+        for (Pair<Long, Long> tableInfo : dynamicPartitionTableInfo) {
+            Long dbId = tableInfo.first;
+            Long tableId = tableInfo.second;
+            Database db = Catalog.getInstance().getDb(dbId);
+            if (db == null) {
+                removeDynamicPartitionTable(dbId, tableId);
 
 Review comment:
   dynamicPartitionTableInfo is changed in removeDynamicPartitionTable function when iterating it. This will cause execption.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org