Tests: Improve stability and logging of TemplateUpgradeServiceIT tests (#25386)
Relates to #25382
This commit is contained in:
parent
da0b991331
commit
79a8336559
|
@ -120,10 +120,13 @@ public class TemplateUpgradeService extends AbstractComponent implements Cluster
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
lastTemplateMetaData = templates;
|
lastTemplateMetaData = templates;
|
||||||
Optional<Tuple<Map<String, BytesReference>, Set<String>>> changes = calculateTemplateChanges(templates);
|
Optional<Tuple<Map<String, BytesReference>, Set<String>>> changes = calculateTemplateChanges(templates);
|
||||||
if (changes.isPresent()) {
|
if (changes.isPresent()) {
|
||||||
|
logger.info("Starting template upgrade to version {}, {} templates will be updated and {} will be removed",
|
||||||
|
Version.CURRENT,
|
||||||
|
changes.get().v1().size(),
|
||||||
|
changes.get().v2().size());
|
||||||
if (updatesInProgress.compareAndSet(0, changes.get().v1().size() + changes.get().v2().size())) {
|
if (updatesInProgress.compareAndSet(0, changes.get().v1().size() + changes.get().v2().size())) {
|
||||||
threadPool.generic().execute(() -> updateTemplates(changes.get().v1(), changes.get().v2()));
|
threadPool.generic().execute(() -> updateTemplates(changes.get().v1(), changes.get().v2()));
|
||||||
}
|
}
|
||||||
|
@ -140,8 +143,12 @@ public class TemplateUpgradeService extends AbstractComponent implements Cluster
|
||||||
DiscoveryNode localNode = nodes.getLocalNode();
|
DiscoveryNode localNode = nodes.getLocalNode();
|
||||||
// Only data and master nodes should update the template
|
// Only data and master nodes should update the template
|
||||||
if (localNode.isDataNode() || localNode.isMasterNode()) {
|
if (localNode.isDataNode() || localNode.isMasterNode()) {
|
||||||
|
DiscoveryNode masterNode = nodes.getMasterNode();
|
||||||
|
if (masterNode == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Version maxVersion = nodes.getLargestNonClientNodeVersion();
|
Version maxVersion = nodes.getLargestNonClientNodeVersion();
|
||||||
if (maxVersion.equals(nodes.getMasterNode().getVersion())) {
|
if (maxVersion.equals(masterNode.getVersion())) {
|
||||||
// If the master has the latest version - we will allow it to handle the update
|
// If the master has the latest version - we will allow it to handle the update
|
||||||
return nodes.isLocalNodeElectedMaster();
|
return nodes.isLocalNodeElectedMaster();
|
||||||
} else {
|
} else {
|
||||||
|
@ -171,7 +178,9 @@ public class TemplateUpgradeService extends AbstractComponent implements Cluster
|
||||||
client.admin().indices().putTemplate(request, new ActionListener<PutIndexTemplateResponse>() {
|
client.admin().indices().putTemplate(request, new ActionListener<PutIndexTemplateResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(PutIndexTemplateResponse response) {
|
public void onResponse(PutIndexTemplateResponse response) {
|
||||||
updatesInProgress.decrementAndGet();
|
if(updatesInProgress.decrementAndGet() == 0) {
|
||||||
|
logger.info("Finished upgrading templates to version {}", Version.CURRENT);
|
||||||
|
}
|
||||||
if (response.isAcknowledged() == false) {
|
if (response.isAcknowledged() == false) {
|
||||||
logger.warn("Error updating template [{}], request was not acknowledged", change.getKey());
|
logger.warn("Error updating template [{}], request was not acknowledged", change.getKey());
|
||||||
}
|
}
|
||||||
|
@ -179,7 +188,9 @@ public class TemplateUpgradeService extends AbstractComponent implements Cluster
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Exception e) {
|
public void onFailure(Exception e) {
|
||||||
updatesInProgress.decrementAndGet();
|
if(updatesInProgress.decrementAndGet() == 0) {
|
||||||
|
logger.info("Templates were upgraded to version {}", Version.CURRENT);
|
||||||
|
}
|
||||||
logger.warn(new ParameterizedMessage("Error updating template [{}]", change.getKey()), e);
|
logger.warn(new ParameterizedMessage("Error updating template [{}]", change.getKey()), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.elasticsearch.test.ESIntegTestCase;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.watcher.ResourceWatcherService;
|
import org.elasticsearch.watcher.ResourceWatcherService;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -41,8 +40,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||||
import static org.hamcrest.Matchers.empty;
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
|
|
||||||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST)
|
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST)
|
||||||
public class TemplateUpgradeServiceIT extends ESIntegTestCase {
|
public class TemplateUpgradeServiceIT extends ESIntegTestCase {
|
||||||
|
@ -105,10 +104,15 @@ public class TemplateUpgradeServiceIT extends ESIntegTestCase {
|
||||||
assertAcked(client().admin().indices().preparePutTemplate("test_removed_template").setOrder(1)
|
assertAcked(client().admin().indices().preparePutTemplate("test_removed_template").setOrder(1)
|
||||||
.setPatterns(Collections.singletonList("*")).get());
|
.setPatterns(Collections.singletonList("*")).get());
|
||||||
|
|
||||||
|
AtomicInteger updateCount = new AtomicInteger();
|
||||||
// Wait for the templates to be updated back to normal
|
// Wait for the templates to be updated back to normal
|
||||||
assertBusy(() -> {
|
assertBusy(() -> {
|
||||||
|
// the updates only happen on cluster state updates, so we need to make sure that the cluster state updates are happening
|
||||||
|
// so we need to simulate updates to make sure the template upgrade kicks in
|
||||||
|
assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(
|
||||||
|
Settings.builder().put(TestPlugin.UPDATE_TEMPLATE_DUMMY_SETTING.getKey(), updateCount.incrementAndGet())
|
||||||
|
).get());
|
||||||
List<IndexTemplateMetaData> templates = client().admin().indices().prepareGetTemplates("test_*").get().getIndexTemplates();
|
List<IndexTemplateMetaData> templates = client().admin().indices().prepareGetTemplates("test_*").get().getIndexTemplates();
|
||||||
assertThat(templates.size(), equalTo(3));
|
|
||||||
boolean addedFound = false;
|
boolean addedFound = false;
|
||||||
boolean changedFound = false;
|
boolean changedFound = false;
|
||||||
boolean dummyFound = false;
|
boolean dummyFound = false;
|
||||||
|
@ -133,10 +137,10 @@ public class TemplateUpgradeServiceIT extends ESIntegTestCase {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue(addedFound);
|
assertTrue(addedFound);
|
||||||
assertTrue(changedFound);
|
assertTrue(changedFound);
|
||||||
assertTrue(dummyFound);
|
assertTrue(dummyFound);
|
||||||
|
assertThat(templates.size(), equalTo(3));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Wipe out all templates
|
// Wipe out all templates
|
||||||
|
@ -157,7 +161,6 @@ public class TemplateUpgradeServiceIT extends ESIntegTestCase {
|
||||||
).get());
|
).get());
|
||||||
|
|
||||||
List<IndexTemplateMetaData> templates = client().admin().indices().prepareGetTemplates("test_*").get().getIndexTemplates();
|
List<IndexTemplateMetaData> templates = client().admin().indices().prepareGetTemplates("test_*").get().getIndexTemplates();
|
||||||
assertThat(templates.size(), equalTo(2));
|
|
||||||
boolean addedFound = false;
|
boolean addedFound = false;
|
||||||
boolean changedFound = false;
|
boolean changedFound = false;
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
|
@ -180,6 +183,7 @@ public class TemplateUpgradeServiceIT extends ESIntegTestCase {
|
||||||
|
|
||||||
assertTrue(addedFound);
|
assertTrue(addedFound);
|
||||||
assertTrue(changedFound);
|
assertTrue(changedFound);
|
||||||
|
assertThat(templates, hasSize(2));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue