Skip to content
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
56 changes: 43 additions & 13 deletions fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -1007,22 +1007,14 @@ private void computeTabletInfo() throws UserException {
*/
Preconditions.checkState(scanBackendIds.isEmpty());
Preconditions.checkState(scanTabletIds.isEmpty());
Map<Long, Set<Long>> backendAlivePathHashs = Maps.newHashMap();
for (Backend backend : olapTable.getAllBackendsByAllCluster().values()) {
Set<Long> hashSet = Sets.newLinkedHashSet();
for (DiskInfo diskInfo : backend.getDisks().values()) {
if (diskInfo.isAlive()) {
hashSet.add(diskInfo.getPathHash());
}
}
backendAlivePathHashs.put(backend.getId(), hashSet);
}

ConnectContext connectContext = ConnectContext.get();
boolean isNereids = connectContext != null && connectContext.getState().isNereids();
boolean isPointQuery = connectContext != null
&& connectContext.getStatementContext() != null
&& connectContext.getStatementContext().isShortCircuitQuery();
ImmutableMap<Long, Backend> allBackends = olapTable.getAllBackendsByAllCluster();
Map<Long, Set<Long>> backendAlivePathHashes = isPointQuery
? null : getBackendAlivePathHashes(allBackends.values());
for (Long partitionId : selectedPartitionIds) {
final Partition partition = olapTable.getPartition(partitionId);
final MaterializedIndex selectedTable = olapTable.getPartitionIndex(partition, selectedIndexId);
Expand Down Expand Up @@ -1070,7 +1062,7 @@ private void computeTabletInfo() throws UserException {
scanTabletIds.addAll(allTabletIds);
}

if (!isPointQuery()) {
if (!isPointQuery) {
int bucketNum = partition.getDistributionInfo().getBucketNum();
for (int i = 0; i < allTabletIds.size(); i++) {
tabletId2BucketInfo.put(allTabletIds.get(i), encodeBucketInfo(i, bucketNum));
Expand All @@ -1079,8 +1071,46 @@ private void computeTabletInfo() throws UserException {

totalTabletsNum += selectedTable.getTablets().size();
selectedSplitNum += tablets.size();
addScanRangeLocations(partition, tablets, backendAlivePathHashs);
Map<Long, Set<Long>> currentBackendAlivePathHashes = isPointQuery
? getBackendAlivePathHashes(allBackends, tablets) : backendAlivePathHashes;
addScanRangeLocations(partition, tablets, currentBackendAlivePathHashes);
}
}

private static Map<Long, Set<Long>> getBackendAlivePathHashes(Collection<Backend> backends) {
Map<Long, Set<Long>> backendAlivePathHashes = Maps.newHashMap();
for (Backend backend : backends) {
backendAlivePathHashes.put(backend.getId(), getBackendAlivePathHashes(backend));
}
return backendAlivePathHashes;
}

@VisibleForTesting
static Map<Long, Set<Long>> getBackendAlivePathHashes(
Map<Long, Backend> backends, List<Tablet> tablets) {
Map<Long, Set<Long>> backendAlivePathHashes = Maps.newHashMap();
for (Tablet tablet : tablets) {
for (Replica replica : tablet.getReplicas()) {
Comment thread
zyp-V marked this conversation as resolved.
long backendId = replica.getBackendIdWithoutException();
Comment thread
zyp-V marked this conversation as resolved.
Backend backend = backends.get(backendId);
if (backend != null) {
backendAlivePathHashes.computeIfAbsent(
backendId, id -> getBackendAlivePathHashes(backend));
}
}
}
return backendAlivePathHashes;
}

private static Set<Long> getBackendAlivePathHashes(Backend backend) {
Map<String, DiskInfo> disks = backend.getDisks();
Set<Long> alivePathHashes = Sets.newHashSetWithExpectedSize(disks.size());
for (DiskInfo diskInfo : disks.values()) {
if (diskInfo.isAlive()) {
alivePathHashes.add(diskInfo.getPathHash());
}
}
return alivePathHashes;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,30 @@
import org.apache.doris.analysis.TupleDescriptor;
import org.apache.doris.analysis.TupleId;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.DiskInfo;
import org.apache.doris.catalog.LocalReplica;
import org.apache.doris.catalog.LocalTablet;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.Partition;
import org.apache.doris.catalog.PartitionKey;
import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.RangePartitionInfo;
import org.apache.doris.catalog.RangePartitionItem;
import org.apache.doris.catalog.Replica.ReplicaState;
import org.apache.doris.catalog.Tablet;
import org.apache.doris.catalog.info.TableNameInfo;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
import org.apache.doris.common.util.DebugPointUtil;
import org.apache.doris.datasource.InternalCatalog;
import org.apache.doris.system.Backend;
import org.apache.doris.thrift.TOlapScanNode;
import org.apache.doris.thrift.TPaloScanRange;
import org.apache.doris.thrift.TPartitionBoundary;
import org.apache.doris.thrift.TScanRange;
import org.apache.doris.thrift.TScanRangeLocations;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Range;
Expand All @@ -59,6 +66,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public class OlapScanNodeTest {
Expand Down Expand Up @@ -356,6 +364,45 @@ private Map<Long, Long> getBucketInfo(OlapScanNode scanNode) throws Exception {
return (Map<Long, Long>) bucketInfoField.get(scanNode);
}

@Test
public void testPointQueryBackendAlivePathsOnlyUseSelectedTabletBackends() {
Backend firstBackend = backendWithDisks(1L, 11L, 12L);
Backend secondBackend = backendWithDisks(2L, 21L, 22L);
Backend unrelatedBackend = backendWithDisks(3L, 31L, 32L);
Map<Long, Backend> backends = ImmutableMap.of(
firstBackend.getId(), firstBackend,
secondBackend.getId(), secondBackend,
unrelatedBackend.getId(), unrelatedBackend);

LocalTablet selectedTablet = new LocalTablet(10L);
selectedTablet.addReplica(new LocalReplica(101L, firstBackend.getId(), 0, ReplicaState.NORMAL), true);
selectedTablet.addReplica(new LocalReplica(102L, secondBackend.getId(), 0, ReplicaState.NORMAL), true);
selectedTablet.addReplica(new LocalReplica(103L, 4L, 0, ReplicaState.NORMAL), true);

Map<Long, Set<Long>> alivePathHashes = OlapScanNode.getBackendAlivePathHashes(
backends, Lists.<Tablet>newArrayList(selectedTablet));

Assert.assertEquals(2, alivePathHashes.size());
Assert.assertEquals(Collections.singleton(11L), alivePathHashes.get(firstBackend.getId()));
Assert.assertEquals(Collections.singleton(21L), alivePathHashes.get(secondBackend.getId()));
Assert.assertFalse(alivePathHashes.containsKey(unrelatedBackend.getId()));
Assert.assertFalse(alivePathHashes.containsKey(4L));
}

private Backend backendWithDisks(long backendId, long alivePathHash, long offlinePathHash) {
DiskInfo aliveDisk = new DiskInfo("/alive-" + backendId);
aliveDisk.setPathHash(alivePathHash);
DiskInfo offlineDisk = new DiskInfo("/offline-" + backendId);
offlineDisk.setPathHash(offlinePathHash);
offlineDisk.setState(DiskInfo.DiskState.OFFLINE);

Backend backend = new Backend(backendId, "127.0.0." + backendId, 9050);
backend.setDisks(ImmutableMap.of(
aliveDisk.getRootPath(), aliveDisk,
offlineDisk.getRootPath(), offlineDisk));
return backend;
}

private Partition mockPartition(String name) {
Partition partition = Mockito.mock(Partition.class);
Mockito.when(partition.getName()).thenReturn(name);
Expand Down
Loading