Skip to content

Commit

Permalink
[fix](cloud) Optimize prompt messages when no cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
deardeng committed Aug 8, 2024
1 parent 3f74137 commit 1441a55
Show file tree
Hide file tree
Showing 60 changed files with 715 additions and 326 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.doris.catalog.Tablet;
import org.apache.doris.cloud.datasource.CloudInternalCatalog;
import org.apache.doris.cloud.proto.Cloud;
import org.apache.doris.cloud.qe.ClusterException;
import org.apache.doris.cloud.system.CloudSystemInfoService;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.MetaNotFoundException;
Expand Down Expand Up @@ -90,7 +91,12 @@ public CloudRollupJobV2(String rawSql, long jobId, long dbId, long tableId, Stri
baseSchemaHash, rollupSchemaHash, rollupKeysType, rollupShortKeyColumnCount, origStmt);
ConnectContext context = ConnectContext.get();
if (context != null) {
String clusterName = context.getCloudCluster();
String clusterName = "";
try {
clusterName = context.getCloudCluster();
} catch (ClusterException e) {
LOG.warn("failed to get cluster name", e);
}
LOG.debug("rollup job add cloud cluster, context not null, cluster: {}", clusterName);
if (!Strings.isNullOrEmpty(clusterName)) {
setCloudClusterName(clusterName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.doris.catalog.Tablet;
import org.apache.doris.cloud.datasource.CloudInternalCatalog;
import org.apache.doris.cloud.proto.Cloud;
import org.apache.doris.cloud.qe.ClusterException;
import org.apache.doris.cloud.system.CloudSystemInfoService;
import org.apache.doris.common.Config;
import org.apache.doris.common.MetaNotFoundException;
Expand Down Expand Up @@ -79,7 +80,12 @@ public CloudSchemaChangeJobV2(String rawSql, long jobId, long dbId, long tableId
super(rawSql, jobId, dbId, tableId, tableName, timeoutMs);
ConnectContext context = ConnectContext.get();
if (context != null) {
String clusterName = context.getCloudCluster();
String clusterName = "";
try {
clusterName = context.getCloudCluster();
} catch (ClusterException e) {
LOG.warn("failed to get cluster name", e);
}
LOG.debug("rollup job add cloud cluster, context not null, cluster: {}", clusterName);
if (!Strings.isNullOrEmpty(clusterName)) {
setCloudClusterName(clusterName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,14 @@ protected void runWaitingTxnJob() throws AlterCancelException {
long originTabletId = originTablet.getId();
List<Replica> originReplicas = originTablet.getReplicas();
for (Replica originReplica : originReplicas) {
if (originReplica.getBackendId() < 0) {
LOG.warn("replica:{}, backendId: {}", originReplica, originReplica.getBackendId());
if (originReplica.getBackendIdWithoutException() < 0) {
LOG.warn("replica:{}, backendId: {}", originReplica,
originReplica.getBackendIdWithoutException());
throw new AlterCancelException("originReplica:" + originReplica.getId()
+ " backendId < 0");
}
AlterInvertedIndexTask alterInvertedIndexTask = new AlterInvertedIndexTask(
originReplica.getBackendId(), db.getId(), olapTable.getId(),
originReplica.getBackendIdWithoutException(), db.getId(), olapTable.getId(),
partitionId, originIndexId, originTabletId,
originSchemaHash, olapTable.getIndexes(),
alterInvertedIndexes, originSchemaColumns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ private RollupJobV2 createMaterializedViewJob(String rawSql, String mvName, Stri
int healthyReplicaNum = 0;
for (Replica baseReplica : baseReplicas) {
long mvReplicaId = idGeneratorBuffer.getNextId();
long backendId = baseReplica.getBackendId();
long backendId = baseReplica.getBackendIdWithoutException();
if (baseReplica.getState() == ReplicaState.CLONE
|| baseReplica.getState() == ReplicaState.DECOMMISSION
|| baseReplica.getState() == ReplicaState.COMPACTION_TOO_SLOW
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ protected void createRollupReplica() throws AlterCancelException {
long rollupTabletId = rollupTablet.getId();
List<Replica> rollupReplicas = rollupTablet.getReplicas();
for (Replica rollupReplica : rollupReplicas) {
long backendId = rollupReplica.getBackendId();
long backendId = rollupReplica.getBackendIdWithoutException();
long rollupReplicaId = rollupReplica.getId();
Preconditions.checkNotNull(tabletIdMap.get(rollupTabletId)); // baseTabletId
countDownLatch.addMark(backendId, rollupTabletId);
Expand Down Expand Up @@ -474,8 +474,8 @@ protected void runWaitingTxnJob() throws AlterCancelException {


for (Replica rollupReplica : rollupReplicas) {
AlterReplicaTask rollupTask = new AlterReplicaTask(rollupReplica.getBackendId(), dbId, tableId,
partitionId, rollupIndexId, baseIndexId, rollupTabletId, baseTabletId,
AlterReplicaTask rollupTask = new AlterReplicaTask(rollupReplica.getBackendIdWithoutException(),
dbId, tableId, partitionId, rollupIndexId, baseIndexId, rollupTabletId, baseTabletId,
rollupReplica.getId(), rollupSchemaHash, baseSchemaHash, visibleVersion, jobId,
JobType.ROLLUP, defineExprs, descTable, tbl.getSchemaByIndexId(baseIndexId, true),
objectPool, whereClause, expiration, vaultId);
Expand Down Expand Up @@ -611,7 +611,7 @@ private void onFinished(OlapTable tbl) {
List<Long> failedBackends = failedTabletBackends.get(tablet.getId());
for (Replica replica : tablet.getReplicas()) {
replica.setState(ReplicaState.NORMAL);
if (failedBackends != null && failedBackends.contains(replica.getBackendId())) {
if (failedBackends != null && failedBackends.contains(replica.getBackendIdWithoutException())) {
replica.setBad(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2239,8 +2239,9 @@ private void sendClearAlterTask(Database db, OlapTable olapTable) {
int schemaHash = olapTable.getSchemaHashByIndexId(index.getId());
for (Tablet tablet : index.getTablets()) {
for (Replica replica : tablet.getReplicas()) {
ClearAlterTask alterTask = new ClearAlterTask(replica.getBackendId(), db.getId(),
olapTable.getId(), partition.getId(), index.getId(), tablet.getId(), schemaHash);
ClearAlterTask alterTask = new ClearAlterTask(replica.getBackendIdWithoutException(),
db.getId(), olapTable.getId(), partition.getId(),
index.getId(), tablet.getId(), schemaHash);
batchTask.addTask(alterTask);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ protected void createShadowIndexReplica() throws AlterCancelException {
long shadowTabletId = shadowTablet.getId();
List<Replica> shadowReplicas = shadowTablet.getReplicas();
for (Replica shadowReplica : shadowReplicas) {
long backendId = shadowReplica.getBackendId();
long backendId = shadowReplica.getBackendIdWithoutException();
long shadowReplicaId = shadowReplica.getId();
countDownLatch.addMark(backendId, shadowTabletId);
CreateReplicaTask createReplicaTask = new CreateReplicaTask(
Expand Down Expand Up @@ -496,7 +496,8 @@ protected void runWaitingTxnJob() throws AlterCancelException {
long originTabletId = partitionIndexTabletMap.get(partitionId, shadowIdxId).get(shadowTabletId);
List<Replica> shadowReplicas = shadowTablet.getReplicas();
for (Replica shadowReplica : shadowReplicas) {
AlterReplicaTask rollupTask = new AlterReplicaTask(shadowReplica.getBackendId(), dbId,
AlterReplicaTask rollupTask
= new AlterReplicaTask(shadowReplica.getBackendIdWithoutException(), dbId,
tableId, partitionId, shadowIdxId, originIdxId, shadowTabletId, originTabletId,
shadowReplica.getId(), shadowSchemaHash, originSchemaHash, visibleVersion, jobId,
JobType.SCHEMA_CHANGE, defineExprs, descTable, originSchemaColumns, objectPool,
Expand Down Expand Up @@ -667,7 +668,7 @@ private void onFinished(OlapTable tbl) {
List<Long> failedBackends = failedTabletBackends.get(tablet.getId());
for (Replica replica : tablet.getReplicas()) {
replica.setState(ReplicaState.NORMAL);
if (failedBackends != null && failedBackends.contains(replica.getBackendId())) {
if (failedBackends != null && failedBackends.contains(replica.getBackendIdWithoutException())) {
replica.setBad(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ private synchronized boolean tryNewTabletSnapshotTask(SnapshotTask task) {
taskProgress.remove(task.getTabletId());
taskErrMsg.remove(task.getTabletId());

SnapshotTask newTask = new SnapshotTask(null, replica.getBackendId(), task.getTabletId(),
SnapshotTask newTask = new SnapshotTask(null, replica.getBackendIdWithoutException(), task.getTabletId(),
task.getJobId(), task.getDbId(), tbl.getId(), task.getPartitionId(),
task.getIndexId(), task.getTabletId(),
task.getVersion(),
task.getSchemaHash(), timeoutMs, false /* not restore task */);
AgentBatchTask batchTask = new AgentBatchTask();
batchTask.addTask(newTask);
unfinishedTaskIds.put(tablet.getId(), replica.getBackendId());
unfinishedTaskIds.put(tablet.getId(), replica.getBackendIdWithoutException());

//send task
AgentTaskQueue.addTask(newTask);
Expand Down Expand Up @@ -609,13 +609,13 @@ private Status prepareSnapshotTaskForOlapTableWithoutLock(Database db, OlapTable
+ ". visible version: " + visibleVersion);
return status;
}
SnapshotTask task = new SnapshotTask(null, replica.getBackendId(), tablet.getId(),
SnapshotTask task = new SnapshotTask(null, replica.getBackendIdWithoutException(), tablet.getId(),
jobId, dbId, olapTable.getId(), partition.getId(),
index.getId(), tablet.getId(),
visibleVersion,
schemaHash, timeoutMs, false /* not restore task */);
batchTask.addTask(task);
unfinishedTaskIds.put(tablet.getId(), replica.getBackendId());
unfinishedTaskIds.put(tablet.getId(), replica.getBackendIdWithoutException());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -991,12 +991,13 @@ private void prepareAndSendSnapshotTaskForOlapTable(Database db) {
Tablet tablet = index.getTablet(idChain.getTabletId());
Replica replica = tablet.getReplicaById(idChain.getReplicaId());
long signature = env.getNextId();
SnapshotTask task = new SnapshotTask(null, replica.getBackendId(), signature, jobId, db.getId(),
SnapshotTask task = new SnapshotTask(null, replica.getBackendIdWithoutException(),
signature, jobId, db.getId(),
tbl.getId(), part.getId(), index.getId(), tablet.getId(), part.getVisibleVersion(),
tbl.getSchemaHashByIndexId(index.getId()), timeoutMs, true /* is restore task*/);
batchTask.addTask(task);
unfinishedSignatureToId.put(signature, tablet.getId());
bePathsMap.put(replica.getBackendId(), replica.getPathHash());
bePathsMap.put(replica.getBackendIdWithoutException(), replica.getPathHash());
} finally {
tbl.readUnlock();
}
Expand Down Expand Up @@ -1103,7 +1104,7 @@ private void createReplicas(Database db, AgentBatchTask batchTask, OlapTable loc
Env.getCurrentInvertedIndex().addTablet(restoreTablet.getId(), tabletMeta);
for (Replica restoreReplica : restoreTablet.getReplicas()) {
Env.getCurrentInvertedIndex().addReplica(restoreTablet.getId(), restoreReplica);
CreateReplicaTask task = new CreateReplicaTask(restoreReplica.getBackendId(), dbId,
CreateReplicaTask task = new CreateReplicaTask(restoreReplica.getBackendIdWithoutException(), dbId,
localTbl.getId(), restorePart.getId(), restoredIdx.getId(),
restoreTablet.getId(), restoreReplica.getId(), indexMeta.getShortKeyColumnCount(),
indexMeta.getSchemaHash(), restoreReplica.getVersion(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private void sendTableGcInfoToBe(Map<Long, BinlogGcTask> beBinlogGcTaskMap, Olap
for (Tablet tablet : tablets) {
List<Replica> replicas = tablet.getReplicas();
for (Replica replica : replicas) {
long beId = replica.getBackendId();
long beId = replica.getBackendIdWithoutException();
long signature = -1;
BinlogGcTask binlogGcTask = null;
if (beBinlogGcTaskMap.containsKey(beId)) {
Expand Down
6 changes: 3 additions & 3 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -6276,7 +6276,7 @@ private static void getTableMeta(OlapTable olapTable, TGetMetaDBMeta dbMeta) {
for (Replica replica : tablet.getReplicas()) {
TGetMetaReplicaMeta replicaMeta = new TGetMetaReplicaMeta();
replicaMeta.setId(replica.getId());
replicaMeta.setBackendId(replica.getBackendId());
replicaMeta.setBackendId(replica.getBackendIdWithoutException());
replicaMeta.setVersion(replica.getVersion());
tabletMeta.addToReplicas(replicaMeta);
}
Expand Down Expand Up @@ -6350,8 +6350,8 @@ public void compactTable(AdminCompactTableStmt stmt) throws DdlException {
for (MaterializedIndex idx : partition.getMaterializedIndices(IndexExtState.VISIBLE)) {
for (Tablet tablet : idx.getTablets()) {
for (Replica replica : tablet.getReplicas()) {
CompactionTask compactionTask = new CompactionTask(replica.getBackendId(), db.getId(),
olapTable.getId(), partition.getId(), idx.getId(), tablet.getId(),
CompactionTask compactionTask = new CompactionTask(replica.getBackendIdWithoutException(),
db.getId(), olapTable.getId(), partition.getId(), idx.getId(), tablet.getId(),
olapTable.getSchemaHashByIndexId(idx.getId()), type);
batchTask.addTask(compactionTask);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static List<List<String>> getTabletStatus(String dbName, String tblName,
List<String> row = Lists.newArrayList();

ReplicaStatus status = ReplicaStatus.OK;
Backend be = infoService.getBackend(replica.getBackendId());
Backend be = infoService.getBackend(replica.getBackendIdWithoutException());
if (be == null || !be.isAlive() || replica.isBad()) {
status = ReplicaStatus.DEAD;
} else if (replica.getVersion() < visibleVersion
Expand All @@ -107,7 +107,7 @@ private static List<List<String>> getTabletStatus(String dbName, String tblName,

row.add(String.valueOf(tabletId));
row.add(String.valueOf(replica.getId()));
row.add(String.valueOf(replica.getBackendId()));
row.add(String.valueOf(replica.getBackendIdWithoutException()));
row.add(String.valueOf(replica.getVersion()));
row.add(String.valueOf(replica.getLastFailedVersion()));
row.add(String.valueOf(replica.getLastSuccessVersion()));
Expand Down Expand Up @@ -215,12 +215,13 @@ private static List<List<String>> getTabletDistribution(
for (MaterializedIndex index : partition.getMaterializedIndices(IndexExtState.VISIBLE)) {
for (Tablet tablet : index.getTablets()) {
for (Replica replica : tablet.getReplicas()) {
if (!countMap.containsKey(replica.getBackendId())) {
if (!countMap.containsKey(replica.getBackendIdWithoutException())) {
continue;
}
countMap.put(replica.getBackendId(), countMap.get(replica.getBackendId()) + 1);
sizeMap.put(replica.getBackendId(),
sizeMap.get(replica.getBackendId()) + replica.getDataSize());
countMap.put(replica.getBackendIdWithoutException(),
countMap.get(replica.getBackendIdWithoutException()) + 1);
sizeMap.put(replica.getBackendIdWithoutException(),
sizeMap.get(replica.getBackendIdWithoutException()) + replica.getDataSize());
totalReplicaNum++;
totalReplicaSize += replica.getDataSize();
}
Expand Down
12 changes: 11 additions & 1 deletion fe/fe-core/src/main/java/org/apache/doris/catalog/Replica.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.doris.catalog;

import org.apache.doris.common.Config;
import org.apache.doris.common.UserException;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.util.DebugPointUtil;
import org.apache.doris.system.Backend;
Expand Down Expand Up @@ -239,7 +240,16 @@ public long getId() {
return this.id;
}

public long getBackendId() {
public long getBackendIdWithoutException() {
try {
return getBackendId();
} catch (UserException e) {
LOG.warn("getBackendIdWithoutException: ", e);
return -1;
}
}

public long getBackendId() throws UserException {
return this.backendId;
}

Expand Down
Loading

0 comments on commit 1441a55

Please sign in to comment.