Skip to content

Commit eee0086

Browse files
committed
[CCR] Delay auto follow license check (#33557)
* [CCR] Delay auto follow license check so that we're sure that there are auto follow patterns configured Otherwise we log a warning in case someone is running with basic or gold license and has not used the ccr feature.
1 parent b7ef3eb commit eee0086

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ public AutoFollowCoordinator(
7070
}
7171

7272
private void doAutoFollow() {
73-
if (ccrLicenseChecker.isCcrAllowed() == false) {
74-
// TODO: set non-compliant status on auto-follow coordination that can be viewed via a stats API
75-
LOGGER.warn("skipping auto-follower coordination", LicenseUtils.newComplianceException("ccr"));
76-
threadPool.schedule(pollInterval, ThreadPool.Names.SAME, this::doAutoFollow);
77-
return;
78-
}
7973
if (localNodeMaster == false) {
8074
return;
8175
}
@@ -91,6 +85,13 @@ private void doAutoFollow() {
9185
return;
9286
}
9387

88+
if (ccrLicenseChecker.isCcrAllowed() == false) {
89+
// TODO: set non-compliant status on auto-follow coordination that can be viewed via a stats API
90+
LOGGER.warn("skipping auto-follower coordination", LicenseUtils.newComplianceException("ccr"));
91+
threadPool.schedule(pollInterval, ThreadPool.Names.SAME, this::doAutoFollow);
92+
return;
93+
}
94+
9495
Consumer<Exception> handler = e -> {
9596
if (e != null) {
9697
LOGGER.warn("failure occurred during auto-follower coordination", e);

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrLicenseIT.java

+40
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
import org.elasticsearch.ElasticsearchSecurityException;
1313
import org.elasticsearch.action.ActionListener;
1414
import org.elasticsearch.action.support.master.AcknowledgedResponse;
15+
import org.elasticsearch.cluster.ClusterState;
16+
import org.elasticsearch.cluster.ClusterStateUpdateTask;
17+
import org.elasticsearch.cluster.metadata.MetaData;
18+
import org.elasticsearch.cluster.service.ClusterService;
1519
import org.elasticsearch.common.logging.Loggers;
1620
import org.elasticsearch.common.unit.TimeValue;
1721
import org.elasticsearch.plugins.Plugin;
@@ -23,6 +27,8 @@
2327
import org.elasticsearch.xpack.ccr.action.FollowIndexAction;
2428
import org.elasticsearch.xpack.ccr.action.PutAutoFollowPatternAction;
2529
import org.elasticsearch.xpack.ccr.action.ShardFollowNodeTask;
30+
import org.elasticsearch.xpack.core.ccr.AutoFollowMetadata;
31+
import org.elasticsearch.xpack.core.ccr.AutoFollowMetadata.AutoFollowPattern;
2632

2733
import java.util.Collection;
2834
import java.util.Collections;
@@ -127,6 +133,40 @@ public void onFailure(final Exception e) {
127133
}
128134

129135
public void testAutoFollowCoordinatorLogsSkippingAutoFollowCoordinationWithNonCompliantLicense() throws Exception {
136+
// Update the cluster state so that we have auto follow patterns and verify that we log a warning in case of incompatible license:
137+
CountDownLatch latch = new CountDownLatch(1);
138+
ClusterService clusterService = getInstanceFromNode(ClusterService.class);
139+
clusterService.submitStateUpdateTask("test-add-auto-follow-pattern", new ClusterStateUpdateTask() {
140+
141+
@Override
142+
public ClusterState execute(ClusterState currentState) throws Exception {
143+
AutoFollowPattern autoFollowPattern =
144+
new AutoFollowPattern(Collections.singletonList("logs-*"), null, null, null, null, null, null, null, null);
145+
AutoFollowMetadata autoFollowMetadata = new AutoFollowMetadata(
146+
Collections.singletonMap("test_alias", autoFollowPattern),
147+
Collections.emptyMap()
148+
);
149+
150+
ClusterState.Builder newState = ClusterState.builder(currentState);
151+
newState.metaData(MetaData.builder(currentState.getMetaData())
152+
.putCustom(AutoFollowMetadata.TYPE, autoFollowMetadata)
153+
.build());
154+
return newState.build();
155+
}
156+
157+
@Override
158+
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
159+
latch.countDown();
160+
}
161+
162+
@Override
163+
public void onFailure(String source, Exception e) {
164+
latch.countDown();
165+
fail("unexpected error [" + e.getMessage() + "]");
166+
}
167+
});
168+
latch.await();
169+
130170
final Logger logger = LogManager.getLogger(AutoFollowCoordinator.class);
131171
final MockLogAppender appender = new MockLogAppender();
132172
appender.start();

0 commit comments

Comments
 (0)