This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.0 by this push:
     new c1d2ee07788 branch-4.0: [fix](blockrule)Fix concurrency issues in 
SqlBlockRuleMgr after restart fe #58296 (#58326)
c1d2ee07788 is described below

commit c1d2ee077888b038744c3805f6b2ced5c33fea14
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Tue Nov 25 15:59:33 2025 +0800

    branch-4.0: [fix](blockrule)Fix concurrency issues in SqlBlockRuleMgr after 
restart fe #58296 (#58326)
    
    Cherry-picked from #58296
    
    Co-authored-by: zhangdong <[email protected]>
---
 .../apache/doris/blockrule/SqlBlockRuleMgr.java    | 18 +++++++++-
 .../doris/blockrule/SqlBlockRuleMgrTest.java       | 42 ++++++++++++++++++++++
 2 files changed, 59 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/blockrule/SqlBlockRuleMgr.java 
b/fe/fe-core/src/main/java/org/apache/doris/blockrule/SqlBlockRuleMgr.java
index b9469dcbcec..cad0ebafa6a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/blockrule/SqlBlockRuleMgr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/blockrule/SqlBlockRuleMgr.java
@@ -29,9 +29,11 @@ import org.apache.doris.metric.MetricRepo;
 import org.apache.doris.mysql.privilege.Auth;
 import org.apache.doris.nereids.trees.plans.commands.AlterSqlBlockRuleCommand;
 import org.apache.doris.nereids.trees.plans.commands.CreateSqlBlockRuleCommand;
+import org.apache.doris.persist.gson.GsonPostProcessable;
 import org.apache.doris.persist.gson.GsonUtils;
 import org.apache.doris.qe.ConnectContext;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.gson.annotations.SerializedName;
@@ -51,7 +53,7 @@ import java.util.stream.Collectors;
 /**
  * Manage SqlBlockRule.
  **/
-public class SqlBlockRuleMgr implements Writable {
+public class SqlBlockRuleMgr implements Writable, GsonPostProcessable {
     private static final Logger LOG = 
LogManager.getLogger(SqlBlockRuleMgr.class);
 
     private ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
@@ -311,6 +313,11 @@ public class SqlBlockRuleMgr implements Writable {
         }
     }
 
+    @VisibleForTesting
+    public Map<String, SqlBlockRule> getNameToSqlBlockRuleMap() {
+        return nameToSqlBlockRuleMap;
+    }
+
     @Override
     public void write(DataOutput out) throws IOException {
         Text.writeString(out, GsonUtils.GSON.toJson(this));
@@ -320,4 +327,13 @@ public class SqlBlockRuleMgr implements Writable {
         String json = Text.readString(in);
         return GsonUtils.GSON.fromJson(json, SqlBlockRuleMgr.class);
     }
+
+    @Override
+    public void gsonPostProcess() throws IOException {
+        Map<String, SqlBlockRule> nameToSqlBlockRuleMapNew = 
Maps.newConcurrentMap();
+        if (this.nameToSqlBlockRuleMap != null) {
+            nameToSqlBlockRuleMapNew.putAll(this.nameToSqlBlockRuleMap);
+        }
+        this.nameToSqlBlockRuleMap = nameToSqlBlockRuleMapNew;
+    }
 }
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/blockrule/SqlBlockRuleMgrTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/blockrule/SqlBlockRuleMgrTest.java
new file mode 100644
index 00000000000..06e2fef9f43
--- /dev/null
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/blockrule/SqlBlockRuleMgrTest.java
@@ -0,0 +1,42 @@
+// 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.blockrule;
+
+import org.apache.doris.persist.gson.GsonUtils;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class SqlBlockRuleMgrTest {
+    @Test
+    public void testToInfoString() {
+        SqlBlockRuleMgr mgr = new SqlBlockRuleMgr();
+        Assert.assertTrue(mgr.getNameToSqlBlockRuleMap() instanceof 
ConcurrentHashMap);
+        SqlBlockRule rule = new SqlBlockRule();
+        mgr.getNameToSqlBlockRuleMap().put("r1", rule);
+        String mgrJson = GsonUtils.GSON.toJson(mgr);
+        SqlBlockRuleMgr mgrNew = GsonUtils.GSON.fromJson(mgrJson, 
SqlBlockRuleMgr.class);
+        Map<String, SqlBlockRule> nameToSqlBlockRuleMap = 
mgrNew.getNameToSqlBlockRuleMap();
+        Assert.assertTrue(nameToSqlBlockRuleMap instanceof ConcurrentHashMap);
+        Assert.assertTrue(nameToSqlBlockRuleMap.containsKey("r1"));
+    }
+
+}


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

Reply via email to