|
69 | 69 | * different version value. If you need to know whether the cluster as a whole speaks a new enough {@link TransportVersion} to understand a |
70 | 70 | * newly-added feature, use {@link org.elasticsearch.cluster.ClusterState#getMinTransportVersion}. |
71 | 71 | */ |
72 | | -public class TransportVersion implements VersionId<TransportVersion> { |
73 | | - |
74 | | - private final String name; |
75 | | - private final int id; |
76 | | - private final TransportVersion nextPatchVersion; |
77 | | - |
78 | | - public TransportVersion(int id) { |
79 | | - this(null, id, null); |
80 | | - } |
81 | | - |
82 | | - public TransportVersion(String name, int id, TransportVersion patchVersion) { |
83 | | - this.name = name; |
84 | | - this.id = id; |
85 | | - this.nextPatchVersion = patchVersion; |
86 | | - } |
87 | | - |
88 | | - public String name() { |
89 | | - return name; |
90 | | - } |
91 | | - |
92 | | - public int id() { |
93 | | - return id; |
94 | | - } |
95 | | - |
96 | | - public TransportVersion nextPatchVersion() { |
97 | | - return nextPatchVersion; |
98 | | - } |
| 72 | +public record TransportVersion(String name, int id, TransportVersion nextPatchVersion) implements VersionId<TransportVersion> { |
99 | 73 |
|
100 | 74 | private static final ParseField NAME = new ParseField("name"); |
101 | 75 | private static final ParseField IDS = new ParseField("ids"); |
@@ -288,7 +262,7 @@ public int hashCode() { |
288 | 262 |
|
289 | 263 | @Override |
290 | 264 | public String toString() { |
291 | | - return "" + id; |
| 265 | + return Integer.toString(id); |
292 | 266 | } |
293 | 267 |
|
294 | 268 | private static class VersionsHolder { |
@@ -332,38 +306,56 @@ private static class VersionsHolder { |
332 | 306 | private static Map<String, TransportVersion> loadTransportVersionsByName() { |
333 | 307 | Map<String, TransportVersion> transportVersions = new HashMap<>(); |
334 | 308 |
|
335 | | - String latestLocation = "/transport/latest/" + Version.CURRENT.major + "." + Version.CURRENT.minor + "-LATEST.json"; |
336 | | - int latestId; |
| 309 | + String latestLocation = "/transport/latest/" + Version.CURRENT.major + "." + Version.CURRENT.minor + ".json"; |
| 310 | + int latestId = -1; |
337 | 311 | try (InputStream inputStream = TransportVersion.class.getResourceAsStream(latestLocation)) { |
338 | | - TransportVersion latest = fromXContent(inputStream, Integer.MAX_VALUE); |
339 | | - if (latest == null) { |
340 | | - throw new IllegalStateException( |
341 | | - "invalid latest transport version for release version [" + Version.CURRENT.major + "." + Version.CURRENT.minor + "]" |
342 | | - ); |
| 312 | + // this check is required until bootstrapping for the new transport versions format is completed; |
| 313 | + // when load is false, we will only use the transport versions in the legacy format; |
| 314 | + // load becomes false if we don't find the latest or manifest files required for the new format |
| 315 | + if (inputStream != null) { |
| 316 | + TransportVersion latest = fromXContent(inputStream, Integer.MAX_VALUE); |
| 317 | + if (latest == null) { |
| 318 | + throw new IllegalStateException( |
| 319 | + "invalid latest transport version for release version [" |
| 320 | + + Version.CURRENT.major |
| 321 | + + "." |
| 322 | + + Version.CURRENT.minor |
| 323 | + + "]" |
| 324 | + ); |
| 325 | + } |
| 326 | + latestId = latest.id(); |
343 | 327 | } |
344 | | - latestId = latest.id(); |
345 | 328 | } catch (IOException ioe) { |
346 | 329 | throw new UncheckedIOException("latest transport version file not found at [" + latestLocation + "]", ioe); |
347 | 330 | } |
348 | 331 |
|
349 | | - String manifestLocation = "/transport/generated/generated-transport-versions-files-manifest.txt"; |
350 | | - List<String> versionFileNames; |
351 | | - try (InputStream transportVersionsManifest = TransportVersion.class.getResourceAsStream(manifestLocation)) { |
352 | | - BufferedReader reader = new BufferedReader(new InputStreamReader(transportVersionsManifest, StandardCharsets.UTF_8)); |
353 | | - versionFileNames = reader.lines().filter(line -> line.isBlank() == false).toList(); |
354 | | - } catch (IOException ioe) { |
355 | | - throw new UncheckedIOException("transport version manifest file not found at [" + manifestLocation + "]", ioe); |
| 332 | + String manifestLocation = "/transport/constant/constant-transport-versions-files-manifest.txt"; |
| 333 | + List<String> versionFileNames = null; |
| 334 | + if (latestId > -1) { |
| 335 | + try (InputStream inputStream = TransportVersion.class.getResourceAsStream(manifestLocation)) { |
| 336 | + if (inputStream == null) { |
| 337 | + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); |
| 338 | + versionFileNames = reader.lines().filter(line -> line.isBlank() == false).toList(); |
| 339 | + } |
| 340 | + } catch (IOException ioe) { |
| 341 | + throw new UncheckedIOException("transport version manifest file not found at [" + manifestLocation + "]", ioe); |
| 342 | + } |
356 | 343 | } |
357 | 344 |
|
358 | | - for (String name : versionFileNames) { |
359 | | - String versionLocation = "/transport/generated/" + name; |
360 | | - try (InputStream inputStream = TransportVersion.class.getResourceAsStream(versionLocation)) { |
361 | | - TransportVersion transportVersion = TransportVersion.fromXContent(inputStream, latestId); |
362 | | - if (transportVersion != null) { |
363 | | - transportVersions.put(transportVersion.name(), transportVersion); |
| 345 | + if (versionFileNames != null) { |
| 346 | + for (String name : versionFileNames) { |
| 347 | + String versionLocation = "/transport/constant/" + name; |
| 348 | + try (InputStream inputStream = TransportVersion.class.getResourceAsStream(versionLocation)) { |
| 349 | + if (inputStream == null) { |
| 350 | + throw new IllegalStateException("transport version file not found at [" + versionLocation + "]"); |
| 351 | + } |
| 352 | + TransportVersion transportVersion = TransportVersion.fromXContent(inputStream, latestId); |
| 353 | + if (transportVersion != null) { |
| 354 | + transportVersions.put(transportVersion.name(), transportVersion); |
| 355 | + } |
| 356 | + } catch (IOException ioe) { |
| 357 | + throw new UncheckedIOException("transport version file not found at [ " + versionLocation + "]", ioe); |
364 | 358 | } |
365 | | - } catch (IOException ioe) { |
366 | | - throw new UncheckedIOException("transport version set file not found at [ " + versionLocation + "]", ioe); |
367 | 359 | } |
368 | 360 | } |
369 | 361 |
|
|
0 commit comments