|
10 | 10 |
|
11 | 11 | import org.elasticsearch.common.settings.ClusterSettings; |
12 | 12 | import org.elasticsearch.common.settings.Settings; |
| 13 | +import org.elasticsearch.common.unit.ByteSizeUnit; |
| 14 | +import org.elasticsearch.common.unit.ByteSizeValue; |
| 15 | +import org.elasticsearch.core.Nullable; |
13 | 16 | import org.elasticsearch.core.Releasable; |
| 17 | +import org.elasticsearch.jdk.JavaVersion; |
14 | 18 | import org.elasticsearch.test.ESTestCase; |
15 | 19 |
|
| 20 | +import java.util.ArrayList; |
| 21 | +import java.util.HashSet; |
| 22 | +import java.util.Objects; |
| 23 | +import java.util.Set; |
| 24 | + |
| 25 | +import static org.elasticsearch.common.util.set.Sets.newHashSet; |
| 26 | +import static org.elasticsearch.indices.recovery.RecoverySettings.DEFAULT_MAX_BYTES_PER_SEC; |
| 27 | +import static org.elasticsearch.indices.recovery.RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING; |
16 | 28 | import static org.elasticsearch.indices.recovery.RecoverySettings.INDICES_RECOVERY_MAX_CONCURRENT_SNAPSHOT_FILE_DOWNLOADS; |
17 | 29 | import static org.elasticsearch.indices.recovery.RecoverySettings.INDICES_RECOVERY_MAX_CONCURRENT_SNAPSHOT_FILE_DOWNLOADS_PER_NODE; |
18 | 30 | import static org.elasticsearch.indices.recovery.RecoverySettings.INDICES_RECOVERY_USE_SNAPSHOTS_SETTING; |
| 31 | +import static org.elasticsearch.indices.recovery.RecoverySettings.JAVA_VERSION_OVERRIDING_TEST_SETTING; |
| 32 | +import static org.elasticsearch.indices.recovery.RecoverySettings.TOTAL_PHYSICAL_MEMORY_OVERRIDING_TEST_SETTING; |
| 33 | +import static org.elasticsearch.node.NodeRoleSettings.NODE_ROLES_SETTING; |
19 | 34 | import static org.hamcrest.Matchers.containsString; |
| 35 | +import static org.hamcrest.Matchers.equalTo; |
20 | 36 | import static org.hamcrest.Matchers.is; |
21 | 37 | import static org.hamcrest.Matchers.notNullValue; |
22 | 38 | import static org.hamcrest.Matchers.nullValue; |
@@ -89,4 +105,206 @@ public void testMaxConcurrentSnapshotFileDownloadsPerNodeIsValidated() { |
89 | 105 | ) |
90 | 106 | ); |
91 | 107 | } |
| 108 | + |
| 109 | + public void testDefaultMaxBytesPerSecOnNonDataNode() { |
| 110 | + assertThat( |
| 111 | + "Non-data nodes have a default 40mb rate limit", |
| 112 | + nodeRecoverySettings().withRole(randomFrom("master", "ingest", "ml")).withRandomMemory().build().getMaxBytesPerSec(), |
| 113 | + equalTo(DEFAULT_MAX_BYTES_PER_SEC) |
| 114 | + ); |
| 115 | + } |
| 116 | + |
| 117 | + public void testMaxBytesPerSecOnNonDataNodeWithIndicesRecoveryMaxBytesPerSec() { |
| 118 | + final ByteSizeValue random = randomByteSizeValue(); |
| 119 | + assertThat( |
| 120 | + "Non-data nodes should use the defined rate limit when set", |
| 121 | + nodeRecoverySettings().withRole(randomFrom("master", "ingest", "ml")) |
| 122 | + .withIndicesRecoveryMaxBytesPerSec(random) |
| 123 | + .withRandomMemory() |
| 124 | + .build() |
| 125 | + .getMaxBytesPerSec(), |
| 126 | + equalTo(random) |
| 127 | + ); |
| 128 | + } |
| 129 | + |
| 130 | + public void testDefaultMaxBytesPerSecOnDataNode() { |
| 131 | + assertThat( |
| 132 | + "Data nodes that are not dedicated to cold/frozen have a default 40mb rate limit", |
| 133 | + nodeRecoverySettings().withRole(randomFrom("data", "data_hot", "data_warm", "data_content")) |
| 134 | + .withRandomMemory() |
| 135 | + .build() |
| 136 | + .getMaxBytesPerSec(), |
| 137 | + equalTo(DEFAULT_MAX_BYTES_PER_SEC) |
| 138 | + ); |
| 139 | + } |
| 140 | + |
| 141 | + public void testMaxBytesPerSecOnDataNodeWithIndicesRecoveryMaxBytesPerSec() { |
| 142 | + final Set<String> roles = new HashSet<>(randomSubsetOf(randomIntBetween(1, 4), "data", "data_hot", "data_warm", "data_content")); |
| 143 | + roles.addAll(randomSubsetOf(newHashSet("data_cold", "data_frozen"))); |
| 144 | + final ByteSizeValue random = randomByteSizeValue(); |
| 145 | + assertThat( |
| 146 | + "Data nodes that are not dedicated to cold/frozen should use the defined rate limit when set", |
| 147 | + nodeRecoverySettings().withRoles(roles) |
| 148 | + .withIndicesRecoveryMaxBytesPerSec(random) |
| 149 | + .withRandomMemory() |
| 150 | + .build() |
| 151 | + .getMaxBytesPerSec(), |
| 152 | + equalTo(random) |
| 153 | + ); |
| 154 | + } |
| 155 | + |
| 156 | + public void testDefaultMaxBytesPerSecOnColdOrFrozenNodeWithOldJvm() { |
| 157 | + assertThat( |
| 158 | + "Data nodes with only cold/frozen data roles have a default 40mb rate limit on Java version prior to 14", |
| 159 | + nodeRecoverySettings().withRoles( |
| 160 | + randomFrom(newHashSet("data_cold"), newHashSet("data_frozen"), newHashSet("data_cold", "data_frozen")) |
| 161 | + ).withJavaVersion(randomFrom("8", "9", "11")).withRandomMemory().build().getMaxBytesPerSec(), |
| 162 | + equalTo(DEFAULT_MAX_BYTES_PER_SEC) |
| 163 | + ); |
| 164 | + } |
| 165 | + |
| 166 | + public void testDefaultMaxBytesPerSecOnColdOrFrozenNode() { |
| 167 | + final Set<String> dataRoles = randomFrom( |
| 168 | + newHashSet("data_cold"), |
| 169 | + newHashSet("data_frozen"), |
| 170 | + newHashSet("data_cold", "data_frozen") |
| 171 | + ); |
| 172 | + final String recentVersion = JavaVersion.current().compareTo(JavaVersion.parse("14")) < 0 ? "14" : null; |
| 173 | + { |
| 174 | + assertThat( |
| 175 | + "Dedicated cold/frozen data nodes with <= 4GB of RAM have a default 40mb rate limit", |
| 176 | + nodeRecoverySettings().withRoles(dataRoles) |
| 177 | + .withMemory(ByteSizeValue.ofBytes(randomLongBetween(1L, ByteSizeUnit.GB.toBytes(4L)))) |
| 178 | + .withJavaVersion(recentVersion) |
| 179 | + .build() |
| 180 | + .getMaxBytesPerSec(), |
| 181 | + equalTo(new ByteSizeValue(40, ByteSizeUnit.MB)) |
| 182 | + ); |
| 183 | + } |
| 184 | + { |
| 185 | + assertThat( |
| 186 | + "Dedicated cold/frozen data nodes with 4GB < RAM <= 8GB have a default 60mb rate limit", |
| 187 | + nodeRecoverySettings().withRoles(dataRoles) |
| 188 | + .withMemory(ByteSizeValue.ofBytes(randomLongBetween(ByteSizeUnit.GB.toBytes(4L) + 1L, ByteSizeUnit.GB.toBytes(8L)))) |
| 189 | + .withJavaVersion(recentVersion) |
| 190 | + .build() |
| 191 | + .getMaxBytesPerSec(), |
| 192 | + equalTo(new ByteSizeValue(60, ByteSizeUnit.MB)) |
| 193 | + ); |
| 194 | + } |
| 195 | + { |
| 196 | + assertThat( |
| 197 | + "Dedicated cold/frozen data nodes with 8GB < RAM <= 16GB have a default 90mb rate limit", |
| 198 | + nodeRecoverySettings().withRoles(dataRoles) |
| 199 | + .withMemory(ByteSizeValue.ofBytes(randomLongBetween(ByteSizeUnit.GB.toBytes(8L) + 1L, ByteSizeUnit.GB.toBytes(16L)))) |
| 200 | + .withJavaVersion(recentVersion) |
| 201 | + .build() |
| 202 | + .getMaxBytesPerSec(), |
| 203 | + equalTo(new ByteSizeValue(90, ByteSizeUnit.MB)) |
| 204 | + ); |
| 205 | + } |
| 206 | + { |
| 207 | + assertThat( |
| 208 | + "Dedicated cold/frozen data nodes with 16GB < RAM <= 32GB have a default 90mb rate limit", |
| 209 | + nodeRecoverySettings().withRoles(dataRoles) |
| 210 | + .withMemory(ByteSizeValue.ofBytes(randomLongBetween(ByteSizeUnit.GB.toBytes(16L) + 1L, ByteSizeUnit.GB.toBytes(32L)))) |
| 211 | + .withJavaVersion(recentVersion) |
| 212 | + .build() |
| 213 | + .getMaxBytesPerSec(), |
| 214 | + equalTo(new ByteSizeValue(125, ByteSizeUnit.MB)) |
| 215 | + ); |
| 216 | + } |
| 217 | + { |
| 218 | + assertThat( |
| 219 | + "Dedicated cold/frozen data nodes with RAM > 32GB have a default 250mb rate limit", |
| 220 | + nodeRecoverySettings().withRoles(dataRoles) |
| 221 | + .withMemory(ByteSizeValue.ofBytes(randomLongBetween(ByteSizeUnit.GB.toBytes(32L) + 1L, ByteSizeUnit.TB.toBytes(4L)))) |
| 222 | + .withJavaVersion(recentVersion) |
| 223 | + .build() |
| 224 | + .getMaxBytesPerSec(), |
| 225 | + equalTo(new ByteSizeValue(250, ByteSizeUnit.MB)) |
| 226 | + ); |
| 227 | + } |
| 228 | + } |
| 229 | + |
| 230 | + public void testMaxBytesPerSecOnColdOrFrozenNodeWithIndicesRecoveryMaxBytesPerSec() { |
| 231 | + final ByteSizeValue random = randomByteSizeValue(); |
| 232 | + assertThat( |
| 233 | + "Dedicated cold/frozen data nodes should use the defined rate limit when set", |
| 234 | + nodeRecoverySettings().withRoles( |
| 235 | + randomFrom(newHashSet("data_cold"), newHashSet("data_frozen"), newHashSet("data_cold", "data_frozen")) |
| 236 | + ) |
| 237 | + .withJavaVersion(JavaVersion.current().compareTo(JavaVersion.parse("14")) < 0 ? "14" : null) |
| 238 | + .withMemory(ByteSizeValue.ofBytes(randomLongBetween(1L, ByteSizeUnit.TB.toBytes(4L)))) |
| 239 | + .withIndicesRecoveryMaxBytesPerSec(random) |
| 240 | + .build() |
| 241 | + .getMaxBytesPerSec(), |
| 242 | + equalTo(random) |
| 243 | + ); |
| 244 | + } |
| 245 | + |
| 246 | + public static ByteSizeValue randomByteSizeValue() { |
| 247 | + return new ByteSizeValue(randomLongBetween(0L, Long.MAX_VALUE >> 16)); |
| 248 | + } |
| 249 | + |
| 250 | + public static ByteSizeValue randomNonZeroByteSizeValue() { |
| 251 | + return new ByteSizeValue(randomLongBetween(1L, Long.MAX_VALUE >> 16)); |
| 252 | + } |
| 253 | + |
| 254 | + static NodeRecoverySettings nodeRecoverySettings() { |
| 255 | + return new NodeRecoverySettings(); |
| 256 | + } |
| 257 | + |
| 258 | + private static class NodeRecoverySettings { |
| 259 | + |
| 260 | + private Set<String> roles; |
| 261 | + private ByteSizeValue physicalMemory; |
| 262 | + private @Nullable String javaVersion; |
| 263 | + private @Nullable ByteSizeValue indicesRecoveryMaxBytesPerSec; |
| 264 | + |
| 265 | + NodeRecoverySettings withRole(String role) { |
| 266 | + this.roles = new HashSet<>(); |
| 267 | + this.roles.add(Objects.requireNonNull(role)); |
| 268 | + return this; |
| 269 | + } |
| 270 | + |
| 271 | + NodeRecoverySettings withRoles(Set<String> roles) { |
| 272 | + this.roles = Objects.requireNonNull(roles); |
| 273 | + return this; |
| 274 | + } |
| 275 | + |
| 276 | + NodeRecoverySettings withMemory(ByteSizeValue physicalMemory) { |
| 277 | + this.physicalMemory = Objects.requireNonNull(physicalMemory); |
| 278 | + return this; |
| 279 | + } |
| 280 | + |
| 281 | + NodeRecoverySettings withRandomMemory() { |
| 282 | + return withMemory(ByteSizeValue.ofBytes(randomLongBetween(ByteSizeUnit.GB.toBytes(1L), ByteSizeUnit.TB.toBytes(4L)))); |
| 283 | + } |
| 284 | + |
| 285 | + NodeRecoverySettings withJavaVersion(String javaVersion) { |
| 286 | + this.javaVersion = javaVersion; |
| 287 | + return this; |
| 288 | + } |
| 289 | + |
| 290 | + NodeRecoverySettings withIndicesRecoveryMaxBytesPerSec(ByteSizeValue indicesRecoveryMaxBytesPerSec) { |
| 291 | + this.indicesRecoveryMaxBytesPerSec = Objects.requireNonNull(indicesRecoveryMaxBytesPerSec); |
| 292 | + return this; |
| 293 | + } |
| 294 | + |
| 295 | + RecoverySettings build() { |
| 296 | + final Settings.Builder settings = Settings.builder(); |
| 297 | + settings.put(TOTAL_PHYSICAL_MEMORY_OVERRIDING_TEST_SETTING.getKey(), Objects.requireNonNull(physicalMemory)); |
| 298 | + if (roles.isEmpty() == false) { |
| 299 | + settings.putList(NODE_ROLES_SETTING.getKey(), new ArrayList<>(roles)); |
| 300 | + } |
| 301 | + if (javaVersion != null) { |
| 302 | + settings.put(JAVA_VERSION_OVERRIDING_TEST_SETTING.getKey(), javaVersion); |
| 303 | + } |
| 304 | + if (indicesRecoveryMaxBytesPerSec != null) { |
| 305 | + settings.put(INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey(), indicesRecoveryMaxBytesPerSec); |
| 306 | + } |
| 307 | + return new RecoverySettings(settings.build(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); |
| 308 | + } |
| 309 | + } |
92 | 310 | } |
0 commit comments