wenzhenghu commented on code in PR #59065:
URL: https://github.com/apache/doris/pull/59065#discussion_r2684934754


##########
fe/fe-core/src/main/java/org/apache/doris/datasource/FileCacheAdmissionManager.java:
##########
@@ -0,0 +1,697 @@
+// 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.datasource;
+
+import org.apache.doris.common.Config;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+public class FileCacheAdmissionManager {
+    private static final Logger LOG = 
LogManager.getLogger(FileCacheAdmissionManager.class);
+
+    public enum RuleType {
+        EXCLUDE(0),
+        INCLUDE(1);
+
+        private final int value;
+
+        RuleType(int value) {
+            this.value = value;
+        }
+
+        public static RuleType fromValue(int value) {
+            if (value == 0) {
+                return EXCLUDE;
+            } else if (value == 1) {
+                return INCLUDE;
+            }
+            throw new IllegalArgumentException("Invalid RuleType Value: " + 
value);
+        }
+    }
+
+    public enum RuleLevel {
+        PARTITION,   // 0
+        TABLE,       // 1
+        DATABASE,    // 2
+        CATALOG,     // 3
+        GLOBAL,      // 4
+        INVALID      // 5
+    }
+
+    public static class RulePattern {
+        private final long id;
+        private final String userIdentity;
+        private final String catalog;
+        private final String database;
+        private final String table;
+        private final String partitionPattern;
+        private final RuleType ruleType;
+
+        public RulePattern(long id, String userIdentity, String catalog, 
String database,
+                           String table, String partitionPattern, RuleType 
ruleType) {
+            this.id = id;
+            this.userIdentity = userIdentity;
+            this.catalog = catalog != null ? catalog : "";
+            this.database = database != null ? database : "";
+            this.table = table != null ? table : "";
+            this.partitionPattern = partitionPattern != null ? 
partitionPattern : "";
+            this.ruleType = ruleType;
+        }
+
+        public long getId() {
+            return id;
+        }
+
+        public String getUserIdentity() {
+            return userIdentity;
+        }
+
+        public String getCatalog() {
+            return catalog;
+        }
+
+        public String getDatabase() {
+            return database;
+        }
+
+        public String getTable() {
+            return table;
+        }
+
+        public String getPartitionPattern() {
+            return partitionPattern;
+        }
+
+        public RuleType getRuleType() {
+            return ruleType;
+        }
+    }
+
+    public static class AdmissionRule {
+        private final long id;
+        private final String userIdentity;
+        private final String catalog;
+        private final String database;
+        private final String table;
+        private final String partitionPattern;
+        private final RuleType ruleType;
+        private final boolean enabled;
+        private final long createdTime;
+        private final long updatedTime;
+
+        @JsonCreator
+        public AdmissionRule(
+                @JsonProperty("id") long id,
+                @JsonProperty("user_identity") String userIdentity,
+                @JsonProperty("catalog_name") String catalog,
+                @JsonProperty("database_name") String database,
+                @JsonProperty("table_name") String table,
+                @JsonProperty("partition_pattern") String partitionPattern,
+                @JsonProperty("rule_type") int ruleType,
+                @JsonProperty("enabled") boolean enabled,
+                @JsonProperty("created_time") long createdTime,
+                @JsonProperty("updated_time") long updatedTime) {
+            this.id = id;
+            this.userIdentity = userIdentity != null ? userIdentity : "";
+            this.catalog = catalog != null ? catalog : "";
+            this.database = database != null ? database : "";
+            this.table = table != null ? table : "";
+            this.partitionPattern = partitionPattern != null ? 
partitionPattern : "";
+            this.ruleType = RuleType.fromValue(ruleType);
+            this.enabled = enabled;
+            this.createdTime = createdTime;
+            this.updatedTime = updatedTime;
+        }
+
+        public RulePattern toRulePattern() {
+            return new RulePattern(id, userIdentity, catalog, database, table, 
partitionPattern, ruleType);
+        }
+
+        public long getId() {
+            return id;
+        }
+
+        public String getUserIdentity() {
+            return userIdentity;
+        }
+
+        public String getTable() {
+            return table;
+        }
+
+        public String getDatabase() {
+            return database;
+        }
+
+        public String getCatalog() {
+            return catalog;
+        }
+
+        public String getPartitionPattern() {
+            return partitionPattern;
+        }
+
+        public RuleType getRuleType() {
+            return ruleType;
+        }
+
+        public boolean getEnabled() {
+            return enabled;
+        }
+
+        public long getCreatedTime() {
+            return createdTime;
+        }
+
+        public long getUpdatedTime() {
+            return updatedTime;
+        }
+    }
+
+    public static class RuleLoader {
+        private static final ObjectMapper MAPPER = new ObjectMapper();
+
+        public static List<AdmissionRule> loadRulesFromFile(String filePath) 
throws Exception {
+            File file = new File(filePath);
+            if (!file.exists()) {
+                throw new IllegalArgumentException("File cache admission JSON 
file does not exist: " + filePath);
+            }
+
+            return MAPPER.readValue(file, new 
TypeReference<List<AdmissionRule>>() {});
+        }
+    }
+
+    public static class ConcurrentRuleCollection {

Review Comment:
   Originally, it was intended to indicate that the rule can be accessed 
concurrently, but after revising the plan, it's no longer particularly 
meaningful. We'll simply remove it.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to