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

[improvement](create table) add backend details to creating table failed msg #41463

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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 @@ -258,7 +258,8 @@ private static void checkReplicaAllocation(ReplicaAllocation replicaAlloc, int h
} catch (DdlException e) {
throw new DdlException("Failed to find enough backend for ssd storage medium. When setting "
+ DynamicPartitionProperty.HOT_PARTITION_NUM + " > 0, the hot partitions will store "
+ "in ssd. Please check the replication num,replication tag and storage medium.");
+ "in ssd. Please check the replication num,replication tag and storage medium."
+ Env.getCurrentSystemInfo().getDetailsForCreateReplica(replicaAlloc));
}
}

Expand Down
65 changes: 65 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/system/Backend.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,71 @@ public long getCurrentFragmentNum() {
return this.backendStatus.currentFragmentNum;
}

public String getDetailsForCreateReplica() {
int hddBad = 0;
int hddExceedLimit = 0;
int hddOk = 0;
int ssdBad = 0;
int ssdExceedLimit = 0;
int ssdOk = 0;
for (DiskInfo disk : disksRef.values()) {
TStorageMedium storageMedium = disk.getStorageMedium();
if (storageMedium == TStorageMedium.HDD) {
if (!disk.isAlive()) {
hddBad++;
} else if (disk.exceedLimit(true)) {
hddExceedLimit++;
} else {
hddOk++;
}
} else if (storageMedium == TStorageMedium.SSD) {
if (!disk.isAlive()) {
ssdBad++;
} else if (disk.exceedLimit(true)) {
ssdExceedLimit++;
} else {
ssdOk++;
}
}
}

StringBuilder sb = new StringBuilder("[");
sb.append("backendId=").append(id);
sb.append(", host=").append(host);
if (!isAlive()) {
sb.append(", isAlive=false, exclude it");
} else if (isDecommissioned()) {
sb.append(", isDecommissioned=true, exclude it");
} else if (isComputeNode()) {
sb.append(", isComputeNode=true, exclude it");
} else {
sb.append(", hdd disks count={");
if (hddOk > 0) {
sb.append("ok=").append(hddOk).append(",");
}
if (hddBad > 0) {
sb.append("bad=").append(hddBad).append(",");
}
if (hddExceedLimit > 0) {
sb.append("capExceedLimit=").append(hddExceedLimit).append(",");
}
sb.append("}, ssd disk count={");
if (ssdOk > 0) {
sb.append("ok=").append(ssdOk).append(",");
}
if (ssdBad > 0) {
sb.append("bad=").append(ssdBad).append(",");
}
if (ssdExceedLimit > 0) {
sb.append("capExceedLimit=").append(ssdExceedLimit).append(",");
}
sb.append("}");
}
sb.append("]");

return sb.toString();
}

// for test only
public void updateOnce(int bePort, int httpPort, int beRpcPort) {
if (this.bePort != bePort) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ public Pair<Map<Tag, List<Long>>, TStorageMedium> selectBackendIdsForReplicaCrea
String failedMsg = Joiner.on("\n").join(failedEntries);
throw new DdlException("Failed to find enough backend, please check the replication num,"
+ "replication tag and storage medium and avail capacity of backends "
+ "or maybe all be on same host.\n"
+ "or maybe all be on same host." + getDetailsForCreateReplica(replicaAlloc) + "\n"
+ "Create failed replications:\n" + failedMsg);
}
}
Expand All @@ -552,6 +552,18 @@ public Pair<Map<Tag, List<Long>>, TStorageMedium> selectBackendIdsForReplicaCrea
return Pair.of(chosenBackendIds, storageMedium);
}

public String getDetailsForCreateReplica(ReplicaAllocation replicaAlloc) {
StringBuilder sb = new StringBuilder(" Backends details: ");
for (Tag tag : replicaAlloc.getAllocMap().keySet()) {
sb.append("backends with tag ").append(tag).append(" is ");
sb.append(idToBackendRef.values().stream().filter(be -> be.getLocationTag() == tag)
.map(Backend::getDetailsForCreateReplica)
.collect(Collectors.toList()));
sb.append(", ");
}
return sb.toString();
}

