Skip to content
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 @@ -1129,17 +1129,21 @@ public List<TOlapTableLocationParam> createDummyLocation(OlapTable table) throws

final long fakeTabletId = 0;
SystemInfoService clusterInfo = Env.getCurrentSystemInfo();
List<Long> aliveBe = clusterInfo.getAllBackendIds(true);
if (aliveBe.isEmpty()) {
List<Long> availableBeIds = clusterInfo.getBackendsByCurrentCluster().values().stream()
.filter(Backend::isLoadAvailable)
.filter(backend -> !backend.isDecommissioned() && !backend.isDecommissioning())
.map(Backend::getId)
.collect(Collectors.toList());
if (availableBeIds.isEmpty()) {
throw new UserException(InternalErrorCode.REPLICA_FEW_ERR, "no available BE in cluster");
}
for (int i = 0; i < table.getIndexNumber(); i++) {
// only one fake tablet here
Long[] nodes = aliveBe.toArray(new Long[0]);
Long[] nodes = availableBeIds.toArray(new Long[0]);
Random random = new SecureRandom();
int nodeIndex = random.nextInt(nodes.length);
if (singleReplicaLoad) {
List<Long> slaveBe = aliveBe;
List<Long> slaveBe = new ArrayList<>(availableBeIds);
locationParam.addToTablets(new TTabletLocation(fakeTabletId,
Arrays.asList(nodes[nodeIndex])));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,84 @@

package org.apache.doris.planner;

import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.planner.OlapTableSink.AdaptiveBucketAssignment;
import org.apache.doris.planner.OlapTableSink.AdaptiveIndexBucketAssignment;
import org.apache.doris.system.Backend;
import org.apache.doris.system.SystemInfoService;
import org.apache.doris.thrift.TOlapTableIndexTablets;
import org.apache.doris.thrift.TOlapTableLocationParam;
import org.apache.doris.thrift.TOlapTablePartition;
import org.apache.doris.thrift.TTabletLocation;

import com.google.common.collect.ImmutableMap;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class OlapTableSinkTest {
@Test
public void testCreateDummyLocationUsesLoadAvailableBackendInCurrentComputeGroup() throws Exception {
SystemInfoService systemInfoService = Mockito.mock(SystemInfoService.class);
Backend currentComputeGroupBackend = Mockito.mock(Backend.class);
Backend loadDisabledBackend = Mockito.mock(Backend.class);
OlapTable table = Mockito.mock(OlapTable.class);

Mockito.when(currentComputeGroupBackend.getId()).thenReturn(1L);
Mockito.when(currentComputeGroupBackend.isLoadAvailable()).thenReturn(true);
Mockito.when(loadDisabledBackend.getId()).thenReturn(2L);
Mockito.when(loadDisabledBackend.isLoadAvailable()).thenReturn(false);
Mockito.when(systemInfoService.getBackendsByCurrentCluster())
.thenReturn(ImmutableMap.of(1L, currentComputeGroupBackend, 2L, loadDisabledBackend));
Mockito.when(systemInfoService.getAllBackendIds(true)).thenReturn(Collections.singletonList(3L));
Mockito.when(table.getIndexNumber()).thenReturn(1);

try (MockedStatic<Env> mockedEnv = Mockito.mockStatic(Env.class)) {
mockedEnv.when(Env::getCurrentSystemInfo).thenReturn(systemInfoService);

OlapTableSink sink = new OlapTableSink(table, null, Collections.emptyList(), false);
List<TOlapTableLocationParam> locationParams = sink.createDummyLocation(table);

Assert.assertEquals(Collections.singletonList(1L),
locationParams.get(0).getTablets().get(0).getNodeIds());
Mockito.verify(systemInfoService, Mockito.never()).getAllBackendIds(true);
Mockito.verify(systemInfoService).getBackendsByCurrentCluster();
}
}

@Test
public void testCreateDummyLocationDoesNotShareBackendCandidatesAcrossIndexes() throws Exception {
SystemInfoService systemInfoService = Mockito.mock(SystemInfoService.class);
Backend currentComputeGroupBackend = Mockito.mock(Backend.class);
OlapTable table = Mockito.mock(OlapTable.class);

Mockito.when(currentComputeGroupBackend.getId()).thenReturn(1L);
Mockito.when(currentComputeGroupBackend.isLoadAvailable()).thenReturn(true);
Mockito.when(systemInfoService.getBackendsByCurrentCluster())
.thenReturn(ImmutableMap.of(1L, currentComputeGroupBackend));
Mockito.when(table.getIndexNumber()).thenReturn(2);

try (MockedStatic<Env> mockedEnv = Mockito.mockStatic(Env.class)) {
mockedEnv.when(Env::getCurrentSystemInfo).thenReturn(systemInfoService);

OlapTableSink sink = new OlapTableSink(table, null, Collections.emptyList(), true);
List<TOlapTableLocationParam> locationParams = sink.createDummyLocation(table);

Assert.assertEquals(2, locationParams.get(0).getTabletsSize());
Assert.assertEquals(Collections.singletonList(1L),
locationParams.get(0).getTablets().get(0).getNodeIds());
Assert.assertEquals(Collections.singletonList(1L),
locationParams.get(0).getTablets().get(1).getNodeIds());
}
}

@Test
public void testAdaptiveRandomBucketAssignmentIsPerIndex() {
TOlapTablePartition partition = new TOlapTablePartition();
Expand Down
Loading