Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[branch-2.0](fe ut) fix unstable test DecommissionBackendTest #26891 #27173

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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