/**
* Select a set of backends by the given policy.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ public void testAbnormal() throws DdlException, ConfigException {
ExceptionChecker
.expectThrowsWithMsg(DdlException.class,
"Failed to find enough backend, please check the replication num,replication tag and storage medium and avail capacity of backends "
+ "or maybe all be on same host.\n"
+ "or maybe all be on same host."
+ Env.getCurrentSystemInfo().getDetailsForCreateReplica(new ReplicaAllocation((short) 1)) + "\n"
+ "Create failed replications:\n"
+ "replication tag: {\"location\" : \"default\"}, replication num: 1, storage medium: SSD",
() -> createTable(
Expand All @@ -304,7 +305,8 @@ public void testAbnormal() throws DdlException, ConfigException {
ExceptionChecker
.expectThrowsWithMsg(DdlException.class,
"Failed to find enough backend, please check the replication num,replication tag and storage medium and avail capacity of backends "
+ "or maybe all be on same host.\n"
+ "or maybe all be on same host."
+ Env.getCurrentSystemInfo().getDetailsForCreateReplica(new ReplicaAllocation((short) 1)) + "\n"
+ "Create failed replications:\n"
+ "replication tag: {\"location\" : \"default\"}, replication num: 1, storage medium: SSD",
() -> createTable("create table test.tb7_1(key1 int, key2 varchar(10))\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.doris.system.SystemInfoService;
import org.apache.doris.utframe.UtFrameUtils;

import com.google.common.collect.Maps;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -85,7 +86,8 @@ public void testModifyBackendTag() throws Exception {
CreateTableStmt createStmt = (CreateTableStmt) UtFrameUtils.parseAndAnalyzeStmt(createStr, connectContext);
ExceptionChecker.expectThrowsWithMsg(DdlException.class,
"Failed to find enough backend, please check the replication num,replication tag and storage medium and avail capacity of backends "
+ "or maybe all be on same host.\n"
+ "or maybe all be on same host."
+ Env.getCurrentSystemInfo().getDetailsForCreateReplica(new ReplicaAllocation((short) 1)) + "\n"
+ "Create failed replications:\n"
+ "replication tag: {\"location\" : \"default\"}, replication num: 1, storage medium: HDD",
() -> DdlExecutor.execute(Env.getCurrentEnv(), createStmt));
Expand Down Expand Up @@ -154,10 +156,13 @@ public void testModifyBackendTag() throws Exception {
String partName = tbl.getPartitionNames().stream().findFirst().get();
String wrongAlterStr = "alter table test.tbl4 modify partition " + partName
+ " set ('replication_allocation' = 'tag.location.zonex:1')";
Map<Tag, Short> allocMap = Maps.newHashMap();
allocMap.put(Tag.create(Tag.TYPE_LOCATION, "zonex"), (short) 1);
ExceptionChecker.expectThrowsWithMsg(AnalysisException.class, "errCode = 2,"
+ " detailMessage = Failed to find enough backend, "
+ "please check the replication num,replication tag and storage medium and avail capacity of backends "
+ "or maybe all be on same host.\n"
+ "or maybe all be on same host."
+ Env.getCurrentSystemInfo().getDetailsForCreateReplica(new ReplicaAllocation(allocMap)) + "\n"
+ "Create failed replications:\n"
+ "replication tag: {\"location\" : \"zonex\"}, replication num: 1, storage medium: null",
() -> UtFrameUtils.parseAndAnalyzeStmt(wrongAlterStr, connectContext));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.doris.catalog.Database;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.ReplicaAllocation;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.catalog.TabletMeta;
import org.apache.doris.catalog.Type;
Expand Down Expand Up @@ -285,7 +286,9 @@ public void testAbnormal() throws ConfigException {

ConfigBase.setMutableConfig("disable_storage_medium_check", "false");
checkThrow(org.apache.doris.common.DdlException.class,
"Failed to find enough backend, please check the replication num,replication tag and storage medium.\n"
"Failed to find enough backend, please check the replication num,replication tag and storage medium and avail capacity of backends "
+ "or maybe all be on same host."
+ Env.getCurrentSystemInfo().getDetailsForCreateReplica(new ReplicaAllocation((short) 1)) + "\n"
+ "Create failed replications:\n"
+ "replication tag: {\"location\" : \"default\"}, replication num: 1, storage medium: SSD",
() -> createTable("create table test.tb7(key1 int, key2 varchar(10)) distributed by hash(key1) \n"
Expand Down
Loading