Skip to content

Commit 6482b97

Browse files
authored
Skip bootstrap checks on snapshot builds (elastic#128448) (elastic#128499)
Today we determine whether bootstrap checks are enforced (in production builds) based on whether a non-loopback address is configured. This PR we should expand that to also not enforce bootstrap checks when a snapshot build is used, so that is enforceLimits = non-loopback && non-snapshot Fixes elastic#118328
1 parent 415b19e commit 6482b97

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

server/src/main/java/org/elasticsearch/bootstrap/BootstrapChecks.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.apache.logging.log4j.LogManager;
1313
import org.apache.logging.log4j.Logger;
1414
import org.apache.lucene.util.Constants;
15+
import org.elasticsearch.Build;
1516
import org.elasticsearch.cluster.coordination.ClusterBootstrapService;
1617
import org.elasticsearch.common.ReferenceDocs;
1718
import org.elasticsearch.common.settings.Setting;
@@ -39,6 +40,7 @@
3940
import java.util.Collections;
4041
import java.util.List;
4142
import java.util.Locale;
43+
import java.util.function.BooleanSupplier;
4244
import java.util.function.Predicate;
4345
import java.util.stream.Collectors;
4446
import java.util.stream.Stream;
@@ -77,7 +79,11 @@ static void check(
7779
combinedChecks.addAll(additionalChecks);
7880
check(
7981
context,
80-
enforceLimits(boundTransportAddress, DiscoveryModule.DISCOVERY_TYPE_SETTING.get(context.settings())),
82+
enforceLimits(
83+
boundTransportAddress,
84+
DiscoveryModule.DISCOVERY_TYPE_SETTING.get(context.settings()),
85+
Build.current()::isSnapshot
86+
),
8187
Collections.unmodifiableList(combinedChecks)
8288
);
8389
}
@@ -174,17 +180,23 @@ static void log(final Logger logger, final String error) {
174180
}
175181

176182
/**
177-
* Tests if the checks should be enforced.
183+
* Tests if the checks should be enforced. \
184+
* Bootstrap checks are enforced (in production builds) if a non-loopback address is configured and a non-snapshot build is used.
178185
*
179186
* @param boundTransportAddress the node network bindings
180187
* @param discoveryType the discovery type
188+
* @param isSnapshot provider to test if this build is snapshot or not
181189
* @return {@code true} if the checks should be enforced
182190
*/
183-
static boolean enforceLimits(final BoundTransportAddress boundTransportAddress, final String discoveryType) {
191+
static boolean enforceLimits(
192+
final BoundTransportAddress boundTransportAddress,
193+
final String discoveryType,
194+
final BooleanSupplier isSnapshot
195+
) {
184196
final Predicate<TransportAddress> isLoopbackAddress = t -> t.address().getAddress().isLoopbackAddress();
185197
final boolean bound = (Arrays.stream(boundTransportAddress.boundAddresses()).allMatch(isLoopbackAddress)
186198
&& isLoopbackAddress.test(boundTransportAddress.publishAddress())) == false;
187-
return bound && SINGLE_NODE_DISCOVERY_TYPE.equals(discoveryType) == false;
199+
return bound && isSnapshot.getAsBoolean() == false && SINGLE_NODE_DISCOVERY_TYPE.equals(discoveryType) == false;
188200
}
189201

190202
// the list of checks to execute

server/src/main/java/org/elasticsearch/plugins/internal/SettingsExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface SettingsExtension {
2525
List<Setting<?>> getSettings();
2626

2727
/**
28-
* Loads a single BuildExtension, or returns {@code null} if none are found.
28+
* Loads a single SettingsExtension, or returns {@code null} if none are found.
2929
*/
3030
static List<SettingsExtension> load() {
3131
var loader = ServiceLoader.load(SettingsExtension.class);

server/src/test/java/org/elasticsearch/bootstrap/BootstrapChecksTests.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@
3636
import java.util.concurrent.atomic.AtomicReference;
3737
import java.util.function.Consumer;
3838

39+
import static java.lang.Boolean.FALSE;
40+
import static java.lang.Boolean.TRUE;
3941
import static org.elasticsearch.discovery.DiscoveryModule.MULTI_NODE_DISCOVERY_TYPE;
4042
import static org.elasticsearch.discovery.DiscoveryModule.SINGLE_NODE_DISCOVERY_TYPE;
4143
import static org.hamcrest.CoreMatchers.allOf;
4244
import static org.hamcrest.CoreMatchers.containsString;
4345
import static org.hamcrest.CoreMatchers.equalTo;
4446
import static org.hamcrest.CoreMatchers.instanceOf;
4547
import static org.hamcrest.Matchers.hasToString;
48+
import static org.hamcrest.Matchers.is;
4649
import static org.hamcrest.Matchers.not;
4750
import static org.mockito.Mockito.mock;
4851
import static org.mockito.Mockito.verify;
@@ -103,7 +106,7 @@ public void testEnforceLimitsWhenBoundToNonLocalAddress() {
103106
final String discoveryType = randomFrom(MULTI_NODE_DISCOVERY_TYPE, SINGLE_NODE_DISCOVERY_TYPE);
104107

105108
assertEquals(
106-
BootstrapChecks.enforceLimits(boundTransportAddress, discoveryType),
109+
BootstrapChecks.enforceLimits(boundTransportAddress, discoveryType, FALSE::booleanValue),
107110
SINGLE_NODE_DISCOVERY_TYPE.equals(discoveryType) == false
108111
);
109112
}
@@ -124,11 +127,27 @@ public void testEnforceLimitsWhenPublishingToNonLocalAddress() {
124127
final String discoveryType = randomFrom(MULTI_NODE_DISCOVERY_TYPE, SINGLE_NODE_DISCOVERY_TYPE);
125128

126129
assertEquals(
127-
BootstrapChecks.enforceLimits(boundTransportAddress, discoveryType),
130+
BootstrapChecks.enforceLimits(boundTransportAddress, discoveryType, FALSE::booleanValue),
128131
SINGLE_NODE_DISCOVERY_TYPE.equals(discoveryType) == false
129132
);
130133
}
131134

135+
public void testDoNotEnforceLimitsWhenSnapshotBuild() {
136+
final List<TransportAddress> transportAddresses = new ArrayList<>();
137+
138+
for (int i = 0; i < randomIntBetween(1, 8); i++) {
139+
final TransportAddress randomTransportAddress = buildNewFakeTransportAddress();
140+
transportAddresses.add(randomTransportAddress);
141+
}
142+
143+
final TransportAddress publishAddress = new TransportAddress(InetAddress.getLoopbackAddress(), 0);
144+
final BoundTransportAddress boundTransportAddress = mock(BoundTransportAddress.class);
145+
when(boundTransportAddress.boundAddresses()).thenReturn(transportAddresses.toArray(new TransportAddress[0]));
146+
when(boundTransportAddress.publishAddress()).thenReturn(publishAddress);
147+
148+
assertThat(BootstrapChecks.enforceLimits(boundTransportAddress, MULTI_NODE_DISCOVERY_TYPE, TRUE::booleanValue), is(false));
149+
}
150+
132151
public void testExceptionAggregation() {
133152
final List<BootstrapCheck> checks = Arrays.asList(new BootstrapCheck() {
134153
@Override

0 commit comments

Comments
 (0)