Skip to content

Commit

Permalink
[branch-2.0](fe ut) fix unstable test DecommissionBackendTest (apache…
Browse files Browse the repository at this point in the history
  • Loading branch information
yujun777 authored and gnehil committed Dec 4, 2023
1 parent 96f1aa4 commit 32ee785
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,6 +59,7 @@ protected void beforeCreatingConnectContext() throws Exception {
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
Expand Down Expand Up @@ -103,41 +108,47 @@ public void testDecommissionBackend() throws Exception {
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
public void testDecommissionBackendWithDropTable() throws Exception {
// 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);
Expand Down Expand Up @@ -170,9 +181,7 @@ public void testDecommissionBackendWithDropTable() throws Exception {
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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:";

Expand Down Expand Up @@ -378,6 +379,7 @@ protected int startFEServerWithoutRetry(String runningDir)
MockedFrontend frontend = new MockedFrontend();
frontend.init(dorisHome + "/" + runningDir, feConfMap);
frontend.start(new String[0]);
lastFeRpcPort = feRpcPort;
return feRpcPort;
}

Expand Down Expand Up @@ -434,6 +436,10 @@ protected void createDorisClusterWithMultiTag(String runningDir, int backendNum)
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++) {
Expand Down

0 comments on commit 32ee785

Please sign in to comment.