Merge branch 'master' into feature/rank-eval
This commit is contained in:
commit
8772725d46
|
@ -27,7 +27,6 @@ import org.elasticsearch.cluster.node.DiscoveryNodes;
|
|||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.cluster.routing.ShardRoutingState;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
|
@ -160,11 +159,9 @@ public class AllocationBenchmark {
|
|||
public ClusterState measureAllocation() {
|
||||
ClusterState clusterState = initialClusterState;
|
||||
while (clusterState.getRoutingNodes().hasUnassignedShards()) {
|
||||
RoutingAllocation.Result result = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes()
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes()
|
||||
.shardsWithState(ShardRoutingState.INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(result).build();
|
||||
result = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(result).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
}
|
||||
return clusterState;
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
# Do not log at all if it is not really critical - we're in a benchmark
|
||||
benchmarks.es.logger.level=ERROR
|
||||
log4j.rootLogger=${benchmarks.es.logger.level}, out
|
||||
|
||||
log4j.appender.out=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.out.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.out.layout.conversionPattern=[%d{ISO8601}][%-5p][%-25c] %m%n
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
appender.console.type = Console
|
||||
appender.console.name = console
|
||||
appender.console.layout.type = PatternLayout
|
||||
appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %marker%m%n
|
||||
|
||||
# Do not log at all if it is not really critical - we're in a benchmark
|
||||
rootLogger.level = error
|
||||
rootLogger.appenderRef.console.ref = console
|
63
build.gradle
63
build.gradle
|
@ -17,7 +17,6 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import com.bmuschko.gradle.nexus.NexusPlugin
|
||||
import org.eclipse.jgit.lib.Repository
|
||||
import org.eclipse.jgit.lib.RepositoryBuilder
|
||||
import org.gradle.plugins.ide.eclipse.model.SourceFolder
|
||||
|
@ -52,68 +51,6 @@ subprojects {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
plugins.withType(NexusPlugin).whenPluginAdded {
|
||||
modifyPom {
|
||||
project {
|
||||
url 'https://github.com/elastic/elasticsearch'
|
||||
inceptionYear '2009'
|
||||
|
||||
scm {
|
||||
url 'https://github.com/elastic/elasticsearch'
|
||||
connection 'scm:https://elastic@github.com/elastic/elasticsearch'
|
||||
developerConnection 'scm:git://github.com/elastic/elasticsearch.git'
|
||||
}
|
||||
|
||||
licenses {
|
||||
license {
|
||||
name 'The Apache Software License, Version 2.0'
|
||||
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
||||
distribution 'repo'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
extraArchive {
|
||||
javadoc = true
|
||||
tests = false
|
||||
}
|
||||
nexus {
|
||||
String buildSnapshot = System.getProperty('build.snapshot', 'true')
|
||||
if (buildSnapshot == 'false') {
|
||||
Repository repo = new RepositoryBuilder().findGitDir(project.rootDir).build()
|
||||
String shortHash = repo.resolve('HEAD')?.name?.substring(0,7)
|
||||
repositoryUrl = project.hasProperty('build.repository') ? project.property('build.repository') : "file://${System.getenv('HOME')}/elasticsearch-releases/${version}-${shortHash}/"
|
||||
}
|
||||
}
|
||||
// we have our own username/password prompts so that they only happen once
|
||||
// TODO: add gpg signing prompts, which is tricky, as the buildDeb/buildRpm tasks are executed before this code block
|
||||
project.gradle.taskGraph.whenReady { taskGraph ->
|
||||
if (taskGraph.allTasks.any { it.name == 'uploadArchives' }) {
|
||||
Console console = System.console()
|
||||
// no need for username/password on local deploy
|
||||
if (project.nexus.repositoryUrl.startsWith('file://')) {
|
||||
project.rootProject.allprojects.each {
|
||||
it.ext.nexusUsername = 'foo'
|
||||
it.ext.nexusPassword = 'bar'
|
||||
}
|
||||
} else {
|
||||
if (project.hasProperty('nexusUsername') == false) {
|
||||
String nexusUsername = console.readLine('\nNexus username: ')
|
||||
project.rootProject.allprojects.each {
|
||||
it.ext.nexusUsername = nexusUsername
|
||||
}
|
||||
}
|
||||
if (project.hasProperty('nexusPassword') == false) {
|
||||
String nexusPassword = new String(console.readPassword('\nNexus password: '))
|
||||
project.rootProject.allprojects.each {
|
||||
it.ext.nexusPassword = nexusPassword
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
|
|
|
@ -95,7 +95,6 @@ dependencies {
|
|||
compile 'org.eclipse.jgit:org.eclipse.jgit:3.2.0.201312181205-r'
|
||||
compile 'com.perforce:p4java:2012.3.551082' // THIS IS SUPPOSED TO BE OPTIONAL IN THE FUTURE....
|
||||
compile 'de.thetaphi:forbiddenapis:2.2'
|
||||
compile 'com.bmuschko:gradle-nexus-plugin:2.3.1'
|
||||
compile 'org.apache.rat:apache-rat:0.11'
|
||||
compile 'ru.vyarus:gradle-animalsniffer-plugin:1.0.1'
|
||||
}
|
||||
|
@ -109,10 +108,6 @@ if (project == rootProject) {
|
|||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name 'sonatype-snapshots'
|
||||
url "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||
}
|
||||
}
|
||||
test.exclude 'org/elasticsearch/test/NamingConventionsCheckBadClasses*'
|
||||
}
|
||||
|
|
|
@ -28,11 +28,10 @@ import org.gradle.api.Task
|
|||
import org.gradle.api.XmlProvider
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.artifacts.ModuleDependency
|
||||
import org.gradle.api.artifacts.ModuleVersionIdentifier
|
||||
import org.gradle.api.artifacts.ProjectDependency
|
||||
import org.gradle.api.artifacts.ResolvedArtifact
|
||||
import org.gradle.api.artifacts.dsl.RepositoryHandler
|
||||
import org.gradle.api.artifacts.maven.MavenPom
|
||||
import org.gradle.api.plugins.JavaPlugin
|
||||
import org.gradle.api.publish.maven.MavenPublication
|
||||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
|
||||
import org.gradle.api.publish.maven.tasks.GenerateMavenPom
|
||||
|
@ -63,7 +62,6 @@ class BuildPlugin implements Plugin<Project> {
|
|||
project.pluginManager.apply('nebula.info-java')
|
||||
project.pluginManager.apply('nebula.info-scm')
|
||||
project.pluginManager.apply('nebula.info-jar')
|
||||
project.pluginManager.apply('com.bmuschko.nexus')
|
||||
project.pluginManager.apply(ProvidedBasePlugin)
|
||||
|
||||
globalBuildInfo(project)
|
||||
|
@ -71,6 +69,8 @@ class BuildPlugin implements Plugin<Project> {
|
|||
configureConfigurations(project)
|
||||
project.ext.versions = VersionProperties.versions
|
||||
configureCompile(project)
|
||||
configureJavadocJar(project)
|
||||
configureSourcesJar(project)
|
||||
configurePomGeneration(project)
|
||||
|
||||
configureTest(project)
|
||||
|
@ -267,11 +267,6 @@ class BuildPlugin implements Plugin<Project> {
|
|||
project.configurations.compile.dependencies.all(disableTransitiveDeps)
|
||||
project.configurations.testCompile.dependencies.all(disableTransitiveDeps)
|
||||
project.configurations.provided.dependencies.all(disableTransitiveDeps)
|
||||
|
||||
// add exclusions to the pom directly, for each of the transitive deps of this project's deps
|
||||
project.modifyPom { MavenPom pom ->
|
||||
pom.withXml(fixupDependencies(project))
|
||||
}
|
||||
}
|
||||
|
||||
/** Adds repositores used by ES dependencies */
|
||||
|
@ -284,10 +279,6 @@ class BuildPlugin implements Plugin<Project> {
|
|||
repos.mavenLocal()
|
||||
}
|
||||
repos.mavenCentral()
|
||||
repos.maven {
|
||||
name 'sonatype-snapshots'
|
||||
url 'http://oss.sonatype.org/content/repositories/snapshots/'
|
||||
}
|
||||
String luceneVersion = VersionProperties.lucene
|
||||
if (luceneVersion.contains('-snapshot')) {
|
||||
// extract the revision number from the version with a regex matcher
|
||||
|
@ -415,6 +406,25 @@ class BuildPlugin implements Plugin<Project> {
|
|||
}
|
||||
}
|
||||
|
||||
/** Adds a javadocJar task to generate a jar containing javadocs. */
|
||||
static void configureJavadocJar(Project project) {
|
||||
Jar javadocJarTask = project.task('javadocJar', type: Jar)
|
||||
javadocJarTask.classifier = 'javadoc'
|
||||
javadocJarTask.group = 'build'
|
||||
javadocJarTask.description = 'Assembles a jar containing javadocs.'
|
||||
javadocJarTask.from(project.tasks.getByName(JavaPlugin.JAVADOC_TASK_NAME))
|
||||
project.assemble.dependsOn(javadocJarTask)
|
||||
}
|
||||
|
||||
static void configureSourcesJar(Project project) {
|
||||
Jar sourcesJarTask = project.task('sourcesJar', type: Jar)
|
||||
sourcesJarTask.classifier = 'sources'
|
||||
sourcesJarTask.group = 'build'
|
||||
sourcesJarTask.description = 'Assembles a jar containing source files.'
|
||||
sourcesJarTask.from(project.sourceSets.main.allSource)
|
||||
project.assemble.dependsOn(sourcesJarTask)
|
||||
}
|
||||
|
||||
/** Adds additional manifest info to jars, and adds source and javadoc jars */
|
||||
static void configureJars(Project project) {
|
||||
project.tasks.withType(Jar) { Jar jarTask ->
|
||||
|
|
|
@ -53,17 +53,7 @@ public class DocsTestPlugin extends RestTestPlugin {
|
|||
'List snippets that probably should be marked // CONSOLE'
|
||||
listConsoleCandidates.defaultSubstitutions = defaultSubstitutions
|
||||
listConsoleCandidates.perSnippet {
|
||||
if (
|
||||
it.console != null // Already marked, nothing to do
|
||||
|| it.testResponse // It is a response
|
||||
) {
|
||||
return
|
||||
}
|
||||
if ( // js almost always should be `// CONSOLE`
|
||||
it.language == 'js' ||
|
||||
// snippets containing `curl` *probably* should
|
||||
// be `// CONSOLE`
|
||||
it.curl) {
|
||||
if (RestTestsFromSnippetsTask.isConsoleCandidate(it)) {
|
||||
println(it.toString())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,16 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
|
|||
@Input
|
||||
Map<String, String> setups = new HashMap()
|
||||
|
||||
/**
|
||||
* A list of files that contain snippets that *probably* should be
|
||||
* converted to `// CONSOLE` but have yet to be converted. If a file is in
|
||||
* this list and doesn't contain unconverted snippets this task will fail.
|
||||
* If there are unconverted snippets not in this list then this task will
|
||||
* fail. All files are paths relative to the docs dir.
|
||||
*/
|
||||
@Input
|
||||
List<String> expectedUnconvertedCandidates = []
|
||||
|
||||
/**
|
||||
* Root directory of the tests being generated. To make rest tests happy
|
||||
* we generate them in a testRoot() which is contained in this directory.
|
||||
|
@ -56,6 +66,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
|
|||
TestBuilder builder = new TestBuilder()
|
||||
doFirst { outputRoot().delete() }
|
||||
perSnippet builder.&handleSnippet
|
||||
doLast builder.&checkUnconverted
|
||||
doLast builder.&finishLastTest
|
||||
}
|
||||
|
||||
|
@ -67,6 +78,27 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
|
|||
return new File(testRoot, '/rest-api-spec/test')
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this snippet a candidate for conversion to `// CONSOLE`?
|
||||
*/
|
||||
static isConsoleCandidate(Snippet snippet) {
|
||||
/* Snippets that are responses or already marked as `// CONSOLE` or
|
||||
* `// NOTCONSOLE` are not candidates. */
|
||||
if (snippet.console != null || snippet.testResponse) {
|
||||
return false
|
||||
}
|
||||
/* js snippets almost always should be marked with `// CONSOLE`. js
|
||||
* snippets that shouldn't be marked `// CONSOLE`, like examples for
|
||||
* js client, should always be marked with `// NOTCONSOLE`.
|
||||
*
|
||||
* `sh` snippets that contain `curl` almost always should be marked
|
||||
* with `// CONSOLE`. In the exceptionally rare cases where they are
|
||||
* not communicating with Elasticsearch, like the xamples in the ec2
|
||||
* and gce discovery plugins, the snippets should be marked
|
||||
* `// NOTCONSOLE`. */
|
||||
return snippet.language == 'js' || snippet.curl
|
||||
}
|
||||
|
||||
private class TestBuilder {
|
||||
private static final String SYNTAX = {
|
||||
String method = /(?<method>GET|PUT|POST|HEAD|OPTIONS|DELETE)/
|
||||
|
@ -88,11 +120,22 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
|
|||
*/
|
||||
PrintWriter current
|
||||
|
||||
/**
|
||||
* Files containing all snippets that *probably* should be converted
|
||||
* to `// CONSOLE` but have yet to be converted. All files are paths
|
||||
* relative to the docs dir.
|
||||
*/
|
||||
Set<String> unconvertedCandidates = new HashSet<>()
|
||||
|
||||
/**
|
||||
* Called each time a snippet is encountered. Tracks the snippets and
|
||||
* calls buildTest to actually build the test.
|
||||
*/
|
||||
void handleSnippet(Snippet snippet) {
|
||||
if (RestTestsFromSnippetsTask.isConsoleCandidate(snippet)) {
|
||||
unconvertedCandidates.add(snippet.path.toString()
|
||||
.replace('\\', '/'))
|
||||
}
|
||||
if (BAD_LANGUAGES.contains(snippet.language)) {
|
||||
throw new InvalidUserDataException(
|
||||
"$snippet: Use `js` instead of `${snippet.language}`.")
|
||||
|
@ -250,5 +293,35 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
|
|||
current = null
|
||||
}
|
||||
}
|
||||
|
||||
void checkUnconverted() {
|
||||
List<String> listedButNotFound = []
|
||||
for (String listed : expectedUnconvertedCandidates) {
|
||||
if (false == unconvertedCandidates.remove(listed)) {
|
||||
listedButNotFound.add(listed)
|
||||
}
|
||||
}
|
||||
String message = ""
|
||||
if (false == listedButNotFound.isEmpty()) {
|
||||
Collections.sort(listedButNotFound)
|
||||
listedButNotFound = listedButNotFound.collect {' ' + it}
|
||||
message += "Expected unconverted snippets but none found in:\n"
|
||||
message += listedButNotFound.join("\n")
|
||||
}
|
||||
if (false == unconvertedCandidates.isEmpty()) {
|
||||
List<String> foundButNotListed =
|
||||
new ArrayList<>(unconvertedCandidates)
|
||||
Collections.sort(foundButNotListed)
|
||||
foundButNotListed = foundButNotListed.collect {' ' + it}
|
||||
if (false == "".equals(message)) {
|
||||
message += "\n"
|
||||
}
|
||||
message += "Unexpected unconverted snippets:\n"
|
||||
message += foundButNotListed.join("\n")
|
||||
}
|
||||
if (false == "".equals(message)) {
|
||||
throw new InvalidUserDataException(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,12 +56,8 @@ public class PluginBuildPlugin extends BuildPlugin {
|
|||
// for plugins which work with the transport client, we copy the jar
|
||||
// file to a new name, copy the nebula generated pom to the same name,
|
||||
// and generate a different pom for the zip
|
||||
project.signArchives.enabled = false
|
||||
addClientJarPomGeneration(project)
|
||||
addClientJarTask(project)
|
||||
if (isModule == false) {
|
||||
addZipPomGeneration(project)
|
||||
}
|
||||
} else {
|
||||
// no client plugin, so use the pom file from nebula, without jar, for the zip
|
||||
project.ext.set("nebulaPublish.maven.jar", false)
|
||||
|
@ -152,7 +148,7 @@ public class PluginBuildPlugin extends BuildPlugin {
|
|||
/** Adds a task to move jar and associated files to a "-client" name. */
|
||||
protected static void addClientJarTask(Project project) {
|
||||
Task clientJar = project.tasks.create('clientJar')
|
||||
clientJar.dependsOn('generatePomFileForJarPublication', project.jar, project.javadocJar, project.sourcesJar)
|
||||
clientJar.dependsOn(project.jar, 'generatePomFileForClientJarPublication', project.javadocJar, project.sourcesJar)
|
||||
clientJar.doFirst {
|
||||
Path jarFile = project.jar.outputs.files.singleFile.toPath()
|
||||
String clientFileName = jarFile.fileName.toString().replace(project.version, "client-${project.version}")
|
||||
|
@ -197,9 +193,9 @@ public class PluginBuildPlugin extends BuildPlugin {
|
|||
|
||||
project.publishing {
|
||||
publications {
|
||||
jar(MavenPublication) {
|
||||
clientJar(MavenPublication) {
|
||||
from project.components.java
|
||||
artifactId = artifactId + '-client'
|
||||
artifactId = project.pluginProperties.extension.name + '-client'
|
||||
pom.withXml { XmlProvider xml ->
|
||||
Node root = xml.asNode()
|
||||
root.appendNode('name', project.pluginProperties.extension.name)
|
||||
|
@ -221,7 +217,15 @@ public class PluginBuildPlugin extends BuildPlugin {
|
|||
publications {
|
||||
zip(MavenPublication) {
|
||||
artifact project.bundlePlugin
|
||||
pom.packaging = 'pom'
|
||||
}
|
||||
// HUGE HACK: the underlying maven publication library refuses to deploy any attached artifacts
|
||||
// when the packaging type is set to 'pom'. So here we create another publication using the same
|
||||
// name that has the "real" pom, and rely on the fact that gradle will execute the publish tasks
|
||||
// in alphabetical order. We cannot setup a dependency between the tasks because the publishing
|
||||
// tasks are created *extremely* late in the configuration phase, so that we cannot get ahold
|
||||
// of the actual task. Furthermore, this entire hack only exists so we can make publishing to
|
||||
// maven local work, since we publish to maven central externally.
|
||||
zipReal(MavenPublication) {
|
||||
pom.withXml { XmlProvider xml ->
|
||||
Node root = xml.asNode()
|
||||
root.appendNode('name', project.pluginProperties.extension.name)
|
||||
|
|
|
@ -20,8 +20,6 @@ package org.elasticsearch.gradle.test
|
|||
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.tasks.Input
|
||||
|
||||
/** Configuration for an elasticsearch cluster, used for integration tests. */
|
||||
|
@ -47,6 +45,17 @@ class ClusterConfiguration {
|
|||
@Input
|
||||
int transportPort = 0
|
||||
|
||||
/**
|
||||
* An override of the data directory. This may only be used with a single node.
|
||||
* The value is lazily evaluated at runtime as a String path.
|
||||
*/
|
||||
@Input
|
||||
Object dataDir = null
|
||||
|
||||
/** Optional override of the cluster name. */
|
||||
@Input
|
||||
String clusterName = null
|
||||
|
||||
@Input
|
||||
boolean daemonize = true
|
||||
|
||||
|
@ -59,13 +68,24 @@ class ClusterConfiguration {
|
|||
" " + System.getProperty('tests.jvm.argline', '')
|
||||
|
||||
/**
|
||||
* The seed nodes port file. In the case the cluster has more than one node we use a seed node
|
||||
* to form the cluster. The file is null if there is no seed node yet available.
|
||||
* A closure to call which returns the unicast host to connect to for cluster formation.
|
||||
*
|
||||
* Note: this can only be null if the cluster has only one node or if the first node is not yet
|
||||
* configured. All nodes but the first node should see a non null value.
|
||||
* This allows multi node clusters, or a new cluster to connect to an existing cluster.
|
||||
* The closure takes two arguments, the NodeInfo for the first node in the cluster, and
|
||||
* an AntBuilder which may be used to wait on conditions before returning.
|
||||
*/
|
||||
File seedNodePortsFile
|
||||
@Input
|
||||
Closure unicastTransportUri = { NodeInfo seedNode, NodeInfo node, AntBuilder ant ->
|
||||
if (seedNode == node) {
|
||||
return null
|
||||
}
|
||||
ant.waitfor(maxwait: '20', maxwaitunit: 'second', checkevery: '500', checkeveryunit: 'millisecond') {
|
||||
resourceexists {
|
||||
file(file: seedNode.transportPortsFile.toString())
|
||||
}
|
||||
}
|
||||
return seedNode.transportUri()
|
||||
}
|
||||
|
||||
/**
|
||||
* A closure to call before the cluster is considered ready. The closure is passed the node info,
|
||||
|
@ -75,7 +95,11 @@ class ClusterConfiguration {
|
|||
@Input
|
||||
Closure waitCondition = { NodeInfo node, AntBuilder ant ->
|
||||
File tmpFile = new File(node.cwd, 'wait.success')
|
||||
ant.get(src: "http://${node.httpUri()}/_cluster/health?wait_for_nodes=${numNodes}",
|
||||
ant.echo("==> [${new Date()}] checking health: http://${node.httpUri()}/_cluster/health?wait_for_nodes>=${numNodes}")
|
||||
// checking here for wait_for_nodes to be >= the number of nodes because its possible
|
||||
// this cluster is attempting to connect to nodes created by another task (same cluster name),
|
||||
// so there will be more nodes in that case in the cluster state
|
||||
ant.get(src: "http://${node.httpUri()}/_cluster/health?wait_for_nodes>=${numNodes}",
|
||||
dest: tmpFile.toString(),
|
||||
ignoreerrors: true, // do not fail on error, so logging buffers can be flushed by the wait task
|
||||
retries: 10)
|
||||
|
@ -137,12 +161,4 @@ class ClusterConfiguration {
|
|||
}
|
||||
extraConfigFiles.put(path, sourceFile)
|
||||
}
|
||||
|
||||
/** Returns an address and port suitable for a uri to connect to this clusters seed node over transport protocol*/
|
||||
String seedNodeTransportUri() {
|
||||
if (seedNodePortsFile != null) {
|
||||
return seedNodePortsFile.readLines("UTF-8").get(0)
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,9 +46,9 @@ class ClusterFormationTasks {
|
|||
/**
|
||||
* Adds dependent tasks to the given task to start and stop a cluster with the given configuration.
|
||||
*
|
||||
* Returns a NodeInfo object for the first node in the cluster.
|
||||
* Returns a list of NodeInfo objects for each node in the cluster.
|
||||
*/
|
||||
static NodeInfo setup(Project project, Task task, ClusterConfiguration config) {
|
||||
static List<NodeInfo> setup(Project project, Task task, ClusterConfiguration config) {
|
||||
if (task.getEnabled() == false) {
|
||||
// no need to add cluster formation tasks if the task won't run!
|
||||
return
|
||||
|
@ -95,22 +95,14 @@ class ClusterFormationTasks {
|
|||
distro = project.configurations.elasticsearchBwcDistro
|
||||
}
|
||||
NodeInfo node = new NodeInfo(config, i, project, task, elasticsearchVersion, sharedDir)
|
||||
if (i == 0) {
|
||||
if (config.seedNodePortsFile != null) {
|
||||
// we might allow this in the future to be set but for now we are the only authority to set this!
|
||||
throw new GradleException("seedNodePortsFile has a non-null value but first node has not been intialized")
|
||||
}
|
||||
config.seedNodePortsFile = node.transportPortsFile;
|
||||
}
|
||||
nodes.add(node)
|
||||
startTasks.add(configureNode(project, task, cleanup, node, distro))
|
||||
startTasks.add(configureNode(project, task, cleanup, node, distro, nodes.get(0)))
|
||||
}
|
||||
|
||||
Task wait = configureWaitTask("${task.name}#wait", project, nodes, startTasks)
|
||||
task.dependsOn(wait)
|
||||
|
||||
// delay the resolution of the uri by wrapping in a closure, so it is not used until read for tests
|
||||
return nodes[0]
|
||||
return nodes
|
||||
}
|
||||
|
||||
/** Adds a dependency on the given distribution */
|
||||
|
@ -141,7 +133,7 @@ class ClusterFormationTasks {
|
|||
*
|
||||
* @return a task which starts the node.
|
||||
*/
|
||||
static Task configureNode(Project project, Task task, Object dependsOn, NodeInfo node, Configuration configuration) {
|
||||
static Task configureNode(Project project, Task task, Object dependsOn, NodeInfo node, Configuration configuration, NodeInfo seedNode) {
|
||||
|
||||
// tasks are chained so their execution order is maintained
|
||||
Task setup = project.tasks.create(name: taskName(task, node, 'clean'), type: Delete, dependsOn: dependsOn) {
|
||||
|
@ -154,7 +146,7 @@ class ClusterFormationTasks {
|
|||
setup = configureCheckPreviousTask(taskName(task, node, 'checkPrevious'), project, setup, node)
|
||||
setup = configureStopTask(taskName(task, node, 'stopPrevious'), project, setup, node)
|
||||
setup = configureExtractTask(taskName(task, node, 'extract'), project, setup, node, configuration)
|
||||
setup = configureWriteConfigTask(taskName(task, node, 'configure'), project, setup, node)
|
||||
setup = configureWriteConfigTask(taskName(task, node, 'configure'), project, setup, node, seedNode)
|
||||
setup = configureExtraConfigFilesTask(taskName(task, node, 'extraConfig'), project, setup, node)
|
||||
setup = configureCopyPluginsTask(taskName(task, node, 'copyPlugins'), project, setup, node)
|
||||
|
||||
|
@ -181,9 +173,10 @@ class ClusterFormationTasks {
|
|||
Task start = configureStartTask(taskName(task, node, 'start'), project, setup, node)
|
||||
|
||||
if (node.config.daemonize) {
|
||||
// if we are running in the background, make sure to stop the server when the task completes
|
||||
Task stop = configureStopTask(taskName(task, node, 'stop'), project, [], node)
|
||||
// if we are running in the background, make sure to stop the server when the task completes
|
||||
task.finalizedBy(stop)
|
||||
start.finalizedBy(stop)
|
||||
}
|
||||
return start
|
||||
}
|
||||
|
@ -249,7 +242,7 @@ class ClusterFormationTasks {
|
|||
}
|
||||
|
||||
/** Adds a task to write elasticsearch.yml for the given node configuration */
|
||||
static Task configureWriteConfigTask(String name, Project project, Task setup, NodeInfo node) {
|
||||
static Task configureWriteConfigTask(String name, Project project, Task setup, NodeInfo node, NodeInfo seedNode) {
|
||||
Map esConfig = [
|
||||
'cluster.name' : node.clusterName,
|
||||
'pidfile' : node.pidFile,
|
||||
|
@ -266,15 +259,9 @@ class ClusterFormationTasks {
|
|||
|
||||
Task writeConfig = project.tasks.create(name: name, type: DefaultTask, dependsOn: setup)
|
||||
writeConfig.doFirst {
|
||||
if (node.nodeNum > 0) { // multi-node cluster case, we have to wait for the seed node to startup
|
||||
ant.waitfor(maxwait: '20', maxwaitunit: 'second', checkevery: '500', checkeveryunit: 'millisecond') {
|
||||
resourceexists {
|
||||
file(file: node.config.seedNodePortsFile.toString())
|
||||
}
|
||||
}
|
||||
// the seed node is enough to form the cluster - all subsequent nodes will get the seed node as a unicast
|
||||
// host and join the cluster via that.
|
||||
esConfig['discovery.zen.ping.unicast.hosts'] = "\"${node.config.seedNodeTransportUri()}\""
|
||||
String unicastTransportUri = node.config.unicastTransportUri(seedNode, node, project.ant)
|
||||
if (unicastTransportUri != null) {
|
||||
esConfig['discovery.zen.ping.unicast.hosts'] = "\"${unicastTransportUri}\""
|
||||
}
|
||||
File configFile = new File(node.confDir, 'elasticsearch.yml')
|
||||
logger.info("Configuring ${configFile}")
|
||||
|
|
|
@ -57,6 +57,9 @@ class NodeInfo {
|
|||
/** config directory */
|
||||
File confDir
|
||||
|
||||
/** data directory (as an Object, to allow lazy evaluation) */
|
||||
Object dataDir
|
||||
|
||||
/** THE config file */
|
||||
File configFile
|
||||
|
||||
|
@ -95,11 +98,23 @@ class NodeInfo {
|
|||
this.config = config
|
||||
this.nodeNum = nodeNum
|
||||
this.sharedDir = sharedDir
|
||||
clusterName = "${task.path.replace(':', '_').substring(1)}"
|
||||
if (config.clusterName != null) {
|
||||
clusterName = config.clusterName
|
||||
} else {
|
||||
clusterName = "${task.path.replace(':', '_').substring(1)}"
|
||||
}
|
||||
baseDir = new File(project.buildDir, "cluster/${task.name} node${nodeNum}")
|
||||
pidFile = new File(baseDir, 'es.pid')
|
||||
homeDir = homeDir(baseDir, config.distribution, nodeVersion)
|
||||
confDir = confDir(baseDir, config.distribution, nodeVersion)
|
||||
if (config.dataDir != null) {
|
||||
if (config.numNodes != 1) {
|
||||
throw new IllegalArgumentException("Cannot set data dir for integ test with more than one node")
|
||||
}
|
||||
dataDir = config.dataDir
|
||||
} else {
|
||||
dataDir = new File(homeDir, "data")
|
||||
}
|
||||
configFile = new File(confDir, 'elasticsearch.yml')
|
||||
// even for rpm/deb, the logs are under home because we dont start with real services
|
||||
File logsDir = new File(homeDir, 'logs')
|
||||
|
@ -140,7 +155,7 @@ class NodeInfo {
|
|||
}
|
||||
}
|
||||
env.put('ES_JVM_OPTIONS', new File(confDir, 'jvm.options'))
|
||||
args.addAll("-E", "path.conf=${confDir}")
|
||||
args.addAll("-E", "path.conf=${confDir}", "-E", "path.data=${-> dataDir.toString()}")
|
||||
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
||||
args.add('"') // end the entire command, quoted
|
||||
}
|
||||
|
@ -184,6 +199,19 @@ class NodeInfo {
|
|||
return transportPortsFile.readLines("UTF-8").get(0)
|
||||
}
|
||||
|
||||
/** Returns the file which contains the transport protocol ports for this node */
|
||||
File getTransportPortsFile() {
|
||||
return transportPortsFile
|
||||
}
|
||||
|
||||
/** Returns the data directory for this node */
|
||||
File getDataDir() {
|
||||
if (!(dataDir instanceof File)) {
|
||||
return new File(dataDir)
|
||||
}
|
||||
return dataDir
|
||||
}
|
||||
|
||||
/** Returns the directory elasticsearch home is contained in for the given distribution */
|
||||
static File homeDir(File baseDir, String distro, String nodeVersion) {
|
||||
String path
|
||||
|
|
|
@ -34,6 +34,9 @@ public class RestIntegTestTask extends RandomizedTestingTask {
|
|||
|
||||
ClusterConfiguration clusterConfig
|
||||
|
||||
/** Info about nodes in the integ test cluster. Note this is *not* available until runtime. */
|
||||
List<NodeInfo> nodes
|
||||
|
||||
/** Flag indicating whether the rest tests in the rest spec should be run. */
|
||||
@Input
|
||||
boolean includePackaged = false
|
||||
|
@ -52,6 +55,12 @@ public class RestIntegTestTask extends RandomizedTestingTask {
|
|||
parallelism = '1'
|
||||
include('**/*IT.class')
|
||||
systemProperty('tests.rest.load_packaged', 'false')
|
||||
systemProperty('tests.rest.cluster', "${-> nodes[0].httpUri()}")
|
||||
systemProperty('tests.config.dir', "${-> nodes[0].confDir}")
|
||||
// TODO: our "client" qa tests currently use the rest-test plugin. instead they should have their own plugin
|
||||
// that sets up the test cluster and passes this transport uri instead of http uri. Until then, we pass
|
||||
// both as separate sysprops
|
||||
systemProperty('tests.cluster', "${-> nodes[0].transportUri()}")
|
||||
|
||||
// copy the rest spec/tests into the test resources
|
||||
RestSpecHack.configureDependencies(project)
|
||||
|
@ -61,13 +70,7 @@ public class RestIntegTestTask extends RandomizedTestingTask {
|
|||
// this must run after all projects have been configured, so we know any project
|
||||
// references can be accessed as a fully configured
|
||||
project.gradle.projectsEvaluated {
|
||||
NodeInfo node = ClusterFormationTasks.setup(project, this, clusterConfig)
|
||||
systemProperty('tests.rest.cluster', "${-> node.httpUri()}")
|
||||
systemProperty('tests.config.dir', "${-> node.confDir}")
|
||||
// TODO: our "client" qa tests currently use the rest-test plugin. instead they should have their own plugin
|
||||
// that sets up the test cluster and passes this transport uri instead of http uri. Until then, we pass
|
||||
// both as separate sysprops
|
||||
systemProperty('tests.cluster', "${-> node.transportUri()}")
|
||||
nodes = ClusterFormationTasks.setup(project, this, clusterConfig)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,6 +91,10 @@ public class RestIntegTestTask extends RandomizedTestingTask {
|
|||
return clusterConfig
|
||||
}
|
||||
|
||||
public List<NodeInfo> getNodes() {
|
||||
return nodes
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task dependsOn(Object... dependencies) {
|
||||
super.dependsOn(dependencies)
|
||||
|
|
|
@ -43,18 +43,22 @@ public class RestSpecHack {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a task to copy the rest spec files.
|
||||
* Creates a task (if necessary) to copy the rest spec files.
|
||||
*
|
||||
* @param project The project to add the copy task to
|
||||
* @param includePackagedTests true if the packaged tests should be copied, false otherwise
|
||||
*/
|
||||
public static Task configureTask(Project project, boolean includePackagedTests) {
|
||||
Task copyRestSpec = project.tasks.findByName('copyRestSpec')
|
||||
if (copyRestSpec != null) {
|
||||
return copyRestSpec
|
||||
}
|
||||
Map copyRestSpecProps = [
|
||||
name : 'copyRestSpec',
|
||||
type : Copy,
|
||||
dependsOn: [project.configurations.restSpec, 'processTestResources']
|
||||
]
|
||||
Task copyRestSpec = project.tasks.create(copyRestSpecProps) {
|
||||
copyRestSpec = project.tasks.create(copyRestSpecProps) {
|
||||
from { project.zipTree(project.configurations.restSpec.singleFile) }
|
||||
include 'rest-api-spec/api/**'
|
||||
if (includePackagedTests) {
|
||||
|
|
|
@ -972,7 +972,6 @@
|
|||
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]test[/\\]geo[/\\]RandomShapeGenerator.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]test[/\\]hamcrest[/\\]ElasticsearchGeoAssertions.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]timestamp[/\\]SimpleTimestampIT.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]tribe[/\\]TribeIT.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]ttl[/\\]SimpleTTLIT.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]update[/\\]UpdateIT.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]validate[/\\]SimpleValidateQueryIT.java" checks="LineLength" />
|
||||
|
@ -1016,14 +1015,6 @@
|
|||
<suppress files="plugins[/\\]lang-python[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]script[/\\]python[/\\]PythonScriptEngineTests.java" checks="LineLength" />
|
||||
<suppress files="plugins[/\\]lang-python[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]script[/\\]python[/\\]PythonScriptMultiThreadedTests.java" checks="LineLength" />
|
||||
<suppress files="plugins[/\\]lang-python[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]script[/\\]python[/\\]PythonSecurityTests.java" checks="LineLength" />
|
||||
<suppress files="plugins[/\\]mapper-attachments[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]mapper[/\\]attachments[/\\]AttachmentMapper.java" checks="LineLength" />
|
||||
<suppress files="plugins[/\\]mapper-attachments[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]mapper[/\\]attachments[/\\]DateAttachmentMapperTests.java" checks="LineLength" />
|
||||
<suppress files="plugins[/\\]mapper-attachments[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]mapper[/\\]attachments[/\\]EncryptedDocMapperTests.java" checks="LineLength" />
|
||||
<suppress files="plugins[/\\]mapper-attachments[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]mapper[/\\]attachments[/\\]MetadataMapperTests.java" checks="LineLength" />
|
||||
<suppress files="plugins[/\\]mapper-attachments[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]mapper[/\\]attachments[/\\]MultifieldAttachmentMapperTests.java" checks="LineLength" />
|
||||
<suppress files="plugins[/\\]mapper-attachments[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]mapper[/\\]attachments[/\\]SimpleAttachmentMapperTests.java" checks="LineLength" />
|
||||
<suppress files="plugins[/\\]mapper-attachments[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]mapper[/\\]attachments[/\\]StandaloneRunner.java" checks="LineLength" />
|
||||
<suppress files="plugins[/\\]mapper-attachments[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]mapper[/\\]attachments[/\\]VariousDocTests.java" checks="LineLength" />
|
||||
<suppress files="plugins[/\\]mapper-murmur3[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]mapper[/\\]murmur3[/\\]Murmur3FieldMapper.java" checks="LineLength" />
|
||||
<suppress files="plugins[/\\]mapper-murmur3[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]mapper[/\\]murmur3[/\\]Murmur3FieldMapperTests.java" checks="LineLength" />
|
||||
<suppress files="plugins[/\\]mapper-murmur3[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]mapper[/\\]murmur3[/\\]Murmur3FieldMapperUpgradeTests.java" checks="LineLength" />
|
||||
|
|
|
@ -20,4 +20,4 @@ commonscodec = 1.10
|
|||
hamcrest = 1.3
|
||||
securemock = 1.2
|
||||
# benchmark dependencies
|
||||
jmh = 1.12
|
||||
jmh = 1.14
|
||||
|
|
|
@ -64,7 +64,3 @@ dependencies {
|
|||
|
||||
// No licenses for our benchmark deps (we don't ship benchmarks)
|
||||
dependencyLicenses.enabled = false
|
||||
|
||||
extraArchive {
|
||||
javadoc = false
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
group = 'org.elasticsearch.plugin'
|
||||
|
||||
apply plugin: 'elasticsearch.esplugin'
|
||||
apply plugin: 'com.bmuschko.nexus'
|
||||
|
||||
esplugin {
|
||||
name 'client-benchmark-noop-api'
|
||||
|
|
|
@ -26,9 +26,6 @@ apply plugin: 'ru.vyarus.animalsniffer'
|
|||
targetCompatibility = JavaVersion.VERSION_1_7
|
||||
sourceCompatibility = JavaVersion.VERSION_1_7
|
||||
|
||||
install.enabled = false
|
||||
uploadArchives.enabled = false
|
||||
|
||||
dependencies {
|
||||
compile "org.apache.httpcomponents:httpcore:${versions.httpcore}"
|
||||
compile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
|
||||
|
@ -61,4 +58,4 @@ namingConventions.enabled = false
|
|||
|
||||
//we aren't releasing this jar
|
||||
thirdPartyAudit.enabled = false
|
||||
test.enabled = false
|
||||
test.enabled = false
|
||||
|
|
|
@ -22,7 +22,6 @@ import com.carrotsearch.gradle.junit4.RandomizedTestingTask
|
|||
import org.elasticsearch.gradle.BuildPlugin
|
||||
|
||||
apply plugin: 'elasticsearch.build'
|
||||
apply plugin: 'com.bmuschko.nexus'
|
||||
apply plugin: 'nebula.optional-base'
|
||||
apply plugin: 'nebula.maven-base-publish'
|
||||
apply plugin: 'nebula.maven-scm'
|
||||
|
|
|
@ -288,6 +288,7 @@ import org.elasticsearch.rest.action.cat.RestSegmentsAction;
|
|||
import org.elasticsearch.rest.action.cat.RestShardsAction;
|
||||
import org.elasticsearch.rest.action.cat.RestSnapshotAction;
|
||||
import org.elasticsearch.rest.action.cat.RestTasksAction;
|
||||
import org.elasticsearch.rest.action.cat.RestTemplatesAction;
|
||||
import org.elasticsearch.rest.action.cat.RestThreadPoolAction;
|
||||
import org.elasticsearch.rest.action.document.RestBulkAction;
|
||||
import org.elasticsearch.rest.action.document.RestDeleteAction;
|
||||
|
@ -603,6 +604,7 @@ public class ActionModule extends AbstractModule {
|
|||
registerRestHandler(handlers, RestNodeAttrsAction.class);
|
||||
registerRestHandler(handlers, RestRepositoriesAction.class);
|
||||
registerRestHandler(handlers, RestSnapshotAction.class);
|
||||
registerRestHandler(handlers, RestTemplatesAction.class);
|
||||
for (ActionPlugin plugin : actionPlugins) {
|
||||
for (Class<? extends RestHandler> handler : plugin.getRestHandlers()) {
|
||||
registerRestHandler(handlers, handler);
|
||||
|
@ -663,4 +665,8 @@ public class ActionModule extends AbstractModule {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RestController getRestController() {
|
||||
return restController;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.elasticsearch.cluster.block.ClusterBlockException;
|
|||
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingExplanations;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Priority;
|
||||
|
@ -111,15 +110,14 @@ public class TransportClusterRerouteAction extends TransportMasterNodeAction<Clu
|
|||
|
||||
@Override
|
||||
public ClusterState execute(ClusterState currentState) {
|
||||
RoutingAllocation.Result routingResult = allocationService.reroute(currentState, request.getCommands(), request.explain(),
|
||||
request.isRetryFailed());
|
||||
ClusterState newState = ClusterState.builder(currentState).routingResult(routingResult).build();
|
||||
clusterStateToSend = newState;
|
||||
explanations = routingResult.explanations();
|
||||
AllocationService.CommandsResult commandsResult =
|
||||
allocationService.reroute(currentState, request.getCommands(), request.explain(), request.isRetryFailed());
|
||||
clusterStateToSend = commandsResult.getClusterState();
|
||||
explanations = commandsResult.explanations();
|
||||
if (request.dryRun()) {
|
||||
return currentState;
|
||||
}
|
||||
return newState;
|
||||
return commandsResult.getClusterState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
|||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Priority;
|
||||
|
@ -157,11 +156,7 @@ public class TransportClusterUpdateSettingsAction extends TransportMasterNodeAct
|
|||
@Override
|
||||
public ClusterState execute(final ClusterState currentState) {
|
||||
// now, reroute in case things that require it changed (e.g. number of replicas)
|
||||
RoutingAllocation.Result routingResult = allocationService.reroute(currentState, "reroute after cluster update settings");
|
||||
if (!routingResult.changed()) {
|
||||
return currentState;
|
||||
}
|
||||
return ClusterState.builder(currentState).routingResult(routingResult).build();
|
||||
return allocationService.reroute(currentState, "reroute after cluster update settings");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.action.index;
|
||||
|
||||
import org.elasticsearch.action.DocWriteResponse;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
|
@ -56,7 +57,7 @@ public class IndexResponse extends DocWriteResponse {
|
|||
builder.append(",id=").append(getId());
|
||||
builder.append(",version=").append(getVersion());
|
||||
builder.append(",result=").append(getResult().getLowercase());
|
||||
builder.append(",shards=").append(getShardInfo());
|
||||
builder.append(",shards=").append(Strings.toString(getShardInfo(), true));
|
||||
return builder.append("]").toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,6 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.apache.logging.log4j.message.ParameterizedMessage;
|
||||
import org.apache.logging.log4j.util.Supplier;
|
||||
import org.apache.lucene.util.Constants;
|
||||
import org.elasticsearch.cli.ExitCodes;
|
||||
import org.elasticsearch.cli.UserException;
|
||||
import org.elasticsearch.common.SuppressForbidden;
|
||||
import org.elasticsearch.common.io.PathUtils;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
|
@ -178,6 +176,7 @@ final class BootstrapCheck {
|
|||
checks.add(new MaxMapCountCheck());
|
||||
}
|
||||
checks.add(new ClientJvmCheck());
|
||||
checks.add(new UseSerialGCCheck());
|
||||
checks.add(new OnErrorCheck());
|
||||
checks.add(new OnOutOfMemoryErrorCheck());
|
||||
return Collections.unmodifiableList(checks);
|
||||
|
@ -500,6 +499,38 @@ final class BootstrapCheck {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the serial collector is in use. This collector is single-threaded and devastating
|
||||
* for performance and should not be used for a server application like Elasticsearch.
|
||||
*/
|
||||
static class UseSerialGCCheck implements BootstrapCheck.Check {
|
||||
|
||||
@Override
|
||||
public boolean check() {
|
||||
return getUseSerialGC().equals("true");
|
||||
}
|
||||
|
||||
// visible for testing
|
||||
String getUseSerialGC() {
|
||||
return JvmInfo.jvmInfo().useSerialGC();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String errorMessage() {
|
||||
return String.format(
|
||||
Locale.ROOT,
|
||||
"JVM is using the serial collector but should not be for the best performance; " +
|
||||
"either it's the default for the VM [%s] or -XX:+UseSerialGC was explicitly specified",
|
||||
JvmInfo.jvmInfo().getVmName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSystemCheck() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
abstract static class MightForkCheck implements BootstrapCheck.Check {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
|||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.node.internal.InternalSettingsPreparer;
|
||||
import org.elasticsearch.plugins.ActionPlugin;
|
||||
import org.elasticsearch.plugins.NetworkPlugin;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.plugins.PluginsService;
|
||||
import org.elasticsearch.plugins.SearchPlugin;
|
||||
|
@ -52,6 +53,7 @@ import org.elasticsearch.search.SearchModule;
|
|||
import org.elasticsearch.threadpool.ExecutorBuilder;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TcpTransport;
|
||||
import org.elasticsearch.transport.Transport;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
@ -119,10 +121,9 @@ public abstract class TransportClient extends AbstractClient {
|
|||
}
|
||||
SettingsModule settingsModule = new SettingsModule(settings, additionalSettings, additionalSettingsFilter);
|
||||
|
||||
NetworkModule networkModule = new NetworkModule(networkService, settings, true);
|
||||
SearchModule searchModule = new SearchModule(settings, true, pluginsService.filterPlugins(SearchPlugin.class));
|
||||
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
|
||||
entries.addAll(networkModule.getNamedWriteables());
|
||||
entries.addAll(NetworkModule.getNamedWriteables());
|
||||
entries.addAll(searchModule.getNamedWriteables());
|
||||
entries.addAll(pluginsService.filterPlugins(Plugin.class).stream()
|
||||
.flatMap(p -> p.getNamedWriteables().stream())
|
||||
|
@ -134,7 +135,6 @@ public abstract class TransportClient extends AbstractClient {
|
|||
for (Module pluginModule : pluginsService.createGuiceModules()) {
|
||||
modules.add(pluginModule);
|
||||
}
|
||||
modules.add(networkModule);
|
||||
modules.add(b -> b.bind(ThreadPool.class).toInstance(threadPool));
|
||||
ActionModule actionModule = new ActionModule(false, true, settings, null, settingsModule.getClusterSettings(),
|
||||
pluginsService.filterPlugins(ActionPlugin.class));
|
||||
|
@ -147,15 +147,22 @@ public abstract class TransportClient extends AbstractClient {
|
|||
BigArrays bigArrays = new BigArrays(settings, circuitBreakerService);
|
||||
resourcesToClose.add(bigArrays);
|
||||
modules.add(settingsModule);
|
||||
NetworkModule networkModule = new NetworkModule(settings, true, pluginsService.filterPlugins(NetworkPlugin.class), threadPool,
|
||||
bigArrays, circuitBreakerService, namedWriteableRegistry, networkService);
|
||||
final Transport transport = networkModule.getTransportSupplier().get();
|
||||
final TransportService transportService = new TransportService(settings, transport, threadPool,
|
||||
networkModule.getTransportInterceptor());
|
||||
modules.add((b -> {
|
||||
b.bind(BigArrays.class).toInstance(bigArrays);
|
||||
b.bind(PluginsService.class).toInstance(pluginsService);
|
||||
b.bind(CircuitBreakerService.class).toInstance(circuitBreakerService);
|
||||
b.bind(NamedWriteableRegistry.class).toInstance(namedWriteableRegistry);
|
||||
b.bind(Transport.class).toInstance(transport);
|
||||
b.bind(TransportService.class).toInstance(transportService);
|
||||
b.bind(NetworkService.class).toInstance(networkService);
|
||||
}));
|
||||
|
||||
Injector injector = modules.createInjector();
|
||||
final TransportService transportService = injector.getInstance(TransportService.class);
|
||||
final TransportClientNodesService nodesService =
|
||||
new TransportClientNodesService(settings, transportService, threadPool);
|
||||
final TransportProxyClient proxy = new TransportProxyClient(settings, transportService, nodesService,
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.elasticsearch.cluster;
|
|||
import com.carrotsearch.hppc.cursors.IntObjectCursor;
|
||||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
||||
|
||||
import org.elasticsearch.cluster.block.ClusterBlock;
|
||||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
|
@ -37,7 +36,6 @@ import org.elasticsearch.cluster.routing.RoutingNode;
|
|||
import org.elasticsearch.cluster.routing.RoutingNodes;
|
||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -629,12 +627,6 @@ public class ClusterState implements ToXContent, Diffable<ClusterState> {
|
|||
return nodes;
|
||||
}
|
||||
|
||||
public Builder routingResult(RoutingAllocation.Result routingResult) {
|
||||
this.routingTable = routingResult.routingTable();
|
||||
this.metaData = routingResult.metaData();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder routingTable(RoutingTable routingTable) {
|
||||
this.routingTable = routingTable;
|
||||
return this;
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.elasticsearch.cluster.routing.RoutingService;
|
|||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.FailedRerouteAllocation;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Priority;
|
||||
|
@ -311,10 +310,7 @@ public class ShardStateAction extends AbstractComponent {
|
|||
|
||||
ClusterState maybeUpdatedState = currentState;
|
||||
try {
|
||||
RoutingAllocation.Result result = applyFailedShards(currentState, shardRoutingsToBeApplied, staleShardsToBeApplied);
|
||||
if (result.changed()) {
|
||||
maybeUpdatedState = ClusterState.builder(currentState).routingResult(result).build();
|
||||
}
|
||||
maybeUpdatedState = applyFailedShards(currentState, shardRoutingsToBeApplied, staleShardsToBeApplied);
|
||||
batchResultBuilder.successes(tasksToBeApplied);
|
||||
} catch (Exception e) {
|
||||
logger.warn((Supplier<?>) () -> new ParameterizedMessage("failed to apply failed shards {}", shardRoutingsToBeApplied), e);
|
||||
|
@ -327,7 +323,7 @@ public class ShardStateAction extends AbstractComponent {
|
|||
}
|
||||
|
||||
// visible for testing
|
||||
RoutingAllocation.Result applyFailedShards(ClusterState currentState, List<FailedRerouteAllocation.FailedShard> failedShards,
|
||||
ClusterState applyFailedShards(ClusterState currentState, List<FailedRerouteAllocation.FailedShard> failedShards,
|
||||
List<FailedRerouteAllocation.StaleShard> staleShards) {
|
||||
return allocationService.applyFailedShards(currentState, failedShards, staleShards);
|
||||
}
|
||||
|
@ -426,11 +422,7 @@ public class ShardStateAction extends AbstractComponent {
|
|||
|
||||
ClusterState maybeUpdatedState = currentState;
|
||||
try {
|
||||
RoutingAllocation.Result result =
|
||||
allocationService.applyStartedShards(currentState, shardRoutingsToBeApplied, true);
|
||||
if (result.changed()) {
|
||||
maybeUpdatedState = ClusterState.builder(currentState).routingResult(result).build();
|
||||
}
|
||||
maybeUpdatedState = allocationService.applyStartedShards(currentState, shardRoutingsToBeApplied, true);
|
||||
builder.successes(tasksToBeApplied);
|
||||
} catch (Exception e) {
|
||||
logger.warn((Supplier<?>) () -> new ParameterizedMessage("failed to apply started shards {}", shardRoutingsToBeApplied), e);
|
||||
|
|
|
@ -46,7 +46,6 @@ import org.elasticsearch.cluster.routing.RoutingTable;
|
|||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.cluster.routing.ShardRoutingState;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -430,10 +429,9 @@ public class MetaDataCreateIndexService extends AbstractComponent {
|
|||
if (request.state() == State.OPEN) {
|
||||
RoutingTable.Builder routingTableBuilder = RoutingTable.builder(updatedState.routingTable())
|
||||
.addAsNew(updatedState.metaData().index(request.index()));
|
||||
RoutingAllocation.Result routingResult = allocationService.reroute(
|
||||
updatedState = allocationService.reroute(
|
||||
ClusterState.builder(updatedState).routingTable(routingTableBuilder.build()).build(),
|
||||
"index [" + request.index() + "] created");
|
||||
updatedState = ClusterState.builder(updatedState).routingResult(routingResult).build();
|
||||
}
|
||||
removalReason = "cleaning up after validating index on master";
|
||||
return updatedState;
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse;
|
|||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
|
@ -108,9 +107,12 @@ public class MetaDataDeleteIndexService extends AbstractComponent {
|
|||
|
||||
MetaData newMetaData = metaDataBuilder.build();
|
||||
ClusterBlocks blocks = clusterBlocksBuilder.build();
|
||||
RoutingAllocation.Result routingResult = allocationService.reroute(
|
||||
ClusterState.builder(currentState).routingTable(routingTableBuilder.build()).metaData(newMetaData).build(),
|
||||
return allocationService.reroute(
|
||||
ClusterState.builder(currentState)
|
||||
.routingTable(routingTableBuilder.build())
|
||||
.metaData(newMetaData)
|
||||
.blocks(blocks)
|
||||
.build(),
|
||||
"deleted indices [" + indices + "]");
|
||||
return ClusterState.builder(currentState).routingResult(routingResult).metaData(newMetaData).blocks(blocks).build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
|||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
|
@ -125,11 +124,10 @@ public class MetaDataIndexStateService extends AbstractComponent {
|
|||
rtBuilder.remove(index.getIndex().getName());
|
||||
}
|
||||
|
||||
RoutingAllocation.Result routingResult = allocationService.reroute(
|
||||
//no explicit wait for other nodes needed as we use AckedClusterStateUpdateTask
|
||||
return allocationService.reroute(
|
||||
ClusterState.builder(updatedState).routingTable(rtBuilder.build()).build(),
|
||||
"indices closed [" + indicesAsString + "]");
|
||||
//no explicit wait for other nodes needed as we use AckedClusterStateUpdateTask
|
||||
return ClusterState.builder(updatedState).routingResult(routingResult).build();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -188,11 +186,10 @@ public class MetaDataIndexStateService extends AbstractComponent {
|
|||
rtBuilder.addAsFromCloseToOpen(updatedState.metaData().getIndexSafe(index.getIndex()));
|
||||
}
|
||||
|
||||
RoutingAllocation.Result routingResult = allocationService.reroute(
|
||||
//no explicit wait for other nodes needed as we use AckedClusterStateUpdateTask
|
||||
return allocationService.reroute(
|
||||
ClusterState.builder(updatedState).routingTable(rtBuilder.build()).build(),
|
||||
"indices opened [" + indicesAsString + "]");
|
||||
//no explicit wait for other nodes needed as we use AckedClusterStateUpdateTask
|
||||
return ClusterState.builder(updatedState).routingResult(routingResult).build();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.elasticsearch.cluster.block.ClusterBlock;
|
|||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
|
@ -271,8 +270,7 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
|
|||
ClusterState updatedState = ClusterState.builder(currentState).metaData(metaDataBuilder).routingTable(routingTableBuilder.build()).blocks(blocks).build();
|
||||
|
||||
// now, reroute in case things change that require it (like number of replicas)
|
||||
RoutingAllocation.Result routingResult = allocationService.reroute(updatedState, "settings update");
|
||||
updatedState = ClusterState.builder(updatedState).routingResult(routingResult).build();
|
||||
updatedState = allocationService.reroute(updatedState, "settings update");
|
||||
try {
|
||||
for (Index index : openIndices) {
|
||||
final IndexMetaData currentMetaData = currentState.getMetaData().getIndexSafe(index);
|
||||
|
|
|
@ -106,12 +106,7 @@ public class DelayedAllocationService extends AbstractLifecycleComponent impleme
|
|||
@Override
|
||||
public ClusterState execute(ClusterState currentState) throws Exception {
|
||||
removeIfSameTask(this);
|
||||
RoutingAllocation.Result routingResult = allocationService.reroute(currentState, "assign delayed unassigned shards");
|
||||
if (routingResult.changed()) {
|
||||
return ClusterState.builder(currentState).routingResult(routingResult).build();
|
||||
} else {
|
||||
return currentState;
|
||||
}
|
||||
return allocationService.reroute(currentState, "assign delayed unassigned shards");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.elasticsearch.cluster.ClusterChangedEvent;
|
|||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ClusterStateUpdateTask;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
|
@ -96,12 +95,7 @@ public class RoutingService extends AbstractLifecycleComponent {
|
|||
@Override
|
||||
public ClusterState execute(ClusterState currentState) {
|
||||
rerouting.set(false);
|
||||
RoutingAllocation.Result routingResult = allocationService.reroute(currentState, reason);
|
||||
if (!routingResult.changed()) {
|
||||
// no state changed
|
||||
return currentState;
|
||||
}
|
||||
return ClusterState.builder(currentState).routingResult(routingResult).build();
|
||||
return allocationService.reroute(currentState, reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.elasticsearch.cluster.routing.RoutingTable;
|
|||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
||||
import org.elasticsearch.cluster.routing.UnassignedInfo.AllocationStatus;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation.Result;
|
||||
import org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator;
|
||||
import org.elasticsearch.cluster.routing.allocation.command.AllocationCommands;
|
||||
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
|
||||
|
@ -79,15 +78,15 @@ public class AllocationService extends AbstractComponent {
|
|||
* Applies the started shards. Note, only initializing ShardRouting instances that exist in the routing table should be
|
||||
* provided as parameter and no duplicates should be contained.
|
||||
* <p>
|
||||
* If the same instance of the routing table is returned, then no change has been made.</p>
|
||||
* If the same instance of the {@link ClusterState} is returned, then no change has been made.</p>
|
||||
*/
|
||||
public Result applyStartedShards(ClusterState clusterState, List<ShardRouting> startedShards) {
|
||||
public ClusterState applyStartedShards(ClusterState clusterState, List<ShardRouting> startedShards) {
|
||||
return applyStartedShards(clusterState, startedShards, true);
|
||||
}
|
||||
|
||||
public Result applyStartedShards(ClusterState clusterState, List<ShardRouting> startedShards, boolean withReroute) {
|
||||
public ClusterState applyStartedShards(ClusterState clusterState, List<ShardRouting> startedShards, boolean withReroute) {
|
||||
if (startedShards.isEmpty()) {
|
||||
return Result.unchanged(clusterState);
|
||||
return clusterState;
|
||||
}
|
||||
RoutingNodes routingNodes = getMutableRoutingNodes(clusterState);
|
||||
// shuffle the unassigned nodes, just so we won't have things like poison failed shards
|
||||
|
@ -100,35 +99,35 @@ public class AllocationService extends AbstractComponent {
|
|||
reroute(allocation);
|
||||
}
|
||||
String startedShardsAsString = firstListElementsToCommaDelimitedString(startedShards, s -> s.shardId().toString());
|
||||
return buildResultAndLogHealthChange(allocation, "shards started [" + startedShardsAsString + "] ...");
|
||||
return buildResultAndLogHealthChange(clusterState, allocation, "shards started [" + startedShardsAsString + "] ...");
|
||||
}
|
||||
|
||||
protected Result buildResultAndLogHealthChange(RoutingAllocation allocation, String reason) {
|
||||
return buildResultAndLogHealthChange(allocation, reason, new RoutingExplanations());
|
||||
protected ClusterState buildResultAndLogHealthChange(ClusterState oldState, RoutingAllocation allocation, String reason) {
|
||||
return buildResultAndLogHealthChange(oldState, allocation, reason, new RoutingExplanations());
|
||||
}
|
||||
|
||||
protected Result buildResultAndLogHealthChange(RoutingAllocation allocation, String reason, RoutingExplanations explanations) {
|
||||
RoutingTable oldRoutingTable = allocation.routingTable();
|
||||
protected ClusterState buildResultAndLogHealthChange(ClusterState oldState, RoutingAllocation allocation, String reason,
|
||||
RoutingExplanations explanations) {
|
||||
RoutingTable oldRoutingTable = oldState.routingTable();
|
||||
RoutingNodes newRoutingNodes = allocation.routingNodes();
|
||||
final RoutingTable newRoutingTable = new RoutingTable.Builder().updateNodes(oldRoutingTable.version(), newRoutingNodes).build();
|
||||
MetaData newMetaData = allocation.updateMetaDataWithRoutingChanges(newRoutingTable);
|
||||
assert newRoutingTable.validate(newMetaData); // validates the routing table is coherent with the cluster state metadata
|
||||
final ClusterState newState = ClusterState.builder(oldState).routingTable(newRoutingTable).metaData(newMetaData).build();
|
||||
logClusterHealthStateChange(
|
||||
new ClusterStateHealth(ClusterState.builder(clusterName).
|
||||
metaData(allocation.metaData()).routingTable(oldRoutingTable).build()),
|
||||
new ClusterStateHealth(ClusterState.builder(clusterName).
|
||||
metaData(newMetaData).routingTable(newRoutingTable).build()),
|
||||
new ClusterStateHealth(oldState),
|
||||
new ClusterStateHealth(newState),
|
||||
reason
|
||||
);
|
||||
return Result.changed(newRoutingTable, newMetaData, explanations);
|
||||
return newState;
|
||||
}
|
||||
|
||||
public Result applyFailedShard(ClusterState clusterState, ShardRouting failedShard) {
|
||||
public ClusterState applyFailedShard(ClusterState clusterState, ShardRouting failedShard) {
|
||||
return applyFailedShards(clusterState, Collections.singletonList(new FailedRerouteAllocation.FailedShard(failedShard, null, null)),
|
||||
Collections.emptyList());
|
||||
}
|
||||
|
||||
public Result applyFailedShards(ClusterState clusterState, List<FailedRerouteAllocation.FailedShard> failedShards) {
|
||||
public ClusterState applyFailedShards(ClusterState clusterState, List<FailedRerouteAllocation.FailedShard> failedShards) {
|
||||
return applyFailedShards(clusterState, failedShards, Collections.emptyList());
|
||||
}
|
||||
|
||||
|
@ -138,20 +137,20 @@ public class AllocationService extends AbstractComponent {
|
|||
* are no routing entries in the routing table.
|
||||
*
|
||||
* <p>
|
||||
* If the same instance of the routing table is returned, then no change has been made.</p>
|
||||
* If the same instance of ClusterState is returned, then no change has been made.</p>
|
||||
*/
|
||||
public Result applyFailedShards(ClusterState clusterState, List<FailedRerouteAllocation.FailedShard> failedShards,
|
||||
List<FailedRerouteAllocation.StaleShard> staleShards) {
|
||||
public ClusterState applyFailedShards(final ClusterState clusterState, List<FailedRerouteAllocation.FailedShard> failedShards,
|
||||
List<FailedRerouteAllocation.StaleShard> staleShards) {
|
||||
if (staleShards.isEmpty() && failedShards.isEmpty()) {
|
||||
return Result.unchanged(clusterState);
|
||||
return clusterState;
|
||||
}
|
||||
clusterState = IndexMetaDataUpdater.removeStaleIdsWithoutRoutings(clusterState, staleShards);
|
||||
ClusterState tmpState = IndexMetaDataUpdater.removeStaleIdsWithoutRoutings(clusterState, staleShards);
|
||||
|
||||
RoutingNodes routingNodes = getMutableRoutingNodes(clusterState);
|
||||
RoutingNodes routingNodes = getMutableRoutingNodes(tmpState);
|
||||
// shuffle the unassigned nodes, just so we won't have things like poison failed shards
|
||||
routingNodes.unassigned().shuffle();
|
||||
long currentNanoTime = currentNanoTime();
|
||||
FailedRerouteAllocation allocation = new FailedRerouteAllocation(allocationDeciders, routingNodes, clusterState, failedShards,
|
||||
FailedRerouteAllocation allocation = new FailedRerouteAllocation(allocationDeciders, routingNodes, tmpState, failedShards,
|
||||
clusterInfoService.getClusterInfo(), currentNanoTime);
|
||||
|
||||
for (FailedRerouteAllocation.FailedShard failedShardEntry : failedShards) {
|
||||
|
@ -178,14 +177,14 @@ public class AllocationService extends AbstractComponent {
|
|||
|
||||
reroute(allocation);
|
||||
String failedShardsAsString = firstListElementsToCommaDelimitedString(failedShards, s -> s.routingEntry.shardId().toString());
|
||||
return buildResultAndLogHealthChange(allocation, "shards failed [" + failedShardsAsString + "] ...");
|
||||
return buildResultAndLogHealthChange(clusterState, allocation, "shards failed [" + failedShardsAsString + "] ...");
|
||||
}
|
||||
|
||||
/**
|
||||
* unassigned an shards that are associated with nodes that are no longer part of the cluster, potentially promoting replicas
|
||||
* if needed.
|
||||
*/
|
||||
public RoutingAllocation.Result deassociateDeadNodes(ClusterState clusterState, boolean reroute, String reason) {
|
||||
public ClusterState deassociateDeadNodes(final ClusterState clusterState, boolean reroute, String reason) {
|
||||
RoutingNodes routingNodes = getMutableRoutingNodes(clusterState);
|
||||
// shuffle the unassigned nodes, just so we won't have things like poison failed shards
|
||||
routingNodes.unassigned().shuffle();
|
||||
|
@ -200,9 +199,9 @@ public class AllocationService extends AbstractComponent {
|
|||
}
|
||||
|
||||
if (allocation.routingNodesChanged() == false) {
|
||||
return Result.unchanged(clusterState);
|
||||
return clusterState;
|
||||
}
|
||||
return buildResultAndLogHealthChange(allocation, reason);
|
||||
return buildResultAndLogHealthChange(clusterState, allocation, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -244,7 +243,7 @@ public class AllocationService extends AbstractComponent {
|
|||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
public Result reroute(ClusterState clusterState, AllocationCommands commands, boolean explain, boolean retryFailed) {
|
||||
public CommandsResult reroute(final ClusterState clusterState, AllocationCommands commands, boolean explain, boolean retryFailed) {
|
||||
RoutingNodes routingNodes = getMutableRoutingNodes(clusterState);
|
||||
// we don't shuffle the unassigned shards here, to try and get as close as possible to
|
||||
// a consistent result of the effect the commands have on the routing
|
||||
|
@ -261,25 +260,25 @@ public class AllocationService extends AbstractComponent {
|
|||
// the assumption is that commands will move / act on shards (or fail through exceptions)
|
||||
// so, there will always be shard "movements", so no need to check on reroute
|
||||
reroute(allocation);
|
||||
return buildResultAndLogHealthChange(allocation, "reroute commands", explanations);
|
||||
return new CommandsResult(explanations, buildResultAndLogHealthChange(clusterState, allocation, "reroute commands"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reroutes the routing table based on the live nodes.
|
||||
* <p>
|
||||
* If the same instance of the routing table is returned, then no change has been made.
|
||||
* If the same instance of ClusterState is returned, then no change has been made.
|
||||
*/
|
||||
public Result reroute(ClusterState clusterState, String reason) {
|
||||
public ClusterState reroute(ClusterState clusterState, String reason) {
|
||||
return reroute(clusterState, reason, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reroutes the routing table based on the live nodes.
|
||||
* <p>
|
||||
* If the same instance of the routing table is returned, then no change has been made.
|
||||
* If the same instance of ClusterState is returned, then no change has been made.
|
||||
*/
|
||||
protected Result reroute(ClusterState clusterState, String reason, boolean debug) {
|
||||
protected ClusterState reroute(final ClusterState clusterState, String reason, boolean debug) {
|
||||
RoutingNodes routingNodes = getMutableRoutingNodes(clusterState);
|
||||
// shuffle the unassigned nodes, just so we won't have things like poison failed shards
|
||||
routingNodes.unassigned().shuffle();
|
||||
|
@ -288,9 +287,9 @@ public class AllocationService extends AbstractComponent {
|
|||
allocation.debugDecision(debug);
|
||||
reroute(allocation);
|
||||
if (allocation.routingNodesChanged() == false) {
|
||||
return Result.unchanged(clusterState);
|
||||
return clusterState;
|
||||
}
|
||||
return buildResultAndLogHealthChange(allocation, reason);
|
||||
return buildResultAndLogHealthChange(clusterState, allocation, reason);
|
||||
}
|
||||
|
||||
private void logClusterHealthStateChange(ClusterStateHealth previousStateHealth, ClusterStateHealth newStateHealth, String reason) {
|
||||
|
@ -368,4 +367,39 @@ public class AllocationService extends AbstractComponent {
|
|||
protected long currentNanoTime() {
|
||||
return System.nanoTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* this class is used to describe results of applying a set of
|
||||
* {@link org.elasticsearch.cluster.routing.allocation.command.AllocationCommand}
|
||||
*/
|
||||
public static class CommandsResult {
|
||||
|
||||
private final RoutingExplanations explanations;
|
||||
|
||||
private final ClusterState clusterState;
|
||||
|
||||
/**
|
||||
* Creates a new {@link CommandsResult}
|
||||
* @param explanations Explanation for the reroute actions
|
||||
* @param clusterState Resulting cluster state
|
||||
*/
|
||||
private CommandsResult(RoutingExplanations explanations, ClusterState clusterState) {
|
||||
this.clusterState = clusterState;
|
||||
this.explanations = explanations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the explanation of this result
|
||||
*/
|
||||
public RoutingExplanations explanations() {
|
||||
return explanations;
|
||||
}
|
||||
|
||||
/**
|
||||
* thre resulting cluster state, after the commands were applied
|
||||
*/
|
||||
public ClusterState getClusterState() {
|
||||
return clusterState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,83 +46,6 @@ import static java.util.Collections.unmodifiableSet;
|
|||
*/
|
||||
public class RoutingAllocation {
|
||||
|
||||
/**
|
||||
* this class is used to describe results of a {@link RoutingAllocation}
|
||||
*/
|
||||
public static class Result {
|
||||
|
||||
private final boolean changed;
|
||||
|
||||
private final RoutingTable routingTable;
|
||||
|
||||
private final MetaData metaData;
|
||||
|
||||
private final RoutingExplanations explanations;
|
||||
|
||||
/**
|
||||
* Creates a new {@link RoutingAllocation.Result} where no change to the routing table was made.
|
||||
* @param clusterState the unchanged {@link ClusterState}
|
||||
*/
|
||||
public static Result unchanged(ClusterState clusterState) {
|
||||
return new Result(false, clusterState.routingTable(), clusterState.metaData(), new RoutingExplanations());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link RoutingAllocation.Result} where changes were made to the routing table.
|
||||
* @param routingTable the {@link RoutingTable} this Result references
|
||||
* @param metaData the {@link MetaData} this Result references
|
||||
* @param explanations Explanation for the reroute actions
|
||||
*/
|
||||
public static Result changed(RoutingTable routingTable, MetaData metaData, RoutingExplanations explanations) {
|
||||
return new Result(true, routingTable, metaData, explanations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link RoutingAllocation.Result}
|
||||
* @param changed a flag to determine whether the actual {@link RoutingTable} has been changed
|
||||
* @param routingTable the {@link RoutingTable} this Result references
|
||||
* @param metaData the {@link MetaData} this Result references
|
||||
* @param explanations Explanation for the reroute actions
|
||||
*/
|
||||
private Result(boolean changed, RoutingTable routingTable, MetaData metaData, RoutingExplanations explanations) {
|
||||
this.changed = changed;
|
||||
this.routingTable = routingTable;
|
||||
this.metaData = metaData;
|
||||
this.explanations = explanations;
|
||||
}
|
||||
|
||||
/** determine whether the actual {@link RoutingTable} has been changed
|
||||
* @return <code>true</code> if the {@link RoutingTable} has been changed by allocation. Otherwise <code>false</code>
|
||||
*/
|
||||
public boolean changed() {
|
||||
return this.changed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link MetaData} referenced by this result
|
||||
* @return referenced {@link MetaData}
|
||||
*/
|
||||
public MetaData metaData() {
|
||||
return metaData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link RoutingTable} referenced by this result
|
||||
* @return referenced {@link RoutingTable}
|
||||
*/
|
||||
public RoutingTable routingTable() {
|
||||
return routingTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the explanation of this result
|
||||
* @return explanation
|
||||
*/
|
||||
public RoutingExplanations explanations() {
|
||||
return explanations;
|
||||
}
|
||||
}
|
||||
|
||||
private final AllocationDeciders deciders;
|
||||
|
||||
private final RoutingNodes routingNodes;
|
||||
|
|
|
@ -49,7 +49,7 @@ import org.elasticsearch.common.settings.Settings;
|
|||
* To enable allocation awareness in this example nodes should contain a value
|
||||
* for the <tt>rack_id</tt> key like:
|
||||
* <pre>
|
||||
* node.rack_id:1
|
||||
* node.attr.rack_id:1
|
||||
* </pre>
|
||||
* <p>
|
||||
* Awareness can also be used to prevent over-allocation in the case of node or
|
||||
|
|
|
@ -23,12 +23,17 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.apache.lucene.util.InfoStream;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/** An InfoStream (for Lucene's IndexWriter) that redirects
|
||||
* messages to "lucene.iw.ifd" and "lucene.iw" Logger.trace. */
|
||||
public final class LoggerInfoStream extends InfoStream {
|
||||
|
||||
private final Logger parentLogger;
|
||||
|
||||
private final Map<String, Logger> loggers = new ConcurrentHashMap<>();
|
||||
|
||||
public LoggerInfoStream(final Logger parentLogger) {
|
||||
this.parentLogger = parentLogger;
|
||||
}
|
||||
|
@ -46,11 +51,12 @@ public final class LoggerInfoStream extends InfoStream {
|
|||
}
|
||||
|
||||
private Logger getLogger(String component) {
|
||||
return Loggers.getLogger(parentLogger, "." + component);
|
||||
return loggers.computeIfAbsent(component, c -> Loggers.getLogger(parentLogger, "." + c));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,34 +28,38 @@ import org.elasticsearch.cluster.routing.allocation.command.AllocationCommandReg
|
|||
import org.elasticsearch.cluster.routing.allocation.command.CancelAllocationCommand;
|
||||
import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.util.Providers;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry;
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Setting.Property;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.ExtensionPoint;
|
||||
import org.elasticsearch.http.HttpServer;
|
||||
import org.elasticsearch.common.util.BigArrays;
|
||||
import org.elasticsearch.http.HttpServerTransport;
|
||||
import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
||||
import org.elasticsearch.plugins.NetworkPlugin;
|
||||
import org.elasticsearch.tasks.RawTaskStatus;
|
||||
import org.elasticsearch.tasks.Task;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.Transport;
|
||||
import org.elasticsearch.transport.TransportInterceptor;
|
||||
import org.elasticsearch.transport.TransportRequest;
|
||||
import org.elasticsearch.transport.TransportRequestHandler;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
import org.elasticsearch.transport.local.LocalTransport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* A module to handle registering and binding all network related classes.
|
||||
*/
|
||||
public class NetworkModule extends AbstractModule {
|
||||
public final class NetworkModule {
|
||||
|
||||
public static final String TRANSPORT_TYPE_KEY = "transport.type";
|
||||
public static final String HTTP_TYPE_KEY = "http.type";
|
||||
|
@ -70,30 +74,63 @@ public class NetworkModule extends AbstractModule {
|
|||
public static final Setting<Boolean> HTTP_ENABLED = Setting.boolSetting("http.enabled", true, Property.NodeScope);
|
||||
public static final Setting<String> TRANSPORT_TYPE_SETTING = Setting.simpleString(TRANSPORT_TYPE_KEY, Property.NodeScope);
|
||||
|
||||
private final NetworkService networkService;
|
||||
private final Settings settings;
|
||||
private final boolean transportClient;
|
||||
|
||||
private final AllocationCommandRegistry allocationCommandRegistry = new AllocationCommandRegistry();
|
||||
private final ExtensionPoint.SelectedType<Transport> transportTypes = new ExtensionPoint.SelectedType<>("transport", Transport.class);
|
||||
private final ExtensionPoint.SelectedType<HttpServerTransport> httpTransportTypes = new ExtensionPoint.SelectedType<>("http_transport", HttpServerTransport.class);
|
||||
private final List<NamedWriteableRegistry.Entry> namedWriteables = new ArrayList<>();
|
||||
private static final AllocationCommandRegistry allocationCommandRegistry = new AllocationCommandRegistry();
|
||||
private static final List<NamedWriteableRegistry.Entry> namedWriteables = new ArrayList<>();
|
||||
|
||||
private final Map<String, Supplier<Transport>> transportFactories = new HashMap<>();
|
||||
private final Map<String, Supplier<HttpServerTransport>> transportHttpFactories = new HashMap<>();
|
||||
private final List<TransportInterceptor> transportIntercetors = new ArrayList<>();
|
||||
|
||||
static {
|
||||
registerAllocationCommand(CancelAllocationCommand::new, CancelAllocationCommand::fromXContent,
|
||||
CancelAllocationCommand.COMMAND_NAME_FIELD);
|
||||
registerAllocationCommand(MoveAllocationCommand::new, MoveAllocationCommand::fromXContent,
|
||||
MoveAllocationCommand.COMMAND_NAME_FIELD);
|
||||
registerAllocationCommand(AllocateReplicaAllocationCommand::new, AllocateReplicaAllocationCommand::fromXContent,
|
||||
AllocateReplicaAllocationCommand.COMMAND_NAME_FIELD);
|
||||
registerAllocationCommand(AllocateEmptyPrimaryAllocationCommand::new, AllocateEmptyPrimaryAllocationCommand::fromXContent,
|
||||
AllocateEmptyPrimaryAllocationCommand.COMMAND_NAME_FIELD);
|
||||
registerAllocationCommand(AllocateStalePrimaryAllocationCommand::new, AllocateStalePrimaryAllocationCommand::fromXContent,
|
||||
AllocateStalePrimaryAllocationCommand.COMMAND_NAME_FIELD);
|
||||
namedWriteables.add(
|
||||
new NamedWriteableRegistry.Entry(Task.Status.class, ReplicationTask.Status.NAME, ReplicationTask.Status::new));
|
||||
namedWriteables.add(
|
||||
new NamedWriteableRegistry.Entry(Task.Status.class, RawTaskStatus.NAME, RawTaskStatus::new));
|
||||
}
|
||||
/**
|
||||
* Creates a network module that custom networking classes can be plugged into.
|
||||
* @param networkService A constructed network service object to bind.
|
||||
* @param settings The settings for the node
|
||||
* @param transportClient True if only transport classes should be allowed to be registered, false otherwise.
|
||||
*/
|
||||
public NetworkModule(NetworkService networkService, Settings settings, boolean transportClient) {
|
||||
this.networkService = networkService;
|
||||
public NetworkModule(Settings settings, boolean transportClient, List<NetworkPlugin> plugins, ThreadPool threadPool,
|
||||
BigArrays bigArrays,
|
||||
CircuitBreakerService circuitBreakerService,
|
||||
NamedWriteableRegistry namedWriteableRegistry,
|
||||
NetworkService networkService) {
|
||||
this.settings = settings;
|
||||
this.transportClient = transportClient;
|
||||
registerTransport(LOCAL_TRANSPORT, LocalTransport.class);
|
||||
namedWriteables.add(new NamedWriteableRegistry.Entry(Task.Status.class, ReplicationTask.Status.NAME, ReplicationTask.Status::new));
|
||||
namedWriteables.add(new NamedWriteableRegistry.Entry(Task.Status.class, RawTaskStatus.NAME, RawTaskStatus::new));
|
||||
registerBuiltinAllocationCommands();
|
||||
registerTransport(LOCAL_TRANSPORT, () -> new LocalTransport(settings, threadPool, namedWriteableRegistry, circuitBreakerService));
|
||||
for (NetworkPlugin plugin : plugins) {
|
||||
if (transportClient == false && HTTP_ENABLED.get(settings)) {
|
||||
Map<String, Supplier<HttpServerTransport>> httpTransportFactory = plugin.getHttpTransports(settings, threadPool, bigArrays,
|
||||
circuitBreakerService, namedWriteableRegistry, networkService);
|
||||
for (Map.Entry<String, Supplier<HttpServerTransport>> entry : httpTransportFactory.entrySet()) {
|
||||
registerHttpTransport(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
Map<String, Supplier<Transport>> httpTransportFactory = plugin.getTransports(settings, threadPool, bigArrays,
|
||||
circuitBreakerService, namedWriteableRegistry, networkService);
|
||||
for (Map.Entry<String, Supplier<Transport>> entry : httpTransportFactory.entrySet()) {
|
||||
registerTransport(entry.getKey(), entry.getValue());
|
||||
}
|
||||
List<TransportInterceptor> transportInterceptors = plugin.getTransportInterceptors();
|
||||
for (TransportInterceptor interceptor : transportInterceptors) {
|
||||
registerTransportInterceptor(interceptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTransportClient() {
|
||||
|
@ -101,17 +138,21 @@ public class NetworkModule extends AbstractModule {
|
|||
}
|
||||
|
||||
/** Adds a transport implementation that can be selected by setting {@link #TRANSPORT_TYPE_KEY}. */
|
||||
public void registerTransport(String name, Class<? extends Transport> clazz) {
|
||||
transportTypes.registerExtension(name, clazz);
|
||||
private void registerTransport(String key, Supplier<Transport> factory) {
|
||||
if (transportFactories.putIfAbsent(key, factory) != null) {
|
||||
throw new IllegalArgumentException("transport for name: " + key + " is already registered");
|
||||
}
|
||||
}
|
||||
|
||||
/** Adds an http transport implementation that can be selected by setting {@link #HTTP_TYPE_KEY}. */
|
||||
// TODO: we need another name than "http transport"....so confusing with transportClient...
|
||||
public void registerHttpTransport(String name, Class<? extends HttpServerTransport> clazz) {
|
||||
private void registerHttpTransport(String key, Supplier<HttpServerTransport> factory) {
|
||||
if (transportClient) {
|
||||
throw new IllegalArgumentException("Cannot register http transport " + clazz.getName() + " for transport client");
|
||||
throw new IllegalArgumentException("Cannot register http transport " + key + " for transport client");
|
||||
}
|
||||
if (transportHttpFactories.putIfAbsent(key, factory) != null) {
|
||||
throw new IllegalArgumentException("transport for name: " + key + " is already registered");
|
||||
}
|
||||
httpTransportTypes.registerExtension(name, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,7 +165,7 @@ public class NetworkModule extends AbstractModule {
|
|||
* @param commandName the names under which the command should be parsed. The {@link ParseField#getPreferredName()} is special because
|
||||
* it is the name under which the command's reader is registered.
|
||||
*/
|
||||
private <T extends AllocationCommand> void registerAllocationCommand(Writeable.Reader<T> reader, AllocationCommand.Parser<T> parser,
|
||||
private static <T extends AllocationCommand> void registerAllocationCommand(Writeable.Reader<T> reader, AllocationCommand.Parser<T> parser,
|
||||
ParseField commandName) {
|
||||
allocationCommandRegistry.register(parser, commandName);
|
||||
namedWriteables.add(new Entry(AllocationCommand.class, commandName.getPreferredName(), reader));
|
||||
|
@ -133,57 +174,61 @@ public class NetworkModule extends AbstractModule {
|
|||
/**
|
||||
* The registry of allocation command parsers.
|
||||
*/
|
||||
public AllocationCommandRegistry getAllocationCommandRegistry() {
|
||||
public static AllocationCommandRegistry getAllocationCommandRegistry() {
|
||||
return allocationCommandRegistry;
|
||||
}
|
||||
|
||||
public List<Entry> getNamedWriteables() {
|
||||
return namedWriteables;
|
||||
public static List<Entry> getNamedWriteables() {
|
||||
return Collections.unmodifiableList(namedWriteables);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(NetworkService.class).toInstance(networkService);
|
||||
bindTransportService();
|
||||
transportTypes.bindType(binder(), settings, TRANSPORT_TYPE_KEY, TRANSPORT_DEFAULT_TYPE_SETTING.get(settings));
|
||||
bind(TransportInterceptor.class).toInstance(new CompositeTransportInterceptor(this.transportIntercetors));
|
||||
if (transportClient == false) {
|
||||
if (HTTP_ENABLED.get(settings)) {
|
||||
bind(HttpServer.class).asEagerSingleton();
|
||||
httpTransportTypes.bindType(binder(), settings, HTTP_TYPE_SETTING.getKey(), HTTP_DEFAULT_TYPE_SETTING.get(settings));
|
||||
} else {
|
||||
bind(HttpServer.class).toProvider(Providers.of(null));
|
||||
}
|
||||
// Bind the AllocationCommandRegistry so RestClusterRerouteAction can get it.
|
||||
bind(AllocationCommandRegistry.class).toInstance(allocationCommandRegistry);
|
||||
public Supplier<HttpServerTransport> getHttpServerTransportSupplier() {
|
||||
final String name;
|
||||
if (HTTP_TYPE_SETTING.exists(settings)) {
|
||||
name = HTTP_TYPE_SETTING.get(settings);
|
||||
} else {
|
||||
name = HTTP_DEFAULT_TYPE_SETTING.get(settings);
|
||||
}
|
||||
final Supplier<HttpServerTransport> factory = transportHttpFactories.get(name);
|
||||
if (factory == null) {
|
||||
throw new IllegalStateException("Unsupported http.type [" + name + "]");
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
||||
private void registerBuiltinAllocationCommands() {
|
||||
registerAllocationCommand(CancelAllocationCommand::new, CancelAllocationCommand::fromXContent,
|
||||
CancelAllocationCommand.COMMAND_NAME_FIELD);
|
||||
registerAllocationCommand(MoveAllocationCommand::new, MoveAllocationCommand::fromXContent,
|
||||
MoveAllocationCommand.COMMAND_NAME_FIELD);
|
||||
registerAllocationCommand(AllocateReplicaAllocationCommand::new, AllocateReplicaAllocationCommand::fromXContent,
|
||||
AllocateReplicaAllocationCommand.COMMAND_NAME_FIELD);
|
||||
registerAllocationCommand(AllocateEmptyPrimaryAllocationCommand::new, AllocateEmptyPrimaryAllocationCommand::fromXContent,
|
||||
AllocateEmptyPrimaryAllocationCommand.COMMAND_NAME_FIELD);
|
||||
registerAllocationCommand(AllocateStalePrimaryAllocationCommand::new, AllocateStalePrimaryAllocationCommand::fromXContent,
|
||||
AllocateStalePrimaryAllocationCommand.COMMAND_NAME_FIELD);
|
||||
|
||||
public boolean isHttpEnabled() {
|
||||
return transportClient == false && HTTP_ENABLED.get(settings);
|
||||
}
|
||||
|
||||
public boolean canRegisterHttpExtensions() {
|
||||
return transportClient == false;
|
||||
public Supplier<Transport> getTransportSupplier() {
|
||||
final String name;
|
||||
if (TRANSPORT_TYPE_SETTING.exists(settings)) {
|
||||
name = TRANSPORT_TYPE_SETTING.get(settings);
|
||||
} else {
|
||||
name = TRANSPORT_DEFAULT_TYPE_SETTING.get(settings);
|
||||
}
|
||||
final Supplier<Transport> factory = transportFactories.get(name);
|
||||
if (factory == null) {
|
||||
throw new IllegalStateException("Unsupported transport.type [" + name + "]");
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new {@link TransportInterceptor}
|
||||
*/
|
||||
public void addTransportInterceptor(TransportInterceptor interceptor) {
|
||||
private void registerTransportInterceptor(TransportInterceptor interceptor) {
|
||||
this.transportIntercetors.add(Objects.requireNonNull(interceptor, "interceptor must not be null"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composite {@link TransportInterceptor} containing all registered interceptors
|
||||
* @see #registerTransportInterceptor(TransportInterceptor)
|
||||
*/
|
||||
public TransportInterceptor getTransportInterceptor() {
|
||||
return new CompositeTransportInterceptor(this.transportIntercetors);
|
||||
}
|
||||
|
||||
static final class CompositeTransportInterceptor implements TransportInterceptor {
|
||||
final List<TransportInterceptor> transportInterceptors;
|
||||
|
||||
|
@ -208,7 +253,4 @@ public class NetworkModule extends AbstractModule {
|
|||
}
|
||||
}
|
||||
|
||||
protected void bindTransportService() {
|
||||
bind(TransportService.class).asEagerSingleton();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.elasticsearch.cluster.block.ClusterBlocks;
|
|||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
|
@ -167,11 +166,7 @@ public class LocalDiscovery extends AbstractLifecycleComponent implements Discov
|
|||
}
|
||||
nodesBuilder.localNodeId(master.localNode().getId()).masterNodeId(master.localNode().getId());
|
||||
currentState = ClusterState.builder(currentState).nodes(nodesBuilder).build();
|
||||
RoutingAllocation.Result result = master.allocationService.reroute(currentState, "node_add");
|
||||
if (result.changed()) {
|
||||
currentState = ClusterState.builder(currentState).routingResult(result).build();
|
||||
}
|
||||
return currentState;
|
||||
return master.allocationService.reroute(currentState, "node_add");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -234,9 +229,7 @@ public class LocalDiscovery extends AbstractLifecycleComponent implements Discov
|
|||
}
|
||||
// reroute here, so we eagerly remove dead nodes from the routing
|
||||
ClusterState updatedState = ClusterState.builder(currentState).nodes(newNodes).build();
|
||||
RoutingAllocation.Result routingResult = master.allocationService.deassociateDeadNodes(
|
||||
ClusterState.builder(updatedState).build(), true, "node stopped");
|
||||
return ClusterState.builder(updatedState).routingResult(routingResult).build();
|
||||
return master.allocationService.deassociateDeadNodes(updatedState, true, "node stopped");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.elasticsearch.cluster.block.ClusterBlocks;
|
|||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
|
@ -456,17 +455,12 @@ public class NodeJoinController extends AbstractComponent {
|
|||
|
||||
if (nodesChanged) {
|
||||
newState.nodes(nodesBuilder);
|
||||
final ClusterState tmpState = newState.build();
|
||||
RoutingAllocation.Result result = allocationService.reroute(tmpState, "node_join");
|
||||
newState = ClusterState.builder(tmpState);
|
||||
if (result.changed()) {
|
||||
newState.routingResult(result);
|
||||
}
|
||||
return results.build(allocationService.reroute(newState.build(), "node_join"));
|
||||
} else {
|
||||
// we must return a new cluster state instance to force publishing. This is important
|
||||
// for the joining node to finalize its join and set us as a master
|
||||
return results.build(newState.build());
|
||||
}
|
||||
|
||||
// we must return a new cluster state instance to force publishing. This is important
|
||||
// for the joining node to finalize its join and set us as a master
|
||||
return results.build(newState.build());
|
||||
}
|
||||
|
||||
private ClusterState.Builder becomeMasterAndTrimConflictingNodes(ClusterState currentState, List<DiscoveryNode> joiningNodes) {
|
||||
|
@ -486,9 +480,8 @@ public class NodeJoinController extends AbstractComponent {
|
|||
// now trim any left over dead nodes - either left there when the previous master stepped down
|
||||
// or removed by us above
|
||||
ClusterState tmpState = ClusterState.builder(currentState).nodes(nodesBuilder).blocks(clusterBlocks).build();
|
||||
RoutingAllocation.Result result = allocationService.deassociateDeadNodes(tmpState, false,
|
||||
"removed dead nodes on election");
|
||||
return ClusterState.builder(tmpState).routingResult(result);
|
||||
return ClusterState.builder(allocationService.deassociateDeadNodes(tmpState, false,
|
||||
"removed dead nodes on election"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.elasticsearch.cluster.metadata.MetaData;
|
|||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
|
@ -571,9 +570,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implements Discover
|
|||
if (!electMasterService.hasEnoughMasterNodes(remainingNodesClusterState.nodes())) {
|
||||
return resultBuilder.build(rejoin.apply(remainingNodesClusterState, "not enough master nodes"));
|
||||
} else {
|
||||
final RoutingAllocation.Result routingResult =
|
||||
allocationService.deassociateDeadNodes(remainingNodesClusterState, true, describeTasks(tasks));
|
||||
return resultBuilder.build(ClusterState.builder(remainingNodesClusterState).routingResult(routingResult).build());
|
||||
return resultBuilder.build(allocationService.deassociateDeadNodes(remainingNodesClusterState, true, describeTasks(tasks)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.elasticsearch.cluster.metadata.MetaData;
|
|||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
|
@ -282,11 +281,8 @@ public class GatewayService extends AbstractLifecycleComponent implements Cluste
|
|||
routingTableBuilder.version(0);
|
||||
|
||||
// now, reroute
|
||||
RoutingAllocation.Result routingResult = allocationService.reroute(
|
||||
ClusterState.builder(updatedState).routingTable(routingTableBuilder.build()).build(),
|
||||
"state recovered");
|
||||
|
||||
return ClusterState.builder(updatedState).routingResult(routingResult).build();
|
||||
updatedState = ClusterState.builder(updatedState).routingTable(routingTableBuilder.build()).build();
|
||||
return allocationService.reroute(updatedState, "state recovered");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService;
|
|||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
|
@ -169,10 +168,8 @@ public class LocalAllocateDangledIndices extends AbstractComponent {
|
|||
ClusterState updatedState = ClusterState.builder(currentState).metaData(metaData).blocks(blocks).routingTable(routingTable).build();
|
||||
|
||||
// now, reroute
|
||||
RoutingAllocation.Result routingResult = allocationService.reroute(
|
||||
return allocationService.reroute(
|
||||
ClusterState.builder(updatedState).routingTable(routingTable).build(), "dangling indices allocated");
|
||||
|
||||
return ClusterState.builder(updatedState).routingResult(routingResult).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,14 +25,12 @@ import org.elasticsearch.common.breaker.CircuitBreaker;
|
|||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.io.Streams;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
||||
import org.elasticsearch.node.service.NodeService;
|
||||
import org.elasticsearch.rest.BytesRestResponse;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
|
@ -60,7 +58,6 @@ public class HttpServer extends AbstractLifecycleComponent implements HttpServer
|
|||
|
||||
private final CircuitBreakerService circuitBreakerService;
|
||||
|
||||
@Inject
|
||||
public HttpServer(Settings settings, HttpServerTransport transport, RestController restController,
|
||||
NodeClient client, CircuitBreakerService circuitBreakerService) {
|
||||
super(settings);
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.apache.lucene.store.Directory;
|
|||
import org.apache.lucene.store.IOContext;
|
||||
import org.apache.lucene.util.Accountable;
|
||||
import org.apache.lucene.util.Accountables;
|
||||
import org.apache.lucene.util.SetOnce;
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
|
@ -101,7 +102,7 @@ public abstract class Engine implements Closeable {
|
|||
protected final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
|
||||
protected final ReleasableLock readLock = new ReleasableLock(rwl.readLock());
|
||||
protected final ReleasableLock writeLock = new ReleasableLock(rwl.writeLock());
|
||||
protected volatile Exception failedEngine = null;
|
||||
protected final SetOnce<Exception> failedEngine = new SetOnce<>();
|
||||
/*
|
||||
* on <tt>lastWriteNanos</tt> we use System.nanoTime() to initialize this since:
|
||||
* - we use the value for figuring out if the shard / engine is active so if we startup and no write has happened yet we still consider it active
|
||||
|
@ -377,7 +378,7 @@ public abstract class Engine implements Closeable {
|
|||
|
||||
protected void ensureOpen() {
|
||||
if (isClosed.get()) {
|
||||
throw new EngineClosedException(shardId, failedEngine);
|
||||
throw new EngineClosedException(shardId, failedEngine.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -670,17 +671,19 @@ public abstract class Engine implements Closeable {
|
|||
if (failEngineLock.tryLock()) {
|
||||
store.incRef();
|
||||
try {
|
||||
if (failedEngine.get() != null) {
|
||||
logger.warn((Supplier<?>) () -> new ParameterizedMessage("tried to fail engine but engine is already failed. ignoring. [{}]", reason), failure);
|
||||
return;
|
||||
}
|
||||
// this must happen before we close IW or Translog such that we can check this state to opt out of failing the engine
|
||||
// again on any caught AlreadyClosedException
|
||||
failedEngine.set((failure != null) ? failure : new IllegalStateException(reason));
|
||||
try {
|
||||
// we just go and close this engine - no way to recover
|
||||
closeNoLock("engine failed on: [" + reason + "]");
|
||||
} finally {
|
||||
if (failedEngine != null) {
|
||||
logger.debug((Supplier<?>) () -> new ParameterizedMessage("tried to fail engine but engine is already failed. ignoring. [{}]", reason), failure);
|
||||
return;
|
||||
}
|
||||
logger.warn((Supplier<?>) () -> new ParameterizedMessage("failed engine [{}]", reason), failure);
|
||||
// we must set a failure exception, generate one if not supplied
|
||||
failedEngine = (failure != null) ? failure : new IllegalStateException(reason);
|
||||
// we first mark the store as corrupted before we notify any listeners
|
||||
// this must happen first otherwise we might try to reallocate so quickly
|
||||
// on the same node that we don't see the corrupted marker file when
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.lucene.index.MergePolicy;
|
|||
import org.apache.lucene.index.SnapshotDeletionPolicy;
|
||||
import org.apache.lucene.search.QueryCache;
|
||||
import org.apache.lucene.search.QueryCachingPolicy;
|
||||
import org.apache.lucene.search.ReferenceManager;
|
||||
import org.apache.lucene.search.similarities.Similarity;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
|
@ -34,7 +35,6 @@ import org.elasticsearch.common.unit.ByteSizeValue;
|
|||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.IndexSettings;
|
||||
import org.elasticsearch.index.codec.CodecService;
|
||||
import org.elasticsearch.index.shard.RefreshListeners;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.index.shard.TranslogRecoveryPerformer;
|
||||
import org.elasticsearch.index.store.Store;
|
||||
|
@ -68,7 +68,7 @@ public final class EngineConfig {
|
|||
private final QueryCachingPolicy queryCachingPolicy;
|
||||
private final long maxUnsafeAutoIdTimestamp;
|
||||
@Nullable
|
||||
private final RefreshListeners refreshListeners;
|
||||
private final ReferenceManager.RefreshListener refreshListeners;
|
||||
|
||||
/**
|
||||
* Index setting to change the low level lucene codec used for writing new segments.
|
||||
|
@ -112,7 +112,7 @@ public final class EngineConfig {
|
|||
MergePolicy mergePolicy, Analyzer analyzer,
|
||||
Similarity similarity, CodecService codecService, Engine.EventListener eventListener,
|
||||
TranslogRecoveryPerformer translogRecoveryPerformer, QueryCache queryCache, QueryCachingPolicy queryCachingPolicy,
|
||||
TranslogConfig translogConfig, TimeValue flushMergesAfter, RefreshListeners refreshListeners,
|
||||
TranslogConfig translogConfig, TimeValue flushMergesAfter, ReferenceManager.RefreshListener refreshListeners,
|
||||
long maxUnsafeAutoIdTimestamp) {
|
||||
if (openMode == null) {
|
||||
throw new IllegalArgumentException("openMode must not be null");
|
||||
|
@ -322,9 +322,9 @@ public final class EngineConfig {
|
|||
}
|
||||
|
||||
/**
|
||||
* {@linkplain RefreshListeners} instance to configure.
|
||||
* {@linkplain ReferenceManager.RefreshListener} instance to configure.
|
||||
*/
|
||||
public RefreshListeners getRefreshListeners() {
|
||||
public ReferenceManager.RefreshListener getRefreshListeners() {
|
||||
return refreshListeners;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,9 +82,6 @@ import java.util.concurrent.locks.Lock;
|
|||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class InternalEngine extends Engine {
|
||||
/**
|
||||
* When we last pruned expired tombstones from versionMap.deletes:
|
||||
|
@ -170,7 +167,6 @@ public class InternalEngine extends Engine {
|
|||
allowCommits.compareAndSet(true, openMode != EngineConfig.OpenMode.OPEN_INDEX_AND_TRANSLOG);
|
||||
if (engineConfig.getRefreshListeners() != null) {
|
||||
searcherManager.addListener(engineConfig.getRefreshListeners());
|
||||
engineConfig.getRefreshListeners().setTranslog(translog);
|
||||
}
|
||||
success = true;
|
||||
} finally {
|
||||
|
@ -951,7 +947,7 @@ public class InternalEngine extends Engine {
|
|||
failEngine("already closed by tragic event on the index writer", tragedy);
|
||||
} else if (translog.isOpen() == false && translog.getTragicException() != null) {
|
||||
failEngine("already closed by tragic event on the translog", translog.getTragicException());
|
||||
} else {
|
||||
} else if (failedEngine.get() == null) { // we are closed but the engine is not failed yet?
|
||||
// this smells like a bug - we only expect ACE if we are in a fatal case ie. either translog or IW is closed by
|
||||
// a tragic event or has closed itself. if that is not the case we are in a buggy state and raise an assertion error
|
||||
throw new AssertionError("Unexpected AlreadyClosedException", ex);
|
||||
|
|
|
@ -999,7 +999,10 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
|
|||
active.set(true);
|
||||
newEngine.recoverFromTranslog();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onNewEngine(Engine newEngine) {
|
||||
refreshListeners.setTranslog(newEngine.getTranslog());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1548,8 +1551,10 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
|
|||
throw new EngineClosedException(shardId);
|
||||
}
|
||||
assert this.currentEngineReference.get() == null;
|
||||
this.currentEngineReference.set(newEngine(config));
|
||||
|
||||
Engine engine = newEngine(config);
|
||||
onNewEngine(engine); // call this before we pass the memory barrier otherwise actions that happen
|
||||
// inside the callback are not visible. This one enforces happens-before
|
||||
this.currentEngineReference.set(engine);
|
||||
}
|
||||
|
||||
// time elapses after the engine is created above (pulling the config settings) until we set the engine reference, during which
|
||||
|
|
|
@ -114,4 +114,9 @@ public final class ShadowIndexShard extends IndexShard {
|
|||
public Store.MetadataSnapshot snapshotStoreMetadata() throws IOException {
|
||||
throw new UnsupportedOperationException("can't snapshot the directory as the primary may change it underneath us");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewEngine(Engine newEngine) {
|
||||
// nothing to do here - the superclass sets the translog on some listeners but we don't have such a thing
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
@ -112,7 +111,6 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
|
|||
|
||||
// the list of translog readers is guaranteed to be in order of translog generation
|
||||
private final List<TranslogReader> readers = new ArrayList<>();
|
||||
private volatile ScheduledFuture<?> syncScheduler;
|
||||
// this is a concurrent set and is not protected by any of the locks. The main reason
|
||||
// is that is being accessed by two separate classes (additions & reading are done by Translog, remove by View when closed)
|
||||
private final Set<View> outstandingViews = ConcurrentCollections.newConcurrentSet();
|
||||
|
@ -312,7 +310,6 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
|
|||
closeFilesIfNoPendingViews();
|
||||
}
|
||||
} finally {
|
||||
FutureUtils.cancel(syncScheduler);
|
||||
logger.debug("translog closed");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,6 +103,7 @@ public class JvmInfo implements Writeable, ToXContent {
|
|||
String onOutOfMemoryError = null;
|
||||
String useCompressedOops = "unknown";
|
||||
String useG1GC = "unknown";
|
||||
String useSerialGC = "unknown";
|
||||
long configuredInitialHeapSize = -1;
|
||||
long configuredMaxHeapSize = -1;
|
||||
try {
|
||||
|
@ -148,6 +149,13 @@ public class JvmInfo implements Writeable, ToXContent {
|
|||
configuredMaxHeapSize = Long.parseLong((String) valueMethod.invoke(maxHeapSizeVmOptionObject));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
Object useSerialGCVmOptionObject = vmOptionMethod.invoke(hotSpotDiagnosticMXBean, "UseSerialGC");
|
||||
useSerialGC = (String) valueMethod.invoke(useSerialGCVmOptionObject);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
} catch (Exception ignored) {
|
||||
|
||||
}
|
||||
|
@ -155,7 +163,7 @@ public class JvmInfo implements Writeable, ToXContent {
|
|||
INSTANCE = new JvmInfo(pid, System.getProperty("java.version"), runtimeMXBean.getVmName(), runtimeMXBean.getVmVersion(),
|
||||
runtimeMXBean.getVmVendor(), runtimeMXBean.getStartTime(), configuredInitialHeapSize, configuredMaxHeapSize,
|
||||
mem, inputArguments, bootClassPath, classPath, systemProperties, gcCollectors, memoryPools, onError, onOutOfMemoryError,
|
||||
useCompressedOops, useG1GC);
|
||||
useCompressedOops, useG1GC, useSerialGC);
|
||||
}
|
||||
|
||||
public static JvmInfo jvmInfo() {
|
||||
|
@ -186,11 +194,12 @@ public class JvmInfo implements Writeable, ToXContent {
|
|||
private final String onOutOfMemoryError;
|
||||
private final String useCompressedOops;
|
||||
private final String useG1GC;
|
||||
private final String useSerialGC;
|
||||
|
||||
private JvmInfo(long pid, String version, String vmName, String vmVersion, String vmVendor, long startTime,
|
||||
long configuredInitialHeapSize, long configuredMaxHeapSize, Mem mem, String[] inputArguments, String bootClassPath,
|
||||
String classPath, Map<String, String> systemProperties, String[] gcCollectors, String[] memoryPools, String onError,
|
||||
String onOutOfMemoryError, String useCompressedOops, String useG1GC) {
|
||||
String onOutOfMemoryError, String useCompressedOops, String useG1GC, String useSerialGC) {
|
||||
this.pid = pid;
|
||||
this.version = version;
|
||||
this.vmName = vmName;
|
||||
|
@ -210,6 +219,7 @@ public class JvmInfo implements Writeable, ToXContent {
|
|||
this.onOutOfMemoryError = onOutOfMemoryError;
|
||||
this.useCompressedOops = useCompressedOops;
|
||||
this.useG1GC = useG1GC;
|
||||
this.useSerialGC = useSerialGC;
|
||||
}
|
||||
|
||||
public JvmInfo(StreamInput in) throws IOException {
|
||||
|
@ -230,12 +240,13 @@ public class JvmInfo implements Writeable, ToXContent {
|
|||
gcCollectors = in.readStringArray();
|
||||
memoryPools = in.readStringArray();
|
||||
useCompressedOops = in.readString();
|
||||
//the following members are only used locally for boostrap checks, never serialized nor printed out
|
||||
//the following members are only used locally for bootstrap checks, never serialized nor printed out
|
||||
this.configuredMaxHeapSize = -1;
|
||||
this.configuredInitialHeapSize = -1;
|
||||
this.onError = null;
|
||||
this.onOutOfMemoryError = null;
|
||||
this.useG1GC = "unknown";
|
||||
this.useSerialGC = "unknown";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -415,6 +426,10 @@ public class JvmInfo implements Writeable, ToXContent {
|
|||
return this.useG1GC;
|
||||
}
|
||||
|
||||
public String useSerialGC() {
|
||||
return this.useSerialGC;
|
||||
}
|
||||
|
||||
public String[] getGcCollectors() {
|
||||
return gcCollectors;
|
||||
}
|
||||
|
|
|
@ -44,14 +44,17 @@ import org.elasticsearch.cluster.metadata.MetaData;
|
|||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.routing.RoutingService;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.command.AllocationCommandRegistry;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.StopWatch;
|
||||
import org.elasticsearch.common.component.Lifecycle;
|
||||
import org.elasticsearch.common.component.LifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Binder;
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
import org.elasticsearch.common.inject.Key;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.inject.ModulesBuilder;
|
||||
import org.elasticsearch.common.inject.util.Providers;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.lease.Releasables;
|
||||
import org.elasticsearch.common.logging.DeprecationLogger;
|
||||
|
@ -68,7 +71,6 @@ import org.elasticsearch.common.transport.BoundTransportAddress;
|
|||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.util.BigArrays;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.discovery.Discovery;
|
||||
import org.elasticsearch.discovery.DiscoveryModule;
|
||||
import org.elasticsearch.discovery.DiscoverySettings;
|
||||
|
@ -102,6 +104,7 @@ import org.elasticsearch.plugins.ClusterPlugin;
|
|||
import org.elasticsearch.plugins.DiscoveryPlugin;
|
||||
import org.elasticsearch.plugins.IngestPlugin;
|
||||
import org.elasticsearch.plugins.MapperPlugin;
|
||||
import org.elasticsearch.plugins.NetworkPlugin;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.plugins.MetaDataUpgrader;
|
||||
import org.elasticsearch.plugins.PluginsService;
|
||||
|
@ -122,6 +125,8 @@ import org.elasticsearch.snapshots.SnapshotsService;
|
|||
import org.elasticsearch.tasks.TaskResultsService;
|
||||
import org.elasticsearch.threadpool.ExecutorBuilder;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.Transport;
|
||||
import org.elasticsearch.transport.TransportInterceptor;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
import org.elasticsearch.tribe.TribeService;
|
||||
import org.elasticsearch.watcher.ResourceWatcherService;
|
||||
|
@ -144,6 +149,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -321,8 +327,6 @@ public class Node implements Closeable {
|
|||
}
|
||||
final MonitorService monitorService = new MonitorService(settings, nodeEnvironment, threadPool);
|
||||
modules.add(new NodeModule(this, monitorService));
|
||||
NetworkModule networkModule = createNetworkModule(settings, networkService);
|
||||
modules.add(networkModule);
|
||||
modules.add(new DiscoveryModule(this.settings));
|
||||
ClusterModule clusterModule = new ClusterModule(settings, clusterService,
|
||||
pluginsService.filterPlugins(ClusterPlugin.class));
|
||||
|
@ -330,9 +334,10 @@ public class Node implements Closeable {
|
|||
IndicesModule indicesModule = new IndicesModule(pluginsService.filterPlugins(MapperPlugin.class));
|
||||
modules.add(indicesModule);
|
||||
SearchModule searchModule = new SearchModule(settings, false, pluginsService.filterPlugins(SearchPlugin.class));
|
||||
modules.add(new ActionModule(DiscoveryNode.isIngestNode(settings), false, settings,
|
||||
ActionModule actionModule = new ActionModule(DiscoveryNode.isIngestNode(settings), false, settings,
|
||||
clusterModule.getIndexNameExpressionResolver(), settingsModule.getClusterSettings(),
|
||||
pluginsService.filterPlugins(ActionPlugin.class)));
|
||||
pluginsService.filterPlugins(ActionPlugin.class));
|
||||
modules.add(actionModule);
|
||||
modules.add(new GatewayModule());
|
||||
modules.add(new RepositoriesModule(this.environment, pluginsService.filterPlugins(RepositoryPlugin.class)));
|
||||
pluginsService.processModules(modules);
|
||||
|
@ -343,7 +348,7 @@ public class Node implements Closeable {
|
|||
resourcesToClose.add(bigArrays);
|
||||
modules.add(settingsModule);
|
||||
List<NamedWriteableRegistry.Entry> namedWriteables = Stream.of(
|
||||
networkModule.getNamedWriteables().stream(),
|
||||
NetworkModule.getNamedWriteables().stream(),
|
||||
indicesModule.getNamedWriteables().stream(),
|
||||
searchModule.getNamedWriteables().stream(),
|
||||
pluginsService.filterPlugins(Plugin.class).stream()
|
||||
|
@ -355,6 +360,7 @@ public class Node implements Closeable {
|
|||
settingsModule.getClusterSettings(), analysisModule.getAnalysisRegistry(), searchModule.getQueryParserRegistry(),
|
||||
clusterModule.getIndexNameExpressionResolver(), indicesModule.getMapperRegistry(), namedWriteableRegistry,
|
||||
threadPool, settingsModule.getIndexScopedSettings(), circuitBreakerService, metaStateService);
|
||||
|
||||
client = new NodeClient(settings, threadPool);
|
||||
Collection<Object> pluginComponents = pluginsService.filterPlugins(Plugin.class).stream()
|
||||
.flatMap(p -> p.createComponents(client, clusterService, threadPool, resourceWatcherService,
|
||||
|
@ -364,8 +370,26 @@ public class Node implements Closeable {
|
|||
pluginsService.filterPlugins(Plugin.class).stream()
|
||||
.map(Plugin::getCustomMetaDataUpgrader)
|
||||
.collect(Collectors.toList());
|
||||
final NetworkModule networkModule = new NetworkModule(settings, false, pluginsService.filterPlugins(NetworkPlugin.class), threadPool,
|
||||
bigArrays, circuitBreakerService, namedWriteableRegistry, networkService);
|
||||
final MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(customMetaDataUpgraders);
|
||||
|
||||
final Transport transport = networkModule.getTransportSupplier().get();
|
||||
final TransportService transportService = newTransportService(settings, transport, threadPool,
|
||||
networkModule.getTransportInterceptor());
|
||||
final Consumer<Binder> httpBind;
|
||||
if (networkModule.isHttpEnabled()) {
|
||||
HttpServerTransport httpServerTransport = networkModule.getHttpServerTransportSupplier().get();
|
||||
HttpServer httpServer = new HttpServer(settings, httpServerTransport, actionModule.getRestController(), client,
|
||||
circuitBreakerService);
|
||||
httpBind = b -> {
|
||||
b.bind(HttpServer.class).toInstance(httpServer);
|
||||
b.bind(HttpServerTransport.class).toInstance(httpServerTransport);
|
||||
};
|
||||
} else {
|
||||
httpBind = b -> {
|
||||
b.bind(HttpServer.class).toProvider(Providers.of(null));
|
||||
};
|
||||
}
|
||||
modules.add(b -> {
|
||||
b.bind(IndicesQueriesRegistry.class).toInstance(searchModule.getQueryParserRegistry());
|
||||
b.bind(SearchRequestParsers.class).toInstance(searchModule.getSearchRequestParsers());
|
||||
|
@ -389,8 +413,12 @@ public class Node implements Closeable {
|
|||
b.bind(IndicesService.class).toInstance(indicesService);
|
||||
b.bind(SearchService.class).toInstance(newSearchService(clusterService, indicesService,
|
||||
threadPool, scriptModule.getScriptService(), bigArrays, searchModule.getFetchPhase()));
|
||||
b.bind(Transport.class).toInstance(transport);
|
||||
b.bind(TransportService.class).toInstance(transportService);
|
||||
b.bind(NetworkService.class).toInstance(networkService);
|
||||
b.bind(AllocationCommandRegistry.class).toInstance(NetworkModule.getAllocationCommandRegistry());
|
||||
httpBind.accept(b);
|
||||
pluginComponents.stream().forEach(p -> b.bind((Class) p.getClass()).toInstance(p));
|
||||
|
||||
}
|
||||
);
|
||||
injector = modules.createInjector();
|
||||
|
@ -417,8 +445,9 @@ public class Node implements Closeable {
|
|||
}
|
||||
}
|
||||
|
||||
protected NetworkModule createNetworkModule(Settings settings, NetworkService networkService) {
|
||||
return new NetworkModule(networkService, settings, false);
|
||||
protected TransportService newTransportService(Settings settings, Transport transport, ThreadPool threadPool,
|
||||
TransportInterceptor interceptor) {
|
||||
return new TransportService(settings, transport, threadPool, interceptor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -212,11 +212,11 @@ class InstallPluginCommand extends SettingCommand {
|
|||
final String stagingHash = System.getProperty(PROPERTY_STAGING_ID);
|
||||
if (stagingHash != null) {
|
||||
url = String.format(Locale.ROOT,
|
||||
"https://staging.elastic.co/%3$s-%1$s/download/elasticsearch-plugins/%2$s/%2$s-%3$s.zip",
|
||||
"https://staging.elastic.co/%3$s-%1$s/downloads/elasticsearch-plugins/%2$s/%2$s-%3$s.zip",
|
||||
stagingHash, pluginId, version);
|
||||
} else {
|
||||
url = String.format(Locale.ROOT,
|
||||
"https://artifacts.elastic.co/download/elasticsearch-plugins/%1$s/%1$s-%2$s.zip",
|
||||
"https://artifacts.elastic.co/downloads/elasticsearch-plugins/%1$s/%1$s-%2$s.zip",
|
||||
pluginId, version);
|
||||
}
|
||||
terminal.println("-> Downloading " + pluginId + " from elastic");
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.plugins;
|
||||
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.network.NetworkService;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.BigArrays;
|
||||
import org.elasticsearch.http.HttpServerTransport;
|
||||
import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.Transport;
|
||||
import org.elasticsearch.transport.TransportInterceptor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Plugin for extending network and transport related classes
|
||||
*/
|
||||
public interface NetworkPlugin {
|
||||
|
||||
/**
|
||||
* Returns a list of {@link TransportInterceptor} instances that are used to intercept incoming and outgoing
|
||||
* transport (inter-node) requests. This must not return <code>null</code>
|
||||
*/
|
||||
default List<TransportInterceptor> getTransportInterceptors() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of {@link Transport} suppliers.
|
||||
* See {@link org.elasticsearch.common.network.NetworkModule#TRANSPORT_TYPE_KEY} to configure a specific implementation.
|
||||
*/
|
||||
default Map<String, Supplier<Transport>> getTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays,
|
||||
CircuitBreakerService circuitBreakerService,
|
||||
NamedWriteableRegistry namedWriteableRegistry,
|
||||
NetworkService networkService) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
/**
|
||||
* Returns a map of {@link HttpServerTransport} suppliers.
|
||||
* See {@link org.elasticsearch.common.network.NetworkModule#HTTP_TYPE_SETTING} to configure a specific implementation.
|
||||
*/
|
||||
default Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays,
|
||||
CircuitBreakerService circuitBreakerService,
|
||||
NamedWriteableRegistry namedWriteableRegistry,
|
||||
NetworkService networkService) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@ import org.elasticsearch.common.component.LifecycleComponent;
|
|||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteable;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.SettingsModule;
|
||||
|
@ -189,6 +190,14 @@ public abstract class Plugin {
|
|||
@Deprecated
|
||||
public final void onModule(SearchModule module) {}
|
||||
|
||||
/**
|
||||
* Old-style action extension point.
|
||||
*
|
||||
* @deprecated implement {@link NetworkPlugin} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public final void onModule(NetworkModule module) {}
|
||||
|
||||
/**
|
||||
* Provides the list of this plugin's custom thread pools, empty if
|
||||
* none.
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.rest.action.cat;
|
||||
|
||||
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
||||
import org.elasticsearch.client.node.NodeClient;
|
||||
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.common.Table;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.regex.Regex;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.RestResponse;
|
||||
import org.elasticsearch.rest.action.RestResponseListener;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
|
||||
public class RestTemplatesAction extends AbstractCatAction {
|
||||
@Inject
|
||||
public RestTemplatesAction(Settings settings, RestController controller) {
|
||||
super(settings);
|
||||
controller.registerHandler(GET, "/_cat/templates", this);
|
||||
controller.registerHandler(GET, "/_cat/templates/{name}", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void documentation(StringBuilder sb) {
|
||||
sb.append("/_cat/templates\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doRequest(final RestRequest request, RestChannel channel, NodeClient client) {
|
||||
final String matchPattern = request.hasParam("name") ? request.param("name") : null;
|
||||
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.clear().metaData(true);
|
||||
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
|
||||
clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
|
||||
|
||||
client.admin().cluster().state(clusterStateRequest, new RestResponseListener<ClusterStateResponse>(channel) {
|
||||
@Override
|
||||
public RestResponse buildResponse(ClusterStateResponse clusterStateResponse) throws Exception {
|
||||
return RestTable.buildResponse(buildTable(request, clusterStateResponse, matchPattern), channel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Table getTableWithHeader(RestRequest request) {
|
||||
Table table = new Table();
|
||||
table.startHeaders();
|
||||
table.addCell("name", "alias:n;desc:template name");
|
||||
table.addCell("template", "alias:t;desc:template pattern string");
|
||||
table.addCell("order", "alias:o;desc:template application order number");
|
||||
table.addCell("version", "alias:v;desc:version");
|
||||
table.endHeaders();
|
||||
return table;
|
||||
}
|
||||
|
||||
private Table buildTable(RestRequest request, ClusterStateResponse clusterStateResponse, String patternString) {
|
||||
Table table = getTableWithHeader(request);
|
||||
MetaData metadata = clusterStateResponse.getState().metaData();
|
||||
for (ObjectObjectCursor<String, IndexTemplateMetaData> entry : metadata.templates()) {
|
||||
IndexTemplateMetaData indexData = entry.value;
|
||||
if (patternString == null || Regex.simpleMatch(patternString, indexData.name())) {
|
||||
table.startRow();
|
||||
table.addCell(indexData.name());
|
||||
table.addCell(indexData.getTemplate());
|
||||
table.addCell(indexData.getOrder());
|
||||
table.addCell(indexData.getVersion());
|
||||
table.endRow();
|
||||
}
|
||||
}
|
||||
return table;
|
||||
}
|
||||
}
|
|
@ -47,7 +47,6 @@ import org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource;
|
|||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.UUIDs;
|
||||
|
@ -336,10 +335,7 @@ public class RestoreService extends AbstractComponent implements ClusterStateLis
|
|||
|
||||
RoutingTable rt = rtBuilder.build();
|
||||
ClusterState updatedState = builder.metaData(mdBuilder).blocks(blocks).routingTable(rt).build();
|
||||
RoutingAllocation.Result routingResult = allocationService.reroute(
|
||||
ClusterState.builder(updatedState).routingTable(rt).build(),
|
||||
"restored snapshot [" + snapshot + "]");
|
||||
return ClusterState.builder(updatedState).routingResult(routingResult).build();
|
||||
return allocationService.reroute(updatedState, "restored snapshot [" + snapshot + "]");
|
||||
}
|
||||
|
||||
private void checkAliasNameConflicts(Map<String, String> renamedIndices, Set<String> aliases) {
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.elasticsearch.common.breaker.CircuitBreaker;
|
|||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.common.component.Lifecycle;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
|
@ -91,7 +90,6 @@ public class LocalTransport extends AbstractLifecycleComponent implements Transp
|
|||
public static final String TRANSPORT_LOCAL_WORKERS = "transport.local.workers";
|
||||
public static final String TRANSPORT_LOCAL_QUEUE = "transport.local.queue";
|
||||
|
||||
@Inject
|
||||
public LocalTransport(Settings settings, ThreadPool threadPool,
|
||||
NamedWriteableRegistry namedWriteableRegistry, CircuitBreakerService circuitBreakerService) {
|
||||
super(settings);
|
||||
|
|
|
@ -78,9 +78,9 @@ import org.elasticsearch.action.update.UpdateAction;
|
|||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.action.update.UpdateResponse;
|
||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.plugins.NetworkPlugin;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.plugins.PluginsService;
|
||||
import org.elasticsearch.script.MockScriptPlugin;
|
||||
|
@ -739,10 +739,11 @@ public class IndicesRequestIT extends ESIntegTestCase {
|
|||
|
||||
public static class InterceptingTransportService implements TransportInterceptor {
|
||||
|
||||
public static class TestPlugin extends Plugin {
|
||||
public static class TestPlugin extends Plugin implements NetworkPlugin {
|
||||
public final InterceptingTransportService instance = new InterceptingTransportService();
|
||||
public void onModule(NetworkModule module) {
|
||||
module.addTransportInterceptor(instance);
|
||||
@Override
|
||||
public List<TransportInterceptor> getTransportInterceptors() {
|
||||
return Collections.singletonList(instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@ import org.elasticsearch.test.rest.FakeRestRequest;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -74,9 +73,8 @@ public class ClusterRerouteRequestTests extends ESTestCase {
|
|||
private final AllocationCommandRegistry allocationCommandRegistry;
|
||||
|
||||
public ClusterRerouteRequestTests() {
|
||||
NetworkModule networkModule = new NetworkModule(null, null, true);
|
||||
allocationCommandRegistry = networkModule.getAllocationCommandRegistry();
|
||||
namedWriteableRegistry = new NamedWriteableRegistry(networkModule.getNamedWriteables());
|
||||
allocationCommandRegistry = NetworkModule.getAllocationCommandRegistry();
|
||||
namedWriteableRegistry = new NamedWriteableRegistry(NetworkModule.getNamedWriteables());
|
||||
}
|
||||
|
||||
private ClusterRerouteRequest randomRequest() {
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.cluster.reroute;
|
|||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.EmptyClusterInfoService;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
|
@ -28,7 +29,6 @@ import org.elasticsearch.cluster.node.DiscoveryNodes;
|
|||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.FailedRerouteAllocation;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
|
||||
import org.elasticsearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand;
|
||||
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
|
||||
|
@ -41,7 +41,6 @@ import org.elasticsearch.common.io.stream.StreamInput;
|
|||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.test.gateway.NoopGatewayAllocator;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -51,6 +50,8 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
public class ClusterRerouteTests extends ESAllocationTestCase {
|
||||
|
||||
|
@ -64,8 +65,7 @@ public class ClusterRerouteTests extends ESAllocationTestCase {
|
|||
BytesStreamOutput out = new BytesStreamOutput();
|
||||
req.writeTo(out);
|
||||
BytesReference bytes = out.bytes();
|
||||
NetworkModule networkModule = new NetworkModule(null, Settings.EMPTY, true);
|
||||
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(networkModule.getNamedWriteables());
|
||||
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(NetworkModule.getNamedWriteables());
|
||||
StreamInput wrap = new NamedWriteableAwareStreamInput(bytes.streamInput(),
|
||||
namedWriteableRegistry);
|
||||
ClusterRerouteRequest deserializedReq = new ClusterRerouteRequest();
|
||||
|
@ -121,9 +121,9 @@ public class ClusterRerouteTests extends ESAllocationTestCase {
|
|||
List<FailedRerouteAllocation.FailedShard> failedShards = Collections.singletonList(
|
||||
new FailedRerouteAllocation.FailedShard(routingTable.index("idx").shard(0).shards().get(0), "boom" + i,
|
||||
new UnsupportedOperationException()));
|
||||
RoutingAllocation.Result result = allocationService.applyFailedShards(clusterState, failedShards);
|
||||
assertTrue(result.changed());
|
||||
clusterState = ClusterState.builder(clusterState).routingTable(result.routingTable()).build();
|
||||
newState = allocationService.applyFailedShards(clusterState, failedShards);
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingTable = clusterState.routingTable();
|
||||
assertEquals(routingTable.index("idx").shards().size(), 1);
|
||||
if (i == retries-1) {
|
||||
|
|
|
@ -20,8 +20,11 @@ package org.elasticsearch.action.index;
|
|||
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.support.ActiveShardCount;
|
||||
import org.elasticsearch.action.support.replication.ReplicationResponse;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.VersionType;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -150,4 +153,34 @@ public class IndexRequestTests extends ESTestCase {
|
|||
request.process(null, true, "index");
|
||||
assertEquals(IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, request.getAutoGeneratedTimestamp());
|
||||
}
|
||||
|
||||
public void testIndexResponse() {
|
||||
ShardId shardId = new ShardId(randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10), randomIntBetween(0, 1000));
|
||||
String type = randomAsciiOfLengthBetween(3, 10);
|
||||
String id = randomAsciiOfLengthBetween(3, 10);
|
||||
long version = randomLong();
|
||||
boolean created = randomBoolean();
|
||||
IndexResponse indexResponse = new IndexResponse(shardId, type, id, version, created);
|
||||
int total = randomIntBetween(1, 10);
|
||||
int successful = randomIntBetween(1, 10);
|
||||
ReplicationResponse.ShardInfo shardInfo = new ReplicationResponse.ShardInfo(total, successful);
|
||||
indexResponse.setShardInfo(shardInfo);
|
||||
boolean forcedRefresh = false;
|
||||
if (randomBoolean()) {
|
||||
forcedRefresh = randomBoolean();
|
||||
indexResponse.setForcedRefresh(forcedRefresh);
|
||||
}
|
||||
assertEquals(type, indexResponse.getType());
|
||||
assertEquals(id, indexResponse.getId());
|
||||
assertEquals(version, indexResponse.getVersion());
|
||||
assertEquals(shardId, indexResponse.getShardId());
|
||||
assertEquals(created ? RestStatus.CREATED : RestStatus.OK, indexResponse.status());
|
||||
assertEquals(total, indexResponse.getShardInfo().getTotal());
|
||||
assertEquals(successful, indexResponse.getShardInfo().getSuccessful());
|
||||
assertEquals(forcedRefresh, indexResponse.forcedRefresh());
|
||||
assertEquals("IndexResponse[index=" + shardId.getIndexName() + ",type=" + type + ",id="+ id +
|
||||
",version=" + version + ",result=" + (created ? "created" : "updated") +
|
||||
",shards={\"_shards\":{\"total\":" + total + ",\"successful\":" + successful + ",\"failed\":0}}]",
|
||||
indexResponse.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ import org.elasticsearch.cluster.routing.ShardRouting;
|
|||
import org.elasticsearch.cluster.routing.ShardRoutingState;
|
||||
import org.elasticsearch.cluster.routing.TestShardRouting;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
|
@ -296,8 +295,7 @@ public class TransportReplicationActionTests extends ESTestCase {
|
|||
ShardRouting relocationTarget = clusterService.state().getRoutingTable().shardRoutingTable(shardId)
|
||||
.shardsWithState(ShardRoutingState.INITIALIZING).get(0);
|
||||
AllocationService allocationService = ESAllocationTestCase.createAllocationService();
|
||||
RoutingAllocation.Result result = allocationService.applyStartedShards(state, Arrays.asList(relocationTarget));
|
||||
ClusterState updatedState = ClusterState.builder(clusterService.state()).routingResult(result).build();
|
||||
ClusterState updatedState = allocationService.applyStartedShards(state, Arrays.asList(relocationTarget));
|
||||
|
||||
setState(clusterService, updatedState);
|
||||
logger.debug("--> relocation complete state:\n{}", clusterService.state().prettyPrint());
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.lucene.util.Constants;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.BoundTransportAddress;
|
||||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.monitor.jvm.JvmInfo;
|
||||
import org.elasticsearch.node.NodeValidationException;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
|
@ -407,6 +408,27 @@ public class BootstrapCheckTests extends ESTestCase {
|
|||
BootstrapCheck.check(true, false, Collections.singletonList(check), "testClientJvmCheck");
|
||||
}
|
||||
|
||||
public void testUseSerialGCCheck() throws NodeValidationException {
|
||||
final AtomicReference<String> useSerialGC = new AtomicReference<>("true");
|
||||
final BootstrapCheck.Check check = new BootstrapCheck.UseSerialGCCheck() {
|
||||
@Override
|
||||
String getUseSerialGC() {
|
||||
return useSerialGC.get();
|
||||
}
|
||||
};
|
||||
|
||||
final NodeValidationException e = expectThrows(
|
||||
NodeValidationException.class,
|
||||
() -> BootstrapCheck.check(true, false, Collections.singletonList(check), "testUseSerialGCCheck"));
|
||||
assertThat(
|
||||
e.getMessage(),
|
||||
containsString("JVM is using the serial collector but should not be for the best performance; " + "" +
|
||||
"either it's the default for the VM [" + JvmInfo.jvmInfo().getVmName() +"] or -XX:+UseSerialGC was explicitly specified"));
|
||||
|
||||
useSerialGC.set("false");
|
||||
BootstrapCheck.check(true, false, Collections.singletonList(check), "testUseSerialGCCheck");
|
||||
}
|
||||
|
||||
public void testMightForkCheck() throws NodeValidationException {
|
||||
final AtomicBoolean isSeccompInstalled = new AtomicBoolean();
|
||||
final AtomicBoolean mightFork = new AtomicBoolean();
|
||||
|
|
|
@ -31,10 +31,10 @@ import org.elasticsearch.cluster.ClusterName;
|
|||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.plugins.NetworkPlugin;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.plugins.PluginsService;
|
||||
import org.elasticsearch.test.transport.MockTransportService;
|
||||
|
@ -49,6 +49,7 @@ import org.elasticsearch.transport.TransportResponse;
|
|||
import org.elasticsearch.transport.TransportResponseHandler;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -115,11 +116,12 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTestCase {
|
|||
TransportAddress address;
|
||||
|
||||
|
||||
public static class TestPlugin extends Plugin {
|
||||
public static class TestPlugin extends Plugin implements NetworkPlugin {
|
||||
private InternalTransportServiceInterceptor instance = new InternalTransportServiceInterceptor();
|
||||
|
||||
public void onModule(NetworkModule transportModule) {
|
||||
transportModule.addTransportInterceptor(new TransportInterceptor() {
|
||||
@Override
|
||||
public List<TransportInterceptor> getTransportInterceptors() {
|
||||
return Collections.singletonList(new TransportInterceptor() {
|
||||
@Override
|
||||
public <T extends TransportRequest> TransportRequestHandler<T> interceptHandler(String action,
|
||||
TransportRequestHandler<T> actualHandler) {
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.elasticsearch.cluster.routing.ShardRoutingState;
|
|||
import org.elasticsearch.cluster.routing.TestShardRouting;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.FailedRerouteAllocation;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
|
||||
import org.elasticsearch.common.UUIDs;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -116,7 +115,7 @@ public class ShardFailedClusterStateTaskExecutorTests extends ESAllocationTestCa
|
|||
List<ShardStateAction.ShardEntry> nonExistentTasks = createNonExistentShards(currentState, reason);
|
||||
ShardStateAction.ShardFailedClusterStateTaskExecutor failingExecutor = new ShardStateAction.ShardFailedClusterStateTaskExecutor(allocationService, null, logger) {
|
||||
@Override
|
||||
RoutingAllocation.Result applyFailedShards(ClusterState currentState, List<FailedRerouteAllocation.FailedShard> failedShards,
|
||||
ClusterState applyFailedShards(ClusterState currentState, List<FailedRerouteAllocation.FailedShard> failedShards,
|
||||
List<FailedRerouteAllocation.StaleShard> staleShards) {
|
||||
throw new RuntimeException("simulated applyFailedShards failure");
|
||||
}
|
||||
|
@ -161,8 +160,7 @@ public class ShardFailedClusterStateTaskExecutorTests extends ESAllocationTestCa
|
|||
allocationService.reroute(stateAfterAddingNode, reason).routingTable();
|
||||
ClusterState stateAfterReroute = ClusterState.builder(stateAfterAddingNode).routingTable(afterReroute).build();
|
||||
RoutingNodes routingNodes = stateAfterReroute.getRoutingNodes();
|
||||
RoutingAllocation.Result afterStart = allocationService.applyStartedShards(stateAfterReroute, routingNodes.shardsWithState(ShardRoutingState.INITIALIZING));
|
||||
return ClusterState.builder(stateAfterReroute).routingResult(afterStart).build();
|
||||
return allocationService.applyStartedShards(stateAfterReroute, routingNodes.shardsWithState(ShardRoutingState.INITIALIZING));
|
||||
}
|
||||
|
||||
private List<ShardStateAction.ShardEntry> createExistingShards(ClusterState currentState, String reason) {
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.elasticsearch.cluster.SnapshotsInProgress;
|
|||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.Index;
|
||||
|
@ -76,8 +75,7 @@ public class MetaDataDeleteIndexServiceTests extends ESTestCase {
|
|||
ClusterState before = clusterState(index);
|
||||
|
||||
// Mock the built reroute
|
||||
when(allocationService.reroute(any(ClusterState.class), any(String.class))).then(
|
||||
i -> RoutingAllocation.Result.unchanged((ClusterState) i.getArguments()[0]));
|
||||
when(allocationService.reroute(any(ClusterState.class), any(String.class))).then(i -> i.getArguments()[0]);
|
||||
|
||||
// Remove it
|
||||
ClusterState after = service.deleteIndices(before, singleton(before.metaData().getIndices().get(index).getIndex()));
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.cluster.ClusterChangedEvent;
|
|||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ClusterStateUpdateTask;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
|
@ -32,7 +33,6 @@ import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
|||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.threadpool.TestThreadPool;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.junit.After;
|
||||
|
@ -92,15 +92,11 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState)
|
||||
.nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).localNodeId("node1").masterNodeId("node1"))
|
||||
.build();
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocationService.reroute(clusterState, "reroute")).build();
|
||||
clusterState = allocationService.reroute(clusterState, "reroute");
|
||||
// starting primaries
|
||||
clusterState = ClusterState.builder(clusterState)
|
||||
.routingResult(allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)))
|
||||
.build();
|
||||
clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
// starting replicas
|
||||
clusterState = ClusterState.builder(clusterState)
|
||||
.routingResult(allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)))
|
||||
.build();
|
||||
clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(false));
|
||||
ClusterState prevState = clusterState;
|
||||
// remove node2 and reroute
|
||||
|
@ -110,8 +106,7 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
|
|||
nodes.add(newNode("node3"));
|
||||
}
|
||||
clusterState = ClusterState.builder(clusterState).nodes(nodes).build();
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(
|
||||
allocationService.deassociateDeadNodes(clusterState, true, "reroute")).build();
|
||||
clusterState = allocationService.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
ClusterState newState = clusterState;
|
||||
List<ShardRouting> unassignedShards = newState.getRoutingTable().shardsWithState(ShardRoutingState.UNASSIGNED);
|
||||
if (nodeAvailableForAllocation) {
|
||||
|
@ -141,15 +136,11 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
|
|||
.build();
|
||||
final long baseTimestampNanos = System.nanoTime();
|
||||
allocationService.setNanoTimeOverride(baseTimestampNanos);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocationService.reroute(clusterState, "reroute")).build();
|
||||
clusterState = allocationService.reroute(clusterState, "reroute");
|
||||
// starting primaries
|
||||
clusterState = ClusterState.builder(clusterState)
|
||||
.routingResult(allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)))
|
||||
.build();
|
||||
clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
// starting replicas
|
||||
clusterState = ClusterState.builder(clusterState)
|
||||
.routingResult(allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)))
|
||||
.build();
|
||||
clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertFalse("no shards should be unassigned", clusterState.getRoutingNodes().unassigned().size() > 0);
|
||||
String nodeId = null;
|
||||
final List<ShardRouting> allShards = clusterState.getRoutingTable().allShards("test");
|
||||
|
@ -164,8 +155,7 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
|
|||
|
||||
// remove node that has replica and reroute
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove(nodeId)).build();
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(
|
||||
allocationService.deassociateDeadNodes(clusterState, true, "reroute")).build();
|
||||
clusterState = allocationService.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
ClusterState stateWithDelayedShard = clusterState;
|
||||
// make sure the replica is marked as delayed (i.e. not reallocated)
|
||||
assertEquals(1, UnassignedInfo.getNumberOfDelayedUnassigned(stateWithDelayedShard));
|
||||
|
@ -238,15 +228,11 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
|
|||
.add(newNode("node0", singleton(DiscoveryNode.Role.MASTER))).localNodeId("node0").masterNodeId("node0")
|
||||
.add(newNode("node1")).add(newNode("node2")).add(newNode("node3")).add(newNode("node4"))).build();
|
||||
// allocate shards
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocationService.reroute(clusterState, "reroute")).build();
|
||||
clusterState = allocationService.reroute(clusterState, "reroute");
|
||||
// start primaries
|
||||
clusterState = ClusterState.builder(clusterState)
|
||||
.routingResult(allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)))
|
||||
.build();
|
||||
clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
// start replicas
|
||||
clusterState = ClusterState.builder(clusterState)
|
||||
.routingResult(allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)))
|
||||
.build();
|
||||
clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat("all shards should be started", clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(4));
|
||||
|
||||
// find replica of short_delay
|
||||
|
@ -280,8 +266,7 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
|
|||
.build();
|
||||
// make sure both replicas are marked as delayed (i.e. not reallocated)
|
||||
allocationService.setNanoTimeOverride(baseTimestampNanos);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(
|
||||
allocationService.deassociateDeadNodes(clusterState, true, "reroute")).build();
|
||||
clusterState = allocationService.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
final ClusterState stateWithDelayedShards = clusterState;
|
||||
assertEquals(2, UnassignedInfo.getNumberOfDelayedUnassigned(stateWithDelayedShards));
|
||||
RoutingNodes.UnassignedShards.UnassignedIterator iter = stateWithDelayedShards.getRoutingNodes().unassigned().iterator();
|
||||
|
@ -400,15 +385,11 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
|
|||
.build();
|
||||
final long nodeLeftTimestampNanos = System.nanoTime();
|
||||
allocationService.setNanoTimeOverride(nodeLeftTimestampNanos);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocationService.reroute(clusterState, "reroute")).build();
|
||||
clusterState = allocationService.reroute(clusterState, "reroute");
|
||||
// starting primaries
|
||||
clusterState = ClusterState.builder(clusterState)
|
||||
.routingResult(allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)))
|
||||
.build();
|
||||
clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
// starting replicas
|
||||
clusterState = ClusterState.builder(clusterState)
|
||||
.routingResult(allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)))
|
||||
.build();
|
||||
clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertFalse("no shards should be unassigned", clusterState.getRoutingNodes().unassigned().size() > 0);
|
||||
String nodeIdOfFooReplica = null;
|
||||
for (ShardRouting shardRouting : clusterState.getRoutingTable().allShards("foo")) {
|
||||
|
@ -422,8 +403,7 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
|
|||
// remove node that has replica and reroute
|
||||
clusterState = ClusterState.builder(clusterState).nodes(
|
||||
DiscoveryNodes.builder(clusterState.nodes()).remove(nodeIdOfFooReplica)).build();
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(
|
||||
allocationService.deassociateDeadNodes(clusterState, true, "fake node left")).build();
|
||||
clusterState = allocationService.deassociateDeadNodes(clusterState, true, "fake node left");
|
||||
ClusterState stateWithDelayedShard = clusterState;
|
||||
// make sure the replica is marked as delayed (i.e. not reallocated)
|
||||
assertEquals(1, UnassignedInfo.getNumberOfDelayedUnassigned(stateWithDelayedShard));
|
||||
|
@ -466,8 +446,7 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
|
|||
// remove node that has replica and reroute
|
||||
clusterState = ClusterState.builder(stateWithDelayedShard).nodes(
|
||||
DiscoveryNodes.builder(stateWithDelayedShard.nodes()).remove(nodeIdOfBarReplica)).build();
|
||||
ClusterState stateWithShorterDelay = ClusterState.builder(clusterState).routingResult(
|
||||
allocationService.deassociateDeadNodes(clusterState, true, "fake node left")).build();
|
||||
ClusterState stateWithShorterDelay = allocationService.deassociateDeadNodes(clusterState, true, "fake node left");
|
||||
delayedAllocationService.setNanoTimeOverride(clusterChangeEventTimestampNanos);
|
||||
delayedAllocationService.clusterChanged(
|
||||
new ClusterChangedEvent("fake node left", stateWithShorterDelay, stateWithDelayedShard));
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.cluster.routing;
|
|||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.health.ClusterStateHealth;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
|
@ -28,9 +29,7 @@ import org.elasticsearch.cluster.node.DiscoveryNodes;
|
|||
import org.elasticsearch.cluster.node.DiscoveryNodes.Builder;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.FailedRerouteAllocation;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -42,13 +41,12 @@ import java.util.Set;
|
|||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
public class PrimaryTermsTests extends ESAllocationTestCase {
|
||||
|
||||
private static final String TEST_INDEX_1 = "test1";
|
||||
private static final String TEST_INDEX_2 = "test2";
|
||||
private RoutingTable testRoutingTable;
|
||||
private int numberOfShards;
|
||||
private int numberOfReplicas;
|
||||
private static final Settings DEFAULT_SETTINGS = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
|
||||
|
@ -73,7 +71,7 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
|
|||
.put(createIndexMetaData(TEST_INDEX_2))
|
||||
.build();
|
||||
|
||||
this.testRoutingTable = new RoutingTable.Builder()
|
||||
RoutingTable routingTable = new RoutingTable.Builder()
|
||||
.add(new IndexRoutingTable.Builder(metaData.index(TEST_INDEX_1).getIndex()).initializeAsNew(metaData.index(TEST_INDEX_1))
|
||||
.build())
|
||||
.add(new IndexRoutingTable.Builder(metaData.index(TEST_INDEX_2).getIndex()).initializeAsNew(metaData.index(TEST_INDEX_2))
|
||||
|
@ -81,7 +79,7 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
|
|||
.build();
|
||||
|
||||
this.clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
|
||||
.metaData(metaData).routingTable(testRoutingTable).build();
|
||||
.metaData(metaData).routingTable(routingTable).build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,9 +92,8 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
|
|||
discoBuilder = discoBuilder.add(newNode("node" + i));
|
||||
}
|
||||
this.clusterState = ClusterState.builder(clusterState).nodes(discoBuilder).build();
|
||||
RoutingAllocation.Result rerouteResult = allocationService.reroute(clusterState, "reroute");
|
||||
this.testRoutingTable = rerouteResult.routingTable();
|
||||
assertThat(rerouteResult.changed(), is(true));
|
||||
ClusterState rerouteResult = allocationService.reroute(clusterState, "reroute");
|
||||
assertThat(rerouteResult, not(equalTo(this.clusterState)));
|
||||
applyRerouteResult(rerouteResult);
|
||||
primaryTermsPerIndex.keySet().forEach(this::incrementPrimaryTerm);
|
||||
}
|
||||
|
@ -113,17 +110,16 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
|
|||
}
|
||||
|
||||
private boolean startInitializingShards(String index) {
|
||||
this.clusterState = ClusterState.builder(clusterState).routingTable(this.testRoutingTable).build();
|
||||
final List<ShardRouting> startedShards = this.clusterState.getRoutingNodes().shardsWithState(index, INITIALIZING);
|
||||
logger.info("start primary shards for index [{}]: {} ", index, startedShards);
|
||||
RoutingAllocation.Result rerouteResult = allocationService.applyStartedShards(this.clusterState, startedShards);
|
||||
ClusterState rerouteResult = allocationService.applyStartedShards(this.clusterState, startedShards);
|
||||
boolean changed = rerouteResult.equals(this.clusterState) == false;
|
||||
applyRerouteResult(rerouteResult);
|
||||
return rerouteResult.changed();
|
||||
return changed;
|
||||
}
|
||||
|
||||
private void applyRerouteResult(RoutingAllocation.Result rerouteResult) {
|
||||
private void applyRerouteResult(ClusterState newClusterState) {
|
||||
ClusterState previousClusterState = this.clusterState;
|
||||
ClusterState newClusterState = ClusterState.builder(previousClusterState).routingResult(rerouteResult).build();
|
||||
ClusterState.Builder builder = ClusterState.builder(newClusterState).incrementVersion();
|
||||
if (previousClusterState.routingTable() != newClusterState.routingTable()) {
|
||||
builder.routingTable(RoutingTable.builder(newClusterState.routingTable()).version(newClusterState.routingTable().version() + 1)
|
||||
|
@ -133,7 +129,6 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
|
|||
builder.metaData(MetaData.builder(newClusterState.metaData()).version(newClusterState.metaData().version() + 1));
|
||||
}
|
||||
this.clusterState = builder.build();
|
||||
this.testRoutingTable = rerouteResult.routingTable();
|
||||
final ClusterStateHealth clusterHealth = new ClusterStateHealth(clusterState);
|
||||
logger.info("applied reroute. active shards: p [{}], t [{}], init shards: [{}], relocating: [{}]",
|
||||
clusterHealth.getActivePrimaryShards(), clusterHealth.getActiveShards(),
|
||||
|
@ -141,8 +136,7 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
|
|||
}
|
||||
|
||||
private void failSomePrimaries(String index) {
|
||||
this.clusterState = ClusterState.builder(clusterState).routingTable(this.testRoutingTable).build();
|
||||
final IndexRoutingTable indexShardRoutingTable = testRoutingTable.index(index);
|
||||
final IndexRoutingTable indexShardRoutingTable = clusterState.routingTable().index(index);
|
||||
Set<Integer> shardIdsToFail = new HashSet<>();
|
||||
for (int i = 1 + randomInt(numberOfShards - 1); i > 0; i--) {
|
||||
shardIdsToFail.add(randomInt(numberOfShards - 1));
|
||||
|
@ -153,9 +147,7 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
|
|||
failedShards.add(new FailedRerouteAllocation.FailedShard(indexShardRoutingTable.shard(shard).primaryShard(), "test", null));
|
||||
incrementPrimaryTerm(index, shard); // the primary failure should increment the primary term;
|
||||
}
|
||||
RoutingAllocation.Result rerouteResult = allocationService.applyFailedShards(this.clusterState, failedShards,
|
||||
Collections.emptyList());
|
||||
applyRerouteResult(rerouteResult);
|
||||
applyRerouteResult(allocationService.applyFailedShards(this.clusterState, failedShards,Collections.emptyList()));
|
||||
}
|
||||
|
||||
private void addNodes() {
|
||||
|
@ -166,8 +158,7 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
|
|||
nodesBuilder.add(newNode("extra_" + i));
|
||||
}
|
||||
this.clusterState = ClusterState.builder(clusterState).nodes(nodesBuilder).build();
|
||||
RoutingAllocation.Result rerouteResult = allocationService.reroute(this.clusterState, "nodes added");
|
||||
applyRerouteResult(rerouteResult);
|
||||
applyRerouteResult(allocationService.reroute(this.clusterState, "nodes added"));
|
||||
|
||||
}
|
||||
|
||||
|
@ -191,7 +182,7 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
|
|||
private void assertPrimaryTerm(String index) {
|
||||
final long[] terms = primaryTermsPerIndex.get(index);
|
||||
final IndexMetaData indexMetaData = clusterState.metaData().index(index);
|
||||
for (IndexShardRoutingTable shardRoutingTable : this.testRoutingTable.index(index)) {
|
||||
for (IndexShardRoutingTable shardRoutingTable : this.clusterState.routingTable().index(index)) {
|
||||
final int shard = shardRoutingTable.shardId().id();
|
||||
assertThat("primary term mismatch between indexMetaData of [" + index + "] and shard [" + shard + "]'s routing",
|
||||
indexMetaData.primaryTerm(shard), equalTo(terms[shard]));
|
||||
|
|
|
@ -21,15 +21,14 @@ package org.elasticsearch.cluster.routing;
|
|||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes.Builder;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.IndexNotFoundException;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.util.Set;
|
||||
|
@ -37,7 +36,9 @@ import java.util.stream.Collectors;
|
|||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
public class RoutingTableTests extends ESAllocationTestCase {
|
||||
|
@ -45,7 +46,6 @@ public class RoutingTableTests extends ESAllocationTestCase {
|
|||
private static final String TEST_INDEX_1 = "test1";
|
||||
private static final String TEST_INDEX_2 = "test2";
|
||||
private RoutingTable emptyRoutingTable;
|
||||
private RoutingTable testRoutingTable;
|
||||
private int numberOfShards;
|
||||
private int numberOfReplicas;
|
||||
private int shardsPerIndex;
|
||||
|
@ -72,7 +72,7 @@ public class RoutingTableTests extends ESAllocationTestCase {
|
|||
.put(createIndexMetaData(TEST_INDEX_2))
|
||||
.build();
|
||||
|
||||
this.testRoutingTable = new RoutingTable.Builder()
|
||||
RoutingTable testRoutingTable = new RoutingTable.Builder()
|
||||
.add(new IndexRoutingTable.Builder(metaData.index(TEST_INDEX_1).getIndex()).initializeAsNew(metaData.index(TEST_INDEX_1)).build())
|
||||
.add(new IndexRoutingTable.Builder(metaData.index(TEST_INDEX_2).getIndex()).initializeAsNew(metaData.index(TEST_INDEX_2)).build())
|
||||
.build();
|
||||
|
@ -89,18 +89,14 @@ public class RoutingTableTests extends ESAllocationTestCase {
|
|||
discoBuilder = discoBuilder.add(newNode("node" + i));
|
||||
}
|
||||
this.clusterState = ClusterState.builder(clusterState).nodes(discoBuilder).build();
|
||||
RoutingAllocation.Result rerouteResult = ALLOCATION_SERVICE.reroute(clusterState, "reroute");
|
||||
this.testRoutingTable = rerouteResult.routingTable();
|
||||
assertThat(rerouteResult.changed(), is(true));
|
||||
this.clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
ClusterState rerouteResult = ALLOCATION_SERVICE.reroute(clusterState, "reroute");
|
||||
assertThat(rerouteResult, not(equalTo(this.clusterState)));
|
||||
this.clusterState = rerouteResult;
|
||||
}
|
||||
|
||||
private void startInitializingShards(String index) {
|
||||
this.clusterState = ClusterState.builder(clusterState).routingTable(this.testRoutingTable).build();
|
||||
logger.info("start primary shards for index {}", index);
|
||||
RoutingAllocation.Result rerouteResult = ALLOCATION_SERVICE.applyStartedShards(this.clusterState, this.clusterState.getRoutingNodes().shardsWithState(index, INITIALIZING));
|
||||
this.clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
this.testRoutingTable = rerouteResult.routingTable();
|
||||
this.clusterState = ALLOCATION_SERVICE.applyStartedShards(this.clusterState, this.clusterState.getRoutingNodes().shardsWithState(index, INITIALIZING));
|
||||
}
|
||||
|
||||
private IndexMetaData.Builder createIndexMetaData(String indexName) {
|
||||
|
@ -112,11 +108,11 @@ public class RoutingTableTests extends ESAllocationTestCase {
|
|||
|
||||
public void testAllShards() {
|
||||
assertThat(this.emptyRoutingTable.allShards().size(), is(0));
|
||||
assertThat(this.testRoutingTable.allShards().size(), is(this.totalNumberOfShards));
|
||||
assertThat(this.clusterState.routingTable().allShards().size(), is(this.totalNumberOfShards));
|
||||
|
||||
assertThat(this.testRoutingTable.allShards(TEST_INDEX_1).size(), is(this.shardsPerIndex));
|
||||
assertThat(this.clusterState.routingTable().allShards(TEST_INDEX_1).size(), is(this.shardsPerIndex));
|
||||
try {
|
||||
assertThat(this.testRoutingTable.allShards("not_existing").size(), is(0));
|
||||
assertThat(this.clusterState.routingTable().allShards("not_existing").size(), is(0));
|
||||
fail("Exception expected when calling allShards() with non existing index name");
|
||||
} catch (IndexNotFoundException e) {
|
||||
// expected
|
||||
|
@ -124,69 +120,69 @@ public class RoutingTableTests extends ESAllocationTestCase {
|
|||
}
|
||||
|
||||
public void testHasIndex() {
|
||||
assertThat(this.testRoutingTable.hasIndex(TEST_INDEX_1), is(true));
|
||||
assertThat(this.testRoutingTable.hasIndex("foobar"), is(false));
|
||||
assertThat(clusterState.routingTable().hasIndex(TEST_INDEX_1), is(true));
|
||||
assertThat(clusterState.routingTable().hasIndex("foobar"), is(false));
|
||||
}
|
||||
|
||||
public void testIndex() {
|
||||
assertThat(this.testRoutingTable.index(TEST_INDEX_1).getIndex().getName(), is(TEST_INDEX_1));
|
||||
assertThat(this.testRoutingTable.index("foobar"), is(nullValue()));
|
||||
assertThat(clusterState.routingTable().index(TEST_INDEX_1).getIndex().getName(), is(TEST_INDEX_1));
|
||||
assertThat(clusterState.routingTable().index("foobar"), is(nullValue()));
|
||||
}
|
||||
|
||||
public void testIndicesRouting() {
|
||||
assertThat(this.testRoutingTable.indicesRouting().size(), is(2));
|
||||
assertThat(this.testRoutingTable.getIndicesRouting().size(), is(2));
|
||||
assertSame(this.testRoutingTable.getIndicesRouting(), this.testRoutingTable.indicesRouting());
|
||||
assertThat(clusterState.routingTable().indicesRouting().size(), is(2));
|
||||
assertThat(clusterState.routingTable().getIndicesRouting().size(), is(2));
|
||||
assertSame(clusterState.routingTable().getIndicesRouting(), clusterState.routingTable().indicesRouting());
|
||||
}
|
||||
|
||||
public void testShardsWithState() {
|
||||
assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.UNASSIGNED).size(), is(this.totalNumberOfShards));
|
||||
assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.UNASSIGNED).size(), is(this.totalNumberOfShards));
|
||||
|
||||
initPrimaries();
|
||||
assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.UNASSIGNED).size(), is(this.totalNumberOfShards - 2 * this.numberOfShards));
|
||||
assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.INITIALIZING).size(), is(2 * this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.UNASSIGNED).size(), is(this.totalNumberOfShards - 2 * this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.INITIALIZING).size(), is(2 * this.numberOfShards));
|
||||
|
||||
startInitializingShards(TEST_INDEX_1);
|
||||
assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.STARTED).size(), is(this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.STARTED).size(), is(this.numberOfShards));
|
||||
int initializingExpected = this.numberOfShards + this.numberOfShards * this.numberOfReplicas;
|
||||
assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.INITIALIZING).size(), is(initializingExpected));
|
||||
assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.UNASSIGNED).size(), is(this.totalNumberOfShards - initializingExpected - this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.INITIALIZING).size(), is(initializingExpected));
|
||||
assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.UNASSIGNED).size(), is(this.totalNumberOfShards - initializingExpected - this.numberOfShards));
|
||||
|
||||
startInitializingShards(TEST_INDEX_2);
|
||||
assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.STARTED).size(), is(2 * this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.STARTED).size(), is(2 * this.numberOfShards));
|
||||
initializingExpected = 2 * this.numberOfShards * this.numberOfReplicas;
|
||||
assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.INITIALIZING).size(), is(initializingExpected));
|
||||
assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.UNASSIGNED).size(), is(this.totalNumberOfShards - initializingExpected - 2 * this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.INITIALIZING).size(), is(initializingExpected));
|
||||
assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.UNASSIGNED).size(), is(this.totalNumberOfShards - initializingExpected - 2 * this.numberOfShards));
|
||||
|
||||
// now start all replicas too
|
||||
startInitializingShards(TEST_INDEX_1);
|
||||
startInitializingShards(TEST_INDEX_2);
|
||||
assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.STARTED).size(), is(this.totalNumberOfShards));
|
||||
assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.STARTED).size(), is(this.totalNumberOfShards));
|
||||
}
|
||||
|
||||
public void testActivePrimaryShardsGrouped() {
|
||||
assertThat(this.emptyRoutingTable.activePrimaryShardsGrouped(new String[0], true).size(), is(0));
|
||||
assertThat(this.emptyRoutingTable.activePrimaryShardsGrouped(new String[0], false).size(), is(0));
|
||||
|
||||
assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
|
||||
assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
|
||||
assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.numberOfShards));
|
||||
|
||||
initPrimaries();
|
||||
assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
|
||||
assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
|
||||
assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.numberOfShards));
|
||||
|
||||
startInitializingShards(TEST_INDEX_1);
|
||||
assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(this.numberOfShards));
|
||||
assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(this.numberOfShards));
|
||||
assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.numberOfShards));
|
||||
|
||||
startInitializingShards(TEST_INDEX_2);
|
||||
assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_2}, false).size(), is(this.numberOfShards));
|
||||
assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(2 * this.numberOfShards));
|
||||
assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, true).size(), is(2 * this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_2}, false).size(), is(this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(2 * this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, true).size(), is(2 * this.numberOfShards));
|
||||
|
||||
try {
|
||||
this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, "not_exists"}, true);
|
||||
clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, "not_exists"}, true);
|
||||
fail("Calling with non-existing index name should raise IndexMissingException");
|
||||
} catch (IndexNotFoundException e) {
|
||||
// expected
|
||||
|
@ -197,43 +193,43 @@ public class RoutingTableTests extends ESAllocationTestCase {
|
|||
assertThat(this.emptyRoutingTable.allActiveShardsGrouped(new String[0], true).size(), is(0));
|
||||
assertThat(this.emptyRoutingTable.allActiveShardsGrouped(new String[0], false).size(), is(0));
|
||||
|
||||
assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
|
||||
assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
|
||||
assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
|
||||
assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
|
||||
|
||||
initPrimaries();
|
||||
assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
|
||||
assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
|
||||
assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
|
||||
assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
|
||||
|
||||
startInitializingShards(TEST_INDEX_1);
|
||||
assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(this.numberOfShards));
|
||||
assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(this.numberOfShards));
|
||||
assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
|
||||
assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
|
||||
|
||||
startInitializingShards(TEST_INDEX_2);
|
||||
assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_2}, false).size(), is(this.numberOfShards));
|
||||
assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(2 * this.numberOfShards));
|
||||
assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, true).size(), is(this.totalNumberOfShards));
|
||||
assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_2}, false).size(), is(this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(2 * this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, true).size(), is(this.totalNumberOfShards));
|
||||
|
||||
try {
|
||||
this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1, "not_exists"}, true);
|
||||
clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1, "not_exists"}, true);
|
||||
} catch (IndexNotFoundException e) {
|
||||
fail("Calling with non-existing index should be ignored at the moment");
|
||||
}
|
||||
}
|
||||
|
||||
public void testAllAssignedShardsGrouped() {
|
||||
assertThat(this.testRoutingTable.allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
|
||||
assertThat(this.testRoutingTable.allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
|
||||
assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
|
||||
assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
|
||||
|
||||
initPrimaries();
|
||||
assertThat(this.testRoutingTable.allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(this.numberOfShards));
|
||||
assertThat(this.testRoutingTable.allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
|
||||
assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
|
||||
|
||||
assertThat(this.testRoutingTable.allAssignedShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(2 * this.numberOfShards));
|
||||
assertThat(this.testRoutingTable.allAssignedShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, true).size(), is(this.totalNumberOfShards));
|
||||
assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(2 * this.numberOfShards));
|
||||
assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, true).size(), is(this.totalNumberOfShards));
|
||||
|
||||
try {
|
||||
this.testRoutingTable.allAssignedShardsGrouped(new String[]{TEST_INDEX_1, "not_exists"}, false);
|
||||
clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1, "not_exists"}, false);
|
||||
} catch (IndexNotFoundException e) {
|
||||
fail("Calling with non-existing index should be ignored at the moment");
|
||||
}
|
||||
|
@ -242,19 +238,19 @@ public class RoutingTableTests extends ESAllocationTestCase {
|
|||
public void testAllShardsForMultipleIndices() {
|
||||
assertThat(this.emptyRoutingTable.allShards(new String[0]).size(), is(0));
|
||||
|
||||
assertThat(this.testRoutingTable.allShards(new String[]{TEST_INDEX_1}).size(), is(this.shardsPerIndex));
|
||||
assertThat(clusterState.routingTable().allShards(new String[]{TEST_INDEX_1}).size(), is(this.shardsPerIndex));
|
||||
|
||||
initPrimaries();
|
||||
assertThat(this.testRoutingTable.allShards(new String[]{TEST_INDEX_1}).size(), is(this.shardsPerIndex));
|
||||
assertThat(clusterState.routingTable().allShards(new String[]{TEST_INDEX_1}).size(), is(this.shardsPerIndex));
|
||||
|
||||
startInitializingShards(TEST_INDEX_1);
|
||||
assertThat(this.testRoutingTable.allShards(new String[]{TEST_INDEX_1}).size(), is(this.shardsPerIndex));
|
||||
assertThat(clusterState.routingTable().allShards(new String[]{TEST_INDEX_1}).size(), is(this.shardsPerIndex));
|
||||
|
||||
startInitializingShards(TEST_INDEX_2);
|
||||
assertThat(this.testRoutingTable.allShards(new String[]{TEST_INDEX_1, TEST_INDEX_2}).size(), is(this.totalNumberOfShards));
|
||||
assertThat(clusterState.routingTable().allShards(new String[]{TEST_INDEX_1, TEST_INDEX_2}).size(), is(this.totalNumberOfShards));
|
||||
|
||||
try {
|
||||
this.testRoutingTable.allShards(new String[]{TEST_INDEX_1, "not_exists"});
|
||||
clusterState.routingTable().allShards(new String[]{TEST_INDEX_1, "not_exists"});
|
||||
} catch (IndexNotFoundException e) {
|
||||
fail("Calling with non-existing index should be ignored at the moment");
|
||||
}
|
||||
|
|
|
@ -178,9 +178,9 @@ public class UnassignedInfoTests extends ESAllocationTestCase {
|
|||
.metaData(metaData)
|
||||
.routingTable(RoutingTable.builder().addAsNew(metaData.index(index)).build()).build();
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.reroute(clusterState, "reroute")).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
// starting primaries
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
IndexRoutingTable.Builder builder = IndexRoutingTable.builder(index);
|
||||
for (IndexShardRoutingTable indexShardRoutingTable : clusterState.routingTable().index(index)) {
|
||||
builder.addIndexShard(indexShardRoutingTable);
|
||||
|
@ -218,15 +218,15 @@ public class UnassignedInfoTests extends ESAllocationTestCase {
|
|||
.metaData(metaData)
|
||||
.routingTable(RoutingTable.builder().addAsNew(metaData.index("test")).build()).build();
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.reroute(clusterState, "reroute")).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
// starting primaries
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
// starting replicas
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(false));
|
||||
// remove node2 and reroute
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove("node2")).build();
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.deassociateDeadNodes(clusterState, true, "reroute")).build();
|
||||
clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
// verify that NODE_LEAVE is the reason for meta
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(true));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).size(), equalTo(1));
|
||||
|
@ -247,15 +247,15 @@ public class UnassignedInfoTests extends ESAllocationTestCase {
|
|||
.metaData(metaData)
|
||||
.routingTable(RoutingTable.builder().addAsNew(metaData.index("test")).build()).build();
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.reroute(clusterState, "reroute")).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
// starting primaries
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
// starting replicas
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(false));
|
||||
// fail shard
|
||||
ShardRouting shardToFail = clusterState.getRoutingNodes().shardsWithState(STARTED).get(0);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyFailedShards(clusterState, Collections.singletonList(new FailedRerouteAllocation.FailedShard(shardToFail, "test fail", null)))).build();
|
||||
clusterState = allocation.applyFailedShards(clusterState, Collections.singletonList(new FailedRerouteAllocation.FailedShard(shardToFail, "test fail", null)));
|
||||
// verify the reason and details
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(true));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).size(), equalTo(1));
|
||||
|
@ -297,17 +297,17 @@ public class UnassignedInfoTests extends ESAllocationTestCase {
|
|||
.metaData(metaData)
|
||||
.routingTable(RoutingTable.builder().addAsNew(metaData.index("test1")).addAsNew(metaData.index("test2")).build()).build();
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.reroute(clusterState, "reroute")).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
assertThat(UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), equalTo(0));
|
||||
// starting primaries
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
// starting replicas
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(false));
|
||||
// remove node2 and reroute
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove("node2")).build();
|
||||
// make sure both replicas are marked as delayed (i.e. not reallocated)
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.deassociateDeadNodes(clusterState, true, "reroute")).build();
|
||||
clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
assertThat(clusterState.prettyPrint(), UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), equalTo(2));
|
||||
}
|
||||
|
||||
|
@ -325,24 +325,24 @@ public class UnassignedInfoTests extends ESAllocationTestCase {
|
|||
.metaData(metaData)
|
||||
.routingTable(RoutingTable.builder().addAsNew(metaData.index("test1")).addAsNew(metaData.index("test2")).build()).build();
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.reroute(clusterState, "reroute")).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
assertThat(UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), equalTo(0));
|
||||
// starting primaries
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
// starting replicas
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(false));
|
||||
// remove node2 and reroute
|
||||
final long baseTime = System.nanoTime();
|
||||
allocation.setNanoTimeOverride(baseTime);
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove("node2")).build();
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.deassociateDeadNodes(clusterState, true, "reroute")).build();
|
||||
clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
|
||||
final long delta = randomBoolean() ? 0 : randomInt((int) expectMinDelaySettingsNanos - 1);
|
||||
|
||||
if (delta > 0) {
|
||||
allocation.setNanoTimeOverride(baseTime + delta);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.reroute(clusterState, "time moved")).build();
|
||||
clusterState = allocation.reroute(clusterState, "time moved");
|
||||
}
|
||||
|
||||
assertThat(UnassignedInfo.findNextDelayedAllocation(baseTime + delta, clusterState), equalTo(expectMinDelaySettingsNanos - delta));
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.carrotsearch.hppc.cursors.ObjectCursor;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
|
@ -34,7 +35,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllo
|
|||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.CollectionUtils;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
|
@ -43,6 +43,8 @@ import java.util.Collections;
|
|||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
public class AddIncrementallyTests extends ESAllocationTestCase {
|
||||
private final Logger logger = Loggers.getLogger(AddIncrementallyTests.class);
|
||||
|
@ -53,40 +55,40 @@ public class AddIncrementallyTests extends ESAllocationTestCase {
|
|||
AllocationService service = createAllocationService(settings.build());
|
||||
|
||||
ClusterState clusterState = initCluster(service, 1, 3, 3, 1);
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), Matchers.equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(9));
|
||||
int nodeOffset = 1;
|
||||
clusterState = addNodes(clusterState, service, 1, nodeOffset++);
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), Matchers.equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), Matchers.equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(0));
|
||||
assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(3));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(0));
|
||||
assertNumIndexShardsPerNode(clusterState, equalTo(3));
|
||||
clusterState = addNodes(clusterState, service, 1, nodeOffset++);
|
||||
assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(2));
|
||||
assertNumIndexShardsPerNode(clusterState, equalTo(2));
|
||||
clusterState = addNodes(clusterState, service, 1, nodeOffset++);
|
||||
assertNumIndexShardsPerNode(clusterState, Matchers.lessThanOrEqualTo(2));
|
||||
assertAtLeastOneIndexShardPerNode(clusterState);
|
||||
clusterState = removeNodes(clusterState, service, 1);
|
||||
assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(2));
|
||||
assertNumIndexShardsPerNode(clusterState, equalTo(2));
|
||||
|
||||
clusterState = addIndex(clusterState, service, 3, 2, 3);
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(2));
|
||||
assertNumIndexShardsPerNode(clusterState, "test3", Matchers.equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(2));
|
||||
assertNumIndexShardsPerNode(clusterState, "test3", equalTo(2));
|
||||
assertNumIndexShardsPerNode(clusterState, Matchers.lessThanOrEqualTo(2));
|
||||
|
||||
clusterState = addIndex(clusterState, service, 4, 2, 3);
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(4));
|
||||
assertNumIndexShardsPerNode(clusterState, "test4", Matchers.equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(4));
|
||||
assertNumIndexShardsPerNode(clusterState, "test4", equalTo(2));
|
||||
assertNumIndexShardsPerNode(clusterState, Matchers.lessThanOrEqualTo(2));
|
||||
clusterState = addNodes(clusterState, service, 1, nodeOffset++);
|
||||
assertNumIndexShardsPerNode(clusterState, Matchers.lessThanOrEqualTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(0));
|
||||
clusterState = removeNodes(clusterState, service, 1);
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(4));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(4));
|
||||
assertNumIndexShardsPerNode(clusterState, Matchers.lessThanOrEqualTo(2));
|
||||
clusterState = addNodes(clusterState, service, 1, nodeOffset++);
|
||||
assertNumIndexShardsPerNode(clusterState, Matchers.lessThanOrEqualTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(0));
|
||||
logger.debug("ClusterState: {}", clusterState.getRoutingNodes().prettyPrint());
|
||||
}
|
||||
|
||||
|
@ -97,59 +99,57 @@ public class AddIncrementallyTests extends ESAllocationTestCase {
|
|||
AllocationService service = createAllocationService(settings.build());
|
||||
|
||||
ClusterState clusterState = initCluster(service, 1, 3, 3, 1);
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), Matchers.equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(9));
|
||||
int nodeOffset = 1;
|
||||
clusterState = addNodes(clusterState, service, 1, nodeOffset++);
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), Matchers.equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), Matchers.equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(0));
|
||||
assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(3));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(0));
|
||||
assertNumIndexShardsPerNode(clusterState, equalTo(3));
|
||||
|
||||
logger.info("now, start one more node, check that rebalancing will happen because we set it to always");
|
||||
DiscoveryNodes.Builder nodes = DiscoveryNodes.builder(clusterState.nodes());
|
||||
nodes.add(newNode("node2"));
|
||||
clusterState = ClusterState.builder(clusterState).nodes(nodes.build()).build();
|
||||
|
||||
RoutingAllocation.Result routingResult = service.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = service.reroute(clusterState, "reroute");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), Matchers.equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
|
||||
routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
ClusterState newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), Matchers.equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), Matchers.equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
|
||||
routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), Matchers.equalTo(4));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), Matchers.equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(4));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
|
||||
routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), Matchers.equalTo(6));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(6));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
|
||||
routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
assertFalse(routingResult.changed());
|
||||
assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(2));
|
||||
newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
assertNumIndexShardsPerNode(clusterState, equalTo(2));
|
||||
logger.debug("ClusterState: {}", clusterState.getRoutingNodes().prettyPrint());
|
||||
}
|
||||
|
||||
|
@ -161,59 +161,57 @@ public class AddIncrementallyTests extends ESAllocationTestCase {
|
|||
AllocationService service = createAllocationService(settings.build());
|
||||
|
||||
ClusterState clusterState = initCluster(service, 1, 3, 3, 1);
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), Matchers.equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(9));
|
||||
int nodeOffset = 1;
|
||||
clusterState = addNodes(clusterState, service, 1, nodeOffset++);
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), Matchers.equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), Matchers.equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(0));
|
||||
assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(3));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(9));
|
||||
assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(0));
|
||||
assertNumIndexShardsPerNode(clusterState, equalTo(3));
|
||||
|
||||
logger.info("now, start one more node, check that rebalancing will happen because we set it to always");
|
||||
DiscoveryNodes.Builder nodes = DiscoveryNodes.builder(clusterState.nodes());
|
||||
nodes.add(newNode("node2"));
|
||||
clusterState = ClusterState.builder(clusterState).nodes(nodes.build()).build();
|
||||
|
||||
RoutingAllocation.Result routingResult = service.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = service.reroute(clusterState, "reroute");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), Matchers.equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
|
||||
routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
ClusterState newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), Matchers.equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), Matchers.equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
|
||||
routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), Matchers.equalTo(4));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), Matchers.equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(4));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
|
||||
routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), Matchers.equalTo(6));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(6));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
|
||||
routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
assertFalse(routingResult.changed());
|
||||
assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(2));
|
||||
newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
assertNumIndexShardsPerNode(clusterState, equalTo(2));
|
||||
logger.debug("ClusterState: {}", clusterState.getRoutingNodes().prettyPrint());
|
||||
}
|
||||
|
||||
|
@ -250,8 +248,7 @@ public class AddIncrementallyTests extends ESAllocationTestCase {
|
|||
|
||||
clusterState = ClusterState.builder(clusterState).nodes(nodes.build()).build();
|
||||
|
||||
RoutingAllocation.Result routingResult = service.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = service.reroute(clusterState, "reroute");
|
||||
|
||||
// move initializing to started
|
||||
return applyStartedShardsUntilNoChange(clusterState, service);
|
||||
|
@ -282,18 +279,15 @@ public class AddIncrementallyTests extends ESAllocationTestCase {
|
|||
nodes.add(newNode("node" + i));
|
||||
}
|
||||
ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).nodes(nodes).metaData(metaData).routingTable(initialRoutingTable).build();
|
||||
RoutingAllocation.Result routingResult = service.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = service.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("restart all the primary shards, replicas will start initializing");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("start the replica shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
logger.info("complete rebalancing");
|
||||
|
@ -313,18 +307,15 @@ public class AddIncrementallyTests extends ESAllocationTestCase {
|
|||
|
||||
MetaData metaData = metaDataBuilder.build();
|
||||
clusterState = ClusterState.builder(clusterState).metaData(metaData).routingTable(routingTableBuilder.build()).build();
|
||||
RoutingAllocation.Result routingResult = service.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = service.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("restart all the primary shards, replicas will start initializing");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("start the replica shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("complete rebalancing");
|
||||
return applyStartedShardsUntilNoChange(clusterState, service);
|
||||
|
@ -344,22 +335,18 @@ public class AddIncrementallyTests extends ESAllocationTestCase {
|
|||
}
|
||||
|
||||
clusterState = ClusterState.builder(clusterState).nodes(nodes.build()).build();
|
||||
clusterState = ClusterState.builder(clusterState)
|
||||
.routingResult(service.deassociateDeadNodes(clusterState, true, "reroute")).build();
|
||||
clusterState = service.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
|
||||
logger.info("start all the primary shards, replicas will start initializing");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
RoutingAllocation.Result routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("start the replica shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("rebalancing");
|
||||
routingResult = service.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = service.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("complete rebalancing");
|
||||
clusterState = applyStartedShardsUntilNoChange(clusterState, service);
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
|
@ -51,7 +52,6 @@ import org.elasticsearch.common.xcontent.XContentType;
|
|||
import org.elasticsearch.index.IndexNotFoundException;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.index.shard.ShardNotFoundException;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
|
@ -61,6 +61,7 @@ import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
|
|||
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
|
@ -82,12 +83,10 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("adding two nodes and performing rerouting");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("start primary shard");
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("move the shard");
|
||||
String existingNodeId = clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId();
|
||||
|
@ -97,15 +96,15 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
|
|||
} else {
|
||||
toNodeId = "node1";
|
||||
}
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new MoveAllocationCommand("test", 0, existingNodeId, toNodeId)), false, false);
|
||||
assertThat(rerouteResult.changed(), equalTo(true));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
ClusterState newState = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new MoveAllocationCommand("test", 0, existingNodeId, toNodeId)), false, false).getClusterState();
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.getRoutingNodes().node(existingNodeId).iterator().next().state(), equalTo(ShardRoutingState.RELOCATING));
|
||||
assertThat(clusterState.getRoutingNodes().node(toNodeId).iterator().next().state(), equalTo(ShardRoutingState.INITIALIZING));
|
||||
|
||||
logger.info("finish moving the shard");
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().node(existingNodeId).isEmpty(), equalTo(true));
|
||||
assertThat(clusterState.getRoutingNodes().node(toNodeId).iterator().next().state(), equalTo(ShardRoutingState.STARTED));
|
||||
|
@ -146,8 +145,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
|
|||
.add(newNode("node3"))
|
||||
.add(newNode("node4", singleton(DiscoveryNode.Role.MASTER)))
|
||||
).build();
|
||||
RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
|
||||
logger.info("--> allocating to non-existent node, should fail");
|
||||
|
@ -199,16 +197,16 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
|
|||
}
|
||||
|
||||
logger.info("--> allocating empty primary with acceptDataLoss flag set to true");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 0, "node1", true)), false, false);
|
||||
assertThat(rerouteResult.changed(), equalTo(true));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
ClusterState newState = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 0, "node1", true)), false, false).getClusterState();
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
|
||||
|
||||
logger.info("--> start the primary shard");
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
|
||||
|
@ -221,9 +219,10 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
|
|||
}
|
||||
|
||||
logger.info("--> allocate the replica shard on on the second node");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false);
|
||||
assertThat(rerouteResult.changed(), equalTo(true));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
newState = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false).getClusterState();
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
|
||||
|
@ -231,8 +230,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
|
|||
|
||||
|
||||
logger.info("--> start the replica shard");
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
|
||||
|
@ -267,14 +265,14 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
|
|||
.add(newNode("node2"))
|
||||
.add(newNode("node3"))
|
||||
).build();
|
||||
RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
|
||||
logger.info("--> allocating empty primary shard with accept_data_loss flag set to true");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 0, "node1", true)), false, false);
|
||||
assertThat(rerouteResult.changed(), equalTo(true));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
ClusterState newState = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 0, "node1", true)), false, false).getClusterState();
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
|
||||
|
@ -287,8 +285,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
|
|||
}
|
||||
|
||||
logger.info("--> start the primary shard");
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
|
||||
|
@ -301,27 +298,30 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
|
|||
}
|
||||
|
||||
logger.info("--> allocate the replica shard on on the second node");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false);
|
||||
assertThat(rerouteResult.changed(), equalTo(true));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
newState = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false).getClusterState();
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||
|
||||
logger.info("--> cancel the relocation allocation");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node2", false)), false, false);
|
||||
assertThat(rerouteResult.changed(), equalTo(true));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
newState = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new CancelAllocationCommand("test", 0, "node2", false)), false, false).getClusterState();
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(0));
|
||||
|
||||
logger.info("--> allocate the replica shard on on the second node");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false);
|
||||
assertThat(rerouteResult.changed(), equalTo(true));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
newState = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false).getClusterState();
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
|
||||
|
@ -335,41 +335,41 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
|
|||
}
|
||||
|
||||
logger.info("--> start the replica shard");
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(1));
|
||||
|
||||
logger.info("--> cancel allocation of the replica shard");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node2", false)), false, false);
|
||||
assertThat(rerouteResult.changed(), equalTo(true));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
newState = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new CancelAllocationCommand("test", 0, "node2", false)), false, false).getClusterState();
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(0));
|
||||
|
||||
logger.info("--> allocate the replica shard on on the second node");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
assertThat(rerouteResult.changed(), equalTo(true));
|
||||
newState = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false).getClusterState();
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||
logger.info("--> start the replica shard");
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(1));
|
||||
|
||||
logger.info("--> move the replica shard");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new MoveAllocationCommand("test", 0, "node2", "node3")), false, false);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new MoveAllocationCommand("test", 0, "node2", "node3")), false, false).getClusterState();
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
|
||||
|
@ -379,24 +379,25 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
|
|||
|
||||
if (randomBoolean()) {
|
||||
logger.info("--> cancel the primary allocation (with allow_primary set to true)");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node1", true)), false, false);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
assertThat(rerouteResult.changed(), equalTo(true));
|
||||
newState = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new CancelAllocationCommand("test", 0, "node1", true)), false, false).getClusterState();
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).iterator().next().primary(), equalTo(true));
|
||||
assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(0));
|
||||
} else {
|
||||
logger.info("--> cancel the move of the replica shard");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node3", false)), false, false);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new CancelAllocationCommand("test", 0, "node3", false)), false, false).getClusterState();
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(1));
|
||||
|
||||
logger.info("--> move the replica shard again");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new MoveAllocationCommand("test", 0, "node2", "node3")), false, false);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new MoveAllocationCommand("test", 0, "node2", "node3")), false, false).getClusterState();
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
|
||||
|
@ -405,8 +406,8 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
|
|||
assertThat(clusterState.getRoutingNodes().node("node3").shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||
|
||||
logger.info("--> cancel the source replica shard");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node2", false)), false, false);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new CancelAllocationCommand("test", 0, "node2", false)), false, false).getClusterState();
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
|
||||
|
@ -415,17 +416,17 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
|
|||
assertThat(clusterState.getRoutingNodes().node("node3").shardsWithState(INITIALIZING).get(0).relocatingNodeId(), nullValue());
|
||||
|
||||
logger.info("--> start the former target replica shard");
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node3").shardsWithState(STARTED).size(), equalTo(1));
|
||||
|
||||
logger.info("--> cancel the primary allocation (with allow_primary set to true)");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node1", true)), false, false);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
assertThat(rerouteResult.changed(), equalTo(true));
|
||||
newState = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new CancelAllocationCommand("test", 0, "node1", true)), false, false).getClusterState();
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.getRoutingNodes().node("node3").shardsWithState(STARTED).iterator().next().primary(), equalTo(true));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
|
||||
|
@ -445,8 +446,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
|
|||
StreamInput in = bytes.bytes().streamInput();
|
||||
|
||||
// Since the commands are named writeable we need to register them and wrap the input stream
|
||||
NetworkModule networkModule = new NetworkModule(null, Settings.EMPTY, true);
|
||||
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(networkModule.getNamedWriteables());
|
||||
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(NetworkModule.getNamedWriteables());
|
||||
in = new NamedWriteableAwareStreamInput(in, namedWriteableRegistry);
|
||||
|
||||
// Now we can read them!
|
||||
|
@ -492,7 +492,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
|
|||
// move two tokens, parser expected to be "on" `commands` field
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
AllocationCommandRegistry registry = new NetworkModule(null, Settings.EMPTY, true).getAllocationCommandRegistry();
|
||||
AllocationCommandRegistry registry = NetworkModule.getAllocationCommandRegistry();
|
||||
AllocationCommands sCommands = AllocationCommands.fromXContent(parser, ParseFieldMatcher.STRICT, registry);
|
||||
|
||||
assertThat(sCommands.commands().size(), equalTo(5));
|
||||
|
|
|
@ -20,13 +20,13 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
|
||||
|
@ -68,29 +68,24 @@ public class AllocationPriorityTests extends ESAllocationTestCase {
|
|||
ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(initialRoutingTable).build();
|
||||
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingTable(rerouteResult.routingTable()).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
|
||||
RoutingAllocation.Result routingResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
assertEquals(2, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size());
|
||||
assertEquals(highPriorityName, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(0).getIndexName());
|
||||
assertEquals(highPriorityName, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(1).getIndexName());
|
||||
|
||||
routingResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertEquals(2, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size());
|
||||
assertEquals(lowPriorityName, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(0).getIndexName());
|
||||
assertEquals(lowPriorityName, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(1).getIndexName());
|
||||
|
||||
routingResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertEquals(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).toString(),2, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size());
|
||||
assertEquals(highPriorityName, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(0).getIndexName());
|
||||
assertEquals(highPriorityName, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(1).getIndexName());
|
||||
|
||||
routingResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertEquals(2, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size());
|
||||
assertEquals(lowPriorityName, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(0).getIndexName());
|
||||
assertEquals(lowPriorityName, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(1).getIndexName());
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
|
@ -34,7 +35,6 @@ import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationComman
|
|||
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
|
@ -73,17 +73,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode("node1", singletonMap("rack_id", "1")))
|
||||
.add(newNode("node2", singletonMap("rack_id", "1")))
|
||||
).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||
|
||||
logger.info("--> start the shards (primaries)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> start the shards (replicas)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
|
||||
|
||||
|
@ -91,16 +88,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3", singletonMap("rack_id", "2")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).get(0).relocatingNodeId(), equalTo("node3"));
|
||||
|
||||
logger.info("--> complete relocation");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
|
||||
|
||||
|
@ -111,9 +106,8 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node4", singletonMap("rack_id", "3")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
assertFalse(routingResult.changed());
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
ClusterState newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(2));
|
||||
}
|
||||
|
||||
|
@ -140,17 +134,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode("node2", singletonMap("rack_id", "1")))
|
||||
.add(newNode("node3", singletonMap("rack_id", "1")))
|
||||
).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||
|
||||
logger.info("--> start the shards (primaries)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> start the shards (replicas)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
|
||||
|
||||
|
@ -158,16 +149,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node4", singletonMap("rack_id", "2")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).get(0).relocatingNodeId(), equalTo("node4"));
|
||||
|
||||
logger.info("--> complete relocation");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
|
||||
|
||||
|
@ -178,9 +167,8 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node5", singletonMap("rack_id", "3")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
assertFalse(routingResult.changed());
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
ClusterState newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(2));
|
||||
}
|
||||
|
||||
|
@ -213,8 +201,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode("node1", singletonMap("rack_id", "1")))
|
||||
.add(newNode("node2", singletonMap("rack_id", "1")))
|
||||
).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("Initializing shards: {}", clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
logger.info("Started shards: {}", clusterState.getRoutingNodes().shardsWithState(STARTED));
|
||||
|
@ -224,12 +211,10 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(5));
|
||||
|
||||
logger.info("--> start the shards (primaries)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> start the shards (replicas)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
|
||||
|
||||
|
@ -237,8 +222,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3", singletonMap("rack_id", "2")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(5));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(5));
|
||||
|
@ -246,12 +230,10 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).get(0).relocatingNodeId(), equalTo("node3"));
|
||||
|
||||
logger.info("--> complete initializing");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> run it again, since we still might have relocation");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
|
||||
|
||||
|
@ -262,13 +244,11 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node4", singletonMap("rack_id", "3")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), greaterThan(0));
|
||||
|
||||
logger.info("--> complete relocation");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
|
||||
|
||||
|
@ -304,17 +284,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode("node1", singletonMap("rack_id", "1")))
|
||||
.add(newNode("node2", singletonMap("rack_id", "1")))
|
||||
).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(10));
|
||||
|
||||
logger.info("--> start the shards (primaries)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> start the shards (replicas)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(20));
|
||||
|
||||
|
@ -322,8 +299,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3", singletonMap("rack_id", "2")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(10));
|
||||
|
@ -333,11 +309,9 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
logger.info("--> complete initializing");
|
||||
for (int i = 0; i < 2; i++) {
|
||||
logger.info("--> complete initializing round: [{}]", i);
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
}
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
}
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(20));
|
||||
assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(10));
|
||||
|
@ -351,16 +325,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node4", singletonMap("rack_id", "3")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), greaterThan(0));
|
||||
|
||||
logger.info("--> complete relocation");
|
||||
for (int i = 0; i < 2; i++) {
|
||||
logger.info("--> complete initializing round: [{}]", i);
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
}
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
}
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(20));
|
||||
assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(5));
|
||||
assertThat(clusterState.getRoutingNodes().node("node4").size(), equalTo(5));
|
||||
|
@ -395,17 +367,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode("node1", singletonMap("rack_id", "1")))
|
||||
.add(newNode("node2", singletonMap("rack_id", "1")))
|
||||
).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||
|
||||
logger.info("--> start the shards (primaries)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> start the shards (replicas)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
|
||||
|
||||
|
@ -413,16 +382,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3", singletonMap("rack_id", "2")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo("node3"));
|
||||
|
||||
logger.info("--> complete relocation");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(3));
|
||||
|
||||
|
@ -433,15 +400,13 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node4", singletonMap("rack_id", "3")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).get(0).relocatingNodeId(), equalTo("node4"));
|
||||
|
||||
logger.info("--> complete relocation");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(3));
|
||||
|
||||
|
@ -475,17 +440,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode("node3", singletonMap("rack_id", "1")))
|
||||
.add(newNode("node4", singletonMap("rack_id", "1")))
|
||||
).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||
|
||||
logger.info("--> start the shards (primaries)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> start the shards (replicas)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(4));
|
||||
|
||||
|
@ -493,16 +455,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node5", singletonMap("rack_id", "2")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(3));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).get(0).relocatingNodeId(), equalTo("node5"));
|
||||
|
||||
logger.info("--> complete relocation");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(4));
|
||||
|
||||
|
@ -513,15 +473,13 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node6", singletonMap("rack_id", "3")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(3));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).get(0).relocatingNodeId(), equalTo("node6"));
|
||||
|
||||
logger.info("--> complete relocation");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(4));
|
||||
|
||||
|
@ -554,13 +512,11 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode("node1", singletonMap("rack_id", "1")))
|
||||
.add(newNode("node2", singletonMap("rack_id", "1")))
|
||||
).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||
|
||||
logger.info("--> start the shards (primaries)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> replica will not start because we have only one rack value");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(1));
|
||||
|
@ -570,16 +526,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3", singletonMap("rack_id", "2")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo("node3"));
|
||||
|
||||
logger.info("--> complete relocation");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
|
||||
|
||||
|
@ -590,9 +544,8 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node4", singletonMap("rack_id", "3")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
assertFalse(routingResult.changed());
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
ClusterState newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(2));
|
||||
}
|
||||
|
||||
|
@ -622,13 +575,11 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode("node2", singletonMap("rack_id", "1")))
|
||||
.add(newNode("node3", singletonMap("rack_id", "1")))
|
||||
).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||
|
||||
logger.info("--> start the shards (primaries)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> replica will not start because we have only one rack value");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(1));
|
||||
|
@ -638,16 +589,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node4", singletonMap("rack_id", "2")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo("node4"));
|
||||
|
||||
logger.info("--> complete relocation");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
|
||||
|
||||
|
@ -658,9 +607,8 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node5", singletonMap("rack_id", "3")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
assertFalse(routingResult.changed());
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
ClusterState newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(2));
|
||||
}
|
||||
|
||||
|
@ -696,13 +644,11 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode("node1", singletonMap("rack_id", "1")))
|
||||
.add(newNode("node2", singletonMap("rack_id", "1")))
|
||||
).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(10));
|
||||
|
||||
logger.info("--> start the shards (primaries)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
|
||||
|
||||
|
@ -710,20 +656,17 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3", singletonMap("rack_id", "2")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(10));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo("node3"));
|
||||
|
||||
logger.info("--> complete initializing");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> run it again, since we still might have relocation");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(20));
|
||||
|
||||
|
@ -734,13 +677,11 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node4", singletonMap("rack_id", "3")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), greaterThan(0));
|
||||
|
||||
logger.info("--> complete relocation");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(20));
|
||||
|
||||
|
@ -775,19 +716,16 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode("A-0", singletonMap("zone", "a")))
|
||||
.add(newNode("B-0", singletonMap("zone", "b")))
|
||||
).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(5));
|
||||
|
||||
logger.info("--> start the shards (primaries)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(5));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(5));
|
||||
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
logger.info("--> all replicas are allocated and started since we have on node in each zone");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(10));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(0));
|
||||
|
@ -796,15 +734,13 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("A-1", singletonMap("zone", "a")))
|
||||
).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(8));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo("A-1"));
|
||||
logger.info("--> starting initializing shards on the new node");
|
||||
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
|
||||
assertThat(clusterState.getRoutingNodes().node("A-1").size(), equalTo(2));
|
||||
|
@ -840,14 +776,12 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode("A-4", singletonMap("zone", "a")))
|
||||
.add(newNode("B-0", singletonMap("zone", "b")))
|
||||
).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||
|
||||
logger.info("--> start the shard (primary)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(3));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).size(), equalTo(1)); // Unassigned shard is expected.
|
||||
|
@ -864,8 +798,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
|
|||
}
|
||||
commands.add(new MoveAllocationCommand("test", 0, primaryNode, "A-4"));
|
||||
|
||||
routingResult = strategy.reroute(clusterState, commands, false, false);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, commands, false, false).getClusterState();
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(0));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), equalTo(1));
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.apache.lucene.util.ArrayUtil;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.EmptyClusterInfoService;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
|
@ -40,7 +41,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllo
|
|||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.ClusterSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.test.gateway.NoopGatewayAllocator;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
|
@ -132,18 +132,15 @@ public class BalanceConfigurationTests extends ESAllocationTestCase {
|
|||
nodes.add(newNode("node" + i));
|
||||
}
|
||||
ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).nodes(nodes).metaData(metaData).routingTable(initialRoutingTable).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("restart all the primary shards, replicas will start initializing");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("start the replica shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("complete rebalancing");
|
||||
return applyStartedShardsUntilNoChange(clusterState, strategy);
|
||||
|
@ -174,24 +171,19 @@ public class BalanceConfigurationTests extends ESAllocationTestCase {
|
|||
|
||||
clusterState = ClusterState.builder(clusterState).nodes(nodes.build()).build();
|
||||
if (removed) {
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(
|
||||
strategy.deassociateDeadNodes(clusterState, randomBoolean(), "removed nodes")
|
||||
).build();
|
||||
clusterState = strategy.deassociateDeadNodes(clusterState, randomBoolean(), "removed nodes");
|
||||
}
|
||||
|
||||
logger.info("start all the primary shards, replicas will start initializing");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
RoutingAllocation.Result routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("start the replica shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("rebalancing");
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("complete rebalancing");
|
||||
return applyStartedShardsUntilNoChange(clusterState, strategy);
|
||||
|
|
|
@ -65,14 +65,12 @@ public class BalanceUnbalancedClusterTests extends CatAllocationTestCase {
|
|||
.build();
|
||||
|
||||
ClusterState clusterState = ClusterState.builder(state).metaData(metaData).routingTable(initialRoutingTable).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
while (true) {
|
||||
if (clusterState.routingTable().shardsWithState(INITIALIZING).isEmpty()) {
|
||||
break;
|
||||
}
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
|
||||
}
|
||||
Map<String, Integer> counts = new HashMap<>();
|
||||
for (IndexShardRoutingTable table : clusterState.routingTable().index(index)) {
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
|
@ -31,7 +32,6 @@ import org.elasticsearch.cluster.routing.ShardRouting;
|
|||
import org.elasticsearch.cluster.routing.ShardRoutingState;
|
||||
import org.elasticsearch.cluster.routing.TestShardRouting;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
@ -149,10 +149,9 @@ public abstract class CatAllocationTestCase extends ESAllocationTestCase {
|
|||
}
|
||||
|
||||
private ClusterState rebalance(ClusterState clusterState) {
|
||||
RoutingTable routingTable;AllocationService strategy = createAllocationService(Settings.builder()
|
||||
AllocationService strategy = createAllocationService(Settings.builder()
|
||||
.build());
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
int numRelocations = 0;
|
||||
while (true) {
|
||||
List<ShardRouting> initializing = clusterState.routingTable().shardsWithState(INITIALIZING);
|
||||
|
@ -161,8 +160,7 @@ public abstract class CatAllocationTestCase extends ESAllocationTestCase {
|
|||
}
|
||||
logger.debug("Initializing shards: {}", initializing);
|
||||
numRelocations += initializing.size();
|
||||
routingResult = strategy.applyStartedShards(clusterState, initializing);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, initializing);
|
||||
}
|
||||
logger.debug("--> num relocations to get balance: {}", numRelocations);
|
||||
return clusterState;
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
|
@ -32,7 +33,6 @@ import org.elasticsearch.cluster.routing.UnassignedInfo;
|
|||
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.test.gateway.NoopGatewayAllocator;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
@ -43,6 +43,7 @@ import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
|
|||
import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED;
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
||||
private final Logger logger = Loggers.getLogger(ClusterRebalanceRoutingTests.class);
|
||||
|
@ -65,8 +66,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start two nodes");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
|
||||
|
@ -82,9 +82,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start all the primary shards for test1, replicas will start initializing");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
|
||||
|
@ -100,8 +98,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start the test1 replica shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
|
@ -120,8 +117,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3")))
|
||||
.build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(routingNodes.node("node3").size(), equalTo(1));
|
||||
|
@ -147,9 +143,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start two nodes");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test1").shard(i).size(), equalTo(2));
|
||||
assertThat(clusterState.routingTable().index("test1").shard(i).primaryShard().state(), equalTo(INITIALIZING));
|
||||
|
@ -164,8 +158,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start all the primary shards for test1, replicas will start initializing");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
|
@ -182,8 +175,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start the test1 replica shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
|
@ -200,8 +192,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start all the primary shards for test2, replicas will start initializing");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test2", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test2", INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
|
@ -220,8 +211,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3")))
|
||||
.build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(routingNodes.node("node3").size(), equalTo(1));
|
||||
|
@ -246,8 +236,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start two nodes");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
|
||||
|
@ -263,8 +252,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start all the primary shards for test1, replicas will start initializing");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
|
@ -281,8 +269,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start the test1 replica shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
|
@ -301,8 +288,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3")))
|
||||
.build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(routingNodes.node("node3").isEmpty(), equalTo(true));
|
||||
|
@ -326,8 +312,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start two nodes");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
|
||||
|
@ -343,8 +328,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start all the primary shards for test1, replicas will start initializing");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
|
@ -361,8 +345,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start the test1 replica shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
|
@ -379,8 +362,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start all the primary shards for test2, replicas will start initializing");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test2", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test2", INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
|
@ -397,8 +379,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start the test2 replica shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test2", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test2", INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
|
@ -417,8 +398,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3")))
|
||||
.build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(routingNodes.node("node3").size(), equalTo(1));
|
||||
|
@ -443,8 +423,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start two nodes");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
|
||||
|
@ -460,8 +439,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start all the primary shards for test1, replicas will start initializing");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
|
@ -478,8 +456,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start the test1 replica shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
|
@ -498,8 +475,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3")))
|
||||
.build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(routingNodes.node("node3").isEmpty(), equalTo(true));
|
||||
|
@ -523,8 +499,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start two nodes");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
|
||||
|
@ -540,8 +515,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start all the primary shards for test1, replicas will start initializing");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
|
@ -558,8 +532,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start the test1 replica shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
|
@ -576,8 +549,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start all the primary shards for test2, replicas will start initializing");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test2", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test2", INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
|
@ -596,8 +568,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3")))
|
||||
.build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(routingNodes.node("node3").isEmpty(), equalTo(true));
|
||||
|
@ -638,8 +609,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start two nodes");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(1));
|
||||
|
@ -648,9 +618,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.debug("start all the primary shards for test");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test", INITIALIZING));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(1));
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).primaryShard().state(), equalTo(STARTED));
|
||||
|
@ -661,10 +629,8 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
.add(newNode("node2")))
|
||||
.build();
|
||||
logger.debug("reroute and check that nothing has changed");
|
||||
RoutingAllocation.Result reroute = strategy.reroute(clusterState, "reroute");
|
||||
assertFalse(reroute.changed());
|
||||
routingResult = reroute;
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
ClusterState resultingState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(resultingState, equalTo(clusterState));
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(1));
|
||||
|
@ -676,10 +642,9 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
}
|
||||
logger.debug("now set allocateTest1 to true and reroute we should see the [test1] index initializing");
|
||||
allocateTest1.set(true);
|
||||
reroute = strategy.reroute(clusterState, "reroute");
|
||||
assertTrue(reroute.changed());
|
||||
routingResult = reroute;
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
resultingState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(resultingState, not(equalTo(clusterState)));
|
||||
clusterState = resultingState;
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(1));
|
||||
assertThat(clusterState.routingTable().index("test1").shard(i).primaryShard().state(), equalTo(INITIALIZING));
|
||||
|
@ -688,8 +653,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
logger.debug("now start initializing shards and expect exactly one rebalance from node1 to node 2 since index [test] is all on node1");
|
||||
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(1));
|
||||
|
@ -738,8 +702,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start two nodes");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(1));
|
||||
|
@ -748,9 +711,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.debug("start all the primary shards for test");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test", INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test", INITIALIZING));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(1));
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).primaryShard().state(), equalTo(STARTED));
|
||||
|
@ -761,8 +722,8 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
.add(newNode("node2")))
|
||||
.build();
|
||||
logger.debug("reroute and check that nothing has changed");
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
assertFalse(routingResult.changed());
|
||||
ClusterState resultState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(resultState, equalTo(clusterState));
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(1));
|
||||
|
@ -774,9 +735,9 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
}
|
||||
logger.debug("now set hasFetches to true and reroute we should now see exactly one relocating shard");
|
||||
hasFetches.set(false);
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
assertTrue(routingResult.changed());
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
resultState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(resultState, not(equalTo(clusterState)));
|
||||
clusterState = resultState;
|
||||
int numStarted = 0;
|
||||
int numRelocating = 0;
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
|
@ -29,7 +30,6 @@ import org.elasticsearch.cluster.routing.RoutingNodes;
|
|||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
|
||||
|
@ -70,8 +70,7 @@ public class ConcurrentRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start two nodes and fully start the shards");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(2));
|
||||
|
@ -81,8 +80,7 @@ public class ConcurrentRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start all the primary shards, replicas will start initializing");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(2));
|
||||
|
@ -94,8 +92,7 @@ public class ConcurrentRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3")).add(newNode("node4")).add(newNode("node5")).add(newNode("node6")).add(newNode("node7")).add(newNode("node8")).add(newNode("node9")).add(newNode("node10")))
|
||||
.build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(2));
|
||||
|
@ -105,8 +102,7 @@ public class ConcurrentRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start the replica shards, rebalancing should start, but, only 3 should be rebalancing");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
// we only allow one relocation at a time
|
||||
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(7));
|
||||
|
@ -114,8 +110,7 @@ public class ConcurrentRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("finalize this session relocation, 3 more should relocate now");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
// we only allow one relocation at a time
|
||||
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(7));
|
||||
|
@ -123,8 +118,7 @@ public class ConcurrentRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("finalize this session relocation, 2 more should relocate now");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
// we only allow one relocation at a time
|
||||
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(8));
|
||||
|
@ -132,8 +126,7 @@ public class ConcurrentRebalanceRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("finalize this session relocation, no more relocation");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
// we only allow one relocation at a time
|
||||
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(10));
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
|
@ -31,12 +32,12 @@ import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationComman
|
|||
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -64,15 +65,12 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode("node2"))
|
||||
).build();
|
||||
|
||||
RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
|
||||
// starting primaries
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
// starting replicas
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> verifying all is allocated");
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
|
@ -87,8 +85,7 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode(nodeIdRemaining))
|
||||
).build();
|
||||
|
||||
rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().node(nodeIdRemaining).iterator().next().primary(), equalTo(true));
|
||||
assertThat(clusterState.getRoutingNodes().node(nodeIdRemaining).iterator().next().state(), equalTo(STARTED));
|
||||
|
@ -115,15 +112,12 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode("node2"))
|
||||
).build();
|
||||
|
||||
RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
|
||||
// starting primaries
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
// starting replicas
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> verifying all is allocated");
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
|
@ -135,8 +129,7 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3"))
|
||||
).build();
|
||||
rerouteResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").iterator().next().state(), equalTo(STARTED));
|
||||
|
@ -148,11 +141,11 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
|
|||
String origReplicaNodeId = clusterState.routingTable().index("test").shard(0).replicaShards().get(0).currentNodeId();
|
||||
|
||||
logger.info("--> moving primary shard to node3");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(
|
||||
AllocationService.CommandsResult commandsResult = allocation.reroute(clusterState, new AllocationCommands(
|
||||
new MoveAllocationCommand("test", 0, clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId(), "node3")),
|
||||
false, false);
|
||||
assertThat(rerouteResult.changed(), equalTo(true));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
assertThat(commandsResult.getClusterState(), not(equalTo(clusterState)));
|
||||
clusterState = commandsResult.getClusterState();
|
||||
assertThat(clusterState.getRoutingNodes().node(origPrimaryNodeId).iterator().next().state(), equalTo(RELOCATING));
|
||||
assertThat(clusterState.getRoutingNodes().node("node3").iterator().next().state(), equalTo(INITIALIZING));
|
||||
|
||||
|
@ -161,8 +154,7 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode(origPrimaryNodeId))
|
||||
.add(newNode(origReplicaNodeId))
|
||||
).build();
|
||||
rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().node(origPrimaryNodeId).iterator().next().state(), equalTo(STARTED));
|
||||
assertThat(clusterState.getRoutingNodes().node(origReplicaNodeId).iterator().next().state(), equalTo(STARTED));
|
||||
|
@ -189,15 +181,12 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode("node2"))
|
||||
).build();
|
||||
|
||||
RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
|
||||
// starting primaries
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
// starting replicas
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> verifying all is allocated");
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
|
@ -209,8 +198,7 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3"))
|
||||
).build();
|
||||
rerouteResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").iterator().next().state(), equalTo(STARTED));
|
||||
|
@ -222,11 +210,11 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
|
|||
String origReplicaNodeId = clusterState.routingTable().index("test").shard(0).replicaShards().get(0).currentNodeId();
|
||||
|
||||
logger.info("--> moving primary shard to node3");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(
|
||||
AllocationService.CommandsResult commandsResult = allocation.reroute(clusterState, new AllocationCommands(
|
||||
new MoveAllocationCommand("test",0 , clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId(), "node3")),
|
||||
false, false);
|
||||
assertThat(rerouteResult.changed(), equalTo(true));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
assertThat(commandsResult.getClusterState(), not(equalTo(clusterState)));
|
||||
clusterState = commandsResult.getClusterState();
|
||||
assertThat(clusterState.getRoutingNodes().node(origPrimaryNodeId).iterator().next().state(), equalTo(RELOCATING));
|
||||
assertThat(clusterState.getRoutingNodes().node("node3").iterator().next().state(), equalTo(INITIALIZING));
|
||||
|
||||
|
@ -235,8 +223,7 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
|
|||
.add(newNode("node3"))
|
||||
.add(newNode(origReplicaNodeId))
|
||||
).build();
|
||||
rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().node(origReplicaNodeId).iterator().next().state(), equalTo(STARTED));
|
||||
assertThat(clusterState.getRoutingNodes().node("node3").iterator().next().state(), equalTo(INITIALIZING));
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
|
@ -30,11 +31,11 @@ import org.elasticsearch.cluster.routing.RoutingNodes;
|
|||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -59,29 +60,26 @@ public class ElectReplicaAsPrimaryDuringRelocationTests extends ESAllocationTest
|
|||
|
||||
logger.info("Adding two nodes and performing rerouting");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("Start the primary shards");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("Start the replica shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
ClusterState resultingState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(resultingState, not(equalTo(clusterState)));
|
||||
clusterState = resultingState;
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(2));
|
||||
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED), equalTo(2));
|
||||
assertThat(routingNodes.node("node2").numberOfShardsWithState(STARTED), equalTo(2));
|
||||
|
||||
logger.info("Start another node and perform rerouting");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("find the replica shard that gets relocated");
|
||||
IndexShardRoutingTable indexShardRoutingTable = null;
|
||||
|
@ -95,8 +93,7 @@ public class ElectReplicaAsPrimaryDuringRelocationTests extends ESAllocationTest
|
|||
if (indexShardRoutingTable != null) {
|
||||
logger.info("kill the node [{}] of the primary shard for the relocating replica", indexShardRoutingTable.primaryShard().currentNodeId());
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove(indexShardRoutingTable.primaryShard().currentNodeId())).build();
|
||||
routingResult = strategy.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
|
||||
logger.info("make sure all the primary shards are active");
|
||||
assertThat(clusterState.routingTable().index("test").shard(0).primaryShard().active(), equalTo(true));
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.Version;
|
|||
import org.elasticsearch.cluster.ClusterInfo;
|
||||
import org.elasticsearch.cluster.ClusterInfoService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
|
@ -35,10 +36,10 @@ import org.elasticsearch.cluster.routing.allocation.command.AllocationCommands;
|
|||
import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -81,23 +82,20 @@ public class ExpectedShardSizeAllocationTests extends ESAllocationTestCase {
|
|||
ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build();
|
||||
logger.info("Adding one node and performing rerouting");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
assertEquals(1, clusterState.getRoutingNodes().node("node1").numberOfShardsWithState(ShardRoutingState.INITIALIZING));
|
||||
assertEquals(byteSize, clusterState.getRoutingTable().shardsWithState(ShardRoutingState.INITIALIZING).get(0).getExpectedShardSize());
|
||||
logger.info("Start the primary shard");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
assertEquals(1, clusterState.getRoutingNodes().node("node1").numberOfShardsWithState(ShardRoutingState.STARTED));
|
||||
assertEquals(1, clusterState.getRoutingNodes().unassigned().size());
|
||||
|
||||
logger.info("Add another one node and reroute");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
assertEquals(1, clusterState.getRoutingNodes().node("node2").numberOfShardsWithState(ShardRoutingState.INITIALIZING));
|
||||
assertEquals(byteSize, clusterState.getRoutingTable().shardsWithState(ShardRoutingState.INITIALIZING).get(0).getExpectedShardSize());
|
||||
|
@ -134,12 +132,10 @@ public class ExpectedShardSizeAllocationTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("adding two nodes and performing rerouting");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("start primary shard");
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("move the shard");
|
||||
String existingNodeId = clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId();
|
||||
|
@ -149,9 +145,10 @@ public class ExpectedShardSizeAllocationTests extends ESAllocationTestCase {
|
|||
} else {
|
||||
toNodeId = "node1";
|
||||
}
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new MoveAllocationCommand("test", 0, existingNodeId, toNodeId)), false, false);
|
||||
assertThat(rerouteResult.changed(), equalTo(true));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
AllocationService.CommandsResult commandsResult =
|
||||
allocation.reroute(clusterState, new AllocationCommands(new MoveAllocationCommand("test", 0, existingNodeId, toNodeId)), false, false);
|
||||
assertThat(commandsResult.getClusterState(), not(equalTo(clusterState)));
|
||||
clusterState = commandsResult.getClusterState();
|
||||
assertEquals(clusterState.getRoutingNodes().node(existingNodeId).iterator().next().state(), ShardRoutingState.RELOCATING);
|
||||
assertEquals(clusterState.getRoutingNodes().node(toNodeId).iterator().next().state(),ShardRoutingState.INITIALIZING);
|
||||
|
||||
|
@ -159,8 +156,7 @@ public class ExpectedShardSizeAllocationTests extends ESAllocationTestCase {
|
|||
assertEquals(clusterState.getRoutingNodes().node(toNodeId).iterator().next().getExpectedShardSize(), byteSize);
|
||||
|
||||
logger.info("finish moving the shard");
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().node(existingNodeId).isEmpty(), equalTo(true));
|
||||
assertThat(clusterState.getRoutingNodes().node(toNodeId).iterator().next().state(), equalTo(ShardRoutingState.STARTED));
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
|
@ -31,7 +32,6 @@ import org.elasticsearch.cluster.routing.RoutingTable;
|
|||
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
|
||||
|
@ -58,19 +58,16 @@ public class FailedNodeRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start 4 nodes");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3")).add(newNode("node4"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("start all the primary shards, replicas will start initializing");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
logger.info("start the replica shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED), equalTo(1));
|
||||
|
@ -86,8 +83,7 @@ public class FailedNodeRoutingTests extends ESAllocationTestCase {
|
|||
.remove(clusterState.routingTable().index("test2").shard(0).primaryShard().currentNodeId())
|
||||
)
|
||||
.build();
|
||||
routingResult = strategy.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (RoutingNode routingNode : routingNodes) {
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
|
@ -33,7 +34,6 @@ import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationComman
|
|||
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -77,15 +77,12 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
.add(newNode("node2"))
|
||||
).build();
|
||||
|
||||
RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
|
||||
// starting primaries
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
// starting replicas
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> verifying all is allocated");
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
|
@ -97,8 +94,7 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3"))
|
||||
).build();
|
||||
rerouteResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node("node1").iterator().next().state(), equalTo(STARTED));
|
||||
|
@ -110,33 +106,31 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
String origReplicaNodeId = clusterState.routingTable().index("test").shard(0).replicaShards().get(0).currentNodeId();
|
||||
|
||||
logger.info("--> moving primary shard to node3");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(
|
||||
AllocationService.CommandsResult commandsResult = allocation.reroute(clusterState, new AllocationCommands(
|
||||
new MoveAllocationCommand("test", 0, clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId(), "node3")),
|
||||
false, false);
|
||||
assertThat(rerouteResult.changed(), equalTo(true));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
assertThat(commandsResult.getClusterState(), not(equalTo(clusterState)));
|
||||
clusterState = commandsResult.getClusterState();
|
||||
assertThat(clusterState.getRoutingNodes().node(origPrimaryNodeId).iterator().next().state(), equalTo(RELOCATING));
|
||||
assertThat(clusterState.getRoutingNodes().node("node3").iterator().next().state(), equalTo(INITIALIZING));
|
||||
|
||||
logger.info("--> fail primary shard recovering instance on node3 being initialized");
|
||||
rerouteResult = allocation.applyFailedShard(clusterState, clusterState.getRoutingNodes().node("node3").iterator().next());
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyFailedShard(clusterState, clusterState.getRoutingNodes().node("node3").iterator().next());
|
||||
|
||||
assertThat(clusterState.getRoutingNodes().node(origPrimaryNodeId).iterator().next().state(), equalTo(STARTED));
|
||||
assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(0));
|
||||
|
||||
logger.info("--> moving primary shard to node3");
|
||||
rerouteResult = allocation.reroute(clusterState, new AllocationCommands(
|
||||
commandsResult = allocation.reroute(clusterState, new AllocationCommands(
|
||||
new MoveAllocationCommand("test", 0, clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId(), "node3")),
|
||||
false, false);
|
||||
assertThat(rerouteResult.changed(), equalTo(true));
|
||||
clusterState = ClusterState.builder(clusterState).routingTable(rerouteResult.routingTable()).build();
|
||||
assertThat(commandsResult.getClusterState(), not(equalTo(clusterState)));
|
||||
clusterState = commandsResult.getClusterState();
|
||||
assertThat(clusterState.getRoutingNodes().node(origPrimaryNodeId).iterator().next().state(), equalTo(RELOCATING));
|
||||
assertThat(clusterState.getRoutingNodes().node("node3").iterator().next().state(), equalTo(INITIALIZING));
|
||||
|
||||
logger.info("--> fail primary shard recovering instance on node1 being relocated");
|
||||
rerouteResult = allocation.applyFailedShard(clusterState, clusterState.getRoutingNodes().node(origPrimaryNodeId).iterator().next());
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyFailedShard(clusterState, clusterState.getRoutingNodes().node(origPrimaryNodeId).iterator().next());
|
||||
|
||||
// check promotion of replica to primary
|
||||
assertThat(clusterState.getRoutingNodes().node(origReplicaNodeId).iterator().next().state(), equalTo(STARTED));
|
||||
|
@ -164,16 +158,16 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Adding two nodes and performing rerouting");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("Start the shards (primaries)");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
ClusterState newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
|
||||
|
@ -187,10 +181,10 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Start the shards (backups)");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
|
||||
|
@ -204,11 +198,10 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("fail the primary shard, will have no place to be rerouted to (single node), so stays unassigned");
|
||||
ShardRouting shardToFail = clusterState.routingTable().index("test").shard(0).primaryShard();
|
||||
routingResult = strategy.applyFailedShard(clusterState, shardToFail);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
newState = strategy.applyFailedShard(clusterState, shardToFail);
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(2));
|
||||
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(2));
|
||||
assertThat(clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId(), not(equalTo(shardToFail.currentNodeId())));
|
||||
|
@ -238,10 +231,10 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Adding single node and performing rerouting");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
ClusterState newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
|
||||
|
@ -254,10 +247,10 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("fail the first shard, will have no place to be rerouted to (single node), so stays unassigned");
|
||||
ShardRouting firstShard = clusterState.getRoutingNodes().node("node1").iterator().next();
|
||||
routingResult = strategy.applyFailedShard(clusterState, firstShard);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.applyFailedShard(clusterState, firstShard);
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
|
||||
|
@ -295,13 +288,9 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(nodeBuilder).build();
|
||||
while (!clusterState.routingTable().shardsWithState(UNASSIGNED).isEmpty()) {
|
||||
// start all initializing
|
||||
clusterState = ClusterState.builder(clusterState)
|
||||
.routingResult(strategy
|
||||
.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING))
|
||||
)
|
||||
.build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
|
||||
// and assign more unassigned
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(strategy.reroute(clusterState, "reroute")).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
}
|
||||
|
||||
int shardsToFail = randomIntBetween(1, numberOfReplicas);
|
||||
|
@ -320,9 +309,7 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
RoutingAllocation.Result routingResult = strategy.applyFailedShards(clusterState, failedShards);
|
||||
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyFailedShards(clusterState, failedShards);
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
for (FailedRerouteAllocation.FailedShard failedShard : failedShards) {
|
||||
if (routingNodes.getByAllocationId(failedShard.routingEntry.shardId(), failedShard.routingEntry.allocationId().getId()) != null) {
|
||||
|
@ -357,11 +344,11 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Adding two nodes and performing rerouting");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
ClusterState newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, not(clusterState));
|
||||
clusterState = newState;
|
||||
final String nodeHoldingPrimary = clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
|
||||
|
@ -374,9 +361,9 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("fail the first shard, will start INITIALIZING on the second node");
|
||||
final ShardRouting firstShard = clusterState.getRoutingNodes().node(nodeHoldingPrimary).iterator().next();
|
||||
routingResult = strategy.applyFailedShard(clusterState, firstShard);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
assertTrue(routingResult.changed());
|
||||
newState = strategy.applyFailedShard(clusterState, firstShard);
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
|
||||
final String nodeHoldingPrimary2 = clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId();
|
||||
assertThat(nodeHoldingPrimary2, not(equalTo(nodeHoldingPrimary)));
|
||||
|
@ -412,15 +399,14 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Adding two nodes and performing rerouting");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("Start the shards (primaries)");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
ClusterState newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(2));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
|
||||
|
@ -434,10 +420,10 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Start the shards (backups)");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(2));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
|
||||
|
@ -451,11 +437,11 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Adding third node and reroute");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(2));
|
||||
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED, RELOCATING), equalTo(2));
|
||||
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED), lessThan(3));
|
||||
|
@ -466,12 +452,11 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Fail the shards on node 3");
|
||||
ShardRouting shardToFail = routingNodes.node("node3").iterator().next();
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyFailedShard(clusterState, shardToFail);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.applyFailedShard(clusterState, shardToFail);
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(2));
|
||||
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED, RELOCATING), equalTo(2));
|
||||
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED), lessThan(3));
|
||||
|
@ -502,15 +487,15 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).size(), equalTo(2));
|
||||
// start primary shards
|
||||
clusterState = ClusterState.builder(clusterState).routingTable(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)).routingTable()).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
|
||||
|
||||
// fail the primary shard, check replicas get removed as well...
|
||||
ShardRouting primaryShardToFail = clusterState.routingTable().index("test").shard(0).primaryShard();
|
||||
RoutingAllocation.Result routingResult = allocation.applyFailedShard(clusterState, primaryShardToFail);
|
||||
assertThat(routingResult.changed(), equalTo(true));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
ClusterState newState = allocation.applyFailedShard(clusterState, primaryShardToFail);
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
// the primary gets allocated on another node, replicas are unassigned
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).size(), equalTo(2));
|
||||
|
@ -519,7 +504,7 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
assertThat(newPrimaryShard, not(equalTo(primaryShardToFail)));
|
||||
|
||||
// start the primary shard
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
|
||||
}
|
||||
|
@ -540,24 +525,24 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
// add 4 nodes
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3")).add(newNode("node4"))).build();
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.reroute(clusterState, "reroute")).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).size(), equalTo(2));
|
||||
// start primary shards
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
|
||||
|
||||
// start another replica shard, while keep one initializing
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, Collections.singletonList(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(0)))).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, Collections.singletonList(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(0)));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
|
||||
|
||||
// fail the primary shard, check one replica gets elected to primary, others become INITIALIZING (from it)
|
||||
ShardRouting primaryShardToFail = clusterState.routingTable().index("test").shard(0).primaryShard();
|
||||
RoutingAllocation.Result routingResult = allocation.applyFailedShard(clusterState, primaryShardToFail);
|
||||
assertThat(routingResult.changed(), equalTo(true));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
ClusterState newState = allocation.applyFailedShard(clusterState, primaryShardToFail);
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.EmptyClusterInfoService;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
|
@ -31,7 +32,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.Decision;
|
|||
import org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider;
|
||||
import org.elasticsearch.common.settings.ClusterSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.test.gateway.NoopGatewayAllocator;
|
||||
|
||||
import java.util.Collections;
|
||||
|
@ -71,12 +71,12 @@ public class FilterAllocationDeciderTests extends ESAllocationTestCase {
|
|||
,allocation), Decision.NO);
|
||||
|
||||
// after failing the shard we are unassigned since the node is blacklisted and we can't initialize on the other node
|
||||
state = stateFromResult(state, service.reroute(state, "try allocate again"));
|
||||
state = service.reroute(state, "try allocate again");
|
||||
routingTable = state.routingTable();
|
||||
assertEquals(routingTable.index("idx").shard(0).shards().get(0).state(), INITIALIZING);
|
||||
assertEquals(routingTable.index("idx").shard(0).shards().get(0).currentNodeId(), "node2");
|
||||
|
||||
state = stateFromResult(state, service.applyStartedShards(state, routingTable.index("idx").shard(0).shards()));
|
||||
state = service.applyStartedShards(state, routingTable.index("idx").shard(0).shards());
|
||||
routingTable = state.routingTable();
|
||||
|
||||
// ok now we are started and can be allocated anywhere!! lets see...
|
||||
|
@ -84,7 +84,7 @@ public class FilterAllocationDeciderTests extends ESAllocationTestCase {
|
|||
assertEquals(routingTable.index("idx").shard(0).shards().get(0).currentNodeId(), "node2");
|
||||
|
||||
// we fail it again to check if we are initializing immediately on the other node
|
||||
state = stateFromResult(state, service.applyFailedShard(state, routingTable.index("idx").shard(0).shards().get(0)));
|
||||
state = service.applyFailedShard(state, routingTable.index("idx").shard(0).shards().get(0));
|
||||
routingTable = state.routingTable();
|
||||
assertEquals(routingTable.index("idx").shard(0).shards().get(0).state(), INITIALIZING);
|
||||
assertEquals(routingTable.index("idx").shard(0).shards().get(0).currentNodeId(), "node1");
|
||||
|
@ -99,10 +99,6 @@ public class FilterAllocationDeciderTests extends ESAllocationTestCase {
|
|||
,allocation), Decision.YES);
|
||||
}
|
||||
|
||||
private ClusterState stateFromResult(ClusterState previousState, RoutingAllocation.Result result) {
|
||||
return ClusterState.builder(previousState).routingTable(result.routingTable()).metaData(result.metaData()).build();
|
||||
}
|
||||
|
||||
private ClusterState createInitialClusterState(AllocationService service, Settings settings) {
|
||||
MetaData.Builder metaBuilder = MetaData.builder();
|
||||
metaBuilder.put(IndexMetaData.builder("idx").settings(settings(Version.CURRENT).put(settings))
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
|
@ -31,7 +32,6 @@ import org.elasticsearch.cluster.routing.ShardRouting;
|
|||
import org.elasticsearch.cluster.routing.ShardRoutingState;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -71,17 +71,14 @@ public class FilterRoutingTests extends ESAllocationTestCase {
|
|||
.add(newNode("node3", singletonMap("tag1", "value3")))
|
||||
.add(newNode("node4", singletonMap("tag1", "value4")))
|
||||
).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
|
||||
|
||||
logger.info("--> start the shards (primaries)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> start the shards (replicas)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> make sure shards are only allocated on tag1 with value1 and value2");
|
||||
List<ShardRouting> startedShards = clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED);
|
||||
|
@ -119,17 +116,14 @@ public class FilterRoutingTests extends ESAllocationTestCase {
|
|||
.add(newNode("node3", singletonMap("tag1", "value3")))
|
||||
.add(newNode("node4", singletonMap("tag1", "value4")))
|
||||
).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
|
||||
|
||||
logger.info("--> start the shards (primaries)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> start the shards (replicas)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> make sure shards are only allocated on tag1 with value1 and value2");
|
||||
List<ShardRouting> startedShards = clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED);
|
||||
|
@ -148,15 +142,13 @@ public class FilterRoutingTests extends ESAllocationTestCase {
|
|||
.build()))
|
||||
.build();
|
||||
clusterState = ClusterState.builder(clusterState).metaData(updatedMetaData).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(2));
|
||||
|
||||
logger.info("--> finish relocation");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
startedShards = clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED);
|
||||
assertThat(startedShards.size(), equalTo(4));
|
||||
|
@ -185,14 +177,12 @@ public class FilterRoutingTests extends ESAllocationTestCase {
|
|||
DiscoveryNode node1 = newNode("node1", singletonMap("tag1", "value1"));
|
||||
DiscoveryNode node2 = newNode("node2", singletonMap("tag1", "value2"));
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(node1).add(node2)).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().node(node1.getId()).numberOfShardsWithState(INITIALIZING), equalTo(2));
|
||||
assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(INITIALIZING), equalTo(2));
|
||||
|
||||
logger.info("--> start the shards (only primaries)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> make sure all shards are started");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(4));
|
||||
|
@ -204,29 +194,24 @@ public class FilterRoutingTests extends ESAllocationTestCase {
|
|||
.build());
|
||||
|
||||
logger.info("--> move shards from node1 to node2");
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
logger.info("--> check that concurrent recoveries only allows 1 shard to move");
|
||||
assertThat(clusterState.getRoutingNodes().node(node1.getId()).numberOfShardsWithState(STARTED), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(INITIALIZING), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(STARTED), equalTo(2));
|
||||
|
||||
logger.info("--> start the shards (only primaries)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("--> move second shard from node1 to node2");
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(INITIALIZING), equalTo(1));
|
||||
assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(STARTED), equalTo(3));
|
||||
|
||||
logger.info("--> start the shards (only primaries)");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(STARTED), equalTo(4));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,15 +78,13 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
|
|||
logger.info("adding three nodes and performing rerouting");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(
|
||||
newNode("node1")).add(newNode("node2")).add(newNode("node3"))).build();
|
||||
RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(0));
|
||||
assertThat(clusterState.metaData().index("test-old").inSyncAllocationIds(0), equalTo(new HashSet<>(Arrays.asList("x", "y"))));
|
||||
|
||||
logger.info("start primary shard");
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingTable().shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(1));
|
||||
|
@ -95,8 +93,7 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
|
|||
assertThat(clusterState.metaData().index("test-old").inSyncAllocationIds(0), equalTo(new HashSet<>(Arrays.asList("x", "y"))));
|
||||
|
||||
logger.info("start replica shards");
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(3));
|
||||
|
||||
|
@ -104,8 +101,7 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.remove("node1"))
|
||||
.build();
|
||||
rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
|
||||
// in-sync allocation ids should not be updated
|
||||
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(3));
|
||||
|
@ -114,8 +110,7 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.remove("node2").remove("node3"))
|
||||
.build();
|
||||
rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
|
||||
// in-sync allocation ids should not be updated
|
||||
assertThat(clusterState.getRoutingTable().shardsWithState(UNASSIGNED).size(), equalTo(3));
|
||||
|
@ -125,24 +120,22 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node1")))
|
||||
.build();
|
||||
rerouteResult = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 0, "node1", true)), false, false);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState,
|
||||
new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 0, "node1", true)), false, false)
|
||||
.getClusterState();
|
||||
|
||||
// check that in-sync allocation ids are reset by forcing an empty primary
|
||||
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(0));
|
||||
|
||||
logger.info("start primary shard");
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingTable().shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(1));
|
||||
|
||||
logger.info("fail primary shard");
|
||||
ShardRouting startedPrimary = clusterState.getRoutingNodes().shardsWithState(STARTED).get(0);
|
||||
rerouteResult = allocation.applyFailedShard(clusterState, startedPrimary);
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyFailedShard(clusterState, startedPrimary);
|
||||
|
||||
assertThat(clusterState.getRoutingTable().shardsWithState(STARTED).size(), equalTo(0));
|
||||
assertEquals(Collections.singleton(startedPrimary.allocationId().getId()),
|
||||
|
@ -165,8 +158,7 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.remove(replicaShard.currentNodeId()))
|
||||
.build();
|
||||
RoutingAllocation.Result rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(2));
|
||||
|
||||
logger.info("fail replica (for which there is no shard routing in the CS anymore)");
|
||||
|
@ -236,8 +228,7 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.remove(replicaShard.currentNodeId()))
|
||||
.build();
|
||||
RoutingAllocation.Result rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
|
||||
// in-sync allocation ids should not be updated
|
||||
assertEquals(inSyncSet, clusterState.metaData().index("test").inSyncAllocationIds(0));
|
||||
|
@ -248,20 +239,17 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode(replicaShard.currentNodeId())))
|
||||
.build();
|
||||
rerouteResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("start replica shards");
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("remove the node");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.remove(replicaShard.currentNodeId()))
|
||||
.build();
|
||||
rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
}
|
||||
clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
}
|
||||
|
||||
// in-sync allocation set is bounded
|
||||
Set<String> newInSyncSet = clusterState.metaData().index("test").inSyncAllocationIds(0);
|
||||
|
@ -285,14 +273,12 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
|
|||
logger.info("adding two nodes and performing rerouting");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(
|
||||
newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(0));
|
||||
|
||||
logger.info("start primary shard");
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.getRoutingTable().shardsWithState(STARTED).size(), equalTo(1));
|
||||
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(1));
|
||||
|
@ -300,8 +286,7 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
|
|||
equalTo(clusterState.metaData().index("test").inSyncAllocationIds(0).iterator().next()));
|
||||
|
||||
logger.info("start replica shard");
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(2));
|
||||
return clusterState;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
|
@ -30,12 +31,12 @@ import org.elasticsearch.cluster.routing.RoutingTable;
|
|||
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
|
@ -84,10 +85,10 @@ public class IndexBalanceTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState)
|
||||
.nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3"))).build();
|
||||
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
ClusterState newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
|
||||
|
@ -100,16 +101,13 @@ public class IndexBalanceTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Another round of rebalancing");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
|
||||
assertFalse(routingResult.changed());
|
||||
newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
|
||||
|
@ -123,16 +121,16 @@ public class IndexBalanceTests extends ESAllocationTestCase {
|
|||
}
|
||||
|
||||
logger.info("Reroute, nothing should change");
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
assertFalse(routingResult.changed());
|
||||
newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
|
||||
logger.info("Start the more shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
|
||||
|
@ -202,10 +200,9 @@ public class IndexBalanceTests extends ESAllocationTestCase {
|
|||
logger.info("Adding one node and performing rerouting");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
|
||||
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
ClusterState newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
|
||||
|
@ -219,17 +216,15 @@ public class IndexBalanceTests extends ESAllocationTestCase {
|
|||
logger.info("Add another node and perform rerouting, nothing will happen since primary not started");
|
||||
clusterState = ClusterState.builder(clusterState)
|
||||
.nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
|
||||
assertFalse(routingResult.changed());
|
||||
|
||||
logger.info("Start the primary shard");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
|
||||
|
@ -243,17 +238,17 @@ public class IndexBalanceTests extends ESAllocationTestCase {
|
|||
}
|
||||
|
||||
logger.info("Reroute, nothing should change");
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
assertFalse(routingResult.changed());
|
||||
newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
|
||||
logger.info("Start the backup shard");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(2));
|
||||
|
@ -273,30 +268,29 @@ public class IndexBalanceTests extends ESAllocationTestCase {
|
|||
logger.info("Add another node and perform rerouting, nothing will happen since primary not started");
|
||||
clusterState = ClusterState.builder(clusterState)
|
||||
.nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
|
||||
logger.info("Reroute, nothing should change");
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
assertFalse(routingResult.changed());
|
||||
newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
|
||||
logger.info("Start the backup shard");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
|
||||
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test1").shards().size(), equalTo(3));
|
||||
assertThat(clusterState.routingTable().index("test1").shards().size(), equalTo(3));
|
||||
|
||||
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED), equalTo(4));
|
||||
assertThat(routingNodes.node("node2").numberOfShardsWithState(STARTED), equalTo(4));
|
||||
|
@ -340,10 +334,9 @@ public class IndexBalanceTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState)
|
||||
.nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3"))).build();
|
||||
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
ClusterState newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
|
||||
|
@ -356,16 +349,14 @@ public class IndexBalanceTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Another round of rebalancing");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
|
||||
assertFalse(routingResult.changed());
|
||||
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
|
||||
|
@ -379,15 +370,15 @@ public class IndexBalanceTests extends ESAllocationTestCase {
|
|||
}
|
||||
|
||||
logger.info("Reroute, nothing should change");
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
assertFalse(routingResult.changed());
|
||||
newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
|
||||
logger.info("Start the more shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
|
||||
|
@ -419,10 +410,9 @@ public class IndexBalanceTests extends ESAllocationTestCase {
|
|||
|
||||
assertThat(clusterState.routingTable().index("test1").shards().size(), equalTo(3));
|
||||
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.routingTable().index("test1").shards().size(), equalTo(3));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test1").shard(i).size(), equalTo(2));
|
||||
|
@ -435,16 +425,14 @@ public class IndexBalanceTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Another round of rebalancing");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
|
||||
assertFalse(routingResult.changed());
|
||||
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
assertThat(clusterState.routingTable().index("test1").shards().size(), equalTo(3));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test1").shard(i).size(), equalTo(2));
|
||||
|
@ -458,15 +446,15 @@ public class IndexBalanceTests extends ESAllocationTestCase {
|
|||
}
|
||||
|
||||
logger.info("Reroute, nothing should change");
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
assertFalse(routingResult.changed());
|
||||
newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
|
||||
logger.info("Start the more shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test1").shards().size(), equalTo(3));
|
||||
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test1").shard(i).size(), equalTo(2));
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.EmptyClusterInfoService;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
|
@ -34,7 +35,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
|
|||
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
|
||||
import org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.test.gateway.NoopGatewayAllocator;
|
||||
|
||||
import java.util.Collections;
|
||||
|
@ -43,6 +43,8 @@ import java.util.List;
|
|||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase {
|
||||
|
||||
|
@ -89,10 +91,10 @@ public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase {
|
|||
List<FailedRerouteAllocation.FailedShard> failedShards = Collections.singletonList(
|
||||
new FailedRerouteAllocation.FailedShard(routingTable.index("idx").shard(0).shards().get(0), "boom" + i,
|
||||
new UnsupportedOperationException()));
|
||||
RoutingAllocation.Result result = strategy.applyFailedShards(clusterState, failedShards);
|
||||
assertTrue(result.changed());
|
||||
routingTable = result.routingTable();
|
||||
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
|
||||
ClusterState newState = strategy.applyFailedShards(clusterState, failedShards);
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingTable = newState.routingTable();
|
||||
assertEquals(routingTable.index("idx").shards().size(), 1);
|
||||
assertEquals(routingTable.index("idx").shard(0).shards().get(0).state(), INITIALIZING);
|
||||
assertEquals(routingTable.index("idx").shard(0).shards().get(0).unassignedInfo().getNumFailedAllocations(), i+1);
|
||||
|
@ -102,18 +104,21 @@ public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase {
|
|||
List<FailedRerouteAllocation.FailedShard> failedShards = Collections.singletonList(
|
||||
new FailedRerouteAllocation.FailedShard(routingTable.index("idx").shard(0).shards().get(0), "boom",
|
||||
new UnsupportedOperationException()));
|
||||
RoutingAllocation.Result result = strategy.applyFailedShards(clusterState, failedShards);
|
||||
assertTrue(result.changed());
|
||||
routingTable = result.routingTable();
|
||||
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
|
||||
ClusterState newState = strategy.applyFailedShards(clusterState, failedShards);
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingTable = newState.routingTable();
|
||||
assertEquals(routingTable.index("idx").shards().size(), 1);
|
||||
assertEquals(routingTable.index("idx").shard(0).shards().get(0).unassignedInfo().getNumFailedAllocations(), retries);
|
||||
assertEquals(routingTable.index("idx").shard(0).shards().get(0).state(), UNASSIGNED);
|
||||
assertEquals(routingTable.index("idx").shard(0).shards().get(0).unassignedInfo().getMessage(), "boom");
|
||||
|
||||
result = strategy.reroute(clusterState, new AllocationCommands(), false, true); // manual reroute should retry once
|
||||
assertTrue(result.changed());
|
||||
routingTable = result.routingTable();
|
||||
// manual reroute should retry once
|
||||
newState = strategy.reroute(clusterState, new AllocationCommands(), false, true).getClusterState();
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingTable = newState.routingTable();
|
||||
|
||||
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
|
||||
assertEquals(routingTable.index("idx").shards().size(), 1);
|
||||
assertEquals(routingTable.index("idx").shard(0).shards().get(0).unassignedInfo().getNumFailedAllocations(), retries);
|
||||
|
@ -124,10 +129,11 @@ public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase {
|
|||
failedShards = Collections.singletonList(
|
||||
new FailedRerouteAllocation.FailedShard(routingTable.index("idx").shard(0).shards().get(0), "boom",
|
||||
new UnsupportedOperationException()));
|
||||
result = strategy.applyFailedShards(clusterState, failedShards);
|
||||
assertTrue(result.changed());
|
||||
routingTable = result.routingTable();
|
||||
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
|
||||
|
||||
newState = strategy.applyFailedShards(clusterState, failedShards);
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingTable = newState.routingTable();
|
||||
assertEquals(routingTable.index("idx").shards().size(), 1);
|
||||
assertEquals(routingTable.index("idx").shard(0).shards().get(0).unassignedInfo().getNumFailedAllocations(), retries+1);
|
||||
assertEquals(routingTable.index("idx").shard(0).shards().get(0).state(), UNASSIGNED);
|
||||
|
@ -144,10 +150,10 @@ public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase {
|
|||
List<FailedRerouteAllocation.FailedShard> failedShards = Collections.singletonList(
|
||||
new FailedRerouteAllocation.FailedShard(routingTable.index("idx").shard(0).shards().get(0), "boom" + i,
|
||||
new UnsupportedOperationException()));
|
||||
RoutingAllocation.Result result = strategy.applyFailedShards(clusterState, failedShards);
|
||||
assertTrue(result.changed());
|
||||
routingTable = result.routingTable();
|
||||
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
|
||||
ClusterState newState = strategy.applyFailedShards(clusterState, failedShards);
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingTable = newState.routingTable();
|
||||
assertEquals(routingTable.index("idx").shards().size(), 1);
|
||||
ShardRouting unassignedPrimary = routingTable.index("idx").shard(0).shards().get(0);
|
||||
assertEquals(unassignedPrimary.state(), INITIALIZING);
|
||||
|
@ -162,10 +168,10 @@ public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase {
|
|||
List<FailedRerouteAllocation.FailedShard> failedShards = Collections.singletonList(
|
||||
new FailedRerouteAllocation.FailedShard(routingTable.index("idx").shard(0).shards().get(0), "boom",
|
||||
new UnsupportedOperationException()));
|
||||
RoutingAllocation.Result result = strategy.applyFailedShards(clusterState, failedShards);
|
||||
assertTrue(result.changed());
|
||||
routingTable = result.routingTable();
|
||||
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
|
||||
ClusterState newState = strategy.applyFailedShards(clusterState, failedShards);
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingTable = newState.routingTable();
|
||||
assertEquals(routingTable.index("idx").shards().size(), 1);
|
||||
ShardRouting unassignedPrimary = routingTable.index("idx").shard(0).shards().get(0);
|
||||
assertEquals(unassignedPrimary.unassignedInfo().getNumFailedAllocations(), retries);
|
||||
|
@ -183,10 +189,10 @@ public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase {
|
|||
Settings.builder().put(clusterState.metaData().index("idx").getSettings()).put("index.allocation.max_retries",
|
||||
retries+1).build()
|
||||
).build(), true).build()).build();
|
||||
RoutingAllocation.Result result = strategy.reroute(clusterState, "settings changed", false);
|
||||
assertTrue(result.changed());
|
||||
routingTable = result.routingTable();
|
||||
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
|
||||
ClusterState newState = strategy.reroute(clusterState, "settings changed", false);
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingTable = newState.routingTable();
|
||||
// good we are initializing and we are maintaining failure information
|
||||
assertEquals(routingTable.index("idx").shards().size(), 1);
|
||||
ShardRouting unassignedPrimary = routingTable.index("idx").shard(0).shards().get(0);
|
||||
|
@ -211,10 +217,10 @@ public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase {
|
|||
List<FailedRerouteAllocation.FailedShard> failedShards = Collections.singletonList(
|
||||
new FailedRerouteAllocation.FailedShard(routingTable.index("idx").shard(0).shards().get(0), "ZOOOMG",
|
||||
new UnsupportedOperationException()));
|
||||
result = strategy.applyFailedShards(clusterState, failedShards);
|
||||
assertTrue(result.changed());
|
||||
routingTable = result.routingTable();
|
||||
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
|
||||
newState = strategy.applyFailedShards(clusterState, failedShards);
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingTable = newState.routingTable();
|
||||
assertEquals(routingTable.index("idx").shards().size(), 1);
|
||||
unassignedPrimary = routingTable.index("idx").shard(0).shards().get(0);
|
||||
assertEquals(unassignedPrimary.unassignedInfo().getNumFailedAllocations(), 1);
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.EmptyClusterInfoService;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
|
@ -39,7 +40,6 @@ import org.elasticsearch.cluster.routing.ShardRoutingState;
|
|||
import org.elasticsearch.cluster.routing.TestShardRouting;
|
||||
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
|
||||
import org.elasticsearch.cluster.routing.allocation.command.AllocationCommands;
|
||||
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider;
|
||||
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
|
||||
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
|
||||
import org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider;
|
||||
|
@ -52,7 +52,6 @@ import org.elasticsearch.common.util.set.Sets;
|
|||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.snapshots.Snapshot;
|
||||
import org.elasticsearch.snapshots.SnapshotId;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.elasticsearch.test.gateway.NoopGatewayAllocator;
|
||||
|
||||
|
@ -68,7 +67,6 @@ import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
|
|||
import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
|
@ -110,8 +108,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start two nodes and fully start the shards");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(3));
|
||||
|
@ -122,9 +119,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start all the primary shards, replicas will start initializing");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(3));
|
||||
|
@ -134,9 +129,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase {
|
|||
}
|
||||
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(3));
|
||||
|
@ -148,9 +141,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3", VersionUtils.getPreviousVersion())))
|
||||
.build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(3));
|
||||
|
@ -163,8 +154,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node4")))
|
||||
.build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(3));
|
||||
|
@ -174,8 +164,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase {
|
|||
}
|
||||
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(3));
|
||||
|
@ -338,11 +327,10 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase {
|
|||
AllocationService strategy = new MockAllocationService(Settings.EMPTY,
|
||||
allocationDeciders,
|
||||
NoopGatewayAllocator.INSTANCE, new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE);
|
||||
RoutingAllocation.Result result = strategy.reroute(state, new AllocationCommands(), true, false);
|
||||
state = strategy.reroute(state, new AllocationCommands(), true, false).getClusterState();
|
||||
// the two indices must stay as is, the replicas cannot move to oldNode2 because versions don't match
|
||||
state = ClusterState.builder(state).routingResult(result).build();
|
||||
assertThat(result.routingTable().index(shard2.getIndex()).shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(0));
|
||||
assertThat(result.routingTable().index(shard1.getIndex()).shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(0));
|
||||
assertThat(state.routingTable().index(shard2.getIndex()).shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(0));
|
||||
assertThat(state.routingTable().index(shard1.getIndex()).shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(0));
|
||||
}
|
||||
|
||||
public void testRestoreDoesNotAllocateSnapshotOnOlderNodes() {
|
||||
|
@ -371,35 +359,31 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase {
|
|||
AllocationService strategy = new MockAllocationService(Settings.EMPTY,
|
||||
allocationDeciders,
|
||||
NoopGatewayAllocator.INSTANCE, new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE);
|
||||
RoutingAllocation.Result result = strategy.reroute(state, new AllocationCommands(), true, false);
|
||||
state = strategy.reroute(state, new AllocationCommands(), true, false).getClusterState();
|
||||
|
||||
// Make sure that primary shards are only allocated on the new node
|
||||
for (int i = 0; i < numberOfShards; i++) {
|
||||
assertEquals("newNode", result.routingTable().index("test").getShards().get(i).primaryShard().currentNodeId());
|
||||
assertEquals("newNode", state.routingTable().index("test").getShards().get(i).primaryShard().currentNodeId());
|
||||
}
|
||||
}
|
||||
|
||||
private ClusterState stabilize(ClusterState clusterState, AllocationService service) {
|
||||
logger.trace("RoutingNodes: {}", clusterState.getRoutingNodes().prettyPrint());
|
||||
|
||||
RoutingAllocation.Result routingResult = service.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = service.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
assertRecoveryNodeVersions(routingNodes);
|
||||
|
||||
logger.info("complete rebalancing");
|
||||
for (int i = 0; i < 1000; i++) { // at most 200 iters - this should be enough for all tests
|
||||
boolean changed;
|
||||
do {
|
||||
logger.trace("RoutingNodes: {}", clusterState.getRoutingNodes().prettyPrint());
|
||||
routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
ClusterState newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
changed = newState.equals(clusterState) == false;
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
if (routingResult.changed() == false) {
|
||||
break;
|
||||
}
|
||||
assertRecoveryNodeVersions(routingNodes);
|
||||
}
|
||||
logger.info("stabilized success [{}]", routingResult.changed() == false);
|
||||
assertFalse(routingResult.changed());
|
||||
} while (changed);
|
||||
return clusterState;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,13 +20,13 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
|
@ -69,12 +69,11 @@ public class PreferLocalPrimariesToRelocatingPrimariesTests extends ESAllocation
|
|||
.add(newNode("node1", singletonMap("tag1", "value1")))
|
||||
.add(newNode("node2", singletonMap("tag1", "value2")))).build();
|
||||
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
|
||||
while (!clusterState.getRoutingNodes().shardsWithState(INITIALIZING).isEmpty()) {
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
}
|
||||
|
||||
logger.info("remove one of the nodes and apply filter to move everything from another node");
|
||||
|
@ -92,8 +91,7 @@ public class PreferLocalPrimariesToRelocatingPrimariesTests extends ESAllocation
|
|||
.build()))
|
||||
.build();
|
||||
clusterState = ClusterState.builder(clusterState).metaData(metaData).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove("node1")).build();
|
||||
routingResult = strategy.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
|
||||
logger.info("[{}] primaries should be still started but [{}] other primaries should be unassigned", numberOfShards, numberOfShards);
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(numberOfShards));
|
||||
|
@ -103,8 +101,7 @@ public class PreferLocalPrimariesToRelocatingPrimariesTests extends ESAllocation
|
|||
logger.info("start node back up");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node1", singletonMap("tag1", "value1")))).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
while (clusterState.getRoutingNodes().shardsWithState(STARTED).size() < totalNumberOfShards) {
|
||||
int localInitializations = 0;
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
|
@ -29,7 +30,6 @@ import org.elasticsearch.cluster.routing.RoutingTable;
|
|||
import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
@ -63,12 +63,10 @@ public class PreferPrimaryAllocationTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("adding two nodes and performing rerouting till all are allocated");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
while (!clusterState.getRoutingNodes().shardsWithState(INITIALIZING).isEmpty()) {
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
}
|
||||
|
||||
logger.info("increasing the number of replicas to 1, and perform a reroute (to get the replicas allocation going)");
|
||||
|
@ -76,8 +74,7 @@ public class PreferPrimaryAllocationTests extends ESAllocationTestCase {
|
|||
metaData = MetaData.builder(clusterState.metaData()).updateNumberOfReplicas(1).build();
|
||||
clusterState = ClusterState.builder(clusterState).routingTable(updatedRoutingTable).metaData(metaData).build();
|
||||
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("2 replicas should be initializing now for the existing indices (we throttle to 1)");
|
||||
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
|
||||
|
@ -94,8 +91,7 @@ public class PreferPrimaryAllocationTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).metaData(metaData).routingTable(updatedRoutingTable).build();
|
||||
|
||||
logger.info("reroute, verify that primaries for the new index primary shards are allocated");
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.routingTable().index("new_index").shardsWithState(INITIALIZING).size(), equalTo(2));
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
|
@ -29,7 +30,6 @@ import org.elasticsearch.cluster.routing.RoutingNodes;
|
|||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
|
||||
|
@ -59,28 +59,23 @@ public class PrimaryElectionRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Adding two nodes and performing rerouting");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
|
||||
RoutingAllocation.Result result = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(result).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
|
||||
result = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(result).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("Start the primary shard (on node1)");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
result = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(result).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("Start the backup shard (on node2)");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
result = strategy.applyStartedShards(clusterState, routingNodes.node("node2").shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(result).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.node("node2").shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("Adding third node and reroute and kill first node");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3")).remove("node1")).build();
|
||||
RoutingTable prevRoutingTable = clusterState.routingTable();
|
||||
result = strategy.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(result).build();
|
||||
clusterState = strategy.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingTable = clusterState.routingTable();
|
||||
|
||||
|
@ -112,13 +107,11 @@ public class PrimaryElectionRoutingTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Adding two nodes and performing rerouting");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("Start the primary shards");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
rerouteResult = allocation.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = allocation.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(routingNodes.shardsWithState(STARTED).size(), equalTo(2));
|
||||
|
@ -130,11 +123,8 @@ public class PrimaryElectionRoutingTests extends ESAllocationTestCase {
|
|||
logger.info("--> fail node with primary");
|
||||
String nodeIdToFail = clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId();
|
||||
String nodeIdRemaining = nodeIdToFail.equals("node1") ? "node2" : "node1";
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
|
||||
.add(newNode(nodeIdRemaining))
|
||||
).build();
|
||||
rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode(nodeIdRemaining))).build();
|
||||
clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(routingNodes.shardsWithState(STARTED).size(), equalTo(1));
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
|
@ -29,7 +30,6 @@ import org.elasticsearch.cluster.routing.RoutingNodes;
|
|||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
|
||||
|
@ -62,28 +62,24 @@ public class PrimaryNotRelocatedWhileBeingRecoveredTests extends ESAllocationTes
|
|||
|
||||
logger.info("Adding two nodes and performing rerouting");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("Start the primary shard (on node1)");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(5));
|
||||
|
||||
logger.info("start another node, replica will start recovering form primary");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(5));
|
||||
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(5));
|
||||
|
||||
logger.info("start another node, make sure the primary is not relocated");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(5));
|
||||
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(5));
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.EmptyClusterInfoService;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
|
@ -37,7 +38,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.Decision;
|
|||
import org.elasticsearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider;
|
||||
import org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.test.gateway.NoopGatewayAllocator;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
|
@ -83,7 +83,7 @@ public class RandomAllocationDeciderTests extends ESAllocationTestCase {
|
|||
int nodeIdCounter = 0;
|
||||
int atMostNodes = scaledRandomIntBetween(Math.max(1, maxNumReplicas), 15);
|
||||
final boolean frequentNodes = randomBoolean();
|
||||
RoutingAllocation.Result routingResult;
|
||||
AllocationService.CommandsResult routingResult;
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
logger.info("Start iteration [{}]", i);
|
||||
ClusterState.Builder stateBuilder = ClusterState.builder(clusterState);
|
||||
|
@ -109,14 +109,12 @@ public class RandomAllocationDeciderTests extends ESAllocationTestCase {
|
|||
stateBuilder.nodes(newNodesBuilder.build());
|
||||
clusterState = stateBuilder.build();
|
||||
if (nodesRemoved) {
|
||||
routingResult = strategy.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
clusterState = strategy.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
} else {
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
}
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
if (clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size() > 0) {
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
}
|
||||
}
|
||||
logger.info("Fill up nodes such that every shard can be allocated");
|
||||
|
@ -137,11 +135,9 @@ public class RandomAllocationDeciderTests extends ESAllocationTestCase {
|
|||
int iterations = 0;
|
||||
do {
|
||||
iterations++;
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
if (clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size() > 0) {
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
}
|
||||
|
||||
} while (clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size() != 0 ||
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.Version;
|
|||
import org.elasticsearch.cluster.ClusterInfo;
|
||||
import org.elasticsearch.cluster.ClusterInfoService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
|
@ -34,7 +35,6 @@ import org.elasticsearch.cluster.routing.ShardRouting;
|
|||
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
|
||||
|
@ -100,8 +100,7 @@ public class RebalanceAfterActiveTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start two nodes and fully start the shards");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(2));
|
||||
|
@ -111,8 +110,7 @@ public class RebalanceAfterActiveTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start all the primary shards, replicas will start initializing");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
|
@ -126,8 +124,7 @@ public class RebalanceAfterActiveTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(newNode("node3")).add(newNode("node4")).add(newNode("node5")).add(newNode("node6")).add(newNode("node7")).add(newNode("node8")).add(newNode("node9")).add(newNode("node10")))
|
||||
.build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
|
||||
|
@ -140,8 +137,7 @@ public class RebalanceAfterActiveTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("start the replica shards, rebalancing should start");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
// we only allow one relocation at a time
|
||||
|
@ -160,8 +156,7 @@ public class RebalanceAfterActiveTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("complete relocation, other half of relocation should happen");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
// we now only relocate 3, since 2 remain where they are!
|
||||
|
@ -178,8 +173,7 @@ public class RebalanceAfterActiveTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("complete relocation, that's it!");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(10));
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
|
@ -32,11 +33,11 @@ import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllo
|
|||
import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -71,8 +72,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
|
|||
assertThat(routingNodes.hasInactivePrimaries(), equalTo(false));
|
||||
assertThat(routingNodes.hasUnassignedPrimaries(), equalTo(true));
|
||||
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(assertShardStats(routingNodes), equalTo(true));
|
||||
|
@ -82,21 +82,18 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Another round of rebalancing");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("Reroute, nothing should change");
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
assertFalse(routingResult.changed());
|
||||
ClusterState newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
|
||||
logger.info("Start the more shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(assertShardStats(routingNodes), equalTo(true));
|
||||
|
@ -104,8 +101,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
|
|||
assertThat(routingNodes.hasInactivePrimaries(), equalTo(false));
|
||||
assertThat(routingNodes.hasUnassignedPrimaries(), equalTo(false));
|
||||
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
}
|
||||
|
||||
|
@ -128,57 +124,51 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
|
|||
logger.info("Adding one node and performing rerouting");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
|
||||
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("Add another node and perform rerouting, nothing will happen since primary not started");
|
||||
clusterState = ClusterState.builder(clusterState)
|
||||
.nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("Start the primary shard");
|
||||
RoutingNodes routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
|
||||
logger.info("Reroute, nothing should change");
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("Start the backup shard");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
logger.info("Add another node and perform rerouting, nothing will happen since primary not started");
|
||||
clusterState = ClusterState.builder(clusterState)
|
||||
.nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("Reroute, nothing should change");
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
assertFalse(routingResult.changed());
|
||||
ClusterState newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
|
||||
logger.info("Start the backup shard");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
|
||||
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
assertThat(newState, not(equalTo(clusterState)));
|
||||
clusterState = newState;
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertTrue(routingResult.changed());
|
||||
assertThat(clusterState.routingTable().index("test1").shards().size(), equalTo(3));
|
||||
|
||||
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED), equalTo(4));
|
||||
|
@ -220,8 +210,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
|
|||
assertThat(routingNodes.hasInactivePrimaries(), equalTo(false));
|
||||
assertThat(routingNodes.hasUnassignedPrimaries(), equalTo(true));
|
||||
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(assertShardStats(routingNodes), equalTo(true));
|
||||
|
@ -231,18 +220,15 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Another round of rebalancing");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
|
||||
assertFalse(routingResult.changed());
|
||||
ClusterState newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
assertThat(routingNodes.node("node1").numberOfShardsWithState(INITIALIZING), equalTo(1));
|
||||
assertThat(routingNodes.node("node2").numberOfShardsWithState(INITIALIZING), equalTo(1));
|
||||
assertThat(routingNodes.node("node3").numberOfShardsWithState(INITIALIZING), equalTo(1));
|
||||
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(assertShardStats(routingNodes), equalTo(true));
|
||||
|
@ -254,13 +240,12 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
|
|||
assertThat(routingNodes.node("node3").numberOfShardsWithState(STARTED), equalTo(1));
|
||||
|
||||
logger.info("Reroute, nothing should change");
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
assertFalse(routingResult.changed());
|
||||
newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
|
||||
logger.info("Start the more shards");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(assertShardStats(routingNodes), equalTo(true));
|
||||
|
@ -297,13 +282,12 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
|
|||
|
||||
assertThat(clusterState.routingTable().index("test1").shards().size(), equalTo(3));
|
||||
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
logger.info("Reroute, assign");
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
newState = strategy.reroute(clusterState, "reroute");
|
||||
assertThat(newState, equalTo(clusterState));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(assertShardStats(routingNodes), equalTo(true));
|
||||
|
@ -311,12 +295,10 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
|
|||
assertThat(routingNodes.hasInactivePrimaries(), equalTo(true));
|
||||
assertThat(routingNodes.hasUnassignedPrimaries(), equalTo(false));
|
||||
|
||||
assertFalse(routingResult.changed());
|
||||
|
||||
logger.info("Reroute, start the primaries");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(assertShardStats(routingNodes), equalTo(true));
|
||||
|
@ -326,8 +308,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Reroute, start the replicas");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(assertShardStats(routingNodes), equalTo(true));
|
||||
|
@ -347,8 +328,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
|
|||
logger.info("kill one node");
|
||||
IndexShardRoutingTable indexShardRoutingTable = clusterState.routingTable().index("test").shard(0);
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove(indexShardRoutingTable.primaryShard().currentNodeId())).build();
|
||||
routingResult = strategy.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.deassociateDeadNodes(clusterState, true, "reroute");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(assertShardStats(routingNodes), equalTo(true));
|
||||
|
@ -359,8 +339,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Start Recovering shards round 1");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(assertShardStats(routingNodes), equalTo(true));
|
||||
|
@ -370,8 +349,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
|
|||
|
||||
logger.info("Start Recovering shards round 2");
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
|
||||
routingNodes = clusterState.getRoutingNodes();
|
||||
|
||||
assertThat(assertShardStats(routingNodes), equalTo(true));
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
|
@ -34,7 +35,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationD
|
|||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.LocalTransportAddress;
|
||||
import org.elasticsearch.cluster.ESAllocationTestCase;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
|
@ -67,14 +67,12 @@ public class SameShardRoutingTests extends ESAllocationTestCase {
|
|||
MASTER_DATA_ROLES, Version.CURRENT))
|
||||
.add(new DiscoveryNode("node2", "node2", "node2", "test1", "test1", LocalTransportAddress.buildUnique(), emptyMap(),
|
||||
MASTER_DATA_ROLES, Version.CURRENT))).build();
|
||||
RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(numberOfShardsOfType(clusterState.getRoutingNodes(), ShardRoutingState.INITIALIZING), equalTo(2));
|
||||
|
||||
logger.info("--> start all primary shards, no replica will be started since its on the same host");
|
||||
routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
|
||||
|
||||
assertThat(numberOfShardsOfType(clusterState.getRoutingNodes(), ShardRoutingState.STARTED), equalTo(2));
|
||||
assertThat(numberOfShardsOfType(clusterState.getRoutingNodes(), ShardRoutingState.INITIALIZING), equalTo(0));
|
||||
|
@ -83,8 +81,7 @@ public class SameShardRoutingTests extends ESAllocationTestCase {
|
|||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.add(new DiscoveryNode("node3", "node3", "node3", "test2", "test2", LocalTransportAddress.buildUnique(), emptyMap(),
|
||||
MASTER_DATA_ROLES, Version.CURRENT))).build();
|
||||
routingResult = strategy.reroute(clusterState, "reroute");
|
||||
clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
|
||||
clusterState = strategy.reroute(clusterState, "reroute");
|
||||
|
||||
assertThat(numberOfShardsOfType(clusterState.getRoutingNodes(), ShardRoutingState.STARTED), equalTo(2));
|
||||
assertThat(numberOfShardsOfType(clusterState.getRoutingNodes(), ShardRoutingState.INITIALIZING), equalTo(2));
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue