Skip to content

Commit 6600707

Browse files
authored
Build: Allow preserving shared dir (#24962)
This adds an option to `ClusterConfiguration` to preserve the `shared` directory when starting up a new cluster and switches the `qa:full-cluster-restart` tests to use it rather than disable the clean shared task. Relates to #24846
1 parent e22a682 commit 6600707

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ class ClusterConfiguration {
7676
" " + "-Xmx" + System.getProperty('tests.heap.size', '512m') +
7777
" " + System.getProperty('tests.jvm.argline', '')
7878

79+
/**
80+
* Should the shared environment be cleaned on cluster startup? Defaults
81+
* to {@code true} so we run with a clean cluster but some tests wish to
82+
* preserve snapshots between clusters so they set this to true.
83+
*/
84+
@Input
85+
boolean cleanShared = true
86+
7987
/**
8088
* A closure to call which returns the unicast host to connect to for cluster formation.
8189
*

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,24 @@ class ClusterFormationTasks {
5454
*/
5555
static List<NodeInfo> setup(Project project, String prefix, Task runner, ClusterConfiguration config) {
5656
File sharedDir = new File(project.buildDir, "cluster/shared")
57-
// first we remove everything in the shared cluster directory to ensure there are no leftovers in repos or anything
58-
// in theory this should not be necessary but repositories are only deleted in the cluster-state and not on-disk
59-
// such that snapshots survive failures / test runs and there is no simple way today to fix that.
60-
Task cleanup = project.tasks.create(name: "${prefix}#prepareCluster.cleanShared", type: Delete, dependsOn: config.dependencies) {
61-
delete sharedDir
62-
doLast {
63-
sharedDir.mkdirs()
64-
}
57+
Object startDependencies = config.dependencies
58+
/* First, if we want a clean environment, we remove everything in the
59+
* shared cluster directory to ensure there are no leftovers in repos
60+
* or anything in theory this should not be necessary but repositories
61+
* are only deleted in the cluster-state and not on-disk such that
62+
* snapshots survive failures / test runs and there is no simple way
63+
* today to fix that. */
64+
if (config.cleanShared) {
65+
Task cleanup = project.tasks.create(
66+
name: "${prefix}#prepareCluster.cleanShared",
67+
type: Delete,
68+
dependsOn: startDependencies) {
69+
delete sharedDir
70+
doLast {
71+
sharedDir.mkdirs()
72+
}
73+
}
74+
startDependencies = cleanup
6575
}
6676
List<Task> startTasks = []
6777
List<NodeInfo> nodes = []
@@ -103,7 +113,7 @@ class ClusterFormationTasks {
103113
}
104114
NodeInfo node = new NodeInfo(config, i, project, prefix, elasticsearchVersion, sharedDir)
105115
nodes.add(node)
106-
Task dependsOn = startTasks.empty ? cleanup : startTasks.get(0)
116+
Object dependsOn = startTasks.empty ? startDependencies : startTasks.get(0)
107117
startTasks.add(configureNode(project, prefix, runner, dependsOn, node, config, distro, nodes.get(0)))
108118
}
109119

qa/full-cluster-restart/build.gradle

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ for (Version version : indexCompatVersions) {
6666
clusterName = 'full-cluster-restart'
6767
numNodes = 2
6868
dataDir = { nodeNum -> oldClusterTest.nodes[nodeNum].dataDir }
69+
cleanShared = false // We want to keep snapshots made by the old cluster!
6970
}
7071

7172
tasks.getByName("${baseName}#upgradedClusterTestRunner").configure {
@@ -78,13 +79,6 @@ for (Version version : indexCompatVersions) {
7879
dependsOn = [upgradedClusterTest]
7980
}
8081

81-
/* Delay this change because the task we need to modify isn't created until
82-
* after projects are evaluated. */
83-
gradle.projectsEvaluated {
84-
// Disable cleaning the repository so we can test loading a snapshot
85-
tasks.getByName("${baseName}#upgradedClusterTestCluster#prepareCluster.cleanShared").enabled = false
86-
}
87-
8882
bwcTest.dependsOn(versionBwcTest)
8983
}
9084

0 commit comments

Comments
 (0)