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
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ static String getLocationFromConfig(String preferable, String selfLocation) {

@VisibleForTesting
static String detectLocalDC(List<EndpointRecord> endpoints, Ticker ticker) {
// Endpoints without a known location carry no information about datacenters. They must be
// filtered out because groupingBy rejects a null key - the endpoint the transport bootstraps
// with has no location until the first discovery completes.
Map<String, List<EndpointRecord>> dcLocationToNodes = endpoints
.stream()
.filter(endpoint -> endpoint.getLocation() != null && !endpoint.getLocation().isEmpty())
.collect(Collectors.groupingBy(EndpointRecord::getLocation));

if (dcLocationToNodes.size() < 2) {
Expand Down
14 changes: 14 additions & 0 deletions core/src/test/java/tech/ydb/core/impl/pool/PriorityPickerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import javax.net.ServerSocketFactory;

import com.google.common.base.Ticker;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -56,6 +57,19 @@ public void detectLocalDCFallbackTest() {
Assert.assertEquals(0, ignoreSelfLocation.getEndpointPriority("DC3"));
}

@Test
public void detectLocalDCWithoutLocationsTest() {
// the endpoint a transport bootstraps with has no location until the first discovery completes
List<EndpointRecord> bootstrap = Collections.singletonList(new EndpointRecord("localhost", 2136));
PriorityPicker picker = PriorityPicker.from(BalancingSettings.detectLocalDs(), null, bootstrap);

Assert.assertEquals(0, picker.getEndpointPriority("DC1"));
Assert.assertEquals(0, picker.getEndpointPriority(null));

Assert.assertNull(PriorityPicker.detectLocalDC(bootstrap, Ticker.systemTicker()));
Assert.assertNull(PriorityPicker.detectLocalDC(Collections.emptyList(), Ticker.systemTicker()));
}

@Test
public void detectLocalDCTest() {
TestTicker testTicker = new TestTicker(
Expand Down
Loading