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

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


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 2f30475ecce [branch-2.0](fe ut) fix unstable test 
DecommissionBackendTest  (#27173)
2f30475ecce is described below

commit 2f30475ecce0e104dd2a848932f6a74d749f2aee
Author: yujun <[email protected]>
AuthorDate: Sat Nov 18 00:23:00 2023 +0800

    [branch-2.0](fe ut) fix unstable test DecommissionBackendTest  (#27173)
---
 .../doris/cluster/DecommissionBackendTest.java     | 43 +++++++++++++---------
 .../apache/doris/utframe/TestWithFeService.java    |  6 +++
 2 files changed, 32 insertions(+), 17 deletions(-)

diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/cluster/DecommissionBackendTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/cluster/DecommissionBackendTest.java
index 209f8a11276..e689723cdf8 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/cluster/DecommissionBackendTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/cluster/DecommissionBackendTest.java
@@ -18,11 +18,15 @@
 package org.apache.doris.cluster;
 
 import org.apache.doris.analysis.AlterSystemStmt;
+import org.apache.doris.catalog.Database;
 import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.MaterializedIndex;
+import org.apache.doris.catalog.OlapTable;
 import org.apache.doris.common.AnalysisException;
 import org.apache.doris.common.Config;
 import org.apache.doris.common.FeConstants;
 import org.apache.doris.system.Backend;
+import org.apache.doris.system.SystemInfoService;
 import org.apache.doris.utframe.TestWithFeService;
 
 import com.google.common.collect.ImmutableMap;
@@ -55,6 +59,7 @@ public class DecommissionBackendTest extends 
TestWithFeService {
         FeConstants.tablet_checker_interval_ms = 1000;
         Config.tablet_repair_delay_factor_second = 1;
         Config.allow_replica_on_same_host = true;
+        Config.disable_balance = true;
     }
 
     @Test
@@ -103,11 +108,8 @@ public class DecommissionBackendTest extends 
TestWithFeService {
                 Env.getCurrentInvertedIndex().getTabletMetaMap().size());
 
         // 6. add backend
-        String addBackendStmtStr = "alter system add backend \"127.0.0.1:" + 
srcBackend.getHeartbeatPort() + "\"";
-        AlterSystemStmt addBackendStmt = (AlterSystemStmt) 
parseAndAnalyzeStmt(addBackendStmtStr);
-        
Env.getCurrentEnv().getAlterInstance().processAlterCluster(addBackendStmt);
+        addNewBackend();
         Assertions.assertEquals(backendNum(), 
Env.getCurrentSystemInfo().getIdToBackend().size());
-
     }
 
     @Test
@@ -115,29 +117,38 @@ public class DecommissionBackendTest extends 
TestWithFeService {
         // 1. create connect context
         connectContext = createDefaultCtx();
 
-        ImmutableMap<Long, Backend> idToBackendRef = 
Env.getCurrentSystemInfo().getIdToBackend();
+        SystemInfoService infoService = Env.getCurrentSystemInfo();
+
+        ImmutableMap<Long, Backend> idToBackendRef = 
infoService.getIdToBackend();
         Assertions.assertEquals(backendNum(), idToBackendRef.size());
 
         // 2. create database db2
         createDatabase("db2");
         System.out.println(Env.getCurrentInternalCatalog().getDbNames());
 
+        long availableBeNum = infoService.getAllBackendIds(true).stream()
+                .filter(beId -> 
infoService.checkBackendScheduleAvailable(beId)).count();
+
         // 3. create table tbl1 tbl2
-        createTable("create table db2.tbl1(k1 int) distributed by hash(k1) 
buckets 3 properties('replication_num' = '2');");
+        createTable("create table db2.tbl1(k1 int) distributed by hash(k1) 
buckets 3 properties('replication_num' = '"
+                + availableBeNum + "');");
         createTable("create table db2.tbl2(k1 int) distributed by hash(k1) 
buckets 3 properties('replication_num' = '1');");
 
         // 4. query tablet num
         int tabletNum = 
Env.getCurrentInvertedIndex().getTabletMetaMap().size();
         Assertions.assertTrue(tabletNum > 0);
 
-        Backend srcBackend = null;
-        for (Backend backend : idToBackendRef.values()) {
-            if 
(Env.getCurrentInvertedIndex().getTabletIdsByBackendId(backend.getId()).size() 
> 0) {
-                srcBackend = backend;
-                break;
-            }
-        }
-        Assertions.assertTrue(srcBackend != null);
+        Database db = 
Env.getCurrentInternalCatalog().getDbOrMetaException("default_cluster:db2");
+        OlapTable tbl = (OlapTable) db.getTableOrMetaException("tbl1");
+        Assertions.assertNotNull(tbl);
+        long backendId = tbl.getPartitions().iterator().next()
+                
.getMaterializedIndices(MaterializedIndex.IndexExtState.ALL).iterator().next()
+                .getTablets().iterator().next()
+                .getReplicas().iterator().next()
+                .getBackendId();
+
+        Backend srcBackend = infoService.getBackend(backendId);
+        Assertions.assertNotNull(srcBackend);
 
         // 5. drop table tbl1
         dropTable("db2.tbl1", false);
@@ -170,9 +181,7 @@ public class DecommissionBackendTest extends 
TestWithFeService {
         Assertions.assertDoesNotThrow(() -> recoverTable("db2.tbl1"));
         Assertions.assertDoesNotThrow(() -> showCreateTable(sql));
 
-        String addBackendStmtStr = "alter system add backend \"127.0.0.1:" + 
srcBackend.getHeartbeatPort() + "\"";
-        AlterSystemStmt addBackendStmt = (AlterSystemStmt) 
parseAndAnalyzeStmt(addBackendStmtStr);
-        
Env.getCurrentEnv().getAlterInstance().processAlterCluster(addBackendStmt);
+        addNewBackend();
         Assertions.assertEquals(backendNum(), 
Env.getCurrentSystemInfo().getIdToBackend().size());
     }
 
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/utframe/TestWithFeService.java 
b/fe/fe-core/src/test/java/org/apache/doris/utframe/TestWithFeService.java
index 9a86b264a62..b032ddd2a50 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/utframe/TestWithFeService.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/utframe/TestWithFeService.java
@@ -125,6 +125,7 @@ public abstract class TestWithFeService {
     protected String runningDir = "fe/mocked/" + getClass().getSimpleName() + 
"/" + UUID.randomUUID() + "/";
     protected ConnectContext connectContext;
     protected boolean needCleanDir = true;
+    protected int lastFeRpcPort = 0;
 
     protected static final String DEFAULT_CLUSTER_PREFIX = "default_cluster:";
 
@@ -378,6 +379,7 @@ public abstract class TestWithFeService {
         MockedFrontend frontend = new MockedFrontend();
         frontend.init(dorisHome + "/" + runningDir, feConfMap);
         frontend.start(new String[0]);
+        lastFeRpcPort = feRpcPort;
         return feRpcPort;
     }
 
@@ -434,6 +436,10 @@ public abstract class TestWithFeService {
         checkBEHeartbeat(bes);
     }
 
+    protected Backend addNewBackend() throws IOException, InterruptedException 
{
+        return createBackend("127.0.0.1", lastFeRpcPort);
+    }
+
     protected Backend createBackend(String beHost, int feRpcPort) throws 
IOException, InterruptedException {
         IOException exception = null;
         for (int i = 0; i <= 3; i++) {


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

Reply via email to