[Enhancement] Allow dropping cn/be without specifying a warehouse name (#62940)

Signed-off-by: crossoverJie <crossoverJie@gmail.com>
This commit is contained in:
crossoverJie 2025-10-10 11:01:58 +08:00 committed by GitHub
parent 6461e22e0d
commit b93ef4ecde
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 90 additions and 16 deletions

View File

@ -4770,7 +4770,7 @@ public class AstBuilder extends com.starrocks.sql.parser.StarRocksBaseVisitor<Pa
@Override
public ParseNode visitDropBackendClause(com.starrocks.sql.parser.StarRocksParser.DropBackendClauseContext context) {
String whName = WarehouseManager.DEFAULT_WAREHOUSE_NAME;
String whName = "";
String cngroupName = "";
if (context.warehouseName != null) {
Identifier identifier = (Identifier) visit(context.identifierOrString().get(0));
@ -4832,7 +4832,7 @@ public class AstBuilder extends com.starrocks.sql.parser.StarRocksBaseVisitor<Pa
@Override
public ParseNode visitDropComputeNodeClause(com.starrocks.sql.parser.StarRocksParser.DropComputeNodeClauseContext context) {
String whName = WarehouseManager.DEFAULT_WAREHOUSE_NAME;
String whName = "";
String cngroupName = "";
if (context.warehouseName != null) {
Identifier identifier = (Identifier) visit(context.identifierOrString().get(0));

View File

@ -575,14 +575,9 @@ public class SystemInfoService implements GsonPostProcessable {
}
public void dropComputeNodes(DropComputeNodeClause dropComputeNodeClause) throws DdlException {
String warehouse = dropComputeNodeClause.getWarehouse();
// check if the warehouse exist
if (GlobalStateMgr.getCurrentState().getWarehouseMgr().getWarehouseAllowNull(warehouse) == null) {
ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_WAREHOUSE, String.format("name: %s", warehouse));
}
for (HostPort hostPort : dropComputeNodeClause.getHostPortPairs()) {
dropComputeNode(hostPort.getHost(), hostPort.getPort(), warehouse, dropComputeNodeClause.getCNGroupName());
dropComputeNode(hostPort.getHost(), hostPort.getPort(), dropComputeNodeClause.getWarehouse(),
dropComputeNodeClause.getCNGroupName());
}
}
@ -601,6 +596,11 @@ public class SystemInfoService implements GsonPostProcessable {
}
if (!Strings.isNullOrEmpty(warehouse)) {
// check if the warehouse exist
if (GlobalStateMgr.getCurrentState().getWarehouseMgr().getWarehouseAllowNull(warehouse) == null) {
ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_WAREHOUSE, String.format("name: %s", warehouse));
}
// check if warehouseName is right
Warehouse wh = GlobalStateMgr.getCurrentState().getWarehouseMgr()
.getWarehouseAllowNull(dropComputeNode.getWarehouseId());
@ -631,14 +631,9 @@ public class SystemInfoService implements GsonPostProcessable {
List<HostPort> hostPortPairs = dropBackendClause.getHostPortPairs();
boolean needCheckWithoutForce = !dropBackendClause.isForce();
String warehouse = dropBackendClause.getWarehouse();
// check if the warehouse exist
if (GlobalStateMgr.getCurrentState().getWarehouseMgr().getWarehouseAllowNull(warehouse) == null) {
ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_WAREHOUSE, String.format("name: %s", warehouse));
}
for (HostPort hostPort : hostPortPairs) {
dropBackend(hostPort.getHost(), hostPort.getPort(), warehouse, dropBackendClause.cngroupName, needCheckWithoutForce);
dropBackend(hostPort.getHost(), hostPort.getPort(), dropBackendClause.getWarehouse(), dropBackendClause.cngroupName,
needCheckWithoutForce);
}
}
@ -708,6 +703,11 @@ public class SystemInfoService implements GsonPostProcessable {
}
if (!Strings.isNullOrEmpty(warehouse)) {
// check if the warehouse exist
if (GlobalStateMgr.getCurrentState().getWarehouseMgr().getWarehouseAllowNull(warehouse) == null) {
ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_WAREHOUSE, String.format("name: %s", warehouse));
}
// check if warehouseName is right
Warehouse wh = GlobalStateMgr.getCurrentState().getWarehouseMgr()
.getWarehouseAllowNull(droppedBackend.getWarehouseId());

View File

@ -32,6 +32,16 @@ public class DropBackendClauseTest {
Assertions.assertTrue(dropStmt.getCNGroupName().isEmpty());
Assertions.assertFalse(dropStmt.isForce());
}
@Test
public void testDropBackendWithoutWarehouse() {
String sqlText = "ALTER SYSTEM DROP BACKEND 'backend01:9010' ";
AlterSystemStmt stmt =
(AlterSystemStmt) SqlParser.parseSingleStatement(sqlText, SqlModeHelper.MODE_DEFAULT);
DropBackendClause dropStmt = (DropBackendClause) stmt.getAlterClause();
Assertions.assertTrue(dropStmt.getWarehouse().isEmpty());
Assertions.assertTrue(dropStmt.getCNGroupName().isEmpty());
Assertions.assertFalse(dropStmt.isForce());
}
@Test
public void testDropBackendIntoWarehouseCnGroup() {

View File

@ -31,6 +31,15 @@ public class DropComputeNodeClauseTest {
Assertions.assertEquals("warehouse1", dropStmt.getWarehouse());
Assertions.assertTrue(dropStmt.getCNGroupName().isEmpty());
}
@Test
public void testDropComputeNodeWithoutWarehouse() {
String sqlText = "ALTER SYSTEM DROP COMPUTE NODE 'backend01:9010'";
AlterSystemStmt stmt =
(AlterSystemStmt) SqlParser.parseSingleStatement(sqlText, SqlModeHelper.MODE_DEFAULT);
DropComputeNodeClause dropStmt = (DropComputeNodeClause) stmt.getAlterClause();
Assertions.assertTrue(dropStmt.getWarehouse().isEmpty());
Assertions.assertTrue(dropStmt.getCNGroupName().isEmpty());
}
@Test
public void testDropComputeNodeIntoWarehouseCnGroup() {

View File

@ -17,6 +17,7 @@ package com.starrocks.system;
import com.google.api.client.util.Maps;
import com.starrocks.common.Config;
import com.starrocks.common.DdlException;
import com.starrocks.common.ErrorCode;
import com.starrocks.common.Pair;
import com.starrocks.lake.StarOSAgent;
import com.starrocks.persist.DropBackendInfo;
@ -288,6 +289,52 @@ public class SystemInfoServiceTest {
ComputeNode cnIP = service.getComputeNodeWithHeartbeatPort("newHost", 1000);
Assertions.assertTrue(cnIP == null);
Config.enable_trace_historical_node = savedConfig;
}
@Test
public void testDropComputeNode2() throws Exception {
new MockUp<RunMode>() {
@Mock
public RunMode getCurrentRunMode() {
return RunMode.SHARED_DATA;
}
};
Boolean savedConfig = Config.enable_trace_historical_node;
Config.enable_trace_historical_node = true;
ComputeNode cn = new ComputeNode(10001, "newHost", 1000);
service.addComputeNode(cn);
WarehouseManager warehouseManager = new WarehouseManager();
warehouseManager.initDefaultWarehouse();
new MockUp<WarehouseManager>() {
@Mock
public ComputeResource acquireComputeResource(CRAcquireContext acquireContext) {
return WarehouseManager.DEFAULT_RESOURCE;
}
};
new MockUp<EditLog>() {
@Mock
public void logDropComputeNode(DropComputeNodeLog log, WALApplier applier) {
applier.apply(log);
}
};
cn.setStarletPort(1001);
{
Assertions.assertThrows(DdlException.class, () ->
service.dropComputeNode("newHost", 1000, "warehousename-cn-not-exists", ""),
ErrorCode.ERR_UNKNOWN_WAREHOUSE.formatErrorMsg("name: warehousename-cn-not-exists"));
}
service.dropComputeNode("newHost", 1000, "", "");
ComputeNode cnIP = service.getComputeNodeWithHeartbeatPort("newHost", 1000);
Assertions.assertNull(cnIP);
Config.enable_trace_historical_node = savedConfig;
}
@ -337,6 +384,14 @@ public class SystemInfoServiceTest {
};
service.addBackend(be);
be.setStarletPort(1001);
{
Assertions.assertThrows(DdlException.class, () ->
service.dropBackend("newHost", 1000, "warehousename-cn-not-exists",
"", false),
ErrorCode.ERR_UNKNOWN_WAREHOUSE.formatErrorMsg("name: warehousename-cn-not-exists"));
}
service.dropBackend("newHost", 1000, null, null, false);
Backend beIP = service.getBackendWithHeartbeatPort("newHost", 1000);
Assertions.assertNull(beIP);