From fd3dde1c6e04c854fed25237c2a4530c02d0c97f Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Thu, 12 Jan 2023 11:31:57 +0000 Subject: [PATCH 01/22] Add TransportVersion file --- .../org/elasticsearch/TransportVersion.java | 243 ++++++++++++++++++ .../main/java/org/elasticsearch/Version.java | 179 ++++++------- 2 files changed, 334 insertions(+), 88 deletions(-) create mode 100644 server/src/main/java/org/elasticsearch/TransportVersion.java diff --git a/server/src/main/java/org/elasticsearch/TransportVersion.java b/server/src/main/java/org/elasticsearch/TransportVersion.java new file mode 100644 index 0000000000000..c8addf429c275 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/TransportVersion.java @@ -0,0 +1,243 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch; + +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; + +public class TransportVersion implements Comparable { + public static final TransportVersion ZERO = new TransportVersion(0, "00000000-0000-0000-0000-000000000000"); + /* + * Legacy transport versions that matched the on-prem release version + */ + public static final TransportVersion V_7_0_0 = new TransportVersion(7_00_00_99, "7505fd05-d982-43ce-a63f-ff4c6c8bdeec"); + public static final TransportVersion V_7_0_1 = new TransportVersion(7_00_01_99, "ae772780-e6f9-46a1-b0a0-20ed0cae37f7"); + public static final TransportVersion V_7_1_0 = new TransportVersion(7_01_00_99, "fd09007c-1c54-450a-af99-9f941e1a53c2"); + public static final TransportVersion V_7_1_1 = new TransportVersion(7_01_01_99, "f7ddb16c-3495-42ef-8d54-1461570ca68c"); + public static final TransportVersion V_7_2_0 = new TransportVersion(7_02_00_99, "b74dbc52-e727-472c-af21-2156482e8796"); + public static final TransportVersion V_7_2_1 = new TransportVersion(7_02_01_99, "a3217b94-f436-4aab-a020-162c83ba18f2"); + public static final TransportVersion V_7_3_0 = new TransportVersion(7_03_00_99, "4f04e4c9-c5aa-49e4-8b99-abeb4e284a5a"); + public static final TransportVersion V_7_3_1 = new TransportVersion(7_03_01_99, "532b9bc9-e11f-48a2-b997-67ca68ffb354"); + public static final TransportVersion V_7_3_2 = new TransportVersion(7_03_02_99, "60da3953-8415-4d4f-a18d-853c3e68ebd6"); + public static final TransportVersion V_7_4_0 = new TransportVersion(7_04_00_99, "ec7e58aa-55b4-4064-a9dd-fd723a2ba7a8"); + public static final TransportVersion V_7_4_1 = new TransportVersion(7_04_01_99, "a316c26d-8e6a-4608-b1ec-062331552b98"); + public static final TransportVersion V_7_4_2 = new TransportVersion(7_04_02_99, "031a77e1-3640-4c8a-80cf-28ded96bab48"); + public static final TransportVersion V_7_5_0 = new TransportVersion(7_05_00_99, "cc6e14dc-9dc7-4b74-8e15-1f99a6cfbe03"); + public static final TransportVersion V_7_5_1 = new TransportVersion(7_05_01_99, "9d12be44-16dc-44a8-a89a-45c9174ea596"); + public static final TransportVersion V_7_5_2 = new TransportVersion(7_05_02_99, "484ed9de-7f5b-4e6b-a79a-0cb5e7570093"); + public static final TransportVersion V_7_6_0 = new TransportVersion(7_06_00_99, "4637b8ae-f3df-43ae-a065-ad4c29f3373a"); + public static final TransportVersion V_7_6_1 = new TransportVersion(7_06_01_99, "fe5b9f95-a311-4a92-943b-30ec256a331c"); + public static final TransportVersion V_7_6_2 = new TransportVersion(7_06_02_99, "5396cb30-d91c-4789-85e8-77efd552c785"); + public static final TransportVersion V_7_7_0 = new TransportVersion(7_07_00_99, "7bb73c48-ddb8-4437-b184-30371c35dd4b"); + public static final TransportVersion V_7_7_1 = new TransportVersion(7_07_01_99, "85507b0f-0fca-4daf-a80b-451fe75e04a0"); + public static final TransportVersion V_7_8_0 = new TransportVersion(7_08_00_99, "c3cc74af-d15e-494b-a907-6ad6dd2f4660"); + public static final TransportVersion V_7_8_1 = new TransportVersion(7_08_01_99, "7acb9f6e-32f2-45ce-b87d-ca1f165b8e7a"); + public static final TransportVersion V_7_9_0 = new TransportVersion(7_09_00_99, "9388fe76-192a-4053-b51c-d2a7b8eae545"); + public static final TransportVersion V_7_9_1 = new TransportVersion(7_09_01_99, "30fa10fc-df6b-4435-bd9e-acdb9ae1b268"); + public static final TransportVersion V_7_9_2 = new TransportVersion(7_09_02_99, "b58bb181-cecc-464e-b955-f6c1c1e7b4d0"); + public static final TransportVersion V_7_9_3 = new TransportVersion(7_09_03_99, "4406926c-e2b6-4b9a-a72a-1bee8357ad3e"); + public static final TransportVersion V_7_10_0 = new TransportVersion(7_10_00_90, "4efca195-38e4-4f74-b877-c26fb2a40733"); + public static final TransportVersion V_7_10_1 = new TransportVersion(7_10_01_90, "0070260c-aa0b-4fc2-9c87-5cd5f23b005f"); + public static final TransportVersion V_7_10_2 = new TransportVersion(7_10_02_90, "b369e2ed-261c-4b2f-8b42-0f0ba0549f8c"); + public static final TransportVersion V_7_11_0 = new TransportVersion(7_11_00_90, "3b43bcbc-1c5e-4cc2-a3b4-8ac8b64239e8"); + public static final TransportVersion V_7_11_1 = new TransportVersion(7_11_01_90, "2f75d13c-adde-4762-a46e-def8acce62b7"); + public static final TransportVersion V_7_11_2 = new TransportVersion(7_11_02_90, "2c852a4b-236d-4e8b-9373-336c9b52685a"); + public static final TransportVersion V_7_12_0 = new TransportVersion(7_12_00_90, "3be9ff6f-2d9f-4fc2-ba91-394dd5ebcf33"); + public static final TransportVersion V_7_12_1 = new TransportVersion(7_12_01_90, "ee4fdfac-2039-4b00-b42d-579cbde7120c"); + public static final TransportVersion V_7_13_0 = new TransportVersion(7_13_00_92, "e1fe494a-7c66-4571-8f8f-1d7e6d8df1b3"); + public static final TransportVersion V_7_13_1 = new TransportVersion(7_13_01_92, "66bc8d82-36da-4d54-b22d-aca691dc3d70"); + public static final TransportVersion V_7_13_2 = new TransportVersion(7_13_02_92, "2a6fc74c-4c44-4264-a619-37437cd2c5a0"); + public static final TransportVersion V_7_13_3 = new TransportVersion(7_13_03_92, "a31592f5-f8d2-490c-a02e-da9501823d8d"); + public static final TransportVersion V_7_13_4 = new TransportVersion(7_13_04_92, "3143240d-1831-4186-8a19-963336c4cea0"); + public static final TransportVersion V_7_14_0 = new TransportVersion(7_14_00_90, "8cf0954c-b085-467f-b20b-3cb4b2e69e3e"); + public static final TransportVersion V_7_14_1 = new TransportVersion(7_14_01_90, "3dbb62c3-cf73-4c76-8d5a-4ca70afe2c70"); + public static final TransportVersion V_7_14_2 = new TransportVersion(7_14_02_90, "7943ae20-df60-45e5-97ba-82fc0dfc8b89"); + public static final TransportVersion V_7_15_0 = new TransportVersion(7_15_00_90, "2273ac0e-00bb-4024-9e2e-ab78981623c6"); + public static final TransportVersion V_7_15_1 = new TransportVersion(7_15_01_90, "a8c3503d-3452-45cf-b385-e855e16547fe"); + public static final TransportVersion V_7_15_2 = new TransportVersion(7_15_02_90, "fbb8ad69-02e2-4c90-b2e4-23947107f8b4\n"); + public static final TransportVersion V_7_16_0 = new TransportVersion(7_16_00_9_1, "59abadd2-25db-4547-a991-c92306a3934e"); + public static final TransportVersion V_7_16_1 = new TransportVersion(7_16_01_9_1, "4ace6b6b-8bba-427f-8755-9e3b40092138"); + public static final TransportVersion V_7_16_2 = new TransportVersion(7_16_02_9_1, "785567b9-b320-48ef-b538-1753228904cd"); + public static final TransportVersion V_7_16_3 = new TransportVersion(7_16_03_9_1, "facf5ae7-3d4e-479c-9142-72529b784e30"); + public static final TransportVersion V_7_17_0 = new TransportVersion(7_17_00_9_1, "322efe93-4c73-4e15-9274-bb76836c8fa8"); + public static final TransportVersion V_7_17_1 = new TransportVersion(7_17_01_9_1, "51c72842-7974-4669-ad25-bf13ba307307"); + public static final TransportVersion V_7_17_2 = new TransportVersion(7_17_02_9_1, "82bea8d0-bfea-47c2-b7d3-217d8feb67e3"); + public static final TransportVersion V_7_17_3 = new TransportVersion(7_17_03_9_1, "a909c2f4-5cb8-46bf-af0f-cd18d1b7e9d2"); + public static final TransportVersion V_7_17_4 = new TransportVersion(7_17_04_9_1, "5076e164-18a4-4373-8be7-15f1843c46db"); + public static final TransportVersion V_7_17_5 = new TransportVersion(7_17_05_9_1, "da7e3509-7f61-4dd2-8d23-a61f628a62f6"); + public static final TransportVersion V_7_17_6 = new TransportVersion(7_17_06_9_1, "a47ecf02-e457-474f-887d-ee15a7ebd969"); + public static final TransportVersion V_7_17_7 = new TransportVersion(7_17_07_9_1, "108ba576-bb28-42f4-bcbf-845a0ce52560"); + public static final TransportVersion V_7_17_8 = new TransportVersion(7_17_08_9_1, "82a3e70d-cf0e-4efb-ad16-6077ab9fe19f"); + public static final TransportVersion V_7_17_9 = new TransportVersion(7_17_09_9_1, "afd50dda-735f-4eae-9309-3218ffec1b2d"); + public static final TransportVersion V_8_0_0 = new TransportVersion(8_00_00_99, "c7d2372c-9f01-4a79-8b11-227d862dfe4f"); + public static final TransportVersion V_8_0_1 = new TransportVersion(8_00_01_99, "56e044c3-37e5-4f7e-bd38-f493927354ac"); + public static final TransportVersion V_8_1_0 = new TransportVersion(8_01_00_99, "3dc49dce-9cef-492a-ac8d-3cc79f6b4280"); + public static final TransportVersion V_8_1_1 = new TransportVersion(8_01_01_99, "40cf32e5-17b0-4187-9de1-022cdea69db9"); + public static final TransportVersion V_8_1_2 = new TransportVersion(8_01_02_99, "54aa6394-08f3-4db7-b82e-314ae4b5b562"); + public static final TransportVersion V_8_1_3 = new TransportVersion(8_01_03_99, "9772b54b-1e14-485f-92e8-8847b3a3d569"); + public static final TransportVersion V_8_2_0 = new TransportVersion(8_02_00_99, "8ce6d555-202e-47db-ab7d-ade9dda1b7e8"); + public static final TransportVersion V_8_2_1 = new TransportVersion(8_02_01_99, "ffbb67e8-cc33-4b02-a995-b461d9ee36c8"); + public static final TransportVersion V_8_2_2 = new TransportVersion(8_02_02_99, "2499ee77-187d-4e10-8366-8e60d5f03676"); + public static final TransportVersion V_8_2_3 = new TransportVersion(8_02_03_99, "046aae43-3090-4ece-8c27-8d489f097548"); + public static final TransportVersion V_8_3_0 = new TransportVersion(8_03_00_99, "559ddb66-d857-4208-bed5-a995ccf478ea"); + public static final TransportVersion V_8_3_1 = new TransportVersion(8_03_01_99, "31f9b136-dbbe-4fa1-b811-d6afa2a1b472"); + public static final TransportVersion V_8_3_2 = new TransportVersion(8_03_02_99, "f6e9cd4c-2a71-4f9b-80d4-7ba97ebd18b2"); + public static final TransportVersion V_8_3_3 = new TransportVersion(8_03_03_99, "a784de3e-533e-4844-8728-c55c6932dd8e"); + public static final TransportVersion V_8_4_0 = new TransportVersion(8_04_00_99, "c0d12906-aa5b-45d4-94c7-cbcf4d9818ca"); + public static final TransportVersion V_8_4_1 = new TransportVersion(8_04_01_99, "9a915f76-f259-4361-b53d-3f19c7797fd8"); + public static final TransportVersion V_8_4_2 = new TransportVersion(8_04_02_99, "87c5b7b2-0f57-4172-8a81-b9f9a0198525"); + public static final TransportVersion V_8_4_3 = new TransportVersion(8_04_03_99, "327cb1a0-9b5d-4be9-8033-285c2549f770"); + public static final TransportVersion V_8_5_0 = new TransportVersion(8_05_00_99, "be3d7f23-7240-4904-9d7f-e25a0f766eca"); + public static final TransportVersion V_8_5_1 = new TransportVersion(8_05_01_99, "d349d202-f01c-4dbb-85dd-947fb4267c99"); + public static final TransportVersion V_8_5_2 = new TransportVersion(8_05_02_99, "b68b1331-fd64-44d9-9e71-f6796ec2024c"); + public static final TransportVersion V_8_5_3 = new TransportVersion(8_05_03_99, "9ca3c835-e3b7-4622-a08e-d51e42403b06"); + public static final TransportVersion V_8_5_4 = new TransportVersion(8_05_04_99, "97ee525c-555d-45ca-83dc-59cd592c8e86"); + public static final TransportVersion V_8_6_0 = new TransportVersion(8_06_00_99, "e209c5ed-3488-4415-b561-33492ca3b789"); + public static final TransportVersion V_8_7_0 = new TransportVersion(8_07_00_99, "f1ee7a85-4fa6-43f5-8679-33e2b750448b"); + /* + * Detached transport versions added below here. Starts at ES major version 10 equivalent. + */ + // public static final TransportVersion V10_000_000 = new TransportVersion(10_000_000, "dc3cbf06-3ed5-4e1b-9978-ee1d04d235bc"); + /* + * When adding a new transport version, ensure there is a gap (say, 100) between versions + * This is to make it possible to add intermediate versions for any bug fixes that may be required. + */ + + /** Reference to the latest transport version */ + public static final TransportVersion CURRENT = V_8_7_0; + + /** Reference to the earliest compatible transport version to this version of the codebase */ + public static final TransportVersion MINIMUM_COMPATIBLE = V_7_17_0; + + private static final Map idToVersion; + + static { + Map builder = new HashMap<>(); + Map uniqueIds = new HashMap<>(); + + for (Field declaredField : TransportVersion.class.getFields()) { + if (declaredField.getType().equals(TransportVersion.class)) { + String fieldName = declaredField.getName(); + try { + TransportVersion version = (TransportVersion) declaredField.get(null); + + TransportVersion maybePrevious = builder.put(version.id, version); + assert maybePrevious == null + : "expected [" + version.id + "] to be uniquely mapped but saw [" + maybePrevious + "] and [" + version + "]"; + + TransportVersion sameUniqueId = uniqueIds.put(version.uniqueId, version); + assert sameUniqueId == null + : "Versions " + + version + + " and " + + sameUniqueId + + " have the same unique id. Each TransportVersion should have a different unique id"; + + } catch (IllegalAccessException e) { + assert false : "Version field [" + fieldName + "] should be public"; + } + } + } + idToVersion = Map.copyOf(builder); + } + + public static TransportVersion readVersion(StreamInput in) throws IOException { + return fromId(in.readVInt()); + } + + public static TransportVersion fromId(int id) { + TransportVersion known = idToVersion.get(id); + if (known != null) { + return known; + } + // this is a version we don't otherwise know about - just create a placeholder + return new TransportVersion(id, ""); + } + + public static void writeVersion(TransportVersion version, StreamOutput out) throws IOException { + out.writeVInt(version.id); + } + + /** + * Returns the minimum version between the 2. + */ + public static TransportVersion min(TransportVersion version1, TransportVersion version2) { + return version1.id < version2.id ? version1 : version2; + } + + /** + * Returns the maximum version between the 2 + */ + public static TransportVersion max(TransportVersion version1, TransportVersion version2) { + return version1.id > version2.id ? version1 : version2; + } + + private final int id; + private final String uniqueId; + + TransportVersion(int id, String uniqueId) { + this.id = id; + this.uniqueId = Strings.requireNonEmpty(uniqueId, "Each TransportVersion needs a unique string id"); + } + + public boolean after(TransportVersion version) { + return version.id < id; + } + + public boolean onOrAfter(TransportVersion version) { + return version.id <= id; + } + + public boolean before(TransportVersion version) { + return version.id > id; + } + + public boolean onOrBefore(TransportVersion version) { + return version.id >= id; + } + + @Override + public int compareTo(TransportVersion other) { + return Integer.compare(this.id, other.id); + } + + @Override + public String toString() { + return Integer.toString(id); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TransportVersion version = (TransportVersion) o; + + if (id != version.id) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + return id; + } +} diff --git a/server/src/main/java/org/elasticsearch/Version.java b/server/src/main/java/org/elasticsearch/Version.java index 437a56d296a2a..d678540425f70 100644 --- a/server/src/main/java/org/elasticsearch/Version.java +++ b/server/src/main/java/org/elasticsearch/Version.java @@ -46,91 +46,91 @@ public class Version implements Comparable, ToXContentFragment { */ public static final int V_EMPTY_ID = 0; - public static final Version V_EMPTY = new Version(V_EMPTY_ID, org.apache.lucene.util.Version.LATEST); - public static final Version V_7_0_0 = new Version(7_00_00_99, org.apache.lucene.util.Version.LUCENE_8_0_0); - public static final Version V_7_0_1 = new Version(7_00_01_99, org.apache.lucene.util.Version.LUCENE_8_0_0); - public static final Version V_7_1_0 = new Version(7_01_00_99, org.apache.lucene.util.Version.LUCENE_8_0_0); - public static final Version V_7_1_1 = new Version(7_01_01_99, org.apache.lucene.util.Version.LUCENE_8_0_0); - public static final Version V_7_2_0 = new Version(7_02_00_99, org.apache.lucene.util.Version.LUCENE_8_0_0); - public static final Version V_7_2_1 = new Version(7_02_01_99, org.apache.lucene.util.Version.LUCENE_8_0_0); - public static final Version V_7_3_0 = new Version(7_03_00_99, org.apache.lucene.util.Version.LUCENE_8_1_0); - public static final Version V_7_3_1 = new Version(7_03_01_99, org.apache.lucene.util.Version.LUCENE_8_1_0); - public static final Version V_7_3_2 = new Version(7_03_02_99, org.apache.lucene.util.Version.LUCENE_8_1_0); - public static final Version V_7_4_0 = new Version(7_04_00_99, org.apache.lucene.util.Version.LUCENE_8_2_0); - public static final Version V_7_4_1 = new Version(7_04_01_99, org.apache.lucene.util.Version.LUCENE_8_2_0); - public static final Version V_7_4_2 = new Version(7_04_02_99, org.apache.lucene.util.Version.LUCENE_8_2_0); - public static final Version V_7_5_0 = new Version(7_05_00_99, org.apache.lucene.util.Version.LUCENE_8_3_0); - public static final Version V_7_5_1 = new Version(7_05_01_99, org.apache.lucene.util.Version.LUCENE_8_3_0); - public static final Version V_7_5_2 = new Version(7_05_02_99, org.apache.lucene.util.Version.LUCENE_8_3_0); - public static final Version V_7_6_0 = new Version(7_06_00_99, org.apache.lucene.util.Version.LUCENE_8_4_0); - public static final Version V_7_6_1 = new Version(7_06_01_99, org.apache.lucene.util.Version.LUCENE_8_4_0); - public static final Version V_7_6_2 = new Version(7_06_02_99, org.apache.lucene.util.Version.LUCENE_8_4_0); - public static final Version V_7_7_0 = new Version(7_07_00_99, org.apache.lucene.util.Version.LUCENE_8_5_1); - public static final Version V_7_7_1 = new Version(7_07_01_99, org.apache.lucene.util.Version.LUCENE_8_5_1); - public static final Version V_7_8_0 = new Version(7_08_00_99, org.apache.lucene.util.Version.LUCENE_8_5_1); - public static final Version V_7_8_1 = new Version(7_08_01_99, org.apache.lucene.util.Version.LUCENE_8_5_1); - public static final Version V_7_9_0 = new Version(7_09_00_99, org.apache.lucene.util.Version.LUCENE_8_6_0); - public static final Version V_7_9_1 = new Version(7_09_01_99, org.apache.lucene.util.Version.LUCENE_8_6_2); - public static final Version V_7_9_2 = new Version(7_09_02_99, org.apache.lucene.util.Version.LUCENE_8_6_2); - public static final Version V_7_9_3 = new Version(7_09_03_99, org.apache.lucene.util.Version.LUCENE_8_6_2); - public static final Version V_7_10_0 = new Version(7_10_00_99, org.apache.lucene.util.Version.LUCENE_8_7_0); - public static final Version V_7_10_1 = new Version(7_10_01_99, org.apache.lucene.util.Version.LUCENE_8_7_0); - public static final Version V_7_10_2 = new Version(7_10_02_99, org.apache.lucene.util.Version.LUCENE_8_7_0); - public static final Version V_7_11_0 = new Version(7_11_00_99, org.apache.lucene.util.Version.LUCENE_8_7_0); - public static final Version V_7_11_1 = new Version(7_11_01_99, org.apache.lucene.util.Version.LUCENE_8_7_0); - public static final Version V_7_11_2 = new Version(7_11_02_99, org.apache.lucene.util.Version.LUCENE_8_7_0); - public static final Version V_7_12_0 = new Version(7_12_00_99, org.apache.lucene.util.Version.LUCENE_8_8_0); - public static final Version V_7_12_1 = new Version(7_12_01_99, org.apache.lucene.util.Version.LUCENE_8_8_0); - public static final Version V_7_13_0 = new Version(7_13_00_99, org.apache.lucene.util.Version.LUCENE_8_8_2); - public static final Version V_7_13_1 = new Version(7_13_01_99, org.apache.lucene.util.Version.LUCENE_8_8_2); - public static final Version V_7_13_2 = new Version(7_13_02_99, org.apache.lucene.util.Version.LUCENE_8_8_2); - public static final Version V_7_13_3 = new Version(7_13_03_99, org.apache.lucene.util.Version.LUCENE_8_8_2); - public static final Version V_7_13_4 = new Version(7_13_04_99, org.apache.lucene.util.Version.LUCENE_8_8_2); - public static final Version V_7_14_0 = new Version(7_14_00_99, org.apache.lucene.util.Version.LUCENE_8_9_0); - public static final Version V_7_14_1 = new Version(7_14_01_99, org.apache.lucene.util.Version.LUCENE_8_9_0); - public static final Version V_7_14_2 = new Version(7_14_02_99, org.apache.lucene.util.Version.LUCENE_8_9_0); - public static final Version V_7_15_0 = new Version(7_15_00_99, org.apache.lucene.util.Version.LUCENE_8_9_0); - public static final Version V_7_15_1 = new Version(7_15_01_99, org.apache.lucene.util.Version.LUCENE_8_9_0); - public static final Version V_7_15_2 = new Version(7_15_02_99, org.apache.lucene.util.Version.LUCENE_8_9_0); - public static final Version V_7_16_0 = new Version(7_16_00_99, org.apache.lucene.util.Version.LUCENE_8_10_1); - public static final Version V_7_16_1 = new Version(7_16_01_99, org.apache.lucene.util.Version.LUCENE_8_10_1); - public static final Version V_7_16_2 = new Version(7_16_02_99, org.apache.lucene.util.Version.LUCENE_8_10_1); - public static final Version V_7_16_3 = new Version(7_16_03_99, org.apache.lucene.util.Version.LUCENE_8_10_1); - public static final Version V_7_17_0 = new Version(7_17_00_99, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_1 = new Version(7_17_01_99, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_2 = new Version(7_17_02_99, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_3 = new Version(7_17_03_99, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_4 = new Version(7_17_04_99, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_5 = new Version(7_17_05_99, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_6 = new Version(7_17_06_99, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_7 = new Version(7_17_07_99, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_8 = new Version(7_17_08_99, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_7_17_9 = new Version(7_17_09_99, org.apache.lucene.util.Version.LUCENE_8_11_1); - public static final Version V_8_0_0 = new Version(8_00_00_99, org.apache.lucene.util.Version.LUCENE_9_0_0); - public static final Version V_8_0_1 = new Version(8_00_01_99, org.apache.lucene.util.Version.LUCENE_9_0_0); - public static final Version V_8_1_0 = new Version(8_01_00_99, org.apache.lucene.util.Version.LUCENE_9_0_0); - public static final Version V_8_1_1 = new Version(8_01_01_99, org.apache.lucene.util.Version.LUCENE_9_0_0); - public static final Version V_8_1_2 = new Version(8_01_02_99, org.apache.lucene.util.Version.LUCENE_9_0_0); - public static final Version V_8_1_3 = new Version(8_01_03_99, org.apache.lucene.util.Version.LUCENE_9_0_0); - public static final Version V_8_2_0 = new Version(8_02_00_99, org.apache.lucene.util.Version.LUCENE_9_1_0); - public static final Version V_8_2_1 = new Version(8_02_01_99, org.apache.lucene.util.Version.LUCENE_9_1_0); - public static final Version V_8_2_2 = new Version(8_02_02_99, org.apache.lucene.util.Version.LUCENE_9_1_0); - public static final Version V_8_2_3 = new Version(8_02_03_99, org.apache.lucene.util.Version.LUCENE_9_1_0); - public static final Version V_8_3_0 = new Version(8_03_00_99, org.apache.lucene.util.Version.LUCENE_9_2_0); - public static final Version V_8_3_1 = new Version(8_03_01_99, org.apache.lucene.util.Version.LUCENE_9_2_0); - public static final Version V_8_3_2 = new Version(8_03_02_99, org.apache.lucene.util.Version.LUCENE_9_2_0); - public static final Version V_8_3_3 = new Version(8_03_03_99, org.apache.lucene.util.Version.LUCENE_9_2_0); - public static final Version V_8_4_0 = new Version(8_04_00_99, org.apache.lucene.util.Version.LUCENE_9_3_0); - public static final Version V_8_4_1 = new Version(8_04_01_99, org.apache.lucene.util.Version.LUCENE_9_3_0); - public static final Version V_8_4_2 = new Version(8_04_02_99, org.apache.lucene.util.Version.LUCENE_9_3_0); - public static final Version V_8_4_3 = new Version(8_04_03_99, org.apache.lucene.util.Version.LUCENE_9_3_0); - public static final Version V_8_5_0 = new Version(8_05_00_99, org.apache.lucene.util.Version.LUCENE_9_4_1); - public static final Version V_8_5_1 = new Version(8_05_01_99, org.apache.lucene.util.Version.LUCENE_9_4_1); - public static final Version V_8_5_2 = new Version(8_05_02_99, org.apache.lucene.util.Version.LUCENE_9_4_1); - public static final Version V_8_5_3 = new Version(8_05_03_99, org.apache.lucene.util.Version.LUCENE_9_4_2); - public static final Version V_8_6_0 = new Version(8_06_00_99, org.apache.lucene.util.Version.LUCENE_9_4_2); - public static final Version V_8_6_1 = new Version(8_06_01_99, org.apache.lucene.util.Version.LUCENE_9_4_2); - public static final Version V_8_7_0 = new Version(8_07_00_99, org.apache.lucene.util.Version.LUCENE_9_4_2); + public static final Version V_EMPTY = new Version(V_EMPTY_ID, TransportVersion.ZERO, org.apache.lucene.util.Version.LATEST); + public static final Version V_7_0_0 = new Version(7_00_00_99, TransportVersion.V_7_0_0, org.apache.lucene.util.Version.LUCENE_8_0_0); + public static final Version V_7_0_1 = new Version(7_00_01_99, TransportVersion.V_7_0_1, org.apache.lucene.util.Version.LUCENE_8_0_0); + public static final Version V_7_1_0 = new Version(7_01_00_99, TransportVersion.V_7_1_0, org.apache.lucene.util.Version.LUCENE_8_0_0); + public static final Version V_7_1_1 = new Version(7_01_01_99, TransportVersion.V_7_1_1, org.apache.lucene.util.Version.LUCENE_8_0_0); + public static final Version V_7_2_0 = new Version(7_02_00_99, TransportVersion.V_7_2_0, org.apache.lucene.util.Version.LUCENE_8_0_0); + public static final Version V_7_2_1 = new Version(7_02_01_99, TransportVersion.V_7_2_1, org.apache.lucene.util.Version.LUCENE_8_0_0); + public static final Version V_7_3_0 = new Version(7_03_00_99, TransportVersion.V_7_3_0, org.apache.lucene.util.Version.LUCENE_8_1_0); + public static final Version V_7_3_1 = new Version(7_03_01_99, TransportVersion.V_7_3_1, org.apache.lucene.util.Version.LUCENE_8_1_0); + public static final Version V_7_3_2 = new Version(7_03_02_99, TransportVersion.V_7_3_2, org.apache.lucene.util.Version.LUCENE_8_1_0); + public static final Version V_7_4_0 = new Version(7_04_00_99, TransportVersion.V_7_4_0, org.apache.lucene.util.Version.LUCENE_8_2_0); + public static final Version V_7_4_1 = new Version(7_04_01_99, TransportVersion.V_7_4_1, org.apache.lucene.util.Version.LUCENE_8_2_0); + public static final Version V_7_4_2 = new Version(7_04_02_99, TransportVersion.V_7_4_2, org.apache.lucene.util.Version.LUCENE_8_2_0); + public static final Version V_7_5_0 = new Version(7_05_00_99, TransportVersion.V_7_5_0, org.apache.lucene.util.Version.LUCENE_8_3_0); + public static final Version V_7_5_1 = new Version(7_05_01_99, TransportVersion.V_7_5_1, org.apache.lucene.util.Version.LUCENE_8_3_0); + public static final Version V_7_5_2 = new Version(7_05_02_99, TransportVersion.V_7_5_2, org.apache.lucene.util.Version.LUCENE_8_3_0); + public static final Version V_7_6_0 = new Version(7_06_00_99, TransportVersion.V_7_6_0, org.apache.lucene.util.Version.LUCENE_8_4_0); + public static final Version V_7_6_1 = new Version(7_06_01_99, TransportVersion.V_7_6_1, org.apache.lucene.util.Version.LUCENE_8_4_0); + public static final Version V_7_6_2 = new Version(7_06_02_99, TransportVersion.V_7_6_2, org.apache.lucene.util.Version.LUCENE_8_4_0); + public static final Version V_7_7_0 = new Version(7_07_00_99, TransportVersion.V_7_7_0, org.apache.lucene.util.Version.LUCENE_8_5_1); + public static final Version V_7_7_1 = new Version(7_07_01_99, TransportVersion.V_7_7_1, org.apache.lucene.util.Version.LUCENE_8_5_1); + public static final Version V_7_8_0 = new Version(7_08_00_99, TransportVersion.V_7_8_0, org.apache.lucene.util.Version.LUCENE_8_5_1); + public static final Version V_7_8_1 = new Version(7_08_01_99, TransportVersion.V_7_8_1, org.apache.lucene.util.Version.LUCENE_8_5_1); + public static final Version V_7_9_0 = new Version(7_09_00_99, TransportVersion.V_7_9_0, org.apache.lucene.util.Version.LUCENE_8_6_0); + public static final Version V_7_9_1 = new Version(7_09_01_99, TransportVersion.V_7_9_1, org.apache.lucene.util.Version.LUCENE_8_6_2); + public static final Version V_7_9_2 = new Version(7_09_02_99, TransportVersion.V_7_9_2, org.apache.lucene.util.Version.LUCENE_8_6_2); + public static final Version V_7_9_3 = new Version(7_09_03_99, TransportVersion.V_7_9_3, org.apache.lucene.util.Version.LUCENE_8_6_2); + public static final Version V_7_10_0 = new Version(7_10_00_99, TransportVersion.V_7_10_0, org.apache.lucene.util.Version.LUCENE_8_7_0); + public static final Version V_7_10_1 = new Version(7_10_01_99, TransportVersion.V_7_10_1, org.apache.lucene.util.Version.LUCENE_8_7_0); + public static final Version V_7_10_2 = new Version(7_10_02_99, TransportVersion.V_7_10_2, org.apache.lucene.util.Version.LUCENE_8_7_0); + public static final Version V_7_11_0 = new Version(7_11_00_99, TransportVersion.V_7_11_0, org.apache.lucene.util.Version.LUCENE_8_7_0); + public static final Version V_7_11_1 = new Version(7_11_01_99, TransportVersion.V_7_11_1, org.apache.lucene.util.Version.LUCENE_8_7_0); + public static final Version V_7_11_2 = new Version(7_11_02_99, TransportVersion.V_7_11_2, org.apache.lucene.util.Version.LUCENE_8_7_0); + public static final Version V_7_12_0 = new Version(7_12_00_99, TransportVersion.V_7_12_0, org.apache.lucene.util.Version.LUCENE_8_8_0); + public static final Version V_7_12_1 = new Version(7_12_01_99, TransportVersion.V_7_12_1, org.apache.lucene.util.Version.LUCENE_8_8_0); + public static final Version V_7_13_0 = new Version(7_13_00_99, TransportVersion.V_7_13_0, org.apache.lucene.util.Version.LUCENE_8_8_2); + public static final Version V_7_13_1 = new Version(7_13_01_99, TransportVersion.V_7_13_1, org.apache.lucene.util.Version.LUCENE_8_8_2); + public static final Version V_7_13_2 = new Version(7_13_02_99, TransportVersion.V_7_13_2, org.apache.lucene.util.Version.LUCENE_8_8_2); + public static final Version V_7_13_3 = new Version(7_13_03_99, TransportVersion.V_7_13_3, org.apache.lucene.util.Version.LUCENE_8_8_2); + public static final Version V_7_13_4 = new Version(7_13_04_99, TransportVersion.V_7_13_4, org.apache.lucene.util.Version.LUCENE_8_8_2); + public static final Version V_7_14_0 = new Version(7_14_00_99, TransportVersion.V_7_14_0, org.apache.lucene.util.Version.LUCENE_8_9_0); + public static final Version V_7_14_1 = new Version(7_14_01_99, TransportVersion.V_7_14_1, org.apache.lucene.util.Version.LUCENE_8_9_0); + public static final Version V_7_14_2 = new Version(7_14_02_99, TransportVersion.V_7_14_2, org.apache.lucene.util.Version.LUCENE_8_9_0); + public static final Version V_7_15_0 = new Version(7_15_00_99, TransportVersion.V_7_15_0, org.apache.lucene.util.Version.LUCENE_8_9_0); + public static final Version V_7_15_1 = new Version(7_15_01_99, TransportVersion.V_7_15_1, org.apache.lucene.util.Version.LUCENE_8_9_0); + public static final Version V_7_15_2 = new Version(7_15_02_99, TransportVersion.V_7_15_2, org.apache.lucene.util.Version.LUCENE_8_9_0); + public static final Version V_7_16_0 = new Version(7_16_00_99, TransportVersion.V_7_16_0, org.apache.lucene.util.Version.LUCENE_8_10_1); + public static final Version V_7_16_1 = new Version(7_16_01_99, TransportVersion.V_7_16_1, org.apache.lucene.util.Version.LUCENE_8_10_1); + public static final Version V_7_16_2 = new Version(7_16_02_99, TransportVersion.V_7_16_2, org.apache.lucene.util.Version.LUCENE_8_10_1); + public static final Version V_7_16_3 = new Version(7_16_03_99, TransportVersion.V_7_16_3, org.apache.lucene.util.Version.LUCENE_8_10_1); + public static final Version V_7_17_0 = new Version(7_17_00_99, TransportVersion.V_7_17_0, org.apache.lucene.util.Version.LUCENE_8_11_1); + public static final Version V_7_17_1 = new Version(7_17_01_99, TransportVersion.V_7_17_1, org.apache.lucene.util.Version.LUCENE_8_11_1); + public static final Version V_7_17_2 = new Version(7_17_02_99, TransportVersion.V_7_17_2, org.apache.lucene.util.Version.LUCENE_8_11_1); + public static final Version V_7_17_3 = new Version(7_17_03_99, TransportVersion.V_7_17_3, org.apache.lucene.util.Version.LUCENE_8_11_1); + public static final Version V_7_17_4 = new Version(7_17_04_99, TransportVersion.V_7_17_4, org.apache.lucene.util.Version.LUCENE_8_11_1); + public static final Version V_7_17_5 = new Version(7_17_05_99, TransportVersion.V_7_17_5, org.apache.lucene.util.Version.LUCENE_8_11_1); + public static final Version V_7_17_6 = new Version(7_17_06_99, TransportVersion.V_7_17_6, org.apache.lucene.util.Version.LUCENE_8_11_1); + public static final Version V_7_17_7 = new Version(7_17_07_99, TransportVersion.V_7_17_7, org.apache.lucene.util.Version.LUCENE_8_11_1); + public static final Version V_7_17_8 = new Version(7_17_08_99, TransportVersion.V_7_17_8, org.apache.lucene.util.Version.LUCENE_8_11_1); + public static final Version V_7_17_9 = new Version(7_17_09_99, TransportVersion.V_7_17_9, org.apache.lucene.util.Version.LUCENE_8_11_1); + public static final Version V_8_0_0 = new Version(8_00_00_99, TransportVersion.V_8_0_0, org.apache.lucene.util.Version.LUCENE_9_0_0); + public static final Version V_8_0_1 = new Version(8_00_01_99, TransportVersion.V_8_0_1, org.apache.lucene.util.Version.LUCENE_9_0_0); + public static final Version V_8_1_0 = new Version(8_01_00_99, TransportVersion.V_8_1_0, org.apache.lucene.util.Version.LUCENE_9_0_0); + public static final Version V_8_1_1 = new Version(8_01_01_99, TransportVersion.V_8_1_1, org.apache.lucene.util.Version.LUCENE_9_0_0); + public static final Version V_8_1_2 = new Version(8_01_02_99, TransportVersion.V_8_1_2, org.apache.lucene.util.Version.LUCENE_9_0_0); + public static final Version V_8_1_3 = new Version(8_01_03_99, TransportVersion.V_8_1_3, org.apache.lucene.util.Version.LUCENE_9_0_0); + public static final Version V_8_2_0 = new Version(8_02_00_99, TransportVersion.V_8_2_0, org.apache.lucene.util.Version.LUCENE_9_1_0); + public static final Version V_8_2_1 = new Version(8_02_01_99, TransportVersion.V_8_2_1, org.apache.lucene.util.Version.LUCENE_9_1_0); + public static final Version V_8_2_2 = new Version(8_02_02_99, TransportVersion.V_8_2_2, org.apache.lucene.util.Version.LUCENE_9_1_0); + public static final Version V_8_2_3 = new Version(8_02_03_99, TransportVersion.V_8_2_3, org.apache.lucene.util.Version.LUCENE_9_1_0); + public static final Version V_8_3_0 = new Version(8_03_00_99, TransportVersion.V_8_3_0, org.apache.lucene.util.Version.LUCENE_9_2_0); + public static final Version V_8_3_1 = new Version(8_03_01_99, TransportVersion.V_8_3_1, org.apache.lucene.util.Version.LUCENE_9_2_0); + public static final Version V_8_3_2 = new Version(8_03_02_99, TransportVersion.V_8_3_2, org.apache.lucene.util.Version.LUCENE_9_2_0); + public static final Version V_8_3_3 = new Version(8_03_03_99, TransportVersion.V_8_3_3, org.apache.lucene.util.Version.LUCENE_9_2_0); + public static final Version V_8_4_0 = new Version(8_04_00_99, TransportVersion.V_8_4_0, org.apache.lucene.util.Version.LUCENE_9_3_0); + public static final Version V_8_4_1 = new Version(8_04_01_99, TransportVersion.V_8_4_1, org.apache.lucene.util.Version.LUCENE_9_3_0); + public static final Version V_8_4_2 = new Version(8_04_02_99, TransportVersion.V_8_4_2, org.apache.lucene.util.Version.LUCENE_9_3_0); + public static final Version V_8_4_3 = new Version(8_04_03_99, TransportVersion.V_8_4_3, org.apache.lucene.util.Version.LUCENE_9_3_0); + public static final Version V_8_5_0 = new Version(8_05_00_99, TransportVersion.V_8_5_0, org.apache.lucene.util.Version.LUCENE_9_4_1); + public static final Version V_8_5_1 = new Version(8_05_01_99, TransportVersion.V_8_5_1, org.apache.lucene.util.Version.LUCENE_9_4_1); + public static final Version V_8_5_2 = new Version(8_05_02_99, TransportVersion.V_8_5_2, org.apache.lucene.util.Version.LUCENE_9_4_1); + public static final Version V_8_5_3 = new Version(8_05_03_99, TransportVersion.V_8_5_3, org.apache.lucene.util.Version.LUCENE_9_4_2); + public static final Version V_8_5_4 = new Version(8_05_04_99, TransportVersion.V_8_5_4, org.apache.lucene.util.Version.LUCENE_9_4_2); + public static final Version V_8_6_0 = new Version(8_06_00_99, TransportVersion.V_8_6_0, org.apache.lucene.util.Version.LUCENE_9_4_2); + public static final Version V_8_7_0 = new Version(8_07_00_99, TransportVersion.V_8_7_0, org.apache.lucene.util.Version.LUCENE_9_4_2); public static final Version CURRENT = V_8_7_0; private static final Map idToVersion; @@ -200,7 +200,7 @@ private static Version fromIdSlow(int id) { // Our best guess is to use the same Lucene version as the previous // version in the list, assuming that it didn't change. List versions = DeclaredVersionsHolder.DECLARED_VERSIONS; - Version tmp = new Version(id, org.apache.lucene.util.Version.LATEST); + Version tmp = new Version(id, TransportVersion.CURRENT, org.apache.lucene.util.Version.LATEST); int index = Collections.binarySearch(versions, tmp); if (index < 0) { index = -2 - index; @@ -216,7 +216,8 @@ private static Version fromIdSlow(int id) { } else { luceneVersion = versions.get(index).luceneVersion; } - return new Version(id, luceneVersion); + // TODO: assume this is an old version that has transport version == release version + return new Version(id, TransportVersion.fromId(id), luceneVersion); } public static void writeVersion(Version version, StreamOutput out) throws IOException { @@ -299,16 +300,18 @@ private static Version fromStringSlow(String version) { public final byte minor; public final byte revision; public final byte build; + public final TransportVersion transportVersion; public final org.apache.lucene.util.Version luceneVersion; private final String toString; private final int previousMajorId; - Version(int id, org.apache.lucene.util.Version luceneVersion) { + Version(int id, TransportVersion transportVersion, org.apache.lucene.util.Version luceneVersion) { this.id = id; this.major = (byte) ((id / 1000000) % 100); this.minor = (byte) ((id / 10000) % 100); this.revision = (byte) ((id / 100) % 100); this.build = (byte) (id % 100); + this.transportVersion = Objects.requireNonNull(transportVersion); this.luceneVersion = Objects.requireNonNull(luceneVersion); this.toString = major + "." + minor + "." + revision; this.previousMajorId = major > 0 ? (major - 1) * 1000000 + 99 : major; From b75f0de735a4f9d3fbe654b330f6b3bf2533577e Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Thu, 12 Jan 2023 11:36:39 +0000 Subject: [PATCH 02/22] Update docs/changelog/92869.yaml --- docs/changelog/92869.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/92869.yaml diff --git a/docs/changelog/92869.yaml b/docs/changelog/92869.yaml new file mode 100644 index 0000000000000..439536a07da27 --- /dev/null +++ b/docs/changelog/92869.yaml @@ -0,0 +1,5 @@ +pr: 92869 +summary: Add `TransportVersion` file +area: Infra/Transport API +type: feature +issues: [] From 0bffdf2b12c9a20479a590698eb3c678b2c3b85c Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Thu, 12 Jan 2023 11:39:16 +0000 Subject: [PATCH 03/22] Update for 8.6.1 --- .../src/main/java/org/elasticsearch/TransportVersion.java | 6 ++++++ server/src/main/java/org/elasticsearch/Version.java | 1 + server/src/test/java/org/elasticsearch/VersionTests.java | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/TransportVersion.java b/server/src/main/java/org/elasticsearch/TransportVersion.java index c8addf429c275..4ffa0b1b862d0 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersion.java +++ b/server/src/main/java/org/elasticsearch/TransportVersion.java @@ -16,6 +16,7 @@ import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; +import java.util.Set; public class TransportVersion implements Comparable { public static final TransportVersion ZERO = new TransportVersion(0, "00000000-0000-0000-0000-000000000000"); @@ -105,6 +106,7 @@ public class TransportVersion implements Comparable { public static final TransportVersion V_8_5_3 = new TransportVersion(8_05_03_99, "9ca3c835-e3b7-4622-a08e-d51e42403b06"); public static final TransportVersion V_8_5_4 = new TransportVersion(8_05_04_99, "97ee525c-555d-45ca-83dc-59cd592c8e86"); public static final TransportVersion V_8_6_0 = new TransportVersion(8_06_00_99, "e209c5ed-3488-4415-b561-33492ca3b789"); + public static final TransportVersion V_8_6_1 = new TransportVersion(8_06_01_99, "9f113acb-1b21-4fda-bef9-2a3e669b5c7b"); public static final TransportVersion V_8_7_0 = new TransportVersion(8_07_00_99, "f1ee7a85-4fa6-43f5-8679-33e2b750448b"); /* * Detached transport versions added below here. Starts at ES major version 10 equivalent. @@ -127,9 +129,13 @@ public class TransportVersion implements Comparable { Map builder = new HashMap<>(); Map uniqueIds = new HashMap<>(); + Set ignore = Set.of("ZERO", "CURRENT", "MINIMUM_COMPATIBLE"); for (Field declaredField : TransportVersion.class.getFields()) { if (declaredField.getType().equals(TransportVersion.class)) { String fieldName = declaredField.getName(); + if (ignore.contains(fieldName)) { + continue; + } try { TransportVersion version = (TransportVersion) declaredField.get(null); diff --git a/server/src/main/java/org/elasticsearch/Version.java b/server/src/main/java/org/elasticsearch/Version.java index d678540425f70..582dea382df8a 100644 --- a/server/src/main/java/org/elasticsearch/Version.java +++ b/server/src/main/java/org/elasticsearch/Version.java @@ -130,6 +130,7 @@ public class Version implements Comparable, ToXContentFragment { public static final Version V_8_5_3 = new Version(8_05_03_99, TransportVersion.V_8_5_3, org.apache.lucene.util.Version.LUCENE_9_4_2); public static final Version V_8_5_4 = new Version(8_05_04_99, TransportVersion.V_8_5_4, org.apache.lucene.util.Version.LUCENE_9_4_2); public static final Version V_8_6_0 = new Version(8_06_00_99, TransportVersion.V_8_6_0, org.apache.lucene.util.Version.LUCENE_9_4_2); + public static final Version V_8_6_1 = new Version(8_06_01_99, TransportVersion.V_8_6_1, org.apache.lucene.util.Version.LUCENE_9_4_2); public static final Version V_8_7_0 = new Version(8_07_00_99, TransportVersion.V_8_7_0, org.apache.lucene.util.Version.LUCENE_9_4_2); public static final Version CURRENT = V_8_7_0; diff --git a/server/src/test/java/org/elasticsearch/VersionTests.java b/server/src/test/java/org/elasticsearch/VersionTests.java index 72e958a5a3edc..0c81bed8814ef 100644 --- a/server/src/test/java/org/elasticsearch/VersionTests.java +++ b/server/src/test/java/org/elasticsearch/VersionTests.java @@ -178,7 +178,7 @@ public void testParseVersion() { for (int i = 0; i < iters; i++) { Version version = randomVersion(random()); if (random().nextBoolean()) { - version = new Version(version.id, version.luceneVersion); + version = new Version(version.id, version.transportVersion, version.luceneVersion); } Version parsedVersion = Version.fromString(version.toString()); assertEquals(version, parsedVersion); From 591f740c57b6d41abed8e0c6a801bd2fdba11b8d Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Thu, 12 Jan 2023 13:35:03 +0000 Subject: [PATCH 04/22] Fix id numbers Add initial set of javadocs --- .../org/elasticsearch/TransportVersion.java | 88 +++++++++++-------- 1 file changed, 52 insertions(+), 36 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/TransportVersion.java b/server/src/main/java/org/elasticsearch/TransportVersion.java index 4ffa0b1b862d0..540a3d883f930 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersion.java +++ b/server/src/main/java/org/elasticsearch/TransportVersion.java @@ -18,6 +18,22 @@ import java.util.Map; import java.util.Set; +/** + * Represents the version of the wire protocol used to communicate between ES nodes. + * + * Prior to 8.7.0, the node {@link Version} was used everywhere. This class separates the wire protocol version + * from the running node version. Each node version has a reference to a specific transport version used by that node. + * + * Each transport version constant has got an id number, which for versions prior to 8.7.0 is the same as the node version for compatibility. + * There is also a unique id string. This is not actually used in the protocol, but is there to ensure each protocol version + * is only added once. This string needs to be unique (here, a UUID, but can be any other unique nonempty string). + * If two concurrent PRs added the same protocol version, the unique string causes a git conflict, ensuring the second PR to be merged + * must be updated with the next free version. Without the unique id string, git will happily merge the two versions together, + * causing problems when you try to upgrade between those two PRs. + * + * When adding new transport versions, it is recommended to leave a gap in the numbering scheme (say, 100) + * to leave space for any intermediate fixes that may be needed in the future. + */ public class TransportVersion implements Comparable { public static final TransportVersion ZERO = new TransportVersion(0, "00000000-0000-0000-0000-000000000000"); /* @@ -49,39 +65,39 @@ public class TransportVersion implements Comparable { public static final TransportVersion V_7_9_1 = new TransportVersion(7_09_01_99, "30fa10fc-df6b-4435-bd9e-acdb9ae1b268"); public static final TransportVersion V_7_9_2 = new TransportVersion(7_09_02_99, "b58bb181-cecc-464e-b955-f6c1c1e7b4d0"); public static final TransportVersion V_7_9_3 = new TransportVersion(7_09_03_99, "4406926c-e2b6-4b9a-a72a-1bee8357ad3e"); - public static final TransportVersion V_7_10_0 = new TransportVersion(7_10_00_90, "4efca195-38e4-4f74-b877-c26fb2a40733"); - public static final TransportVersion V_7_10_1 = new TransportVersion(7_10_01_90, "0070260c-aa0b-4fc2-9c87-5cd5f23b005f"); - public static final TransportVersion V_7_10_2 = new TransportVersion(7_10_02_90, "b369e2ed-261c-4b2f-8b42-0f0ba0549f8c"); - public static final TransportVersion V_7_11_0 = new TransportVersion(7_11_00_90, "3b43bcbc-1c5e-4cc2-a3b4-8ac8b64239e8"); - public static final TransportVersion V_7_11_1 = new TransportVersion(7_11_01_90, "2f75d13c-adde-4762-a46e-def8acce62b7"); - public static final TransportVersion V_7_11_2 = new TransportVersion(7_11_02_90, "2c852a4b-236d-4e8b-9373-336c9b52685a"); - public static final TransportVersion V_7_12_0 = new TransportVersion(7_12_00_90, "3be9ff6f-2d9f-4fc2-ba91-394dd5ebcf33"); - public static final TransportVersion V_7_12_1 = new TransportVersion(7_12_01_90, "ee4fdfac-2039-4b00-b42d-579cbde7120c"); - public static final TransportVersion V_7_13_0 = new TransportVersion(7_13_00_92, "e1fe494a-7c66-4571-8f8f-1d7e6d8df1b3"); - public static final TransportVersion V_7_13_1 = new TransportVersion(7_13_01_92, "66bc8d82-36da-4d54-b22d-aca691dc3d70"); - public static final TransportVersion V_7_13_2 = new TransportVersion(7_13_02_92, "2a6fc74c-4c44-4264-a619-37437cd2c5a0"); - public static final TransportVersion V_7_13_3 = new TransportVersion(7_13_03_92, "a31592f5-f8d2-490c-a02e-da9501823d8d"); - public static final TransportVersion V_7_13_4 = new TransportVersion(7_13_04_92, "3143240d-1831-4186-8a19-963336c4cea0"); - public static final TransportVersion V_7_14_0 = new TransportVersion(7_14_00_90, "8cf0954c-b085-467f-b20b-3cb4b2e69e3e"); - public static final TransportVersion V_7_14_1 = new TransportVersion(7_14_01_90, "3dbb62c3-cf73-4c76-8d5a-4ca70afe2c70"); - public static final TransportVersion V_7_14_2 = new TransportVersion(7_14_02_90, "7943ae20-df60-45e5-97ba-82fc0dfc8b89"); - public static final TransportVersion V_7_15_0 = new TransportVersion(7_15_00_90, "2273ac0e-00bb-4024-9e2e-ab78981623c6"); - public static final TransportVersion V_7_15_1 = new TransportVersion(7_15_01_90, "a8c3503d-3452-45cf-b385-e855e16547fe"); - public static final TransportVersion V_7_15_2 = new TransportVersion(7_15_02_90, "fbb8ad69-02e2-4c90-b2e4-23947107f8b4\n"); - public static final TransportVersion V_7_16_0 = new TransportVersion(7_16_00_9_1, "59abadd2-25db-4547-a991-c92306a3934e"); - public static final TransportVersion V_7_16_1 = new TransportVersion(7_16_01_9_1, "4ace6b6b-8bba-427f-8755-9e3b40092138"); - public static final TransportVersion V_7_16_2 = new TransportVersion(7_16_02_9_1, "785567b9-b320-48ef-b538-1753228904cd"); - public static final TransportVersion V_7_16_3 = new TransportVersion(7_16_03_9_1, "facf5ae7-3d4e-479c-9142-72529b784e30"); - public static final TransportVersion V_7_17_0 = new TransportVersion(7_17_00_9_1, "322efe93-4c73-4e15-9274-bb76836c8fa8"); - public static final TransportVersion V_7_17_1 = new TransportVersion(7_17_01_9_1, "51c72842-7974-4669-ad25-bf13ba307307"); - public static final TransportVersion V_7_17_2 = new TransportVersion(7_17_02_9_1, "82bea8d0-bfea-47c2-b7d3-217d8feb67e3"); - public static final TransportVersion V_7_17_3 = new TransportVersion(7_17_03_9_1, "a909c2f4-5cb8-46bf-af0f-cd18d1b7e9d2"); - public static final TransportVersion V_7_17_4 = new TransportVersion(7_17_04_9_1, "5076e164-18a4-4373-8be7-15f1843c46db"); - public static final TransportVersion V_7_17_5 = new TransportVersion(7_17_05_9_1, "da7e3509-7f61-4dd2-8d23-a61f628a62f6"); - public static final TransportVersion V_7_17_6 = new TransportVersion(7_17_06_9_1, "a47ecf02-e457-474f-887d-ee15a7ebd969"); - public static final TransportVersion V_7_17_7 = new TransportVersion(7_17_07_9_1, "108ba576-bb28-42f4-bcbf-845a0ce52560"); - public static final TransportVersion V_7_17_8 = new TransportVersion(7_17_08_9_1, "82a3e70d-cf0e-4efb-ad16-6077ab9fe19f"); - public static final TransportVersion V_7_17_9 = new TransportVersion(7_17_09_9_1, "afd50dda-735f-4eae-9309-3218ffec1b2d"); + public static final TransportVersion V_7_10_0 = new TransportVersion(7_10_00_99, "4efca195-38e4-4f74-b877-c26fb2a40733"); + public static final TransportVersion V_7_10_1 = new TransportVersion(7_10_01_99, "0070260c-aa0b-4fc2-9c87-5cd5f23b005f"); + public static final TransportVersion V_7_10_2 = new TransportVersion(7_10_02_99, "b369e2ed-261c-4b2f-8b42-0f0ba0549f8c"); + public static final TransportVersion V_7_11_0 = new TransportVersion(7_11_00_99, "3b43bcbc-1c5e-4cc2-a3b4-8ac8b64239e8"); + public static final TransportVersion V_7_11_1 = new TransportVersion(7_11_01_99, "2f75d13c-adde-4762-a46e-def8acce62b7"); + public static final TransportVersion V_7_11_2 = new TransportVersion(7_11_02_99, "2c852a4b-236d-4e8b-9373-336c9b52685a"); + public static final TransportVersion V_7_12_0 = new TransportVersion(7_12_00_99, "3be9ff6f-2d9f-4fc2-ba91-394dd5ebcf33"); + public static final TransportVersion V_7_12_1 = new TransportVersion(7_12_01_99, "ee4fdfac-2039-4b00-b42d-579cbde7120c"); + public static final TransportVersion V_7_13_0 = new TransportVersion(7_13_00_99, "e1fe494a-7c66-4571-8f8f-1d7e6d8df1b3"); + public static final TransportVersion V_7_13_1 = new TransportVersion(7_13_01_99, "66bc8d82-36da-4d54-b22d-aca691dc3d70"); + public static final TransportVersion V_7_13_2 = new TransportVersion(7_13_02_99, "2a6fc74c-4c44-4264-a619-37437cd2c5a0"); + public static final TransportVersion V_7_13_3 = new TransportVersion(7_13_03_99, "a31592f5-f8d2-490c-a02e-da9501823d8d"); + public static final TransportVersion V_7_13_4 = new TransportVersion(7_13_04_99, "3143240d-1831-4186-8a19-963336c4cea0"); + public static final TransportVersion V_7_14_0 = new TransportVersion(7_14_00_99, "8cf0954c-b085-467f-b20b-3cb4b2e69e3e"); + public static final TransportVersion V_7_14_1 = new TransportVersion(7_14_01_99, "3dbb62c3-cf73-4c76-8d5a-4ca70afe2c70"); + public static final TransportVersion V_7_14_2 = new TransportVersion(7_14_02_99, "7943ae20-df60-45e5-97ba-82fc0dfc8b89"); + public static final TransportVersion V_7_15_0 = new TransportVersion(7_15_00_99, "2273ac0e-00bb-4024-9e2e-ab78981623c6"); + public static final TransportVersion V_7_15_1 = new TransportVersion(7_15_01_99, "a8c3503d-3452-45cf-b385-e855e16547fe"); + public static final TransportVersion V_7_15_2 = new TransportVersion(7_15_02_99, "fbb8ad69-02e2-4c90-b2e4-23947107f8b4"); + public static final TransportVersion V_7_16_0 = new TransportVersion(7_16_00_99, "59abadd2-25db-4547-a991-c92306a3934e"); + public static final TransportVersion V_7_16_1 = new TransportVersion(7_16_01_99, "4ace6b6b-8bba-427f-8755-9e3b40092138"); + public static final TransportVersion V_7_16_2 = new TransportVersion(7_16_02_99, "785567b9-b320-48ef-b538-1753228904cd"); + public static final TransportVersion V_7_16_3 = new TransportVersion(7_16_03_99, "facf5ae7-3d4e-479c-9142-72529b784e30"); + public static final TransportVersion V_7_17_0 = new TransportVersion(7_17_00_99, "322efe93-4c73-4e15-9274-bb76836c8fa8"); + public static final TransportVersion V_7_17_1 = new TransportVersion(7_17_01_99, "51c72842-7974-4669-ad25-bf13ba307307"); + public static final TransportVersion V_7_17_2 = new TransportVersion(7_17_02_99, "82bea8d0-bfea-47c2-b7d3-217d8feb67e3"); + public static final TransportVersion V_7_17_3 = new TransportVersion(7_17_03_99, "a909c2f4-5cb8-46bf-af0f-cd18d1b7e9d2"); + public static final TransportVersion V_7_17_4 = new TransportVersion(7_17_04_99, "5076e164-18a4-4373-8be7-15f1843c46db"); + public static final TransportVersion V_7_17_5 = new TransportVersion(7_17_05_99, "da7e3509-7f61-4dd2-8d23-a61f628a62f6"); + public static final TransportVersion V_7_17_6 = new TransportVersion(7_17_06_99, "a47ecf02-e457-474f-887d-ee15a7ebd969"); + public static final TransportVersion V_7_17_7 = new TransportVersion(7_17_07_99, "108ba576-bb28-42f4-bcbf-845a0ce52560"); + public static final TransportVersion V_7_17_8 = new TransportVersion(7_17_08_99, "82a3e70d-cf0e-4efb-ad16-6077ab9fe19f"); + public static final TransportVersion V_7_17_9 = new TransportVersion(7_17_09_99, "afd50dda-735f-4eae-9309-3218ffec1b2d"); public static final TransportVersion V_8_0_0 = new TransportVersion(8_00_00_99, "c7d2372c-9f01-4a79-8b11-227d862dfe4f"); public static final TransportVersion V_8_0_1 = new TransportVersion(8_00_01_99, "56e044c3-37e5-4f7e-bd38-f493927354ac"); public static final TransportVersion V_8_1_0 = new TransportVersion(8_01_00_99, "3dc49dce-9cef-492a-ac8d-3cc79f6b4280"); @@ -111,14 +127,14 @@ public class TransportVersion implements Comparable { /* * Detached transport versions added below here. Starts at ES major version 10 equivalent. */ - // public static final TransportVersion V10_000_000 = new TransportVersion(10_000_000, "dc3cbf06-3ed5-4e1b-9978-ee1d04d235bc"); + public static final TransportVersion V10_000_000 = new TransportVersion(10_000_000, "dc3cbf06-3ed5-4e1b-9978-ee1d04d235bc"); /* * When adding a new transport version, ensure there is a gap (say, 100) between versions * This is to make it possible to add intermediate versions for any bug fixes that may be required. */ - /** Reference to the latest transport version */ - public static final TransportVersion CURRENT = V_8_7_0; + /** Reference to the current transport version */ + public static final TransportVersion CURRENT = V10_000_000; /** Reference to the earliest compatible transport version to this version of the codebase */ public static final TransportVersion MINIMUM_COMPATIBLE = V_7_17_0; From 719ff87f8703e3a5278d5ad5c07f06dca11fc615 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Thu, 12 Jan 2023 13:36:31 +0000 Subject: [PATCH 05/22] Delete docs/changelog/92869.yaml --- docs/changelog/92869.yaml | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 docs/changelog/92869.yaml diff --git a/docs/changelog/92869.yaml b/docs/changelog/92869.yaml deleted file mode 100644 index 439536a07da27..0000000000000 --- a/docs/changelog/92869.yaml +++ /dev/null @@ -1,5 +0,0 @@ -pr: 92869 -summary: Add `TransportVersion` file -area: Infra/Transport API -type: feature -issues: [] From 5f0462e648ee05aca807de90e1c8fe8001d00a62 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Thu, 12 Jan 2023 13:53:36 +0000 Subject: [PATCH 06/22] Fix id numbers Add initial set of javadocs --- .../org/elasticsearch/TransportVersion.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/TransportVersion.java b/server/src/main/java/org/elasticsearch/TransportVersion.java index 540a3d883f930..746e11c83b1ac 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersion.java +++ b/server/src/main/java/org/elasticsearch/TransportVersion.java @@ -20,24 +20,30 @@ /** * Represents the version of the wire protocol used to communicate between ES nodes. - * + *

* Prior to 8.7.0, the node {@link Version} was used everywhere. This class separates the wire protocol version * from the running node version. Each node version has a reference to a specific transport version used by that node. - * - * Each transport version constant has got an id number, which for versions prior to 8.7.0 is the same as the node version for compatibility. + *

+ * Each transport version constant has got an id number, which for versions prior to 8.7.0 is the same as the node version + * for backwards compatibility. * There is also a unique id string. This is not actually used in the protocol, but is there to ensure each protocol version - * is only added once. This string needs to be unique (here, a UUID, but can be any other unique nonempty string). + * is only added to the source file once. This string needs to be unique (here, a UUID, but can be any other unique nonempty string). * If two concurrent PRs added the same protocol version, the unique string causes a git conflict, ensuring the second PR to be merged * must be updated with the next free version. Without the unique id string, git will happily merge the two versions together, * causing problems when you try to upgrade between those two PRs. - * - * When adding new transport versions, it is recommended to leave a gap in the numbering scheme (say, 100) + *

+ * When adding new transport versions, it is recommended to leave a gap in the id number (say, 100) * to leave space for any intermediate fixes that may be needed in the future. + *

+ * The earliest compatible version is hardcoded at {@link #MINIMUM_COMPATIBLE}. Previously, this was dynamically calculated + * from the major/minor versions of {@link Version}, but {@code TransportVersion} does not have that concept. So the minimum compatible + * version needs to be hard-coded as the transport version of the minimum compatible node version. That variable should be updated + * appropriately whenever we do a major version release. */ public class TransportVersion implements Comparable { public static final TransportVersion ZERO = new TransportVersion(0, "00000000-0000-0000-0000-000000000000"); /* - * Legacy transport versions that matched the on-prem release version + * Legacy transport versions that match the node version */ public static final TransportVersion V_7_0_0 = new TransportVersion(7_00_00_99, "7505fd05-d982-43ce-a63f-ff4c6c8bdeec"); public static final TransportVersion V_7_0_1 = new TransportVersion(7_00_01_99, "ae772780-e6f9-46a1-b0a0-20ed0cae37f7"); @@ -127,16 +133,17 @@ public class TransportVersion implements Comparable { /* * Detached transport versions added below here. Starts at ES major version 10 equivalent. */ - public static final TransportVersion V10_000_000 = new TransportVersion(10_000_000, "dc3cbf06-3ed5-4e1b-9978-ee1d04d235bc"); + public static final TransportVersion V_10_000_000 = new TransportVersion(10_000_000, "dc3cbf06-3ed5-4e1b-9978-ee1d04d235bc"); /* * When adding a new transport version, ensure there is a gap (say, 100) between versions * This is to make it possible to add intermediate versions for any bug fixes that may be required. */ /** Reference to the current transport version */ - public static final TransportVersion CURRENT = V10_000_000; + public static final TransportVersion CURRENT = V_10_000_000; /** Reference to the earliest compatible transport version to this version of the codebase */ + // TODO: can we programmatically calculate or check this? Don't want to introduce circular ref between Version/TransportVersion public static final TransportVersion MINIMUM_COMPATIBLE = V_7_17_0; private static final Map idToVersion; From 0346113de729100944657b3374f6cf5e98824f8e Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Fri, 13 Jan 2023 11:00:29 +0000 Subject: [PATCH 07/22] Add initial methods to StreamInput and StreamOutput --- .../src/main/java/org/elasticsearch/TransportVersion.java | 5 +++-- server/src/main/java/org/elasticsearch/Version.java | 2 +- .../elasticsearch/common/io/stream/FilterStreamInput.java | 6 ++++++ .../org/elasticsearch/common/io/stream/StreamInput.java | 8 ++++++++ .../org/elasticsearch/common/io/stream/StreamOutput.java | 8 ++++++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/TransportVersion.java b/server/src/main/java/org/elasticsearch/TransportVersion.java index 746e11c83b1ac..b2dca9ede033b 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersion.java +++ b/server/src/main/java/org/elasticsearch/TransportVersion.java @@ -133,14 +133,15 @@ public class TransportVersion implements Comparable { /* * Detached transport versions added below here. Starts at ES major version 10 equivalent. */ - public static final TransportVersion V_10_000_000 = new TransportVersion(10_000_000, "dc3cbf06-3ed5-4e1b-9978-ee1d04d235bc"); + // NOTE: DO NOT UNCOMMENT until all transport code uses TransportVersion + // public static final TransportVersion V_10_000_000 = new TransportVersion(10_000_000, "dc3cbf06-3ed5-4e1b-9978-ee1d04d235bc"); /* * When adding a new transport version, ensure there is a gap (say, 100) between versions * This is to make it possible to add intermediate versions for any bug fixes that may be required. */ /** Reference to the current transport version */ - public static final TransportVersion CURRENT = V_10_000_000; + public static final TransportVersion CURRENT = V_8_7_0; /** Reference to the earliest compatible transport version to this version of the codebase */ // TODO: can we programmatically calculate or check this? Don't want to introduce circular ref between Version/TransportVersion diff --git a/server/src/main/java/org/elasticsearch/Version.java b/server/src/main/java/org/elasticsearch/Version.java index 582dea382df8a..5d68700a1898b 100644 --- a/server/src/main/java/org/elasticsearch/Version.java +++ b/server/src/main/java/org/elasticsearch/Version.java @@ -131,7 +131,7 @@ public class Version implements Comparable, ToXContentFragment { public static final Version V_8_5_4 = new Version(8_05_04_99, TransportVersion.V_8_5_4, org.apache.lucene.util.Version.LUCENE_9_4_2); public static final Version V_8_6_0 = new Version(8_06_00_99, TransportVersion.V_8_6_0, org.apache.lucene.util.Version.LUCENE_9_4_2); public static final Version V_8_6_1 = new Version(8_06_01_99, TransportVersion.V_8_6_1, org.apache.lucene.util.Version.LUCENE_9_4_2); - public static final Version V_8_7_0 = new Version(8_07_00_99, TransportVersion.V_8_7_0, org.apache.lucene.util.Version.LUCENE_9_4_2); + public static final Version V_8_7_0 = new Version(8_07_00_99, TransportVersion.CURRENT, org.apache.lucene.util.Version.LUCENE_9_4_2); public static final Version CURRENT = V_8_7_0; private static final Map idToVersion; diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/FilterStreamInput.java b/server/src/main/java/org/elasticsearch/common/io/stream/FilterStreamInput.java index f46b6c309ae2d..819dfb55b0ded 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/FilterStreamInput.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/FilterStreamInput.java @@ -8,6 +8,7 @@ package org.elasticsearch.common.io.stream; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.common.bytes.ReleasableBytesReference; @@ -90,6 +91,11 @@ public Version getVersion() { return delegate.getVersion(); } + @Override + public TransportVersion getTransportVersion() { + return delegate.getTransportVersion(); + } + @Override public void setVersion(Version version) { delegate.setVersion(version); diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index fc7d5ad5736f8..955aa3e7294af 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -17,6 +17,7 @@ import org.apache.lucene.util.BitUtil; import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; @@ -92,6 +93,13 @@ public Version getVersion() { return this.version; } + /** + * The transport version the data is serialized as. + */ + public TransportVersion getTransportVersion() { + return this.version.transportVersion; + } + /** * Set the version of the node on the other side of this stream. */ diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java index 1ad651e08edc1..59c00266d2e65 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java @@ -17,6 +17,7 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -86,6 +87,13 @@ public Version getVersion() { return this.version; } + /** + * The transport version to serialize the data as. + */ + public TransportVersion getTransportVersion() { + return this.version.transportVersion; + } + /** * Set the version of the node on the other side of this stream. */ From 3fcbd3be5b52d64d81f228074ff7fe594db37b2a Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Fri, 13 Jan 2023 17:54:17 +0100 Subject: [PATCH 08/22] test --- .../org/elasticsearch/TransportVersion.java | 3 +- .../elasticsearch/TransportVersionTests.java | 329 ++++++++++++++++++ .../test/TransportVersionUtils.java | 88 +++++ 3 files changed, 419 insertions(+), 1 deletion(-) create mode 100644 server/src/test/java/org/elasticsearch/TransportVersionTests.java create mode 100644 test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java diff --git a/server/src/main/java/org/elasticsearch/TransportVersion.java b/server/src/main/java/org/elasticsearch/TransportVersion.java index b2dca9ede033b..1c842af297bf2 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersion.java +++ b/server/src/main/java/org/elasticsearch/TransportVersion.java @@ -214,7 +214,8 @@ public static TransportVersion max(TransportVersion version1, TransportVersion v return version1.id > version2.id ? version1 : version2; } - private final int id; + // TODO for testing or a getter? should this be used? + final int id; private final String uniqueId; TransportVersion(int id, String uniqueId) { diff --git a/server/src/test/java/org/elasticsearch/TransportVersionTests.java b/server/src/test/java/org/elasticsearch/TransportVersionTests.java new file mode 100644 index 0000000000000..e9a050dd59b6f --- /dev/null +++ b/server/src/test/java/org/elasticsearch/TransportVersionTests.java @@ -0,0 +1,329 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch; + +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.TransportVersionUtils; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThan; +import static org.hamcrest.Matchers.sameInstance; + +public class TransportVersionTests extends ESTestCase { + + public void testVersionComparison() throws Exception { + TransportVersion V_7_2_0 = TransportVersion.V_7_2_0; + TransportVersion V_8_0_0 = TransportVersion.V_8_0_0; + assertThat(V_7_2_0.before(V_8_0_0), is(true)); + assertThat(V_7_2_0.before(V_7_2_0), is(false)); + assertThat(V_8_0_0.before(V_7_2_0), is(false)); + + assertThat(V_7_2_0.onOrBefore(V_8_0_0), is(true)); + assertThat(V_7_2_0.onOrBefore(V_7_2_0), is(true)); + assertThat(V_8_0_0.onOrBefore(V_7_2_0), is(false)); + + assertThat(V_7_2_0.after(V_8_0_0), is(false)); + assertThat(V_7_2_0.after(V_7_2_0), is(false)); + assertThat(V_8_0_0.after(V_7_2_0), is(true)); + + assertThat(V_7_2_0.onOrAfter(V_8_0_0), is(false)); + assertThat(V_7_2_0.onOrAfter(V_7_2_0), is(true)); + assertThat(V_8_0_0.onOrAfter(V_7_2_0), is(true)); + + assertThat(V_7_2_0, is(lessThan(V_8_0_0))); + assertThat(V_7_2_0.compareTo(V_7_2_0), is(0)); + assertThat(V_8_0_0, is(greaterThan(V_7_2_0))); + } + + public void testMin() { + assertEquals(TransportVersionUtils.getPreviousVersion(), TransportVersion.min(TransportVersion.CURRENT, TransportVersionUtils.getPreviousVersion())); + assertEquals(TransportVersion.fromId(1_01_01_99), TransportVersion.min(TransportVersion.fromId(1_01_01_99), TransportVersion.CURRENT)); + TransportVersion version = TransportVersionUtils.randomVersion(random()); + TransportVersion version1 = TransportVersionUtils.randomVersion(random()); + if (version.id <= version1.id) { + assertEquals(version, TransportVersion.min(version1, version)); + } else { + assertEquals(version1, TransportVersion.min(version1, version)); + } + } + + public void testMax() { + assertEquals(TransportVersion.CURRENT, TransportVersion.max(TransportVersion.CURRENT, TransportVersionUtils.getPreviousVersion())); + assertEquals(TransportVersion.CURRENT, TransportVersion.max(TransportVersion.fromId(1_01_01_99), TransportVersion.CURRENT)); + TransportVersion version = TransportVersionUtils.randomVersion(random()); + TransportVersion version1 = TransportVersionUtils.randomVersion(random()); + if (version.id >= version1.id) { + assertEquals(version, TransportVersion.max(version1, version)); + } else { + assertEquals(version1, TransportVersion.max(version1, version)); + } + } + + public void testVersionConstantPresent() { + assertThat(TransportVersion.CURRENT, sameInstance(TransportVersion.fromId(TransportVersion.CURRENT.id))); + final int iters = scaledRandomIntBetween(20, 100); + for (int i = 0; i < iters; i++) { + TransportVersion version = TransportVersionUtils.randomVersion(random()); + assertThat(version, sameInstance(TransportVersion.fromId(version.id))); + } + } + + public void testCURRENTIsLatest() { + final int iters = scaledRandomIntBetween(100, 1000); + for (int i = 0; i < iters; i++) { + TransportVersion version = TransportVersionUtils.randomVersion(random()); + if (version != TransportVersion.CURRENT) { + assertThat( + "Version: " + version + " should be before: " + Version.CURRENT + " but wasn't", + version.before(TransportVersion.CURRENT), + is(true) + ); + } + } + } + +// public void testVersionFromString() { +// final int iters = scaledRandomIntBetween(100, 1000); +// for (int i = 0; i < iters; i++) { +// TransportVersion version = TransportVersionUtils.randomVersion(random()); +// assertThat(TransportVersion.fromString(version.toString()), sameInstance(version)); +// } +// } + +// public void testTooLongVersionFromString() { +// Exception e = expectThrows(IllegalArgumentException.class, () -> Version.fromString("1.0.0.1.3")); +// assertThat(e.getMessage(), containsString("needs to contain major, minor, and revision")); +// } +// +// public void testTooShortVersionFromString() { +// Exception e = expectThrows(IllegalArgumentException.class, () -> Version.fromString("1.0")); +// assertThat(e.getMessage(), containsString("needs to contain major, minor, and revision")); +// } +// +// public void testWrongVersionFromString() { +// Exception e = expectThrows(IllegalArgumentException.class, () -> Version.fromString("WRONG.VERSION")); +// assertThat(e.getMessage(), containsString("needs to contain major, minor, and revision")); +// } + + public void testMinCompatVersion() { + Version major = Version.fromString("2.0.0"); + assertThat(Version.fromString("2.0.0").minimumCompatibilityVersion(), equalTo(major)); + assertThat(Version.fromString("2.2.0").minimumCompatibilityVersion(), equalTo(major)); + assertThat(Version.fromString("2.3.0").minimumCompatibilityVersion(), equalTo(major)); + + Version major5x = Version.fromString("5.0.0"); + assertThat(Version.fromString("5.0.0").minimumCompatibilityVersion(), equalTo(major5x)); + assertThat(Version.fromString("5.2.0").minimumCompatibilityVersion(), equalTo(major5x)); + assertThat(Version.fromString("5.3.0").minimumCompatibilityVersion(), equalTo(major5x)); + + Version major56x = Version.fromString("5.6.0"); + assertThat(Version.fromString("6.4.0").minimumCompatibilityVersion(), equalTo(major56x)); + assertThat(Version.fromString("6.3.1").minimumCompatibilityVersion(), equalTo(major56x)); + + // from 7.0 on we are supporting the latest minor of the previous major... this might fail once we add a new version ie. 5.x is + // released since we need to bump the supported minor in Version#minimumCompatibilityVersion() + Version lastVersion = Version.fromString("6.8.0"); // TODO: remove this once min compat version is a constant instead of method + assertEquals(lastVersion.major, Version.V_7_0_0.minimumCompatibilityVersion().major); + assertEquals( + "did you miss to bump the minor in Version#minimumCompatibilityVersion()", + lastVersion.minor, + Version.V_7_0_0.minimumCompatibilityVersion().minor + ); + assertEquals(0, Version.V_7_0_0.minimumCompatibilityVersion().revision); + } + + public void testToString() { + assertEquals("5000099", TransportVersion.fromId(5_00_00_99).toString()); + assertEquals("2030099", TransportVersion.fromId(2_03_00_99).toString()); + assertEquals("1000099", TransportVersion.fromId(1_00_00_99).toString()); + assertEquals("2000099", TransportVersion.fromId(2_00_00_99).toString()); + assertEquals("5000099", TransportVersion.fromId(5_00_00_99).toString()); +// assertEquals("0.90.0",TransportVersion.fromId(0_90_0).toString()); + } + +// public void testParseVersion() { +// final int iters = scaledRandomIntBetween(100, 1000); +// for (int i = 0; i < iters; i++) { +// Version version = TransportVersionUtils.randomVersion(random()); +// if (random().nextBoolean()) { +// version = new Version(version.id, version.transportVersion, version.luceneVersion); +// } +// Version parsedVersion = Version.fromString(version.toString()); +// assertEquals(version, parsedVersion); +// } +// +// expectThrows(IllegalArgumentException.class, () -> { Version.fromString("5.0.0-alph2"); }); +// assertSame(Version.CURRENT, Version.fromString(Version.CURRENT.toString())); +// +// assertEquals(Version.fromString("2.0.0-SNAPSHOT"), Version.fromId(2000099)); +// +// expectThrows(IllegalArgumentException.class, () -> { Version.fromString("5.0.0-SNAPSHOT"); }); +// } + +// public void testParseLenient() { +// // note this is just a silly sanity check, we test it in lucene +// for (Version version : VersionUtils.allReleasedVersions()) { +// org.apache.lucene.util.Version luceneVersion = version.luceneVersion; +// String string = luceneVersion.toString().toUpperCase(Locale.ROOT).replaceFirst("^LUCENE_(\\d+)_(\\d+)$", "$1.$2"); +// assertThat(luceneVersion, Matchers.equalTo(Lucene.parseVersionLenient(string, null))); +// } +// } + +// public void testAllVersionsMatchId() throws Exception { +// final Set releasedVersions = new HashSet<>(VersionUtils.allReleasedVersions()); +// final Set unreleasedVersions = new HashSet<>(VersionUtils.allUnreleasedVersions()); +// Map maxBranchVersions = new HashMap<>(); +// for (java.lang.reflect.Field field : Version.class.getFields()) { +// if (field.getName().matches("_ID")) { +// assertTrue(field.getName() + " should be static", Modifier.isStatic(field.getModifiers())); +// assertTrue(field.getName() + " should be final", Modifier.isFinal(field.getModifiers())); +// int versionId = (Integer) field.get(Version.class); +// +// String constantName = field.getName().substring(0, field.getName().indexOf("_ID")); +// java.lang.reflect.Field versionConstant = Version.class.getField(constantName); +// assertTrue(constantName + " should be static", Modifier.isStatic(versionConstant.getModifiers())); +// assertTrue(constantName + " should be final", Modifier.isFinal(versionConstant.getModifiers())); +// +// Version v = (Version) versionConstant.get(null); +// logger.debug("Checking {}", v); +// if (field.getName().endsWith("_UNRELEASED")) { +// assertTrue(unreleasedVersions.contains(v)); +// } else { +// assertTrue(releasedVersions.contains(v)); +// } +// assertEquals("Version id " + field.getName() + " does not point to " + constantName, v, Version.fromId(versionId)); +// assertEquals("Version " + constantName + " does not have correct id", versionId, v.id); +// String number = v.toString(); +// assertEquals("V_" + number.replace('.', '_'), constantName); +// +// // only the latest version for a branch should be a snapshot (ie unreleased) +// String branchName = "" + v.major + "." + v.minor; +// Version maxBranchVersion = maxBranchVersions.get(branchName); +// if (maxBranchVersion == null) { +// maxBranchVersions.put(branchName, v); +// } else if (v.after(maxBranchVersion)) { +// if (v == Version.CURRENT) { +// // Current is weird - it counts as released even though it shouldn't. +// continue; +// } +// assertFalse( +// "Version " + maxBranchVersion + " cannot be a snapshot because version " + v + " exists", +// VersionUtils.allUnreleasedVersions().contains(maxBranchVersion) +// ); +// maxBranchVersions.put(branchName, v); +// } +// } +// } +// } +// +// // this test ensures we never bump the lucene version in a bugfix release +// public void testLuceneVersionIsSameOnMinorRelease() { +// for (Version version : VersionUtils.allReleasedVersions()) { +// for (Version other : VersionUtils.allReleasedVersions()) { +// if (other.onOrAfter(version)) { +// assertTrue("lucene versions must be " + other + " >= " + version, other.luceneVersion.onOrAfter(version.luceneVersion)); +// } +// if (other.major == version.major && other.minor == version.minor) { +// assertEquals(version + " vs. " + other, other.luceneVersion.major, version.luceneVersion.major); +// assertEquals(version + " vs. " + other, other.luceneVersion.minor, version.luceneVersion.minor); +// // should we also assert the lucene bugfix version? +// } +// } +// } +// } +// +// public static void assertUnknownVersion(Version version) { +// assertFalse( +// "Version " + version + " has been releaed don't use a new instance of this version", +// VersionUtils.allReleasedVersions().contains(version) +// ); +// } +// +// public void testIsCompatible() { +// assertTrue(isCompatible(Version.CURRENT, Version.CURRENT.minimumCompatibilityVersion())); +// assertFalse(isCompatible(Version.V_7_0_0, Version.V_8_0_0)); +// assertTrue(isCompatible(Version.fromString("6.8.0"), Version.fromString("7.0.0"))); +// assertFalse(isCompatible(Version.fromId(2000099), Version.V_7_0_0)); +// assertFalse(isCompatible(Version.fromId(2000099), Version.fromString("6.5.0"))); +// +// final Version currentMajorVersion = Version.fromId(Version.CURRENT.major * 1000000 + 99); +// final Version currentOrNextMajorVersion; +// if (Version.CURRENT.minor > 0) { +// currentOrNextMajorVersion = Version.fromId((Version.CURRENT.major + 1) * 1000000 + 99); +// } else { +// currentOrNextMajorVersion = currentMajorVersion; +// } +// final Version lastMinorFromPreviousMajor = VersionUtils.allVersions() +// .stream() +// .filter(v -> v.major == currentOrNextMajorVersion.major - 1) +// .max(Version::compareTo) +// .orElseThrow(() -> new IllegalStateException("expected previous minor version for [" + currentOrNextMajorVersion + "]")); +// final Version previousMinorVersion = VersionUtils.getPreviousMinorVersion(); +// +// boolean isCompatible = previousMinorVersion.major == currentOrNextMajorVersion.major +// || previousMinorVersion.minor == lastMinorFromPreviousMajor.minor; +// +// final String message = String.format( +// Locale.ROOT, +// "[%s] should %s be compatible with [%s]", +// previousMinorVersion, +// isCompatible ? "" : " not", +// currentOrNextMajorVersion +// ); +// assertThat(message, isCompatible(VersionUtils.getPreviousMinorVersion(), currentOrNextMajorVersion), equalTo(isCompatible)); +// +// assertFalse(isCompatible(Version.fromId(5000099), Version.fromString("6.0.0"))); +// assertFalse(isCompatible(Version.fromId(5000099), Version.fromString("7.0.0"))); +// +// Version a = randomVersion(random()); +// Version b = randomVersion(random()); +// assertThat(a.isCompatible(b), equalTo(b.isCompatible(a))); +// } +// +// /* tests that if a new version's minCompatVersion is always equal or higher to any older version */ +// public void testMinCompatVersionOrderRespectsVersionOrder() { +// List versionsByMinCompat = new ArrayList<>(allVersions()); +// versionsByMinCompat.sort(Comparator.comparing(Version::minimumCompatibilityVersion)); +// assertThat(versionsByMinCompat, equalTo(allVersions())); +// +// versionsByMinCompat.sort(Comparator.comparing(Version::minimumIndexCompatibilityVersion)); +// assertThat(versionsByMinCompat, equalTo(allVersions())); +// } +// +// public boolean isCompatible(Version left, Version right) { +// boolean result = left.isCompatible(right); +// assert result == right.isCompatible(left); +// return result; +// } + + // This exists because 5.1.0 was never released due to a mistake in the release process. + // This verifies that we never declare the version as "released" accidentally. + // It would never pass qa tests later on, but those come very far in the build and this is quick to check now. +// public void testUnreleasedVersion() { +// Version VERSION_5_1_0_UNRELEASED = Version.fromString("5.1.0"); +// VersionTests.assertUnknownVersion(VERSION_5_1_0_UNRELEASED); +// } + +// public void testIllegalMinorAndPatchNumbers() { +// IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> Version.fromString("8.2.999")); +// assertThat( +// e.getMessage(), +// containsString("illegal revision version format - only one or two digit numbers are supported but found 999") +// ); +// +// e = expectThrows(IllegalArgumentException.class, () -> Version.fromString("8.888.99")); +// assertThat( +// e.getMessage(), +// containsString("illegal minor version format - only one or two digit numbers are supported but found 888") +// ); +// } + +} diff --git a/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java b/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java new file mode 100644 index 0000000000000..52c339a26b347 --- /dev/null +++ b/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java @@ -0,0 +1,88 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.test; + +import org.elasticsearch.TransportVersion; +import org.elasticsearch.Version; +import org.elasticsearch.core.Tuple; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Random; + +public class TransportVersionUtils { + private static final List ALL_VERSIONS; + + static { +// Tuple, List> versions = resolveReleasedVersions(Version.CURRENT, Version.class); +// RELEASED_VERSIONS = versions.v1(); +// UNRELEASED_VERSIONS = versions.v2(); +// List allVersions = new ArrayList<>(RELEASED_VERSIONS.size() + UNRELEASED_VERSIONS.size()); +// allVersions.addAll(RELEASED_VERSIONS); +// allVersions.addAll(UNRELEASED_VERSIONS); +// Collections.sort(allVersions); + ALL_VERSIONS = getDeclaredVersions();//Collections.emptyList();//Collections.unmodifiableList(allVersions); + } + + /** Returns a random {@link TransportVersion} from all available versions. */ + public static TransportVersion randomVersion(Random random) { + return ALL_VERSIONS.get(random.nextInt(ALL_VERSIONS.size())); + } + + /** + * Extracts a sorted list of declared version constants from a class. + * The argument would normally be Version.class but is exposed for + * testing with other classes-containing-version-constants. + */ + public static List getDeclaredVersions() { + final Field[] fields = TransportVersion.class.getFields(); + final List versions = new ArrayList<>(fields.length); + for (final Field field : fields) { + final int mod = field.getModifiers(); + if (false == Modifier.isStatic(mod) && Modifier.isFinal(mod) && Modifier.isPublic(mod)) { + continue; + } + if (field.getType() != TransportVersion.class) { + continue; + } + switch (field.getName()) { + case "CURRENT": + case "V_EMPTY": + continue; + } + assert field.getName().matches("V(_\\d+){3}?") || field.getName().equals("ZERO") || field.getName().equals("MINIMUM_COMPATIBLE") : field.getName(); + try { + versions.add(((TransportVersion) field.get(null))); + } catch (final IllegalAccessException e) { + throw new RuntimeException(e); + } + } + Collections.sort(versions); + return versions; + } + + public static TransportVersion getPreviousVersion() { + TransportVersion version = getPreviousVersion(TransportVersion.CURRENT); + assert version.before(TransportVersion.CURRENT); + return version; + } + + public static TransportVersion getPreviousVersion(TransportVersion version) { + for (int i = ALL_VERSIONS.size() - 1; i >= 0; i--) {//shoudl be RELEASED_VERSIONS.. + TransportVersion v = ALL_VERSIONS.get(i); + if (v.before(version)) { + return v; + } + } + throw new IllegalArgumentException("couldn't find any released versions before [" + version + "]"); + } +} From dc9ae458c1cb1962e8bf21378054fc51ab2a26f1 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Fri, 13 Jan 2023 17:57:46 +0100 Subject: [PATCH 09/22] remove compatibility test --- .../elasticsearch/TransportVersionTests.java | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/TransportVersionTests.java b/server/src/test/java/org/elasticsearch/TransportVersionTests.java index e9a050dd59b6f..5ec2beb9bc973 100644 --- a/server/src/test/java/org/elasticsearch/TransportVersionTests.java +++ b/server/src/test/java/org/elasticsearch/TransportVersionTests.java @@ -112,33 +112,33 @@ public void testCURRENTIsLatest() { // Exception e = expectThrows(IllegalArgumentException.class, () -> Version.fromString("WRONG.VERSION")); // assertThat(e.getMessage(), containsString("needs to contain major, minor, and revision")); // } - - public void testMinCompatVersion() { - Version major = Version.fromString("2.0.0"); - assertThat(Version.fromString("2.0.0").minimumCompatibilityVersion(), equalTo(major)); - assertThat(Version.fromString("2.2.0").minimumCompatibilityVersion(), equalTo(major)); - assertThat(Version.fromString("2.3.0").minimumCompatibilityVersion(), equalTo(major)); - - Version major5x = Version.fromString("5.0.0"); - assertThat(Version.fromString("5.0.0").minimumCompatibilityVersion(), equalTo(major5x)); - assertThat(Version.fromString("5.2.0").minimumCompatibilityVersion(), equalTo(major5x)); - assertThat(Version.fromString("5.3.0").minimumCompatibilityVersion(), equalTo(major5x)); - - Version major56x = Version.fromString("5.6.0"); - assertThat(Version.fromString("6.4.0").minimumCompatibilityVersion(), equalTo(major56x)); - assertThat(Version.fromString("6.3.1").minimumCompatibilityVersion(), equalTo(major56x)); - - // from 7.0 on we are supporting the latest minor of the previous major... this might fail once we add a new version ie. 5.x is - // released since we need to bump the supported minor in Version#minimumCompatibilityVersion() - Version lastVersion = Version.fromString("6.8.0"); // TODO: remove this once min compat version is a constant instead of method - assertEquals(lastVersion.major, Version.V_7_0_0.minimumCompatibilityVersion().major); - assertEquals( - "did you miss to bump the minor in Version#minimumCompatibilityVersion()", - lastVersion.minor, - Version.V_7_0_0.minimumCompatibilityVersion().minor - ); - assertEquals(0, Version.V_7_0_0.minimumCompatibilityVersion().revision); - } +// +// public void testMinCompatVersion() { +// Version major = Version.fromString("2.0.0"); +// assertThat(Version.fromString("2.0.0").minimumCompatibilityVersion(), equalTo(major)); +// assertThat(Version.fromString("2.2.0").minimumCompatibilityVersion(), equalTo(major)); +// assertThat(Version.fromString("2.3.0").minimumCompatibilityVersion(), equalTo(major)); +// +// Version major5x = Version.fromString("5.0.0"); +// assertThat(Version.fromString("5.0.0").minimumCompatibilityVersion(), equalTo(major5x)); +// assertThat(Version.fromString("5.2.0").minimumCompatibilityVersion(), equalTo(major5x)); +// assertThat(Version.fromString("5.3.0").minimumCompatibilityVersion(), equalTo(major5x)); +// +// Version major56x = Version.fromString("5.6.0"); +// assertThat(Version.fromString("6.4.0").minimumCompatibilityVersion(), equalTo(major56x)); +// assertThat(Version.fromString("6.3.1").minimumCompatibilityVersion(), equalTo(major56x)); +// +// // from 7.0 on we are supporting the latest minor of the previous major... this might fail once we add a new version ie. 5.x is +// // released since we need to bump the supported minor in Version#minimumCompatibilityVersion() +// Version lastVersion = Version.fromString("6.8.0"); // TODO: remove this once min compat version is a constant instead of method +// assertEquals(lastVersion.major, Version.V_7_0_0.minimumCompatibilityVersion().major); +// assertEquals( +// "did you miss to bump the minor in Version#minimumCompatibilityVersion()", +// lastVersion.minor, +// Version.V_7_0_0.minimumCompatibilityVersion().minor +// ); +// assertEquals(0, Version.V_7_0_0.minimumCompatibilityVersion().revision); +// } public void testToString() { assertEquals("5000099", TransportVersion.fromId(5_00_00_99).toString()); From 968995487b0187df4bc3e27a55803621e4cd5b7d Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Mon, 16 Jan 2023 10:18:26 +0000 Subject: [PATCH 10/22] PR comments --- .../java/org/elasticsearch/TransportVersion.java | 12 ++++++++---- server/src/main/java/org/elasticsearch/Version.java | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/TransportVersion.java b/server/src/main/java/org/elasticsearch/TransportVersion.java index b2dca9ede033b..8bb4f57d8bf0a 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersion.java +++ b/server/src/main/java/org/elasticsearch/TransportVersion.java @@ -24,7 +24,7 @@ * Prior to 8.7.0, the node {@link Version} was used everywhere. This class separates the wire protocol version * from the running node version. Each node version has a reference to a specific transport version used by that node. *

- * Each transport version constant has got an id number, which for versions prior to 8.7.0 is the same as the node version + * Each transport version constant has an id number, which for versions prior to 8.7.0 is the same as the node version * for backwards compatibility. * There is also a unique id string. This is not actually used in the protocol, but is there to ensure each protocol version * is only added to the source file once. This string needs to be unique (here, a UUID, but can be any other unique nonempty string). @@ -36,9 +36,9 @@ * to leave space for any intermediate fixes that may be needed in the future. *

* The earliest compatible version is hardcoded at {@link #MINIMUM_COMPATIBLE}. Previously, this was dynamically calculated - * from the major/minor versions of {@link Version}, but {@code TransportVersion} does not have that concept. So the minimum compatible - * version needs to be hard-coded as the transport version of the minimum compatible node version. That variable should be updated - * appropriately whenever we do a major version release. + * from the major/minor versions of {@link Version}, but {@code TransportVersion} does not have separate major/minor version numbers. + * So the minimum compatible version needs to be hard-coded as the transport version of the minimum compatible node version. + * That variable should be updated appropriately whenever we do a major version release. */ public class TransportVersion implements Comparable { public static final TransportVersion ZERO = new TransportVersion(0, "00000000-0000-0000-0000-000000000000"); @@ -131,6 +131,7 @@ public class TransportVersion implements Comparable { public static final TransportVersion V_8_6_1 = new TransportVersion(8_06_01_99, "9f113acb-1b21-4fda-bef9-2a3e669b5c7b"); public static final TransportVersion V_8_7_0 = new TransportVersion(8_07_00_99, "f1ee7a85-4fa6-43f5-8679-33e2b750448b"); /* + * READ THE JAVADOC ABOVE BEFORE ADDING NEW TRANSPORT VERSIONS * Detached transport versions added below here. Starts at ES major version 10 equivalent. */ // NOTE: DO NOT UNCOMMENT until all transport code uses TransportVersion @@ -138,6 +139,9 @@ public class TransportVersion implements Comparable { /* * When adding a new transport version, ensure there is a gap (say, 100) between versions * This is to make it possible to add intermediate versions for any bug fixes that may be required. + * + * When adding versions for patch fixes, add numbers in the middle of the gap. This is to ensure there is always some space + * for patch fixes between any two versions. */ /** Reference to the current transport version */ diff --git a/server/src/main/java/org/elasticsearch/Version.java b/server/src/main/java/org/elasticsearch/Version.java index 5d68700a1898b..582dea382df8a 100644 --- a/server/src/main/java/org/elasticsearch/Version.java +++ b/server/src/main/java/org/elasticsearch/Version.java @@ -131,7 +131,7 @@ public class Version implements Comparable, ToXContentFragment { public static final Version V_8_5_4 = new Version(8_05_04_99, TransportVersion.V_8_5_4, org.apache.lucene.util.Version.LUCENE_9_4_2); public static final Version V_8_6_0 = new Version(8_06_00_99, TransportVersion.V_8_6_0, org.apache.lucene.util.Version.LUCENE_9_4_2); public static final Version V_8_6_1 = new Version(8_06_01_99, TransportVersion.V_8_6_1, org.apache.lucene.util.Version.LUCENE_9_4_2); - public static final Version V_8_7_0 = new Version(8_07_00_99, TransportVersion.CURRENT, org.apache.lucene.util.Version.LUCENE_9_4_2); + public static final Version V_8_7_0 = new Version(8_07_00_99, TransportVersion.V_8_7_0, org.apache.lucene.util.Version.LUCENE_9_4_2); public static final Version CURRENT = V_8_7_0; private static final Map idToVersion; From c64e813844ae362231f449dd0060da3ec3ae4a67 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Mon, 16 Jan 2023 13:01:27 +0100 Subject: [PATCH 11/22] test cleanup --- .../elasticsearch/TransportVersionTests.java | 257 ++---------------- .../test/TransportVersionUtils.java | 32 +-- 2 files changed, 33 insertions(+), 256 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/TransportVersionTests.java b/server/src/test/java/org/elasticsearch/TransportVersionTests.java index 5ec2beb9bc973..4bed6ef40b03b 100644 --- a/server/src/test/java/org/elasticsearch/TransportVersionTests.java +++ b/server/src/test/java/org/elasticsearch/TransportVersionTests.java @@ -11,7 +11,8 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.TransportVersionUtils; -import static org.hamcrest.CoreMatchers.equalTo; +import java.util.Set; + import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.lessThan; @@ -44,10 +45,16 @@ public void testVersionComparison() throws Exception { } public void testMin() { - assertEquals(TransportVersionUtils.getPreviousVersion(), TransportVersion.min(TransportVersion.CURRENT, TransportVersionUtils.getPreviousVersion())); - assertEquals(TransportVersion.fromId(1_01_01_99), TransportVersion.min(TransportVersion.fromId(1_01_01_99), TransportVersion.CURRENT)); - TransportVersion version = TransportVersionUtils.randomVersion(random()); - TransportVersion version1 = TransportVersionUtils.randomVersion(random()); + assertEquals( + TransportVersionUtils.getPreviousVersion(), + TransportVersion.min(TransportVersion.CURRENT, TransportVersionUtils.getPreviousVersion()) + ); + assertEquals( + TransportVersion.fromId(1_01_01_99), + TransportVersion.min(TransportVersion.fromId(1_01_01_99), TransportVersion.CURRENT) + ); + TransportVersion version = TransportVersionUtils.randomVersion(); + TransportVersion version1 = TransportVersionUtils.randomVersion(); if (version.id <= version1.id) { assertEquals(version, TransportVersion.min(version1, version)); } else { @@ -58,8 +65,8 @@ public void testMin() { public void testMax() { assertEquals(TransportVersion.CURRENT, TransportVersion.max(TransportVersion.CURRENT, TransportVersionUtils.getPreviousVersion())); assertEquals(TransportVersion.CURRENT, TransportVersion.max(TransportVersion.fromId(1_01_01_99), TransportVersion.CURRENT)); - TransportVersion version = TransportVersionUtils.randomVersion(random()); - TransportVersion version1 = TransportVersionUtils.randomVersion(random()); + TransportVersion version = TransportVersionUtils.randomVersion(); + TransportVersion version1 = TransportVersionUtils.randomVersion(); if (version.id >= version1.id) { assertEquals(version, TransportVersion.max(version1, version)); } else { @@ -68,10 +75,13 @@ public void testMax() { } public void testVersionConstantPresent() { + // TODO those versions are not cached at the moment, perhaps we should add them to idToVersion set too? + Set ignore = Set.of(TransportVersion.ZERO, TransportVersion.CURRENT, TransportVersion.MINIMUM_COMPATIBLE); assertThat(TransportVersion.CURRENT, sameInstance(TransportVersion.fromId(TransportVersion.CURRENT.id))); final int iters = scaledRandomIntBetween(20, 100); for (int i = 0; i < iters; i++) { - TransportVersion version = TransportVersionUtils.randomVersion(random()); + TransportVersion version = TransportVersionUtils.randomVersion(ignore); + assertThat(version, sameInstance(TransportVersion.fromId(version.id))); } } @@ -79,7 +89,7 @@ public void testVersionConstantPresent() { public void testCURRENTIsLatest() { final int iters = scaledRandomIntBetween(100, 1000); for (int i = 0; i < iters; i++) { - TransportVersion version = TransportVersionUtils.randomVersion(random()); + TransportVersion version = TransportVersionUtils.randomVersion(); if (version != TransportVersion.CURRENT) { assertThat( "Version: " + version + " should be before: " + Version.CURRENT + " but wasn't", @@ -90,240 +100,11 @@ public void testCURRENTIsLatest() { } } -// public void testVersionFromString() { -// final int iters = scaledRandomIntBetween(100, 1000); -// for (int i = 0; i < iters; i++) { -// TransportVersion version = TransportVersionUtils.randomVersion(random()); -// assertThat(TransportVersion.fromString(version.toString()), sameInstance(version)); -// } -// } - -// public void testTooLongVersionFromString() { -// Exception e = expectThrows(IllegalArgumentException.class, () -> Version.fromString("1.0.0.1.3")); -// assertThat(e.getMessage(), containsString("needs to contain major, minor, and revision")); -// } -// -// public void testTooShortVersionFromString() { -// Exception e = expectThrows(IllegalArgumentException.class, () -> Version.fromString("1.0")); -// assertThat(e.getMessage(), containsString("needs to contain major, minor, and revision")); -// } -// -// public void testWrongVersionFromString() { -// Exception e = expectThrows(IllegalArgumentException.class, () -> Version.fromString("WRONG.VERSION")); -// assertThat(e.getMessage(), containsString("needs to contain major, minor, and revision")); -// } -// -// public void testMinCompatVersion() { -// Version major = Version.fromString("2.0.0"); -// assertThat(Version.fromString("2.0.0").minimumCompatibilityVersion(), equalTo(major)); -// assertThat(Version.fromString("2.2.0").minimumCompatibilityVersion(), equalTo(major)); -// assertThat(Version.fromString("2.3.0").minimumCompatibilityVersion(), equalTo(major)); -// -// Version major5x = Version.fromString("5.0.0"); -// assertThat(Version.fromString("5.0.0").minimumCompatibilityVersion(), equalTo(major5x)); -// assertThat(Version.fromString("5.2.0").minimumCompatibilityVersion(), equalTo(major5x)); -// assertThat(Version.fromString("5.3.0").minimumCompatibilityVersion(), equalTo(major5x)); -// -// Version major56x = Version.fromString("5.6.0"); -// assertThat(Version.fromString("6.4.0").minimumCompatibilityVersion(), equalTo(major56x)); -// assertThat(Version.fromString("6.3.1").minimumCompatibilityVersion(), equalTo(major56x)); -// -// // from 7.0 on we are supporting the latest minor of the previous major... this might fail once we add a new version ie. 5.x is -// // released since we need to bump the supported minor in Version#minimumCompatibilityVersion() -// Version lastVersion = Version.fromString("6.8.0"); // TODO: remove this once min compat version is a constant instead of method -// assertEquals(lastVersion.major, Version.V_7_0_0.minimumCompatibilityVersion().major); -// assertEquals( -// "did you miss to bump the minor in Version#minimumCompatibilityVersion()", -// lastVersion.minor, -// Version.V_7_0_0.minimumCompatibilityVersion().minor -// ); -// assertEquals(0, Version.V_7_0_0.minimumCompatibilityVersion().revision); -// } - public void testToString() { assertEquals("5000099", TransportVersion.fromId(5_00_00_99).toString()); assertEquals("2030099", TransportVersion.fromId(2_03_00_99).toString()); assertEquals("1000099", TransportVersion.fromId(1_00_00_99).toString()); assertEquals("2000099", TransportVersion.fromId(2_00_00_99).toString()); assertEquals("5000099", TransportVersion.fromId(5_00_00_99).toString()); -// assertEquals("0.90.0",TransportVersion.fromId(0_90_0).toString()); } - -// public void testParseVersion() { -// final int iters = scaledRandomIntBetween(100, 1000); -// for (int i = 0; i < iters; i++) { -// Version version = TransportVersionUtils.randomVersion(random()); -// if (random().nextBoolean()) { -// version = new Version(version.id, version.transportVersion, version.luceneVersion); -// } -// Version parsedVersion = Version.fromString(version.toString()); -// assertEquals(version, parsedVersion); -// } -// -// expectThrows(IllegalArgumentException.class, () -> { Version.fromString("5.0.0-alph2"); }); -// assertSame(Version.CURRENT, Version.fromString(Version.CURRENT.toString())); -// -// assertEquals(Version.fromString("2.0.0-SNAPSHOT"), Version.fromId(2000099)); -// -// expectThrows(IllegalArgumentException.class, () -> { Version.fromString("5.0.0-SNAPSHOT"); }); -// } - -// public void testParseLenient() { -// // note this is just a silly sanity check, we test it in lucene -// for (Version version : VersionUtils.allReleasedVersions()) { -// org.apache.lucene.util.Version luceneVersion = version.luceneVersion; -// String string = luceneVersion.toString().toUpperCase(Locale.ROOT).replaceFirst("^LUCENE_(\\d+)_(\\d+)$", "$1.$2"); -// assertThat(luceneVersion, Matchers.equalTo(Lucene.parseVersionLenient(string, null))); -// } -// } - -// public void testAllVersionsMatchId() throws Exception { -// final Set releasedVersions = new HashSet<>(VersionUtils.allReleasedVersions()); -// final Set unreleasedVersions = new HashSet<>(VersionUtils.allUnreleasedVersions()); -// Map maxBranchVersions = new HashMap<>(); -// for (java.lang.reflect.Field field : Version.class.getFields()) { -// if (field.getName().matches("_ID")) { -// assertTrue(field.getName() + " should be static", Modifier.isStatic(field.getModifiers())); -// assertTrue(field.getName() + " should be final", Modifier.isFinal(field.getModifiers())); -// int versionId = (Integer) field.get(Version.class); -// -// String constantName = field.getName().substring(0, field.getName().indexOf("_ID")); -// java.lang.reflect.Field versionConstant = Version.class.getField(constantName); -// assertTrue(constantName + " should be static", Modifier.isStatic(versionConstant.getModifiers())); -// assertTrue(constantName + " should be final", Modifier.isFinal(versionConstant.getModifiers())); -// -// Version v = (Version) versionConstant.get(null); -// logger.debug("Checking {}", v); -// if (field.getName().endsWith("_UNRELEASED")) { -// assertTrue(unreleasedVersions.contains(v)); -// } else { -// assertTrue(releasedVersions.contains(v)); -// } -// assertEquals("Version id " + field.getName() + " does not point to " + constantName, v, Version.fromId(versionId)); -// assertEquals("Version " + constantName + " does not have correct id", versionId, v.id); -// String number = v.toString(); -// assertEquals("V_" + number.replace('.', '_'), constantName); -// -// // only the latest version for a branch should be a snapshot (ie unreleased) -// String branchName = "" + v.major + "." + v.minor; -// Version maxBranchVersion = maxBranchVersions.get(branchName); -// if (maxBranchVersion == null) { -// maxBranchVersions.put(branchName, v); -// } else if (v.after(maxBranchVersion)) { -// if (v == Version.CURRENT) { -// // Current is weird - it counts as released even though it shouldn't. -// continue; -// } -// assertFalse( -// "Version " + maxBranchVersion + " cannot be a snapshot because version " + v + " exists", -// VersionUtils.allUnreleasedVersions().contains(maxBranchVersion) -// ); -// maxBranchVersions.put(branchName, v); -// } -// } -// } -// } -// -// // this test ensures we never bump the lucene version in a bugfix release -// public void testLuceneVersionIsSameOnMinorRelease() { -// for (Version version : VersionUtils.allReleasedVersions()) { -// for (Version other : VersionUtils.allReleasedVersions()) { -// if (other.onOrAfter(version)) { -// assertTrue("lucene versions must be " + other + " >= " + version, other.luceneVersion.onOrAfter(version.luceneVersion)); -// } -// if (other.major == version.major && other.minor == version.minor) { -// assertEquals(version + " vs. " + other, other.luceneVersion.major, version.luceneVersion.major); -// assertEquals(version + " vs. " + other, other.luceneVersion.minor, version.luceneVersion.minor); -// // should we also assert the lucene bugfix version? -// } -// } -// } -// } -// -// public static void assertUnknownVersion(Version version) { -// assertFalse( -// "Version " + version + " has been releaed don't use a new instance of this version", -// VersionUtils.allReleasedVersions().contains(version) -// ); -// } -// -// public void testIsCompatible() { -// assertTrue(isCompatible(Version.CURRENT, Version.CURRENT.minimumCompatibilityVersion())); -// assertFalse(isCompatible(Version.V_7_0_0, Version.V_8_0_0)); -// assertTrue(isCompatible(Version.fromString("6.8.0"), Version.fromString("7.0.0"))); -// assertFalse(isCompatible(Version.fromId(2000099), Version.V_7_0_0)); -// assertFalse(isCompatible(Version.fromId(2000099), Version.fromString("6.5.0"))); -// -// final Version currentMajorVersion = Version.fromId(Version.CURRENT.major * 1000000 + 99); -// final Version currentOrNextMajorVersion; -// if (Version.CURRENT.minor > 0) { -// currentOrNextMajorVersion = Version.fromId((Version.CURRENT.major + 1) * 1000000 + 99); -// } else { -// currentOrNextMajorVersion = currentMajorVersion; -// } -// final Version lastMinorFromPreviousMajor = VersionUtils.allVersions() -// .stream() -// .filter(v -> v.major == currentOrNextMajorVersion.major - 1) -// .max(Version::compareTo) -// .orElseThrow(() -> new IllegalStateException("expected previous minor version for [" + currentOrNextMajorVersion + "]")); -// final Version previousMinorVersion = VersionUtils.getPreviousMinorVersion(); -// -// boolean isCompatible = previousMinorVersion.major == currentOrNextMajorVersion.major -// || previousMinorVersion.minor == lastMinorFromPreviousMajor.minor; -// -// final String message = String.format( -// Locale.ROOT, -// "[%s] should %s be compatible with [%s]", -// previousMinorVersion, -// isCompatible ? "" : " not", -// currentOrNextMajorVersion -// ); -// assertThat(message, isCompatible(VersionUtils.getPreviousMinorVersion(), currentOrNextMajorVersion), equalTo(isCompatible)); -// -// assertFalse(isCompatible(Version.fromId(5000099), Version.fromString("6.0.0"))); -// assertFalse(isCompatible(Version.fromId(5000099), Version.fromString("7.0.0"))); -// -// Version a = randomVersion(random()); -// Version b = randomVersion(random()); -// assertThat(a.isCompatible(b), equalTo(b.isCompatible(a))); -// } -// -// /* tests that if a new version's minCompatVersion is always equal or higher to any older version */ -// public void testMinCompatVersionOrderRespectsVersionOrder() { -// List versionsByMinCompat = new ArrayList<>(allVersions()); -// versionsByMinCompat.sort(Comparator.comparing(Version::minimumCompatibilityVersion)); -// assertThat(versionsByMinCompat, equalTo(allVersions())); -// -// versionsByMinCompat.sort(Comparator.comparing(Version::minimumIndexCompatibilityVersion)); -// assertThat(versionsByMinCompat, equalTo(allVersions())); -// } -// -// public boolean isCompatible(Version left, Version right) { -// boolean result = left.isCompatible(right); -// assert result == right.isCompatible(left); -// return result; -// } - - // This exists because 5.1.0 was never released due to a mistake in the release process. - // This verifies that we never declare the version as "released" accidentally. - // It would never pass qa tests later on, but those come very far in the build and this is quick to check now. -// public void testUnreleasedVersion() { -// Version VERSION_5_1_0_UNRELEASED = Version.fromString("5.1.0"); -// VersionTests.assertUnknownVersion(VERSION_5_1_0_UNRELEASED); -// } - -// public void testIllegalMinorAndPatchNumbers() { -// IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> Version.fromString("8.2.999")); -// assertThat( -// e.getMessage(), -// containsString("illegal revision version format - only one or two digit numbers are supported but found 999") -// ); -// -// e = expectThrows(IllegalArgumentException.class, () -> Version.fromString("8.888.99")); -// assertThat( -// e.getMessage(), -// containsString("illegal minor version format - only one or two digit numbers are supported but found 888") -// ); -// } - } diff --git a/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java b/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java index 52c339a26b347..290a4021919cc 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java +++ b/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java @@ -9,39 +9,34 @@ package org.elasticsearch.test; import org.elasticsearch.TransportVersion; -import org.elasticsearch.Version; -import org.elasticsearch.core.Tuple; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Random; +import java.util.Set; +import java.util.stream.Collectors; public class TransportVersionUtils { private static final List ALL_VERSIONS; static { -// Tuple, List> versions = resolveReleasedVersions(Version.CURRENT, Version.class); -// RELEASED_VERSIONS = versions.v1(); -// UNRELEASED_VERSIONS = versions.v2(); -// List allVersions = new ArrayList<>(RELEASED_VERSIONS.size() + UNRELEASED_VERSIONS.size()); -// allVersions.addAll(RELEASED_VERSIONS); -// allVersions.addAll(UNRELEASED_VERSIONS); -// Collections.sort(allVersions); - ALL_VERSIONS = getDeclaredVersions();//Collections.emptyList();//Collections.unmodifiableList(allVersions); + ALL_VERSIONS = getDeclaredVersions(); } /** Returns a random {@link TransportVersion} from all available versions. */ - public static TransportVersion randomVersion(Random random) { - return ALL_VERSIONS.get(random.nextInt(ALL_VERSIONS.size())); + public static TransportVersion randomVersion() { + return ESTestCase.randomFrom(ALL_VERSIONS); + } + + /** Returns a random {@link TransportVersion} from all available versions without the ignore set */ + public static TransportVersion randomVersion(Set ignore) { + return ESTestCase.randomFrom(ALL_VERSIONS.stream().filter(v -> ignore.contains(v) == false).collect(Collectors.toList())); } /** - * Extracts a sorted list of declared version constants from a class. - * The argument would normally be Version.class but is exposed for - * testing with other classes-containing-version-constants. + * Extracts a sorted list of declared transport version constants from a class. */ public static List getDeclaredVersions() { final Field[] fields = TransportVersion.class.getFields(); @@ -59,7 +54,8 @@ public static List getDeclaredVersions() { case "V_EMPTY": continue; } - assert field.getName().matches("V(_\\d+){3}?") || field.getName().equals("ZERO") || field.getName().equals("MINIMUM_COMPATIBLE") : field.getName(); + assert field.getName().matches("V(_\\d+){3}?") || field.getName().equals("ZERO") || field.getName().equals("MINIMUM_COMPATIBLE") + : field.getName(); try { versions.add(((TransportVersion) field.get(null))); } catch (final IllegalAccessException e) { @@ -77,7 +73,7 @@ public static TransportVersion getPreviousVersion() { } public static TransportVersion getPreviousVersion(TransportVersion version) { - for (int i = ALL_VERSIONS.size() - 1; i >= 0; i--) {//shoudl be RELEASED_VERSIONS.. + for (int i = ALL_VERSIONS.size() - 1; i >= 0; i--) {// TODO should be RELEASED_VERSIONS TransportVersion v = ALL_VERSIONS.get(i); if (v.before(version)) { return v; From 7e9690a2c8cfba55c349c2f7e66ba5af2717bb66 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Mon, 16 Jan 2023 14:47:36 +0100 Subject: [PATCH 12/22] cleanup --- .../org/elasticsearch/TransportVersion.java | 14 +++++ .../test/TransportVersionUtils.java | 51 +++---------------- 2 files changed, 21 insertions(+), 44 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/TransportVersion.java b/server/src/main/java/org/elasticsearch/TransportVersion.java index 1c842af297bf2..74d7073aab9c3 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersion.java +++ b/server/src/main/java/org/elasticsearch/TransportVersion.java @@ -16,7 +16,10 @@ import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; +import java.util.NavigableSet; import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; /** * Represents the version of the wire protocol used to communicate between ES nodes. @@ -149,6 +152,8 @@ public class TransportVersion implements Comparable { private static final Map idToVersion; + private static final TreeSet declaredVersions; + static { Map builder = new HashMap<>(); Map uniqueIds = new HashMap<>(); @@ -181,6 +186,7 @@ public class TransportVersion implements Comparable { } } idToVersion = Map.copyOf(builder); + declaredVersions = idToVersion.values().stream().collect(Collectors.toCollection(() -> new TreeSet<>())); } public static TransportVersion readVersion(StreamInput in) throws IOException { @@ -244,6 +250,13 @@ public int compareTo(TransportVersion other) { return Integer.compare(this.id, other.id); } + /** + * returns a sorted list of declared transport version constants + */ + public static NavigableSet getDeclaredVersions() { + return declaredVersions; + } + @Override public String toString() { return Integer.toString(id); @@ -271,4 +284,5 @@ public boolean equals(Object o) { public int hashCode() { return id; } + } diff --git a/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java b/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java index 290a4021919cc..404aa28d45dab 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java +++ b/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java @@ -10,19 +10,15 @@ import org.elasticsearch.TransportVersion; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.NavigableSet; import java.util.Set; import java.util.stream.Collectors; public class TransportVersionUtils { - private static final List ALL_VERSIONS; + private static final NavigableSet ALL_VERSIONS; static { - ALL_VERSIONS = getDeclaredVersions(); + ALL_VERSIONS = TransportVersion.getDeclaredVersions(); } /** Returns a random {@link TransportVersion} from all available versions. */ @@ -35,37 +31,6 @@ public static TransportVersion randomVersion(Set ignore) { return ESTestCase.randomFrom(ALL_VERSIONS.stream().filter(v -> ignore.contains(v) == false).collect(Collectors.toList())); } - /** - * Extracts a sorted list of declared transport version constants from a class. - */ - public static List getDeclaredVersions() { - final Field[] fields = TransportVersion.class.getFields(); - final List versions = new ArrayList<>(fields.length); - for (final Field field : fields) { - final int mod = field.getModifiers(); - if (false == Modifier.isStatic(mod) && Modifier.isFinal(mod) && Modifier.isPublic(mod)) { - continue; - } - if (field.getType() != TransportVersion.class) { - continue; - } - switch (field.getName()) { - case "CURRENT": - case "V_EMPTY": - continue; - } - assert field.getName().matches("V(_\\d+){3}?") || field.getName().equals("ZERO") || field.getName().equals("MINIMUM_COMPATIBLE") - : field.getName(); - try { - versions.add(((TransportVersion) field.get(null))); - } catch (final IllegalAccessException e) { - throw new RuntimeException(e); - } - } - Collections.sort(versions); - return versions; - } - public static TransportVersion getPreviousVersion() { TransportVersion version = getPreviousVersion(TransportVersion.CURRENT); assert version.before(TransportVersion.CURRENT); @@ -73,12 +38,10 @@ public static TransportVersion getPreviousVersion() { } public static TransportVersion getPreviousVersion(TransportVersion version) { - for (int i = ALL_VERSIONS.size() - 1; i >= 0; i--) {// TODO should be RELEASED_VERSIONS - TransportVersion v = ALL_VERSIONS.get(i); - if (v.before(version)) { - return v; - } + TransportVersion prev = ALL_VERSIONS.lower(version); + if (prev == null) { + throw new IllegalArgumentException("couldn't find any released versions before [" + version + "]"); } - throw new IllegalArgumentException("couldn't find any released versions before [" + version + "]"); + return prev; } } From 8b1253015a354caf940813468ccb078dc63681d7 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Wed, 18 Jan 2023 13:45:20 +0000 Subject: [PATCH 13/22] More PR comments --- .../org/elasticsearch/TransportVersion.java | 31 +++++++------- .../main/java/org/elasticsearch/Version.java | 16 ++++---- .../elasticsearch/TransportVersionTests.java | 40 +++++++++++++++++++ .../test/TransportVersionUtils.java | 2 +- 4 files changed, 64 insertions(+), 25 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/TransportVersion.java b/server/src/main/java/org/elasticsearch/TransportVersion.java index 0519505c79f94..3c93a83280413 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersion.java +++ b/server/src/main/java/org/elasticsearch/TransportVersion.java @@ -14,12 +14,12 @@ import java.io.IOException; import java.lang.reflect.Field; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.NavigableSet; import java.util.Set; import java.util.TreeSet; -import java.util.stream.Collectors; /** * Represents the version of the wire protocol used to communicate between ES nodes. @@ -154,9 +154,9 @@ public class TransportVersion implements Comparable { // TODO: can we programmatically calculate or check this? Don't want to introduce circular ref between Version/TransportVersion public static final TransportVersion MINIMUM_COMPATIBLE = V_7_17_0; - private static final Map idToVersion; + private static final Map VERSION_IDS; - private static final TreeSet declaredVersions; + private static final NavigableSet ALL_VERSIONS; static { Map builder = new HashMap<>(); @@ -189,8 +189,8 @@ public class TransportVersion implements Comparable { } } } - idToVersion = Map.copyOf(builder); - declaredVersions = idToVersion.values().stream().collect(Collectors.toCollection(() -> new TreeSet<>())); + VERSION_IDS = Map.copyOf(builder); + ALL_VERSIONS = Collections.unmodifiableNavigableSet(new TreeSet<>(VERSION_IDS.values())); } public static TransportVersion readVersion(StreamInput in) throws IOException { @@ -198,7 +198,7 @@ public static TransportVersion readVersion(StreamInput in) throws IOException { } public static TransportVersion fromId(int id) { - TransportVersion known = idToVersion.get(id); + TransportVersion known = VERSION_IDS.get(id); if (known != null) { return known; } @@ -211,20 +211,26 @@ public static void writeVersion(TransportVersion version, StreamOutput out) thro } /** - * Returns the minimum version between the 2. + * Returns the minimum version of {@code version1} and {@code version2} */ public static TransportVersion min(TransportVersion version1, TransportVersion version2) { return version1.id < version2.id ? version1 : version2; } /** - * Returns the maximum version between the 2 + * Returns the maximum version of {@code version1} and {@code version2} */ public static TransportVersion max(TransportVersion version1, TransportVersion version2) { return version1.id > version2.id ? version1 : version2; } - // TODO for testing or a getter? should this be used? + /** + * returns a sorted set of all transport version constants + */ + public static NavigableSet getAllVersions() { + return ALL_VERSIONS; + } + final int id; private final String uniqueId; @@ -254,13 +260,6 @@ public int compareTo(TransportVersion other) { return Integer.compare(this.id, other.id); } - /** - * returns a sorted list of declared transport version constants - */ - public static NavigableSet getDeclaredVersions() { - return declaredVersions; - } - @Override public String toString() { return Integer.toString(id); diff --git a/server/src/main/java/org/elasticsearch/Version.java b/server/src/main/java/org/elasticsearch/Version.java index 582dea382df8a..f5dad1e51a5e5 100644 --- a/server/src/main/java/org/elasticsearch/Version.java +++ b/server/src/main/java/org/elasticsearch/Version.java @@ -134,8 +134,8 @@ public class Version implements Comparable, ToXContentFragment { public static final Version V_8_7_0 = new Version(8_07_00_99, TransportVersion.V_8_7_0, org.apache.lucene.util.Version.LUCENE_9_4_2); public static final Version CURRENT = V_8_7_0; - private static final Map idToVersion; - private static final Map stringToVersion; + private static final Map VERSION_IDS; + private static final Map VERSION_STRINGS; static { final Map builder = new HashMap<>(); @@ -180,8 +180,8 @@ public class Version implements Comparable, ToXContentFragment { + "]"; builder.put(V_EMPTY_ID, V_EMPTY); builderByString.put(V_EMPTY.toString(), V_EMPTY); - idToVersion = Map.copyOf(builder); - stringToVersion = Map.copyOf(builderByString); + VERSION_IDS = Map.copyOf(builder); + VERSION_STRINGS = Map.copyOf(builderByString); } public static Version readVersion(StreamInput in) throws IOException { @@ -189,7 +189,7 @@ public static Version readVersion(StreamInput in) throws IOException { } public static Version fromId(int id) { - final Version known = idToVersion.get(id); + final Version known = VERSION_IDS.get(id); if (known != null) { return known; } @@ -226,14 +226,14 @@ public static void writeVersion(Version version, StreamOutput out) throws IOExce } /** - * Returns the minimum version between the 2. + * Returns the minimum version of {@code version1} and {@code version2} */ public static Version min(Version version1, Version version2) { return version1.id < version2.id ? version1 : version2; } /** - * Returns the maximum version between the 2 + * Returns the maximum version of {@code version1} and {@code version2} */ public static Version max(Version version1, Version version2) { return version1.id > version2.id ? version1 : version2; @@ -246,7 +246,7 @@ public static Version fromString(String version) { if (Strings.hasLength(version) == false) { return Version.CURRENT; } - final Version cached = stringToVersion.get(version); + final Version cached = VERSION_STRINGS.get(version); if (cached != null) { return cached; } diff --git a/server/src/test/java/org/elasticsearch/TransportVersionTests.java b/server/src/test/java/org/elasticsearch/TransportVersionTests.java index 4bed6ef40b03b..8549547767d5a 100644 --- a/server/src/test/java/org/elasticsearch/TransportVersionTests.java +++ b/server/src/test/java/org/elasticsearch/TransportVersionTests.java @@ -11,7 +11,10 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.TransportVersionUtils; +import java.lang.reflect.Modifier; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; @@ -44,6 +47,43 @@ public void testVersionComparison() throws Exception { assertThat(V_8_0_0, is(greaterThan(V_7_2_0))); } + private static String padNumber(String number) { + return number.length() == 1 ? "0" + number : number; + } + + public void testDefinedConstants() throws IllegalAccessException { + Pattern historicalVersion = Pattern.compile("^V_(\\d{1,2})_(\\d{1,2})_(\\d{1,2})$"); + Pattern transportVersion = Pattern.compile("^V_(\\d{2,})_(\\d{3})_(\\d{3})$"); + Set ignore = Set.of("ZERO", "CURRENT", "MINIMUM_COMPATIBLE"); + + for (java.lang.reflect.Field field : TransportVersion.class.getFields()) { + if (Modifier.isStatic(field.getModifiers()) + && field.getType() == TransportVersion.class + && ignore.contains(field.getName()) == false) { + Matcher historical = historicalVersion.matcher(field.getName()); + Matcher transport; + if (historical.matches()) { + // old-style version constant + String idString = historical.group(1) + padNumber(historical.group(2)) + padNumber(historical.group(3)) + "99"; + assertEquals( + "Field " + field.getName() + " does not have expected id " + idString, + idString, + field.get(null).toString() + ); + } else if ((transport = transportVersion.matcher(field.getName())).matches()) { + String idString = transport.group(1) + transport.group(2) + transport.group(3); + assertEquals( + "Field " + field.getName() + " does not have expected id " + idString, + idString, + field.get(null).toString() + ); + } else { + fail("Field " + field.getName() + " does not have expected format"); + } + } + } + } + public void testMin() { assertEquals( TransportVersionUtils.getPreviousVersion(), diff --git a/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java b/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java index 404aa28d45dab..4e62f23b307c7 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java +++ b/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java @@ -18,7 +18,7 @@ public class TransportVersionUtils { private static final NavigableSet ALL_VERSIONS; static { - ALL_VERSIONS = TransportVersion.getDeclaredVersions(); + ALL_VERSIONS = TransportVersion.getAllVersions(); } /** Returns a random {@link TransportVersion} from all available versions. */ From 6d3a1a49c955719a957d53b09b48f7be23d36d66 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Mon, 16 Jan 2023 17:04:23 +0000 Subject: [PATCH 14/22] Convert TcpTransport infrastructure to TransportVersion --- .../transport/netty4/Netty4Plugin.java | 4 +- .../transport/netty4/Netty4Transport.java | 4 +- .../elasticsearch/ElasticsearchException.java | 6 +- .../org/elasticsearch/TransportVersion.java | 37 +++++---- .../action/search/SearchTransportService.java | 3 +- .../common/io/stream/FilterStreamInput.java | 9 +++ .../common/io/stream/StreamInput.java | 15 +++- .../common/io/stream/StreamOutput.java | 17 ++++- .../elasticsearch/transport/Compression.java | 4 +- .../org/elasticsearch/transport/Header.java | 10 +-- .../transport/InboundDecoder.java | 24 +++--- .../transport/InboundHandler.java | 10 ++- .../transport/InboundMessage.java | 2 +- .../transport/InboundPipeline.java | 4 +- .../transport/NetworkMessage.java | 16 ++-- .../transport/OutboundHandler.java | 20 ++--- .../transport/OutboundMessage.java | 14 ++-- .../transport/RemoteConnectionManager.java | 11 +++ .../transport/TaskTransportChannel.java | 4 +- .../elasticsearch/transport/TcpHeader.java | 8 +- .../elasticsearch/transport/TcpTransport.java | 30 ++++++-- .../transport/TcpTransportChannel.java | 8 +- .../elasticsearch/transport/Transport.java | 10 ++- .../transport/TransportChannel.java | 8 +- .../transport/TransportHandshaker.java | 44 ++++++----- .../transport/TransportLogger.java | 8 +- .../transport/TransportService.java | 5 +- .../ExceptionSerializationTests.java | 25 ++++--- .../node/tasks/CancellableTasksTests.java | 4 +- .../elasticsearch/tasks/TaskManagerTests.java | 6 +- .../ClusterConnectionManagerTests.java | 1 + .../transport/InboundHandlerTests.java | 17 +++-- .../transport/InboundPipelineTests.java | 75 ++++++------------- .../RemoteConnectionManagerTests.java | 1 + .../transport/TransportHandshakerTests.java | 25 ++++--- .../test/TransportVersionUtils.java | 24 ++++-- .../test/transport/StubbableTransport.java | 6 ++ .../AbstractSimpleTransportTestCase.java | 10 +-- .../transport/TestTransportChannels.java | 4 +- 39 files changed, 307 insertions(+), 226 deletions(-) diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Plugin.java b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Plugin.java index c8a9fd3849884..e5d6042382b7a 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Plugin.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Plugin.java @@ -9,7 +9,7 @@ package org.elasticsearch.transport.netty4; import org.apache.lucene.util.SetOnce; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.network.NetworkService; @@ -78,7 +78,7 @@ public Map> getTransports( NETTY_TRANSPORT_NAME, () -> new Netty4Transport( settings, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, networkService, pageCacheRecycler, diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java index 563dc8c77ac30..4f9be7195348b 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java @@ -26,7 +26,7 @@ import org.apache.logging.log4j.Logger; import org.apache.lucene.util.BytesRef; import org.elasticsearch.ExceptionsHelper; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.network.NetworkService; @@ -98,7 +98,7 @@ public class Netty4Transport extends TcpTransport { public Netty4Transport( Settings settings, - Version version, + TransportVersion version, ThreadPool threadPool, NetworkService networkService, PageCacheRecycler pageCacheRecycler, diff --git a/server/src/main/java/org/elasticsearch/ElasticsearchException.java b/server/src/main/java/org/elasticsearch/ElasticsearchException.java index 57500fe6d8c56..ded3862d47d2e 100644 --- a/server/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/server/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -275,7 +275,7 @@ public void writeTo(StreamOutput out) throws IOException { public static ElasticsearchException readException(StreamInput input, int id) throws IOException { CheckedFunction elasticsearchException = ID_TO_SUPPLIER.get(id); if (elasticsearchException == null) { - if (id == 127 && input.getVersion().before(Version.V_7_5_0)) { + if (id == 127 && input.getTransportVersion().before(TransportVersion.V_7_5_0)) { // was SearchContextException return new SearchException(input); } @@ -287,10 +287,10 @@ public static ElasticsearchException readException(StreamInput input, int id) th /** * Returns true iff the given class is a registered for an exception to be read. */ - public static boolean isRegistered(Class exception, Version version) { + public static boolean isRegistered(Class exception, TransportVersion version) { ElasticsearchExceptionHandle elasticsearchExceptionHandle = CLASS_TO_ELASTICSEARCH_EXCEPTION_HANDLE.get(exception); if (elasticsearchExceptionHandle != null) { - return version.onOrAfter(elasticsearchExceptionHandle.versionAdded); + return version.onOrAfter(elasticsearchExceptionHandle.versionAdded.transportVersion); } return false; } diff --git a/server/src/main/java/org/elasticsearch/TransportVersion.java b/server/src/main/java/org/elasticsearch/TransportVersion.java index 3c93a83280413..f4fd02b3daf41 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersion.java +++ b/server/src/main/java/org/elasticsearch/TransportVersion.java @@ -14,12 +14,13 @@ import java.io.IOException; import java.lang.reflect.Field; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.NavigableSet; +import java.util.NavigableMap; import java.util.Set; -import java.util.TreeSet; +import java.util.TreeMap; /** * Represents the version of the wire protocol used to communicate between ES nodes. @@ -154,12 +155,10 @@ public class TransportVersion implements Comparable { // TODO: can we programmatically calculate or check this? Don't want to introduce circular ref between Version/TransportVersion public static final TransportVersion MINIMUM_COMPATIBLE = V_7_17_0; - private static final Map VERSION_IDS; - - private static final NavigableSet ALL_VERSIONS; + private static final NavigableMap VERSION_IDS; static { - Map builder = new HashMap<>(); + NavigableMap builder = new TreeMap<>(); Map uniqueIds = new HashMap<>(); Set ignore = Set.of("ZERO", "CURRENT", "MINIMUM_COMPATIBLE"); @@ -189,8 +188,14 @@ public class TransportVersion implements Comparable { } } } - VERSION_IDS = Map.copyOf(builder); - ALL_VERSIONS = Collections.unmodifiableNavigableSet(new TreeSet<>(VERSION_IDS.values())); + VERSION_IDS = Collections.unmodifiableNavigableMap(builder); + } + + /* To help migrate from Version.minimumCompatibilityVersion() */ + @Deprecated + public TransportVersion minimumCompatibilityVersion() { + assert this == CURRENT; + return MINIMUM_COMPATIBLE; } public static TransportVersion readVersion(StreamInput in) throws IOException { @@ -224,14 +229,7 @@ public static TransportVersion max(TransportVersion version1, TransportVersion v return version1.id > version2.id ? version1 : version2; } - /** - * returns a sorted set of all transport version constants - */ - public static NavigableSet getAllVersions() { - return ALL_VERSIONS; - } - - final int id; + public final int id; private final String uniqueId; TransportVersion(int id, String uniqueId) { @@ -260,6 +258,13 @@ public int compareTo(TransportVersion other) { return Integer.compare(this.id, other.id); } + /** + * returns a sorted collection of declared transport version constants + */ + public static Collection getAllVersions() { + return VERSION_IDS.values(); + } + @Override public String toString() { return Integer.toString(id); diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchTransportService.java b/server/src/main/java/org/elasticsearch/action/search/SearchTransportService.java index ccf58bfeadd6e..71a30c8fd5c42 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchTransportService.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchTransportService.java @@ -8,6 +8,7 @@ package org.elasticsearch.action.search; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListenerResponseHandler; @@ -149,7 +150,7 @@ public void sendCanMatch( SearchTask task, final ActionListener listener ) { - if (connection.getVersion().onOrAfter(Version.V_7_16_0) && connection.getNode().getVersion().onOrAfter(Version.V_7_16_0)) { + if (connection.getTransportVersion().onOrAfter(TransportVersion.V_7_16_0) && connection.getNode().getVersion().onOrAfter(Version.V_7_16_0)) { transportService.sendChildRequest( connection, QUERY_CAN_MATCH_NODE_NAME, diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/FilterStreamInput.java b/server/src/main/java/org/elasticsearch/common/io/stream/FilterStreamInput.java index 819dfb55b0ded..beed68a6ab5b3 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/FilterStreamInput.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/FilterStreamInput.java @@ -87,6 +87,7 @@ public int available() throws IOException { } @Override + @Deprecated(forRemoval = true) public Version getVersion() { return delegate.getVersion(); } @@ -97,12 +98,20 @@ public TransportVersion getTransportVersion() { } @Override + @Deprecated(forRemoval = true) public void setVersion(Version version) { delegate.setVersion(version); // also set the version on this stream directly, so that any uses of this.version are still correct super.setVersion(version); } + @Override + public void setTransportVersion(TransportVersion version) { + delegate.setTransportVersion(version); + // also set the version on this stream directly, so that any uses of this.version are still correct + super.setTransportVersion(version); + } + @Override protected void ensureCanReadBytes(int length) throws EOFException { delegate.ensureCanReadBytes(length); diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index 955aa3e7294af..c50f56e5a0b74 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -84,26 +84,35 @@ */ public abstract class StreamInput extends InputStream { - private Version version = Version.CURRENT; + private TransportVersion version = TransportVersion.CURRENT; /** * The version of the node on the other side of this stream. */ + @Deprecated(forRemoval = true) public Version getVersion() { - return this.version; + return Version.fromId(this.version.id); } /** * The transport version the data is serialized as. */ public TransportVersion getTransportVersion() { - return this.version.transportVersion; + return this.version; } /** * Set the version of the node on the other side of this stream. */ + @Deprecated(forRemoval = true) public void setVersion(Version version) { + this.version = version.transportVersion; + } + + /** + * Set the transport version of the data in this stream. + */ + public void setTransportVersion(TransportVersion version) { this.version = version; } diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java index 59c00266d2e65..7a5d1b59133f1 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java @@ -78,26 +78,35 @@ public abstract class StreamOutput extends OutputStream { private static final int MAX_NESTED_EXCEPTION_LEVEL = 100; - private Version version = Version.CURRENT; + private TransportVersion version = TransportVersion.CURRENT; /** * The version of the node on the other side of this stream. */ + @Deprecated(forRemoval = true) public Version getVersion() { - return this.version; + return Version.fromId(this.version.id); } /** * The transport version to serialize the data as. */ public TransportVersion getTransportVersion() { - return this.version.transportVersion; + return this.version; } /** * Set the version of the node on the other side of this stream. */ + @Deprecated(forRemoval = true) public void setVersion(Version version) { + this.version = version.transportVersion; + } + + /** + * Set the transport version of the data in this stream. + */ + public void setTransportVersion(TransportVersion version) { this.version = version; } @@ -155,7 +164,7 @@ public void writeByteArray(byte[] b) throws IOException { */ public void writeWithSizePrefix(Writeable writeable) throws IOException { final BytesStreamOutput tmp = new BytesStreamOutput(); - tmp.setVersion(version); + tmp.setTransportVersion(version); writeable.writeTo(tmp); writeBytesReference(tmp.bytes()); } diff --git a/server/src/main/java/org/elasticsearch/transport/Compression.java b/server/src/main/java/org/elasticsearch/transport/Compression.java index 5d653a4d9f248..a0290a8c92af6 100644 --- a/server/src/main/java/org/elasticsearch/transport/Compression.java +++ b/server/src/main/java/org/elasticsearch/transport/Compression.java @@ -12,7 +12,7 @@ import net.jpountz.lz4.LZ4Factory; import net.jpountz.lz4.LZ4FastDecompressor; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.core.Booleans; import org.elasticsearch.lz4.ESLZ4Compressor; @@ -27,7 +27,7 @@ public enum Scheme { LZ4, DEFLATE; - static final Version LZ4_VERSION = Version.V_7_14_0; + static final TransportVersion LZ4_VERSION = TransportVersion.V_7_14_0; static final int HEADER_LENGTH = 4; private static final byte[] DEFLATE_HEADER = new byte[] { 'D', 'F', 'L', '\0' }; private static final byte[] LZ4_HEADER = new byte[] { 'L', 'Z', '4', '\0' }; diff --git a/server/src/main/java/org/elasticsearch/transport/Header.java b/server/src/main/java/org/elasticsearch/transport/Header.java index a1fa445f13dce..f84eddec7685c 100644 --- a/server/src/main/java/org/elasticsearch/transport/Header.java +++ b/server/src/main/java/org/elasticsearch/transport/Header.java @@ -8,7 +8,7 @@ package org.elasticsearch.transport; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.core.Tuple; @@ -22,7 +22,7 @@ public class Header { private static final String RESPONSE_NAME = "NO_ACTION_NAME_FOR_RESPONSES"; private final int networkMessageSize; - private final Version version; + private final TransportVersion version; private final long requestId; private final byte status; // These are directly set by tests @@ -30,7 +30,7 @@ public class Header { Tuple, Map>> headers; private Compression.Scheme compressionScheme = null; - Header(int networkMessageSize, long requestId, byte status, Version version) { + Header(int networkMessageSize, long requestId, byte status, TransportVersion version) { this.networkMessageSize = networkMessageSize; this.version = version; this.requestId = requestId; @@ -41,7 +41,7 @@ public int getNetworkMessageSize() { return networkMessageSize; } - Version getVersion() { + TransportVersion getVersion() { return version; } @@ -93,7 +93,7 @@ void finishParsingHeader(StreamInput input) throws IOException { this.headers = ThreadContext.readHeadersFromStream(input); if (isRequest()) { - if (version.before(Version.V_8_0_0)) { + if (version.before(TransportVersion.V_8_0_0)) { // discard features input.readStringArray(); } diff --git a/server/src/main/java/org/elasticsearch/transport/InboundDecoder.java b/server/src/main/java/org/elasticsearch/transport/InboundDecoder.java index 399614175410d..bc573af28eee7 100644 --- a/server/src/main/java/org/elasticsearch/transport/InboundDecoder.java +++ b/server/src/main/java/org/elasticsearch/transport/InboundDecoder.java @@ -9,7 +9,7 @@ package org.elasticsearch.transport; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.ReleasableBytesReference; import org.elasticsearch.common.io.stream.StreamInput; @@ -25,7 +25,7 @@ public class InboundDecoder implements Releasable { static final Object PING = new Object(); static final Object END_CONTENT = new Object(); - private final Version version; + private final TransportVersion version; private final Recycler recycler; private TransportDecompressor decompressor; private int totalNetworkSize = -1; @@ -33,7 +33,7 @@ public class InboundDecoder implements Releasable { private boolean isCompressed = false; private boolean isClosed = false; - public InboundDecoder(Version version, Recycler recycler) { + public InboundDecoder(TransportVersion version, Recycler recycler) { this.version = version; this.recycler = recycler; } @@ -154,7 +154,7 @@ private static int headerBytesToRead(BytesReference reference) { return 0; } - Version remoteVersion = Version.fromId(reference.getInt(TcpHeader.VERSION_POSITION)); + TransportVersion remoteVersion = TransportVersion.fromId(reference.getInt(TcpHeader.VERSION_POSITION)); int fixedHeaderSize = TcpHeader.headerSize(remoteVersion); if (fixedHeaderSize > reference.length()) { return 0; @@ -172,12 +172,12 @@ private static int headerBytesToRead(BytesReference reference) { } // exposed for use in tests - static Header readHeader(Version version, int networkMessageSize, BytesReference bytesReference) throws IOException { + static Header readHeader(TransportVersion version, int networkMessageSize, BytesReference bytesReference) throws IOException { try (StreamInput streamInput = bytesReference.streamInput()) { streamInput.skip(TcpHeader.BYTES_REQUIRED_FOR_MESSAGE_SIZE); long requestId = streamInput.readLong(); byte status = streamInput.readByte(); - Version remoteVersion = Version.fromId(streamInput.readInt()); + TransportVersion remoteVersion = TransportVersion.fromId(streamInput.readInt()); Header header = new Header(networkMessageSize, requestId, status, remoteVersion); final IllegalStateException invalidVersion = ensureVersionCompatibility(remoteVersion, version, header.isHandshake()); if (invalidVersion != null) { @@ -203,14 +203,20 @@ private void ensureOpen() { } } - static IllegalStateException ensureVersionCompatibility(Version remoteVersion, Version currentVersion, boolean isHandshake) { + static IllegalStateException ensureVersionCompatibility( + TransportVersion remoteVersion, + TransportVersion currentVersion, + boolean isHandshake + ) { // for handshakes we are compatible with N-2 since otherwise we can't figure out our initial version // since we are compatible with N-1 and N+1 so we always send our minCompatVersion as the initial version in the // handshake. This looks odd but it's required to establish the connection correctly we check for real compatibility // once the connection is established - final Version compatibilityVersion = isHandshake ? currentVersion.minimumCompatibilityVersion() : currentVersion; + final TransportVersion compatibilityVersion = isHandshake ? currentVersion.minimumCompatibilityVersion() : currentVersion; if (remoteVersion.isCompatible(compatibilityVersion) == false) { - final Version minCompatibilityVersion = isHandshake ? compatibilityVersion : compatibilityVersion.minimumCompatibilityVersion(); + final TransportVersion minCompatibilityVersion = isHandshake + ? compatibilityVersion + : compatibilityVersion.minimumCompatibilityVersion(); String msg = "Received " + (isHandshake ? "handshake " : "") + "message from unsupported version: ["; return new IllegalStateException(msg + remoteVersion + "] minimal compatible version is: [" + minCompatibilityVersion + "]"); } diff --git a/server/src/main/java/org/elasticsearch/transport/InboundHandler.java b/server/src/main/java/org/elasticsearch/transport/InboundHandler.java index c79f9b0cef3db..8995426e22a3f 100644 --- a/server/src/main/java/org/elasticsearch/transport/InboundHandler.java +++ b/server/src/main/java/org/elasticsearch/transport/InboundHandler.java @@ -11,6 +11,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.util.BytesRef; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.common.io.stream.ByteBufferStreamInput; import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; @@ -197,7 +198,7 @@ private void verifyResponseReadFully(Header header, TransportResponseHandler private void handleRequest(TcpChannel channel, Header header, InboundMessage message) throws IOException { final String action = header.getActionName(); final long requestId = header.getRequestId(); - final Version version = header.getVersion(); + final TransportVersion version = header.getVersion(); if (header.isHandshake()) { messageListener.onRequestReceived(requestId, action); // Cannot short circuit handshakes @@ -217,7 +218,7 @@ private void handleRequest(TcpChannel channel, Head try { handshaker.handleHandshake(transportChannel, requestId, stream); } catch (Exception e) { - if (Version.CURRENT.isCompatible(header.getVersion())) { + if (TransportVersion.CURRENT.isCompatible(header.getVersion())) { sendErrorResponse(action, transportChannel, e); } else { logger.warn( @@ -450,7 +451,8 @@ private StreamInput namedWriteableStream(StreamInput delegate) { return new NamedWriteableAwareStreamInput(delegate, namedWriteableRegistry); } - static void assertRemoteVersion(StreamInput in, Version version) { - assert version.equals(in.getVersion()) : "Stream version [" + in.getVersion() + "] does not match version [" + version + "]"; + static void assertRemoteVersion(StreamInput in, TransportVersion version) { + assert version.equals(in.getTransportVersion()) + : "Stream version [" + in.getTransportVersion() + "] does not match version [" + version + "]"; } } diff --git a/server/src/main/java/org/elasticsearch/transport/InboundMessage.java b/server/src/main/java/org/elasticsearch/transport/InboundMessage.java index d9ddbba60b8d1..d420ccc8e2e47 100644 --- a/server/src/main/java/org/elasticsearch/transport/InboundMessage.java +++ b/server/src/main/java/org/elasticsearch/transport/InboundMessage.java @@ -86,7 +86,7 @@ public StreamInput openOrGetStreamInput() throws IOException { assert hasReferences(); if (streamInput == null) { streamInput = content.streamInput(); - streamInput.setVersion(header.getVersion()); + streamInput.setTransportVersion(header.getVersion()); } return streamInput; } diff --git a/server/src/main/java/org/elasticsearch/transport/InboundPipeline.java b/server/src/main/java/org/elasticsearch/transport/InboundPipeline.java index 17744c86c50c4..eb24dadd776bf 100644 --- a/server/src/main/java/org/elasticsearch/transport/InboundPipeline.java +++ b/server/src/main/java/org/elasticsearch/transport/InboundPipeline.java @@ -9,7 +9,7 @@ package org.elasticsearch.transport; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.bytes.CompositeBytesReference; import org.elasticsearch.common.bytes.ReleasableBytesReference; @@ -40,7 +40,7 @@ public class InboundPipeline implements Releasable { private boolean isClosed = false; public InboundPipeline( - Version version, + TransportVersion version, StatsTracker statsTracker, Recycler recycler, LongSupplier relativeTimeInMillis, diff --git a/server/src/main/java/org/elasticsearch/transport/NetworkMessage.java b/server/src/main/java/org/elasticsearch/transport/NetworkMessage.java index 976da4268c3de..f71159df29eba 100644 --- a/server/src/main/java/org/elasticsearch/transport/NetworkMessage.java +++ b/server/src/main/java/org/elasticsearch/transport/NetworkMessage.java @@ -7,7 +7,7 @@ */ package org.elasticsearch.transport; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.util.concurrent.ThreadContext; @@ -17,13 +17,19 @@ */ public abstract class NetworkMessage { - protected final Version version; + protected final TransportVersion version; protected final Writeable threadContext; protected final long requestId; protected final byte status; protected final Compression.Scheme compressionScheme; - NetworkMessage(ThreadContext threadContext, Version version, byte status, long requestId, Compression.Scheme compressionScheme) { + NetworkMessage( + ThreadContext threadContext, + TransportVersion version, + byte status, + long requestId, + Compression.Scheme compressionScheme + ) { this.threadContext = threadContext.captureAsWriteable(); this.version = version; this.requestId = requestId; @@ -35,7 +41,7 @@ public abstract class NetworkMessage { } } - public Version getVersion() { + public TransportVersion getVersion() { return version; } @@ -63,7 +69,7 @@ boolean isError() { return TransportStatus.isError(status); } - private static Compression.Scheme adjustedScheme(Version version, Compression.Scheme compressionScheme) { + private static Compression.Scheme adjustedScheme(TransportVersion version, Compression.Scheme compressionScheme) { return compressionScheme == Compression.Scheme.LZ4 && version.before(Compression.Scheme.LZ4_VERSION) ? null : compressionScheme; } } diff --git a/server/src/main/java/org/elasticsearch/transport/OutboundHandler.java b/server/src/main/java/org/elasticsearch/transport/OutboundHandler.java index 253cc2ec6d24b..bedfa8d7225ae 100644 --- a/server/src/main/java/org/elasticsearch/transport/OutboundHandler.java +++ b/server/src/main/java/org/elasticsearch/transport/OutboundHandler.java @@ -13,7 +13,7 @@ import org.apache.logging.log4j.Logger; import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.action.ActionListener; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.bytes.BytesReference; @@ -36,7 +36,7 @@ final class OutboundHandler { private static final Logger logger = LogManager.getLogger(OutboundHandler.class); private final String nodeName; - private final Version version; + private final TransportVersion version; private final StatsTracker statsTracker; private final ThreadPool threadPool; private final Recycler recycler; @@ -49,7 +49,7 @@ final class OutboundHandler { OutboundHandler( String nodeName, - Version version, + TransportVersion version, StatsTracker statsTracker, ThreadPool threadPool, Recycler recycler, @@ -84,11 +84,11 @@ void sendRequest( final String action, final TransportRequest request, final TransportRequestOptions options, - final Version channelVersion, + final TransportVersion transportVersion, final Compression.Scheme compressionScheme, final boolean isHandshake ) throws IOException, TransportException { - Version version = Version.min(this.version, channelVersion); + TransportVersion version = TransportVersion.min(this.version, transportVersion); OutboundMessage.Request message = new OutboundMessage.Request( threadPool.getThreadContext(), request, @@ -115,10 +115,10 @@ void sendRequest( * Sends the response to the given channel. This method should be used to send {@link TransportResponse} * objects back to the caller. * - * @see #sendErrorResponse(Version, TcpChannel, long, String, Exception) for sending error responses + * @see #sendErrorResponse(TransportVersion, TcpChannel, long, String, Exception) for sending error responses */ void sendResponse( - final Version nodeVersion, + final TransportVersion transportVersion, final TcpChannel channel, final long requestId, final String action, @@ -126,7 +126,7 @@ void sendResponse( final Compression.Scheme compressionScheme, final boolean isHandshake ) throws IOException { - Version version = Version.min(this.version, nodeVersion); + TransportVersion version = TransportVersion.min(this.version, transportVersion); OutboundMessage.Response message = new OutboundMessage.Response( threadPool.getThreadContext(), response, @@ -148,13 +148,13 @@ void sendResponse( * Sends back an error response to the caller via the given channel */ void sendErrorResponse( - final Version nodeVersion, + final TransportVersion transportVersion, final TcpChannel channel, final long requestId, final String action, final Exception error ) throws IOException { - Version version = Version.min(this.version, nodeVersion); + TransportVersion version = TransportVersion.min(this.version, transportVersion); RemoteTransportException tx = new RemoteTransportException(nodeName, channel.getLocalAddress(), action, error); OutboundMessage.Response message = new OutboundMessage.Response(threadPool.getThreadContext(), tx, version, requestId, false, null); sendMessage(channel, message, () -> messageListener.onResponseSent(requestId, action, error)); diff --git a/server/src/main/java/org/elasticsearch/transport/OutboundMessage.java b/server/src/main/java/org/elasticsearch/transport/OutboundMessage.java index eae263cecf84c..492aa82a8eab2 100644 --- a/server/src/main/java/org/elasticsearch/transport/OutboundMessage.java +++ b/server/src/main/java/org/elasticsearch/transport/OutboundMessage.java @@ -7,7 +7,7 @@ */ package org.elasticsearch.transport; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -28,7 +28,7 @@ abstract class OutboundMessage extends NetworkMessage { OutboundMessage( ThreadContext threadContext, - Version version, + TransportVersion version, byte status, long requestId, Compression.Scheme compressionScheme, @@ -39,7 +39,7 @@ abstract class OutboundMessage extends NetworkMessage { } BytesReference serialize(RecyclerBytesStreamOutput bytesStream) throws IOException { - bytesStream.setVersion(version); + bytesStream.setTransportVersion(version); bytesStream.skip(TcpHeader.headerSize(version)); // The compressible bytes stream will not close the underlying bytes stream @@ -56,7 +56,7 @@ BytesReference serialize(RecyclerBytesStreamOutput bytesStream) throws IOExcepti final StreamOutput stream = compress ? wrapCompressed(bytesStream) : bytesStream; final BytesReference zeroCopyBuffer; try { - stream.setVersion(version); + stream.setTransportVersion(version); if (variableHeaderLength == -1) { writeVariableHeader(stream); } @@ -115,7 +115,7 @@ static class Request extends OutboundMessage { Request( ThreadContext threadContext, Writeable message, - Version version, + TransportVersion version, String action, long requestId, boolean isHandshake, @@ -128,7 +128,7 @@ static class Request extends OutboundMessage { @Override protected void writeVariableHeader(StreamOutput stream) throws IOException { super.writeVariableHeader(stream); - if (version.before(Version.V_8_0_0)) { + if (version.before(TransportVersion.V_8_0_0)) { // empty features array stream.writeStringArray(Strings.EMPTY_ARRAY); } @@ -165,7 +165,7 @@ static class Response extends OutboundMessage { Response( ThreadContext threadContext, Writeable message, - Version version, + TransportVersion version, long requestId, boolean isHandshake, Compression.Scheme compressionScheme diff --git a/server/src/main/java/org/elasticsearch/transport/RemoteConnectionManager.java b/server/src/main/java/org/elasticsearch/transport/RemoteConnectionManager.java index 25313970e3be4..8b10575589e9f 100644 --- a/server/src/main/java/org/elasticsearch/transport/RemoteConnectionManager.java +++ b/server/src/main/java/org/elasticsearch/transport/RemoteConnectionManager.java @@ -7,6 +7,7 @@ */ package org.elasticsearch.transport; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -240,6 +241,11 @@ public Version getVersion() { return connection.getVersion(); } + @Override + public TransportVersion getTransportVersion() { + return connection.getTransportVersion(); + } + @Override public Object getCacheKey() { return connection.getCacheKey(); @@ -312,6 +318,11 @@ public Version getVersion() { return connection.getVersion(); } + @Override + public TransportVersion getTransportVersion() { + return connection.getTransportVersion(); + } + @Override public Object getCacheKey() { return connection.getCacheKey(); diff --git a/server/src/main/java/org/elasticsearch/transport/TaskTransportChannel.java b/server/src/main/java/org/elasticsearch/transport/TaskTransportChannel.java index 1c3384847ab10..2288de598b339 100644 --- a/server/src/main/java/org/elasticsearch/transport/TaskTransportChannel.java +++ b/server/src/main/java/org/elasticsearch/transport/TaskTransportChannel.java @@ -8,7 +8,7 @@ package org.elasticsearch.transport; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.core.Releasable; import java.io.IOException; @@ -52,7 +52,7 @@ public void sendResponse(Exception exception) throws IOException { } @Override - public Version getVersion() { + public TransportVersion getVersion() { return channel.getVersion(); } diff --git a/server/src/main/java/org/elasticsearch/transport/TcpHeader.java b/server/src/main/java/org/elasticsearch/transport/TcpHeader.java index 60e08225f7bea..fce72973aa9fa 100644 --- a/server/src/main/java/org/elasticsearch/transport/TcpHeader.java +++ b/server/src/main/java/org/elasticsearch/transport/TcpHeader.java @@ -8,14 +8,14 @@ package org.elasticsearch.transport; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.io.stream.StreamOutput; import java.io.IOException; public class TcpHeader { - public static final Version VERSION_WITH_HEADER_SIZE = Version.V_7_6_0; + public static final TransportVersion VERSION_WITH_HEADER_SIZE = TransportVersion.V_7_6_0; public static final int MARKER_BYTES_SIZE = 2; @@ -41,7 +41,7 @@ public class TcpHeader { private static final int HEADER_SIZE = PRE_76_HEADER_SIZE + VARIABLE_HEADER_SIZE; - public static int headerSize(Version version) { + public static int headerSize(TransportVersion version) { if (version.onOrAfter(VERSION_WITH_HEADER_SIZE)) { return HEADER_SIZE; } else { @@ -55,7 +55,7 @@ public static void writeHeader( StreamOutput output, long requestId, byte status, - Version version, + TransportVersion version, int contentSize, int variableHeaderSize ) throws IOException { diff --git a/server/src/main/java/org/elasticsearch/transport/TcpTransport.java b/server/src/main/java/org/elasticsearch/transport/TcpTransport.java index aac192e3762ad..a1aab47065c69 100644 --- a/server/src/main/java/org/elasticsearch/transport/TcpTransport.java +++ b/server/src/main/java/org/elasticsearch/transport/TcpTransport.java @@ -13,6 +13,7 @@ import org.apache.lucene.util.BytesRef; import org.elasticsearch.Build; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ThreadedActionListener; @@ -130,7 +131,7 @@ public static boolean isUntrustedRemoteClusterEnabled() { protected final NetworkService networkService; protected final Set profileSettingsSet; protected final boolean rstOnClose; - private final Version version; + private final TransportVersion version; private final CircuitBreakerService circuitBreakerService; private final ConcurrentMap profileBoundAddresses = newConcurrentMap(); @@ -154,7 +155,7 @@ public static boolean isUntrustedRemoteClusterEnabled() { public TcpTransport( Settings settings, - Version version, + TransportVersion version, ThreadPool threadPool, PageCacheRecycler pageCacheRecycler, CircuitBreakerService circuitBreakerService, @@ -214,7 +215,7 @@ public TcpTransport( ); } - public Version getVersion() { + public TransportVersion getVersion() { return version; } @@ -253,12 +254,17 @@ public final class NodeChannels extends CloseableConnection { private final Map typeMapping; private final List channels; private final DiscoveryNode node; - private final Version version; + private final TransportVersion version; private final Compression.Enabled compress; private final Compression.Scheme compressionScheme; private final AtomicBoolean isClosing = new AtomicBoolean(false); - NodeChannels(DiscoveryNode node, List channels, ConnectionProfile connectionProfile, Version handshakeVersion) { + NodeChannels( + DiscoveryNode node, + List channels, + ConnectionProfile connectionProfile, + TransportVersion handshakeVersion + ) { this.node = node; this.channels = Collections.unmodifiableList(channels); assert channels.size() == connectionProfile.getNumConnections() @@ -275,6 +281,11 @@ public final class NodeChannels extends CloseableConnection { @Override public Version getVersion() { + return node.getVersion(); + } + + @Override + public TransportVersion getTransportVersion() { return version; } @@ -325,7 +336,7 @@ public void sendRequest(long requestId, String action, TransportRequest request, } final Compression.Scheme schemeToUse = getCompressionScheme(wrapped); - outboundHandler.sendRequest(node, channel, requestId, action, request, options, getVersion(), schemeToUse, false); + outboundHandler.sendRequest(node, channel, requestId, action, request, options, getTransportVersion(), schemeToUse, false); } private Compression.Scheme getCompressionScheme(TransportRequest request) { @@ -933,7 +944,12 @@ public HttpRequestOnTransportException(StreamInput in) throws IOException { } } - public void executeHandshake(DiscoveryNode node, TcpChannel channel, ConnectionProfile profile, ActionListener listener) { + public void executeHandshake( + DiscoveryNode node, + TcpChannel channel, + ConnectionProfile profile, + ActionListener listener + ) { long requestId = responseHandlers.newRequestId(); handshaker.sendHandshake(requestId, node, channel, profile.getHandshakeTimeout(), listener); } diff --git a/server/src/main/java/org/elasticsearch/transport/TcpTransportChannel.java b/server/src/main/java/org/elasticsearch/transport/TcpTransportChannel.java index 96d655e44e8b6..c3ecd0e93d498 100644 --- a/server/src/main/java/org/elasticsearch/transport/TcpTransportChannel.java +++ b/server/src/main/java/org/elasticsearch/transport/TcpTransportChannel.java @@ -8,7 +8,7 @@ package org.elasticsearch.transport; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.core.Releasable; import java.io.IOException; @@ -21,7 +21,7 @@ public final class TcpTransportChannel implements TransportChannel { private final TcpChannel channel; private final String action; private final long requestId; - private final Version version; + private final TransportVersion version; private final Compression.Scheme compressionScheme; private final boolean isHandshake; private final Releasable breakerRelease; @@ -31,7 +31,7 @@ public final class TcpTransportChannel implements TransportChannel { TcpChannel channel, String action, long requestId, - Version version, + TransportVersion version, Compression.Scheme compressionScheme, boolean isHandshake, Releasable breakerRelease @@ -88,7 +88,7 @@ public String getChannelType() { } @Override - public Version getVersion() { + public TransportVersion getVersion() { return version; } diff --git a/server/src/main/java/org/elasticsearch/transport/Transport.java b/server/src/main/java/org/elasticsearch/transport/Transport.java index 23331e050af85..52a370665bd18 100644 --- a/server/src/main/java/org/elasticsearch/transport/Transport.java +++ b/server/src/main/java/org/elasticsearch/transport/Transport.java @@ -8,6 +8,7 @@ package org.elasticsearch.transport; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -118,12 +119,19 @@ void sendRequest(long requestId, String action, TransportRequest request, Transp boolean isClosed(); /** - * Returns the version of the node this connection was established with. + * Returns the version of the node on the other side of this channel. */ default Version getVersion() { return getNode().getVersion(); } + /** + * Returns the version of the data to communicate in this channel. + */ + default TransportVersion getTransportVersion() { + return getVersion().transportVersion; + } + /** * Returns a key that this connection can be cached on. Delegating subclasses must delegate method call to * the original connection. diff --git a/server/src/main/java/org/elasticsearch/transport/TransportChannel.java b/server/src/main/java/org/elasticsearch/transport/TransportChannel.java index 185b9ce6b88a8..c56eca6a9e4a5 100644 --- a/server/src/main/java/org/elasticsearch/transport/TransportChannel.java +++ b/server/src/main/java/org/elasticsearch/transport/TransportChannel.java @@ -8,7 +8,7 @@ package org.elasticsearch.transport; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import java.io.IOException; @@ -26,9 +26,9 @@ public interface TransportChannel { void sendResponse(Exception exception) throws IOException; /** - * Returns the version of the other party that this channel will send a response to. + * Returns the version of the data to communicate in this channel. */ - default Version getVersion() { - return Version.CURRENT; + default TransportVersion getVersion() { + return TransportVersion.CURRENT; } } diff --git a/server/src/main/java/org/elasticsearch/transport/TransportHandshaker.java b/server/src/main/java/org/elasticsearch/transport/TransportHandshaker.java index ca64d15c986bd..5debf99e81df5 100644 --- a/server/src/main/java/org/elasticsearch/transport/TransportHandshaker.java +++ b/server/src/main/java/org/elasticsearch/transport/TransportHandshaker.java @@ -8,7 +8,7 @@ package org.elasticsearch.transport; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.action.ActionListener; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.bytes.BytesReference; @@ -35,13 +35,13 @@ final class TransportHandshaker { private final ConcurrentMap pendingHandshakes = new ConcurrentHashMap<>(); private final CounterMetric numHandshakes = new CounterMetric(); - private final Version version; + private final TransportVersion version; private final ThreadPool threadPool; private final HandshakeRequestSender handshakeRequestSender; private final boolean ignoreDeserializationErrors; TransportHandshaker( - Version version, + TransportVersion version, ThreadPool threadPool, HandshakeRequestSender handshakeRequestSender, boolean ignoreDeserializationErrors @@ -52,7 +52,13 @@ final class TransportHandshaker { this.ignoreDeserializationErrors = ignoreDeserializationErrors; } - void sendHandshake(long requestId, DiscoveryNode node, TcpChannel channel, TimeValue timeout, ActionListener listener) { + void sendHandshake( + long requestId, + DiscoveryNode node, + TcpChannel channel, + TimeValue timeout, + ActionListener listener + ) { numHandshakes.inc(); final HandshakeResponseHandler handler = new HandshakeResponseHandler(requestId, version, listener); pendingHandshakes.put(requestId, handler); @@ -64,7 +70,7 @@ void sendHandshake(long requestId, DiscoveryNode node, TcpChannel channel, TimeV // for the request we use the minCompatVersion since we don't know what's the version of the node we talk to // we also have no payload on the request but the response will contain the actual version of the node we talk // to as the payload. - final Version minCompatVersion = version.minimumCompatibilityVersion(); + final TransportVersion minCompatVersion = version.minimumCompatibilityVersion(); handshakeRequestSender.sendRequest(node, channel, requestId, minCompatVersion); threadPool.schedule( @@ -123,11 +129,11 @@ long getNumHandshakes() { private class HandshakeResponseHandler implements TransportResponseHandler { private final long requestId; - private final Version currentVersion; - private final ActionListener listener; + private final TransportVersion currentVersion; + private final ActionListener listener; private final AtomicBoolean isDone = new AtomicBoolean(false); - private HandshakeResponseHandler(long requestId, Version currentVersion, ActionListener listener) { + private HandshakeResponseHandler(long requestId, TransportVersion currentVersion, ActionListener listener) { this.requestId = requestId; this.currentVersion = currentVersion; this.listener = listener; @@ -141,7 +147,7 @@ public HandshakeResponse read(StreamInput in) throws IOException { @Override public void handleResponse(HandshakeResponse response) { if (isDone.compareAndSet(false, true)) { - Version responseVersion = response.responseVersion; + TransportVersion responseVersion = response.responseVersion; if (currentVersion.isCompatible(responseVersion) == false) { listener.onFailure( new IllegalStateException( @@ -174,9 +180,9 @@ void handleLocalException(TransportException e) { static final class HandshakeRequest extends TransportRequest { - private final Version version; + private final TransportVersion version; - HandshakeRequest(Version version) { + HandshakeRequest(TransportVersion version) { this.version = version; } @@ -192,7 +198,7 @@ static final class HandshakeRequest extends TransportRequest { version = null; } else { try (StreamInput messageStreamInput = remainingMessage.streamInput()) { - this.version = Version.readVersion(messageStreamInput); + this.version = TransportVersion.readVersion(messageStreamInput); } } } @@ -202,7 +208,7 @@ public void writeTo(StreamOutput streamOutput) throws IOException { super.writeTo(streamOutput); assert version != null; try (BytesStreamOutput messageStreamOutput = new BytesStreamOutput(4)) { - Version.writeVersion(version, messageStreamOutput); + TransportVersion.writeVersion(version, messageStreamOutput); BytesReference reference = messageStreamOutput.bytes(); streamOutput.writeBytesReference(reference); } @@ -211,24 +217,24 @@ public void writeTo(StreamOutput streamOutput) throws IOException { static final class HandshakeResponse extends TransportResponse { - private final Version responseVersion; + private final TransportVersion responseVersion; - HandshakeResponse(Version responseVersion) { + HandshakeResponse(TransportVersion responseVersion) { this.responseVersion = responseVersion; } private HandshakeResponse(StreamInput in) throws IOException { super(in); - responseVersion = Version.readVersion(in); + responseVersion = TransportVersion.readVersion(in); } @Override public void writeTo(StreamOutput out) throws IOException { assert responseVersion != null; - Version.writeVersion(responseVersion, out); + TransportVersion.writeVersion(responseVersion, out); } - Version getResponseVersion() { + TransportVersion getResponseVersion() { return responseVersion; } } @@ -236,6 +242,6 @@ Version getResponseVersion() { @FunctionalInterface interface HandshakeRequestSender { - void sendRequest(DiscoveryNode node, TcpChannel channel, long requestId, Version version) throws IOException; + void sendRequest(DiscoveryNode node, TcpChannel channel, long requestId, TransportVersion version) throws IOException; } } diff --git a/server/src/main/java/org/elasticsearch/transport/TransportLogger.java b/server/src/main/java/org/elasticsearch/transport/TransportLogger.java index 34b6720d10e3f..c4b0381ef4523 100644 --- a/server/src/main/java/org/elasticsearch/transport/TransportLogger.java +++ b/server/src/main/java/org/elasticsearch/transport/TransportLogger.java @@ -9,7 +9,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.compress.CompressorFactory; import org.elasticsearch.common.io.stream.InputStreamStreamInput; @@ -77,8 +77,8 @@ private static String format(TcpChannel channel, BytesReference message, String final byte status = streamInput.readByte(); final boolean isRequest = TransportStatus.isRequest(status); final String type = isRequest ? "request" : "response"; - final Version version = Version.fromId(streamInput.readInt()); - streamInput.setVersion(version); + final TransportVersion version = TransportVersion.fromId(streamInput.readInt()); + streamInput.setTransportVersion(version); sb.append(" [length: ").append(messageLengthWithHeader); sb.append(", request id: ").append(requestId); sb.append(", type: ").append(type); @@ -95,7 +95,7 @@ private static String format(TcpChannel channel, BytesReference message, String ThreadContext.readHeadersFromStream(streamInput); if (isRequest) { - if (version.before(Version.V_8_0_0)) { + if (version.before(TransportVersion.V_8_0_0)) { // discard features streamInput.readStringArray(); } diff --git a/server/src/main/java/org/elasticsearch/transport/TransportService.java b/server/src/main/java/org/elasticsearch/transport/TransportService.java index 51781077e1c37..9d692caec55b7 100644 --- a/server/src/main/java/org/elasticsearch/transport/TransportService.java +++ b/server/src/main/java/org/elasticsearch/transport/TransportService.java @@ -11,6 +11,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.Build; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListenerResponseHandler; @@ -1517,8 +1518,8 @@ public String getChannelType() { } @Override - public Version getVersion() { - return localNode.getVersion(); + public TransportVersion getVersion() { + return localNode.getVersion().transportVersion; } } diff --git a/server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java b/server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java index 62250cd8a67f0..b90c99aed4772 100644 --- a/server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java +++ b/server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java @@ -79,6 +79,7 @@ import org.elasticsearch.snapshots.SnapshotInProgressException; import org.elasticsearch.snapshots.SnapshotNameAlreadyInUseException; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.TransportVersionUtils; import org.elasticsearch.test.VersionUtils; import org.elasticsearch.transport.ActionNotFoundTransportException; import org.elasticsearch.transport.ActionTransportException; @@ -167,10 +168,10 @@ private void checkClass(Class clazz) { if (isEsException(clazz) == false) { return; } - if (ElasticsearchException.isRegistered(clazz.asSubclass(Throwable.class), Version.CURRENT) == false + if (ElasticsearchException.isRegistered(clazz.asSubclass(Throwable.class), TransportVersion.CURRENT) == false && ElasticsearchException.class.equals(clazz.getEnclosingClass()) == false) { notRegistered.add(clazz); - } else if (ElasticsearchException.isRegistered(clazz.asSubclass(Throwable.class), Version.CURRENT)) { + } else if (ElasticsearchException.isRegistered(clazz.asSubclass(Throwable.class), TransportVersion.CURRENT)) { registered.add(clazz); try { if (clazz.getMethod("writeTo", StreamOutput.class) != null) { @@ -224,16 +225,16 @@ public TestException(StreamInput in) throws IOException { } private T serialize(T exception) throws IOException { - return serialize(exception, VersionUtils.randomVersion(random())); + return serialize(exception, TransportVersionUtils.randomVersion(random())); } - private T serialize(T exception, Version version) throws IOException { + private T serialize(T exception, TransportVersion version) throws IOException { BytesStreamOutput out = new BytesStreamOutput(); - out.setVersion(version); + out.setTransportVersion(version); out.writeException(exception); StreamInput in = out.bytes().streamInput(); - in.setVersion(version); + in.setTransportVersion(version); return in.readException(); } @@ -347,10 +348,10 @@ public void testActionTransportException() throws IOException { public void testSearchContextMissingException() throws IOException { ShardSearchContextId contextId = new ShardSearchContextId(UUIDs.randomBase64UUID(), randomLong()); - Version version = VersionUtils.randomVersion(random()); + TransportVersion version = TransportVersionUtils.randomVersion(random()); SearchContextMissingException ex = serialize(new SearchContextMissingException(contextId), version); assertThat(ex.contextId().getId(), equalTo(contextId.getId())); - if (version.onOrAfter(Version.V_7_7_0)) { + if (version.onOrAfter(TransportVersion.V_7_7_0)) { assertThat(ex.contextId().getSessionId(), equalTo(contextId.getSessionId())); } else { assertThat(ex.contextId().getSessionId(), equalTo("")); @@ -360,7 +361,7 @@ public void testSearchContextMissingException() throws IOException { public void testCircuitBreakingException() throws IOException { CircuitBreakingException ex = serialize( new CircuitBreakingException("Too large", 0, 100, CircuitBreaker.Durability.TRANSIENT), - Version.V_7_0_0 + TransportVersion.V_7_0_0 ); assertEquals("Too large", ex.getMessage()); assertEquals(100, ex.getByteLimit()); @@ -369,7 +370,7 @@ public void testCircuitBreakingException() throws IOException { } public void testTooManyBucketsException() throws IOException { - Version version = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT); + TransportVersion version = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT); MultiBucketConsumerService.TooManyBucketsException ex = serialize( new MultiBucketConsumerService.TooManyBucketsException("Too many buckets", 100), version @@ -887,7 +888,7 @@ public void testShardLockObtainFailedException() throws IOException { ShardId shardId = new ShardId("foo", "_na_", 1); ShardLockObtainFailedException orig = new ShardLockObtainFailedException(shardId, "boom"); Version version = VersionUtils.randomIndexCompatibleVersion(random()); - ShardLockObtainFailedException ex = serialize(orig, version); + ShardLockObtainFailedException ex = serialize(orig, version.transportVersion); assertEquals(orig.getMessage(), ex.getMessage()); assertEquals(orig.getShardId(), ex.getShardId()); } @@ -895,7 +896,7 @@ public void testShardLockObtainFailedException() throws IOException { public void testSnapshotInProgressException() throws IOException { SnapshotInProgressException orig = new SnapshotInProgressException("boom"); Version version = VersionUtils.randomIndexCompatibleVersion(random()); - SnapshotInProgressException ex = serialize(orig, version); + SnapshotInProgressException ex = serialize(orig, version.transportVersion); assertEquals(orig.getMessage(), ex.getMessage()); } diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/CancellableTasksTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/CancellableTasksTests.java index cf3c30b4f5121..a9c6b4fe093b6 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/CancellableTasksTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/CancellableTasksTests.java @@ -10,7 +10,7 @@ import com.carrotsearch.randomizedtesting.RandomizedContext; import com.carrotsearch.randomizedtesting.generators.RandomNumbers; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksAction; import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksRequest; @@ -408,7 +408,7 @@ public void testRegisterAndExecuteChildTaskWhileParentTaskIsBeingCanceled() thro threadPool, "test", randomNonNegativeLong(), - Version.CURRENT + TransportVersion.CURRENT ) ); CancellableNodesRequest childRequest = new CancellableNodesRequest("child"); diff --git a/server/src/test/java/org/elasticsearch/tasks/TaskManagerTests.java b/server/src/test/java/org/elasticsearch/tasks/TaskManagerTests.java index a1e7aad45293b..05343247fe66c 100644 --- a/server/src/test/java/org/elasticsearch/tasks/TaskManagerTests.java +++ b/server/src/test/java/org/elasticsearch/tasks/TaskManagerTests.java @@ -8,7 +8,7 @@ package org.elasticsearch.tasks; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; @@ -184,7 +184,7 @@ void cancelTaskAndDescendants(CancellableTask task, String reason, boolean waitF threadPool, "action-" + i, randomIntBetween(0, 1000), - Version.CURRENT + TransportVersion.CURRENT ); taskManager.setBan(taskId, "test", tcpTransportChannel); } @@ -233,7 +233,7 @@ void cancelTaskAndDescendants(CancellableTask task, String reason, boolean waitF threadPool, "action", randomIntBetween(1, 10000), - Version.CURRENT + TransportVersion.CURRENT ) ); } diff --git a/server/src/test/java/org/elasticsearch/transport/ClusterConnectionManagerTests.java b/server/src/test/java/org/elasticsearch/transport/ClusterConnectionManagerTests.java index 17e58544ead4c..7a0d510cce275 100644 --- a/server/src/test/java/org/elasticsearch/transport/ClusterConnectionManagerTests.java +++ b/server/src/test/java/org/elasticsearch/transport/ClusterConnectionManagerTests.java @@ -9,6 +9,7 @@ package org.elasticsearch.transport; import org.apache.logging.log4j.Level; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.PlainActionFuture; diff --git a/server/src/test/java/org/elasticsearch/transport/InboundHandlerTests.java b/server/src/test/java/org/elasticsearch/transport/InboundHandlerTests.java index c63e875d96ab2..f24a1e2a9485a 100644 --- a/server/src/test/java/org/elasticsearch/transport/InboundHandlerTests.java +++ b/server/src/test/java/org/elasticsearch/transport/InboundHandlerTests.java @@ -12,6 +12,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.common.bytes.BytesArray; @@ -30,7 +31,7 @@ import org.elasticsearch.tasks.TaskManager; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.MockLogAppender; -import org.elasticsearch.test.VersionUtils; +import org.elasticsearch.test.TransportVersionUtils; import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.tracing.Tracer; @@ -50,7 +51,7 @@ public class InboundHandlerTests extends ESTestCase { private final TestThreadPool threadPool = new TestThreadPool(getClass().getName()); - private final Version version = Version.CURRENT; + private final TransportVersion version = TransportVersion.CURRENT; private TaskManager taskManager; private Transport.ResponseHandlers responseHandlers; @@ -213,7 +214,7 @@ public void testSendsErrorResponseToHandshakeFromCompatibleVersion() throws Exce // successful we can respond correctly in a format this old, but we do not guarantee that we can respond correctly with an error // response. However if the two nodes are from the same major version then we do guarantee compatibility of error responses. - final Version remoteVersion = VersionUtils.randomCompatibleVersion(random(), version); + final TransportVersion remoteVersion = TransportVersionUtils.randomCompatibleVersion(random(), version); final long requestId = randomNonNegativeLong(); final Header requestHeader = new Header( between(0, 100), @@ -256,7 +257,9 @@ public void testClosesChannelOnErrorInHandshakeWithIncompatibleVersion() throws final AtomicBoolean isClosed = new AtomicBoolean(); channel.addCloseListener(ActionListener.wrap(() -> assertTrue(isClosed.compareAndSet(false, true)))); - final Version remoteVersion = Version.fromId(randomIntBetween(0, version.minimumCompatibilityVersion().id - 1)); + final TransportVersion remoteVersion = TransportVersion.fromId( + randomIntBetween(0, version.minimumCompatibilityVersion().id - 1) + ); final long requestId = randomNonNegativeLong(); final Header requestHeader = new Header( between(0, 100), @@ -285,7 +288,7 @@ public void testLogsSlowInboundProcessing() throws Exception { handler.setSlowLogThreshold(TimeValue.timeValueMillis(5L)); try { - final Version remoteVersion = Version.CURRENT; + final TransportVersion remoteVersion = TransportVersion.CURRENT; mockAppender.addExpectation( new MockLogAppender.SeenEventExpectation( @@ -349,7 +352,7 @@ public void onResponseReceived(long requestId, Transport.ResponseContext context } } - private static InboundMessage unreadableInboundHandshake(Version remoteVersion, Header requestHeader) { + private static InboundMessage unreadableInboundHandshake(TransportVersion remoteVersion, Header requestHeader) { return new InboundMessage(requestHeader, ReleasableBytesReference.wrap(BytesArray.EMPTY), () -> {}) { @Override public StreamInput openOrGetStreamInput() { @@ -359,7 +362,7 @@ public int read() { throw new ElasticsearchException("unreadable handshake"); } }); - streamInput.setVersion(remoteVersion); + streamInput.setTransportVersion(remoteVersion); return streamInput; } }; diff --git a/server/src/test/java/org/elasticsearch/transport/InboundPipelineTests.java b/server/src/test/java/org/elasticsearch/transport/InboundPipelineTests.java index 726c876ba5598..f35984fe42eeb 100644 --- a/server/src/test/java/org/elasticsearch/transport/InboundPipelineTests.java +++ b/server/src/test/java/org/elasticsearch/transport/InboundPipelineTests.java @@ -8,7 +8,7 @@ package org.elasticsearch.transport; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.breaker.CircuitBreakingException; import org.elasticsearch.common.breaker.NoopCircuitBreaker; @@ -29,7 +29,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BiConsumer; import java.util.function.LongSupplier; @@ -52,7 +51,7 @@ public void testPipelineHandling() throws IOException { try { final Header header = m.getHeader(); final MessageData actualData; - final Version version = header.getVersion(); + final TransportVersion version = header.getVersion(); final boolean isRequest = header.isRequest(); final long requestId = header.getRequestId(); final Compression.Scheme compressionScheme = header.getCompressionScheme(); @@ -78,7 +77,7 @@ public void testPipelineHandling() throws IOException { final StatsTracker statsTracker = new StatsTracker(); final LongSupplier millisSupplier = () -> TimeValue.nsecToMSec(System.nanoTime()); - final InboundDecoder decoder = new InboundDecoder(Version.CURRENT, recycler); + final InboundDecoder decoder = new InboundDecoder(TransportVersion.CURRENT, recycler); final String breakThisAction = "break_this_action"; final String actionName = "actionName"; final Predicate canTripBreaker = breakThisAction::equals; @@ -98,7 +97,10 @@ public void testPipelineHandling() throws IOException { toRelease.clear(); try (RecyclerBytesStreamOutput streamOutput = new RecyclerBytesStreamOutput(recycler)) { while (streamOutput.size() < BYTE_THRESHOLD) { - final Version version = randomFrom(Version.CURRENT, Version.CURRENT.minimumCompatibilityVersion()); + final TransportVersion version = randomFrom( + TransportVersion.CURRENT, + TransportVersion.CURRENT.minimumCompatibilityVersion() + ); final String value = randomRealisticUnicodeOfCodepointLength(randomIntBetween(200, 400)); final boolean isRequest = randomBoolean(); Compression.Scheme compressionScheme = getCompressionScheme(version); @@ -192,7 +194,7 @@ public void testPipelineHandling() throws IOException { } } - private static Compression.Scheme getCompressionScheme(Version version) { + private static Compression.Scheme getCompressionScheme(TransportVersion version) { if (randomBoolean()) { return null; } else { @@ -208,14 +210,14 @@ public void testDecodeExceptionIsPropagated() throws IOException { BiConsumer messageHandler = (c, m) -> {}; final StatsTracker statsTracker = new StatsTracker(); final LongSupplier millisSupplier = () -> TimeValue.nsecToMSec(System.nanoTime()); - final InboundDecoder decoder = new InboundDecoder(Version.CURRENT, recycler); + final InboundDecoder decoder = new InboundDecoder(TransportVersion.CURRENT, recycler); final Supplier breaker = () -> new NoopCircuitBreaker("test"); final InboundAggregator aggregator = new InboundAggregator(breaker, (Predicate) action -> true); final InboundPipeline pipeline = new InboundPipeline(statsTracker, millisSupplier, decoder, aggregator, messageHandler); try (RecyclerBytesStreamOutput streamOutput = new RecyclerBytesStreamOutput(recycler)) { String actionName = "actionName"; - final Version invalidVersion = Version.CURRENT.minimumCompatibilityVersion().minimumCompatibilityVersion(); + final TransportVersion invalidVersion = TransportVersion.CURRENT.minimumCompatibilityVersion().minimumCompatibilityVersion(); final String value = randomAlphaOfLength(1000); final boolean isRequest = randomBoolean(); final long requestId = randomNonNegativeLong(); @@ -253,14 +255,14 @@ public void testEnsureBodyIsNotPrematurelyReleased() throws IOException { BiConsumer messageHandler = (c, m) -> {}; final StatsTracker statsTracker = new StatsTracker(); final LongSupplier millisSupplier = () -> TimeValue.nsecToMSec(System.nanoTime()); - final InboundDecoder decoder = new InboundDecoder(Version.CURRENT, recycler); + final InboundDecoder decoder = new InboundDecoder(TransportVersion.CURRENT, recycler); final Supplier breaker = () -> new NoopCircuitBreaker("test"); final InboundAggregator aggregator = new InboundAggregator(breaker, (Predicate) action -> true); final InboundPipeline pipeline = new InboundPipeline(statsTracker, millisSupplier, decoder, aggregator, messageHandler); try (RecyclerBytesStreamOutput streamOutput = new RecyclerBytesStreamOutput(recycler)) { String actionName = "actionName"; - final Version version = Version.CURRENT; + final TransportVersion version = TransportVersion.CURRENT; final String value = randomAlphaOfLength(1000); final boolean isRequest = randomBoolean(); final long requestId = randomNonNegativeLong(); @@ -273,7 +275,7 @@ public void testEnsureBodyIsNotPrematurelyReleased() throws IOException { } final BytesReference reference = message.serialize(streamOutput); - final int fixedHeaderSize = TcpHeader.headerSize(Version.CURRENT); + final int fixedHeaderSize = TcpHeader.headerSize(TransportVersion.CURRENT); final int variableHeaderSize = reference.getInt(fixedHeaderSize - 4); final int totalHeaderSize = fixedHeaderSize + variableHeaderSize; final AtomicBoolean bodyReleased = new AtomicBoolean(false); @@ -297,47 +299,12 @@ public void testEnsureBodyIsNotPrematurelyReleased() throws IOException { } } - private static class MessageData { - - private final Version version; - private final long requestId; - private final boolean isRequest; - private final Compression.Scheme compressionScheme; - private final String value; - private final String actionName; - - private MessageData( - Version version, - long requestId, - boolean isRequest, - Compression.Scheme compressionScheme, - String actionName, - String value - ) { - this.version = version; - this.requestId = requestId; - this.isRequest = isRequest; - this.compressionScheme = compressionScheme; - this.actionName = actionName; - this.value = value; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - MessageData that = (MessageData) o; - return requestId == that.requestId - && isRequest == that.isRequest - && Objects.equals(compressionScheme, that.compressionScheme) - && Objects.equals(version, that.version) - && Objects.equals(value, that.value) - && Objects.equals(actionName, that.actionName); - } - - @Override - public int hashCode() { - return Objects.hash(version, requestId, isRequest, compressionScheme, value, actionName); - } - } + private record MessageData( + TransportVersion version, + long requestId, + boolean isRequest, + Compression.Scheme compressionScheme, + String actionName, + String value + ) {} } diff --git a/server/src/test/java/org/elasticsearch/transport/RemoteConnectionManagerTests.java b/server/src/test/java/org/elasticsearch/transport/RemoteConnectionManagerTests.java index 3e8b36455b9d1..a0a9d1ac21d4e 100644 --- a/server/src/test/java/org/elasticsearch/transport/RemoteConnectionManagerTests.java +++ b/server/src/test/java/org/elasticsearch/transport/RemoteConnectionManagerTests.java @@ -7,6 +7,7 @@ */ package org.elasticsearch.transport; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.PlainActionFuture; diff --git a/server/src/test/java/org/elasticsearch/transport/TransportHandshakerTests.java b/server/src/test/java/org/elasticsearch/transport/TransportHandshakerTests.java index e20ac4f5f637e..db2d65d099dec 100644 --- a/server/src/test/java/org/elasticsearch/transport/TransportHandshakerTests.java +++ b/server/src/test/java/org/elasticsearch/transport/TransportHandshakerTests.java @@ -7,6 +7,7 @@ */ package org.elasticsearch.transport; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -52,7 +53,7 @@ public void setUp() throws Exception { Version.CURRENT ); threadPool = new TestThreadPool("thread-poll"); - handshaker = new TransportHandshaker(Version.CURRENT, threadPool, requestSender, false); + handshaker = new TransportHandshaker(TransportVersion.CURRENT, threadPool, requestSender, false); } @Override @@ -62,15 +63,15 @@ public void tearDown() throws Exception { } public void testHandshakeRequestAndResponse() throws IOException { - PlainActionFuture versionFuture = PlainActionFuture.newFuture(); + PlainActionFuture versionFuture = PlainActionFuture.newFuture(); long reqId = randomLongBetween(1, 10); handshaker.sendHandshake(reqId, node, channel, new TimeValue(30, TimeUnit.SECONDS), versionFuture); - verify(requestSender).sendRequest(node, channel, reqId, Version.CURRENT.minimumCompatibilityVersion()); + verify(requestSender).sendRequest(node, channel, reqId, TransportVersion.CURRENT.minimumCompatibilityVersion()); assertFalse(versionFuture.isDone()); - TransportHandshaker.HandshakeRequest handshakeRequest = new TransportHandshaker.HandshakeRequest(Version.CURRENT); + TransportHandshaker.HandshakeRequest handshakeRequest = new TransportHandshaker.HandshakeRequest(TransportVersion.CURRENT); BytesStreamOutput bytesStreamOutput = new BytesStreamOutput(); handshakeRequest.writeTo(bytesStreamOutput); StreamInput input = bytesStreamOutput.bytes().streamInput(); @@ -89,9 +90,9 @@ public void testHandshakeRequestFutureVersionsCompatibility() throws IOException long reqId = randomLongBetween(1, 10); handshaker.sendHandshake(reqId, node, channel, new TimeValue(30, TimeUnit.SECONDS), PlainActionFuture.newFuture()); - verify(requestSender).sendRequest(node, channel, reqId, Version.CURRENT.minimumCompatibilityVersion()); + verify(requestSender).sendRequest(node, channel, reqId, TransportVersion.CURRENT.minimumCompatibilityVersion()); - TransportHandshaker.HandshakeRequest handshakeRequest = new TransportHandshaker.HandshakeRequest(Version.CURRENT); + TransportHandshaker.HandshakeRequest handshakeRequest = new TransportHandshaker.HandshakeRequest(TransportVersion.CURRENT); BytesStreamOutput currentHandshakeBytes = new BytesStreamOutput(); handshakeRequest.writeTo(currentHandshakeBytes); @@ -121,11 +122,11 @@ public void testHandshakeRequestFutureVersionsCompatibility() throws IOException } public void testHandshakeError() throws IOException { - PlainActionFuture versionFuture = PlainActionFuture.newFuture(); + PlainActionFuture versionFuture = PlainActionFuture.newFuture(); long reqId = randomLongBetween(1, 10); handshaker.sendHandshake(reqId, node, channel, new TimeValue(30, TimeUnit.SECONDS), versionFuture); - verify(requestSender).sendRequest(node, channel, reqId, Version.CURRENT.minimumCompatibilityVersion()); + verify(requestSender).sendRequest(node, channel, reqId, TransportVersion.CURRENT.minimumCompatibilityVersion()); assertFalse(versionFuture.isDone()); @@ -138,9 +139,9 @@ public void testHandshakeError() throws IOException { } public void testSendRequestThrowsException() throws IOException { - PlainActionFuture versionFuture = PlainActionFuture.newFuture(); + PlainActionFuture versionFuture = PlainActionFuture.newFuture(); long reqId = randomLongBetween(1, 10); - Version compatibilityVersion = Version.CURRENT.minimumCompatibilityVersion(); + TransportVersion compatibilityVersion = TransportVersion.CURRENT.minimumCompatibilityVersion(); doThrow(new IOException("boom")).when(requestSender).sendRequest(node, channel, reqId, compatibilityVersion); handshaker.sendHandshake(reqId, node, channel, new TimeValue(30, TimeUnit.SECONDS), versionFuture); @@ -152,11 +153,11 @@ public void testSendRequestThrowsException() throws IOException { } public void testHandshakeTimeout() throws IOException { - PlainActionFuture versionFuture = PlainActionFuture.newFuture(); + PlainActionFuture versionFuture = PlainActionFuture.newFuture(); long reqId = randomLongBetween(1, 10); handshaker.sendHandshake(reqId, node, channel, new TimeValue(100, TimeUnit.MILLISECONDS), versionFuture); - verify(requestSender).sendRequest(node, channel, reqId, Version.CURRENT.minimumCompatibilityVersion()); + verify(requestSender).sendRequest(node, channel, reqId, TransportVersion.CURRENT.minimumCompatibilityVersion()); ConnectTransportException cte = expectThrows(ConnectTransportException.class, versionFuture::actionGet); assertThat(cte.getMessage(), containsString("handshake_timeout")); diff --git a/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java b/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java index 4e62f23b307c7..59b0b77d3ea8e 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java +++ b/test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java @@ -9,16 +9,19 @@ package org.elasticsearch.test; import org.elasticsearch.TransportVersion; +import org.elasticsearch.Version; -import java.util.NavigableSet; +import java.util.Collections; +import java.util.List; +import java.util.Random; import java.util.Set; import java.util.stream.Collectors; public class TransportVersionUtils { - private static final NavigableSet ALL_VERSIONS; + private static final List ALL_VERSIONS; static { - ALL_VERSIONS = TransportVersion.getAllVersions(); + ALL_VERSIONS = List.copyOf(TransportVersion.getAllVersions()); } /** Returns a random {@link TransportVersion} from all available versions. */ @@ -31,6 +34,11 @@ public static TransportVersion randomVersion(Set ignore) { return ESTestCase.randomFrom(ALL_VERSIONS.stream().filter(v -> ignore.contains(v) == false).collect(Collectors.toList())); } + /** Returns a random {@link Version} from all available versions. */ + public static TransportVersion randomVersion(Random random) { + return ALL_VERSIONS.get(random.nextInt(ALL_VERSIONS.size())); + } + public static TransportVersion getPreviousVersion() { TransportVersion version = getPreviousVersion(TransportVersion.CURRENT); assert version.before(TransportVersion.CURRENT); @@ -38,10 +46,14 @@ public static TransportVersion getPreviousVersion() { } public static TransportVersion getPreviousVersion(TransportVersion version) { - TransportVersion prev = ALL_VERSIONS.lower(version); - if (prev == null) { + int place = Collections.binarySearch(ALL_VERSIONS, version); + if (place < 0) { + // version does not exist - need the item before the index this version should be inserted + place = -(place + 1); + } + if (place <= 1) { throw new IllegalArgumentException("couldn't find any released versions before [" + version + "]"); } - return prev; + return ALL_VERSIONS.get(place - 1); } } diff --git a/test/framework/src/main/java/org/elasticsearch/test/transport/StubbableTransport.java b/test/framework/src/main/java/org/elasticsearch/test/transport/StubbableTransport.java index dd6b33139a0b6..ce2d5667c076e 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/transport/StubbableTransport.java +++ b/test/framework/src/main/java/org/elasticsearch/test/transport/StubbableTransport.java @@ -8,6 +8,7 @@ package org.elasticsearch.test.transport; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -263,6 +264,11 @@ public Version getVersion() { return connection.getVersion(); } + @Override + public TransportVersion getTransportVersion() { + return connection.getTransportVersion(); + } + @Override public Object getCacheKey() { return connection.getCacheKey(); diff --git a/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java b/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java index 3ef602fb8d06e..3419d1ea4e9c0 100644 --- a/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java @@ -1466,7 +1466,7 @@ public static class Version1Request extends Version0Request { Version1Request(StreamInput in) throws IOException { super(in); - if (in.getVersion().onOrAfter(version1)) { + if (in.getTransportVersion().onOrAfter(version1.transportVersion)) { value2 = in.readInt(); } } @@ -1474,7 +1474,7 @@ public static class Version1Request extends Version0Request { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - if (out.getVersion().onOrAfter(version1)) { + if (out.getTransportVersion().onOrAfter(version1.transportVersion)) { out.writeInt(value2); } } @@ -1509,7 +1509,7 @@ static class Version1Response extends Version0Response { Version1Response(StreamInput in) throws IOException { super(in); - if (in.getVersion().onOrAfter(version1)) { + if (in.getTransportVersion().onOrAfter(version1.transportVersion)) { value2 = in.readInt(); } else { value2 = 0; @@ -1519,7 +1519,7 @@ static class Version1Response extends Version0Response { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - if (out.getVersion().onOrAfter(version1)) { + if (out.getTransportVersion().onOrAfter(version1.transportVersion)) { out.writeInt(value2); } } @@ -2761,7 +2761,7 @@ public void handleException(TransportException exp) { TransportException exception = receivedException.get(); assertNotNull(exception); BytesStreamOutput streamOutput = new BytesStreamOutput(); - streamOutput.setVersion(version0); + streamOutput.setTransportVersion(version0.transportVersion); exception.writeTo(streamOutput); String failedMessage = "Unexpected read bytes size. The transport exception that was received=" + exception; // 53 bytes are the non-exception message bytes that have been received. It should include the initial diff --git a/test/framework/src/main/java/org/elasticsearch/transport/TestTransportChannels.java b/test/framework/src/main/java/org/elasticsearch/transport/TestTransportChannels.java index b0b17b7146301..607232fc9b885 100644 --- a/test/framework/src/main/java/org/elasticsearch/transport/TestTransportChannels.java +++ b/test/framework/src/main/java/org/elasticsearch/transport/TestTransportChannels.java @@ -8,7 +8,7 @@ package org.elasticsearch.transport; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.network.HandlingTimeTracker; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.threadpool.ThreadPool; @@ -21,7 +21,7 @@ public static TcpTransportChannel newFakeTcpTransportChannel( ThreadPool threadPool, String action, long requestId, - Version version + TransportVersion version ) { BytesRefRecycler recycler = new BytesRefRecycler(PageCacheRecycler.NON_RECYCLING_INSTANCE); return new TcpTransportChannel( From f220765bbec0a4179157eaf7cf09ae11be0110f5 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Tue, 17 Jan 2023 10:06:11 +0000 Subject: [PATCH 15/22] Add isCompatible method --- .../netty4/SimpleNetty4TransportTests.java | 5 +++-- .../org/elasticsearch/TransportVersion.java | 19 ++++++++++++------- .../TransportServiceLifecycleTests.java | 3 ++- .../test/transport/MockTransportService.java | 5 +++-- .../AbstractSimpleTransportTestCase.java | 5 +++-- .../netty4/SecurityNetty4Transport.java | 3 ++- .../xpack/security/Security.java | 3 ++- .../transport/ServerTransportFilter.java | 5 +++-- .../netty4/SecurityNetty4ServerTransport.java | 3 ++- ...pleSecurityNetty4ServerTransportTests.java | 5 +++-- 10 files changed, 35 insertions(+), 21 deletions(-) diff --git a/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/SimpleNetty4TransportTests.java b/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/SimpleNetty4TransportTests.java index 91a31f19f0e3b..60e90d42debda 100644 --- a/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/SimpleNetty4TransportTests.java +++ b/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/SimpleNetty4TransportTests.java @@ -8,6 +8,7 @@ package org.elasticsearch.transport.netty4; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -45,7 +46,7 @@ public class SimpleNetty4TransportTests extends AbstractSimpleTransportTestCase { @Override - protected Transport build(Settings settings, final Version version, ClusterSettings clusterSettings, boolean doHandshake) { + protected Transport build(Settings settings, TransportVersion version, ClusterSettings clusterSettings, boolean doHandshake) { NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList()); return new Netty4Transport( settings, @@ -63,7 +64,7 @@ public void executeHandshake( DiscoveryNode node, TcpChannel channel, ConnectionProfile profile, - ActionListener listener + ActionListener listener ) { if (doHandshake) { super.executeHandshake(node, channel, profile, listener); diff --git a/server/src/main/java/org/elasticsearch/TransportVersion.java b/server/src/main/java/org/elasticsearch/TransportVersion.java index f4fd02b3daf41..67181044222d3 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersion.java +++ b/server/src/main/java/org/elasticsearch/TransportVersion.java @@ -191,13 +191,6 @@ public class TransportVersion implements Comparable { VERSION_IDS = Collections.unmodifiableNavigableMap(builder); } - /* To help migrate from Version.minimumCompatibilityVersion() */ - @Deprecated - public TransportVersion minimumCompatibilityVersion() { - assert this == CURRENT; - return MINIMUM_COMPATIBLE; - } - public static TransportVersion readVersion(StreamInput in) throws IOException { return fromId(in.readVInt()); } @@ -237,6 +230,18 @@ public static TransportVersion max(TransportVersion version1, TransportVersion v this.uniqueId = Strings.requireNonEmpty(uniqueId, "Each TransportVersion needs a unique string id"); } + /* To help migrate from Version.minimumCompatibilityVersion() */ + @Deprecated + public TransportVersion minimumCompatibilityVersion() { + assert this == CURRENT; + return MINIMUM_COMPATIBLE; + } + + @Deprecated + public boolean isCompatible(TransportVersion version) { + return this.compareTo(MINIMUM_COMPATIBLE) >= 0 && version.compareTo(MINIMUM_COMPATIBLE) >= 0; + } + public boolean after(TransportVersion version) { return version.id < id; } diff --git a/server/src/test/java/org/elasticsearch/transport/TransportServiceLifecycleTests.java b/server/src/test/java/org/elasticsearch/transport/TransportServiceLifecycleTests.java index 97457a4f014aa..d7e2044010761 100644 --- a/server/src/test/java/org/elasticsearch/transport/TransportServiceLifecycleTests.java +++ b/server/src/test/java/org/elasticsearch/transport/TransportServiceLifecycleTests.java @@ -9,6 +9,7 @@ package org.elasticsearch.transport; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -135,7 +136,7 @@ public ExecutorService executor(String name) { return super.executor(name); } }; - final var tcpTransport = MockTransportService.newMockTransport(Settings.EMPTY, Version.CURRENT, threadPool); + final var tcpTransport = MockTransportService.newMockTransport(Settings.EMPTY, TransportVersion.CURRENT, threadPool); transportService = new TransportService( Settings.EMPTY, tcpTransport, diff --git a/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java b/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java index 57acb1b9e79f0..e7a68d30f2df9 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java +++ b/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.cluster.ClusterModule; @@ -106,7 +107,7 @@ public static MockTransportService createNewService( ) { return createNewService( settings, - newMockTransport(settings, version, threadPool), + newMockTransport(settings, version.transportVersion, threadPool), version, threadPool, clusterSettings, @@ -114,7 +115,7 @@ public static MockTransportService createNewService( ); } - public static TcpTransport newMockTransport(Settings settings, Version version, ThreadPool threadPool) { + public static TcpTransport newMockTransport(Settings settings, TransportVersion version, ThreadPool threadPool) { settings = Settings.builder().put(TransportSettings.PORT.getKey(), ESTestCase.getPortRange()).put(settings).build(); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(ClusterModule.getNamedWriteables()); return new Netty4Transport( diff --git a/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java b/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java index 3419d1ea4e9c0..ec5a3ae996224 100644 --- a/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java @@ -15,6 +15,7 @@ import org.apache.lucene.util.Constants; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListenerResponseHandler; @@ -120,7 +121,7 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { protected volatile DiscoveryNode nodeB; protected volatile MockTransportService serviceB; - protected abstract Transport build(Settings settings, Version version, ClusterSettings clusterSettings, boolean doHandshake); + protected abstract Transport build(Settings settings, TransportVersion version, ClusterSettings clusterSettings, boolean doHandshake); protected int channelsPerNodeConnection() { // This is a customized profile for this test case. @@ -206,7 +207,7 @@ private MockTransportService buildService( if (clusterSettings == null) { clusterSettings = new ClusterSettings(updatedSettings, getSupportedSettings()); } - Transport transport = build(updatedSettings, version, clusterSettings, doHandshake); + Transport transport = build(updatedSettings, version.transportVersion, clusterSettings, doHandshake); MockTransportService service = MockTransportService.createNewService( updatedSettings, transport, diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/core/security/transport/netty4/SecurityNetty4Transport.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/core/security/transport/netty4/SecurityNetty4Transport.java index b8b8b92e1d0cf..9b63e5e63a3fb 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/core/security/transport/netty4/SecurityNetty4Transport.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/core/security/transport/netty4/SecurityNetty4Transport.java @@ -16,6 +16,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -60,7 +61,7 @@ public class SecurityNetty4Transport extends Netty4Transport { public SecurityNetty4Transport( final Settings settings, - final Version version, + final TransportVersion version, final ThreadPool threadPool, final NetworkService networkService, final PageCacheRecycler pageCacheRecycler, diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java index 27d86d1302516..9e27bbd81c0df 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java @@ -9,6 +9,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.util.SetOnce; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; @@ -1523,7 +1524,7 @@ public Map> getTransports( transportReference.set( new SecurityNetty4ServerTransport( settings, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, networkService, pageCacheRecycler, diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/ServerTransportFilter.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/ServerTransportFilter.java index 68b68a876dc23..6aea37fd5ef98 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/ServerTransportFilter.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/ServerTransportFilter.java @@ -8,6 +8,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.IndicesRequest; @@ -100,12 +101,12 @@ requests from all the nodes are attached with a user (either a serialize } } - final Version version = transportChannel.getVersion(); + TransportVersion version = transportChannel.getVersion(); authcService.authenticate(securityAction, request, true, ActionListener.wrap((authentication) -> { if (authentication != null) { if (securityAction.equals(TransportService.HANDSHAKE_ACTION_NAME) && SystemUser.is(authentication.getEffectiveSubject().getUser()) == false) { - securityContext.executeAsSystemUser(version, original -> { + securityContext.executeAsSystemUser(Version.fromId(version.id), original -> { final Authentication replaced = securityContext.getAuthentication(); authzService.authorize(replaced, securityAction, request, listener); }); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4ServerTransport.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4ServerTransport.java index c93dd93444e17..579bd710cb426 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4ServerTransport.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4ServerTransport.java @@ -9,6 +9,7 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.network.NetworkService; @@ -30,7 +31,7 @@ public class SecurityNetty4ServerTransport extends SecurityNetty4Transport { public SecurityNetty4ServerTransport( final Settings settings, - final Version version, + final TransportVersion version, final ThreadPool threadPool, final NetworkService networkService, final PageCacheRecycler pageCacheRecycler, diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SimpleSecurityNetty4ServerTransportTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SimpleSecurityNetty4ServerTransportTests.java index fe1b02b6d3b4e..bae7f95a392f6 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SimpleSecurityNetty4ServerTransportTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SimpleSecurityNetty4ServerTransportTests.java @@ -9,6 +9,7 @@ import io.netty.handler.ssl.SslHandshakeTimeoutException; import org.elasticsearch.ExceptionsHelper; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.PlainActionFuture; @@ -89,7 +90,7 @@ public class SimpleSecurityNetty4ServerTransportTests extends AbstractSimpleTransportTestCase { @Override - protected Transport build(Settings settings, final Version version, ClusterSettings clusterSettings, boolean doHandshake) { + protected Transport build(Settings settings, TransportVersion version, ClusterSettings clusterSettings, boolean doHandshake) { NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList()); NetworkService networkService = new NetworkService(Collections.emptyList()); Settings settings1 = Settings.builder().put(settings).put("xpack.security.transport.ssl.enabled", true).build(); @@ -111,7 +112,7 @@ public void executeHandshake( DiscoveryNode node, TcpChannel channel, ConnectionProfile profile, - ActionListener listener + ActionListener listener ) { if (doHandshake) { super.executeHandshake(node, channel, profile, listener); From d7e919b95667713bad90188c0f5f77b881ce3b28 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Tue, 17 Jan 2023 10:29:59 +0000 Subject: [PATCH 16/22] Update tests --- .../Netty4SizeHeaderFrameDecoderTests.java | 4 +- .../netty4/NettyTransportMultiPortTests.java | 4 +- .../discovery/ec2/EC2RetriesTests.java | 4 +- .../discovery/ec2/Ec2DiscoveryTests.java | 4 +- .../action/search/SearchTransportService.java | 3 +- .../ExceptionSerializationTests.java | 2 +- .../node/tasks/TaskManagerTestCase.java | 3 +- .../fieldcaps/RequestDispatcherTests.java | 3 +- ...TransportResyncReplicationActionTests.java | 4 +- .../BroadcastReplicationTests.java | 4 +- .../TransportReplicationActionTests.java | 4 +- .../FileBasedSeedHostsProviderTests.java | 4 +- .../discovery/SeedHostsResolverTests.java | 12 ++-- .../ClusterConnectionManagerTests.java | 1 - .../transport/InboundAggregatorTests.java | 25 +++++-- .../transport/InboundDecoderTests.java | 69 ++++++++++++------- .../transport/OutboundHandlerTests.java | 19 +++-- .../RemoteConnectionManagerTests.java | 1 - .../transport/TcpTransportTests.java | 6 +- .../transport/TransportLoggerTests.java | 4 +- .../TransportServiceHandshakeTests.java | 3 +- .../test/TransportVersionUtils.java | 34 +++++++++ .../netty4/SecurityNetty4Transport.java | 1 - .../xpack/security/Security.java | 1 - .../netty4/SecurityNetty4ServerTransport.java | 1 - .../transport/ServerTransportFilterTests.java | 4 +- 26 files changed, 147 insertions(+), 77 deletions(-) diff --git a/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/Netty4SizeHeaderFrameDecoderTests.java b/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/Netty4SizeHeaderFrameDecoderTests.java index 2229e46e522a0..28db025015b6a 100644 --- a/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/Netty4SizeHeaderFrameDecoderTests.java +++ b/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/Netty4SizeHeaderFrameDecoderTests.java @@ -8,7 +8,7 @@ package org.elasticsearch.transport.netty4; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.settings.Settings; @@ -56,7 +56,7 @@ public void startThreadPool() { PageCacheRecycler recycler = new MockPageCacheRecycler(Settings.EMPTY); nettyTransport = new Netty4Transport( settings, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, networkService, recycler, diff --git a/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/NettyTransportMultiPortTests.java b/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/NettyTransportMultiPortTests.java index 9648f19ac8c92..1d35a6ac0146a 100644 --- a/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/NettyTransportMultiPortTests.java +++ b/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/NettyTransportMultiPortTests.java @@ -7,7 +7,7 @@ */ package org.elasticsearch.transport.netty4; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.component.Lifecycle; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.network.NetworkService; @@ -110,7 +110,7 @@ private TcpTransport startTransport(Settings settings, ThreadPool threadPool) { PageCacheRecycler recycler = new MockPageCacheRecycler(Settings.EMPTY); TcpTransport transport = new Netty4Transport( settings, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, new NetworkService(Collections.emptyList()), recycler, diff --git a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/EC2RetriesTests.java b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/EC2RetriesTests.java index 806ae2ff9d82f..b0a8242a7ca55 100644 --- a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/EC2RetriesTests.java +++ b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/EC2RetriesTests.java @@ -14,7 +14,7 @@ import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URLEncodedUtils; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; @@ -50,7 +50,7 @@ protected MockTransportService createTransportService() { Settings.EMPTY, new Netty4Transport( Settings.EMPTY, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, networkService, PageCacheRecycler.NON_RECYCLING_INSTANCE, diff --git a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java index a06a767795167..87f9689f5a4d3 100644 --- a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java +++ b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java @@ -17,7 +17,7 @@ import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URLEncodedUtils; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; @@ -63,7 +63,7 @@ public class Ec2DiscoveryTests extends AbstractEC2MockAPITestCase { protected MockTransportService createTransportService() { final Transport transport = new Netty4Transport( Settings.EMPTY, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, new NetworkService(Collections.emptyList()), PageCacheRecycler.NON_RECYCLING_INSTANCE, diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchTransportService.java b/server/src/main/java/org/elasticsearch/action/search/SearchTransportService.java index 71a30c8fd5c42..92f30eef2bd86 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchTransportService.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchTransportService.java @@ -150,7 +150,8 @@ public void sendCanMatch( SearchTask task, final ActionListener listener ) { - if (connection.getTransportVersion().onOrAfter(TransportVersion.V_7_16_0) && connection.getNode().getVersion().onOrAfter(Version.V_7_16_0)) { + if (connection.getTransportVersion().onOrAfter(TransportVersion.V_7_16_0) + && connection.getNode().getVersion().onOrAfter(Version.V_7_16_0)) { transportService.sendChildRequest( connection, QUERY_CAN_MATCH_NODE_NAME, diff --git a/server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java b/server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java index b90c99aed4772..e57d91c859e20 100644 --- a/server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java +++ b/server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java @@ -370,7 +370,7 @@ public void testCircuitBreakingException() throws IOException { } public void testTooManyBucketsException() throws IOException { - TransportVersion version = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT); + TransportVersion version = TransportVersionUtils.randomCompatibleVersion(random(), TransportVersion.CURRENT); MultiBucketConsumerService.TooManyBucketsException ex = serialize( new MultiBucketConsumerService.TooManyBucketsException("Too many buckets", 100), version diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TaskManagerTestCase.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TaskManagerTestCase.java index 8752f493f4562..0f41f1c306389 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TaskManagerTestCase.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TaskManagerTestCase.java @@ -8,6 +8,7 @@ package org.elasticsearch.action.admin.cluster.node.tasks; import org.apache.lucene.util.SetOnce; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.admin.cluster.node.tasks.cancel.TransportCancelTasksAction; @@ -188,7 +189,7 @@ public TestNode(String name, ThreadPool threadPool, Settings settings) { settings, new Netty4Transport( settings, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, new NetworkService(Collections.emptyList()), PageCacheRecycler.NON_RECYCLING_INSTANCE, diff --git a/server/src/test/java/org/elasticsearch/action/fieldcaps/RequestDispatcherTests.java b/server/src/test/java/org/elasticsearch/action/fieldcaps/RequestDispatcherTests.java index f1aea8852d661..67f848a23bc46 100644 --- a/server/src/test/java/org/elasticsearch/action/fieldcaps/RequestDispatcherTests.java +++ b/server/src/test/java/org/elasticsearch/action/fieldcaps/RequestDispatcherTests.java @@ -11,6 +11,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.util.SetOnce; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.OriginalIndices; import org.elasticsearch.cluster.ClusterName; @@ -741,7 +742,7 @@ static TestTransportService newTestTransportService() { final TestThreadPool threadPool = new TestThreadPool("test"); TcpTransport transport = new Netty4Transport( Settings.EMPTY, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, new NetworkService(Collections.emptyList()), PageCacheRecycler.NON_RECYCLING_INSTANCE, diff --git a/server/src/test/java/org/elasticsearch/action/resync/TransportResyncReplicationActionTests.java b/server/src/test/java/org/elasticsearch/action/resync/TransportResyncReplicationActionTests.java index 32adf7b33487a..4a3498ea6baae 100644 --- a/server/src/test/java/org/elasticsearch/action/resync/TransportResyncReplicationActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/resync/TransportResyncReplicationActionTests.java @@ -7,7 +7,7 @@ */ package org.elasticsearch.action.resync; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.PlainActionFuture; @@ -102,7 +102,7 @@ public void testResyncDoesNotBlockOnPrimaryAction() throws Exception { try ( TcpTransport transport = new Netty4Transport( Settings.EMPTY, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, new NetworkService(emptyList()), PageCacheRecycler.NON_RECYCLING_INSTANCE, diff --git a/server/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java b/server/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java index 51363e76d8adb..2a643b0bb6ffb 100644 --- a/server/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java @@ -7,7 +7,7 @@ */ package org.elasticsearch.action.support.replication; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.NoShardAvailableActionException; import org.elasticsearch.action.UnavailableShardsException; @@ -88,7 +88,7 @@ public void setUp() throws Exception { super.setUp(); TcpTransport transport = new Netty4Transport( Settings.EMPTY, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, new NetworkService(Collections.emptyList()), PageCacheRecycler.NON_RECYCLING_INSTANCE, diff --git a/server/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java b/server/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java index 516a7cca0149e..97605ec71928f 100644 --- a/server/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java @@ -10,7 +10,7 @@ import org.apache.lucene.store.AlreadyClosedException; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.UnavailableShardsException; import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; @@ -1282,7 +1282,7 @@ public void testRetryOnReplicaWithRealTransport() throws Exception { NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList()); final Transport transport = new Netty4Transport( Settings.EMPTY, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, new NetworkService(Collections.emptyList()), PageCacheRecycler.NON_RECYCLING_INSTANCE, diff --git a/server/src/test/java/org/elasticsearch/discovery/FileBasedSeedHostsProviderTests.java b/server/src/test/java/org/elasticsearch/discovery/FileBasedSeedHostsProviderTests.java index 8614ca64822d9..ebd43ee5c85b3 100644 --- a/server/src/test/java/org/elasticsearch/discovery/FileBasedSeedHostsProviderTests.java +++ b/server/src/test/java/org/elasticsearch/discovery/FileBasedSeedHostsProviderTests.java @@ -8,7 +8,7 @@ package org.elasticsearch.discovery; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.settings.Settings; @@ -70,7 +70,7 @@ public void tearDown() throws Exception { private void createTransportSvc() { final TcpTransport transport = new Netty4Transport( Settings.EMPTY, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, new NetworkService(Collections.emptyList()), PageCacheRecycler.NON_RECYCLING_INSTANCE, diff --git a/server/src/test/java/org/elasticsearch/discovery/SeedHostsResolverTests.java b/server/src/test/java/org/elasticsearch/discovery/SeedHostsResolverTests.java index 4862ec693e39f..8e652bba1fc10 100644 --- a/server/src/test/java/org/elasticsearch/discovery/SeedHostsResolverTests.java +++ b/server/src/test/java/org/elasticsearch/discovery/SeedHostsResolverTests.java @@ -9,7 +9,7 @@ package org.elasticsearch.discovery; import org.apache.logging.log4j.Level; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.network.NetworkAddress; @@ -136,7 +136,7 @@ public void testRemovingLocalAddresses() { final InetAddress loopbackAddress = InetAddress.getLoopbackAddress(); final Transport transport = new Netty4Transport( Settings.EMPTY, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, networkService, PageCacheRecycler.NON_RECYCLING_INSTANCE, @@ -182,7 +182,7 @@ public void testUnknownHost() { final UnknownHostException unknownHostException = new UnknownHostException(hostname); final Transport transport = new Netty4Transport( Settings.EMPTY, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, networkService, PageCacheRecycler.NON_RECYCLING_INSTANCE, @@ -242,7 +242,7 @@ public void testResolveTimeout() { final CountDownLatch latch = new CountDownLatch(1); final Transport transport = new Netty4Transport( Settings.EMPTY, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, networkService, PageCacheRecycler.NON_RECYCLING_INSTANCE, @@ -316,7 +316,7 @@ public void testCancellationOnClose() throws InterruptedException { final CountDownLatch conditionLatch = new CountDownLatch(1); final Transport transport = new Netty4Transport( Settings.EMPTY, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, networkService, PageCacheRecycler.NON_RECYCLING_INSTANCE, @@ -379,7 +379,7 @@ public TransportAddress[] addressesFromString(String address) throws UnknownHost public void testInvalidHosts() { final Transport transport = new Netty4Transport( Settings.EMPTY, - Version.CURRENT, + TransportVersion.CURRENT, threadPool, new NetworkService(Collections.emptyList()), PageCacheRecycler.NON_RECYCLING_INSTANCE, diff --git a/server/src/test/java/org/elasticsearch/transport/ClusterConnectionManagerTests.java b/server/src/test/java/org/elasticsearch/transport/ClusterConnectionManagerTests.java index 7a0d510cce275..17e58544ead4c 100644 --- a/server/src/test/java/org/elasticsearch/transport/ClusterConnectionManagerTests.java +++ b/server/src/test/java/org/elasticsearch/transport/ClusterConnectionManagerTests.java @@ -9,7 +9,6 @@ package org.elasticsearch.transport; import org.apache.logging.log4j.Level; -import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.PlainActionFuture; diff --git a/server/src/test/java/org/elasticsearch/transport/InboundAggregatorTests.java b/server/src/test/java/org/elasticsearch/transport/InboundAggregatorTests.java index 7e2aad9b5dbbf..43d7219fbdaca 100644 --- a/server/src/test/java/org/elasticsearch/transport/InboundAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/transport/InboundAggregatorTests.java @@ -8,6 +8,7 @@ package org.elasticsearch.transport; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.common.breaker.CircuitBreakingException; import org.elasticsearch.common.breaker.TestCircuitBreaker; @@ -54,7 +55,7 @@ public void setUp() throws Exception { public void testInboundAggregation() throws IOException { long requestId = randomNonNegativeLong(); - Header header = new Header(randomInt(), requestId, TransportStatus.setRequest((byte) 0), Version.CURRENT); + Header header = new Header(randomInt(), requestId, TransportStatus.setRequest((byte) 0), TransportVersion.CURRENT); header.headers = new Tuple<>(Collections.emptyMap(), Collections.emptyMap()); header.actionName = "action_name"; // Initiate Message @@ -101,7 +102,7 @@ public void testInboundAggregation() throws IOException { public void testInboundUnknownAction() throws IOException { long requestId = randomNonNegativeLong(); - Header header = new Header(randomInt(), requestId, TransportStatus.setRequest((byte) 0), Version.CURRENT); + Header header = new Header(randomInt(), requestId, TransportStatus.setRequest((byte) 0), TransportVersion.CURRENT); header.headers = new Tuple<>(Collections.emptyMap(), Collections.emptyMap()); header.actionName = unknownAction; // Initiate Message @@ -125,7 +126,12 @@ public void testInboundUnknownAction() throws IOException { public void testCircuitBreak() throws IOException { circuitBreaker.startBreaking(); // Actions are breakable - Header breakableHeader = new Header(randomInt(), randomNonNegativeLong(), TransportStatus.setRequest((byte) 0), Version.CURRENT); + Header breakableHeader = new Header( + randomInt(), + randomNonNegativeLong(), + TransportStatus.setRequest((byte) 0), + TransportVersion.CURRENT + ); breakableHeader.headers = new Tuple<>(Collections.emptyMap(), Collections.emptyMap()); breakableHeader.actionName = "action_name"; // Initiate Message @@ -145,7 +151,12 @@ public void testCircuitBreak() throws IOException { assertThat(aggregated1.getException(), instanceOf(CircuitBreakingException.class)); // Actions marked as unbreakable are not broken - Header unbreakableHeader = new Header(randomInt(), randomNonNegativeLong(), TransportStatus.setRequest((byte) 0), Version.CURRENT); + Header unbreakableHeader = new Header( + randomInt(), + randomNonNegativeLong(), + TransportStatus.setRequest((byte) 0), + TransportVersion.CURRENT + ); unbreakableHeader.headers = new Tuple<>(Collections.emptyMap(), Collections.emptyMap()); unbreakableHeader.actionName = unBreakableAction; // Initiate Message @@ -164,7 +175,7 @@ public void testCircuitBreak() throws IOException { // Handshakes are not broken final byte handshakeStatus = TransportStatus.setHandshake(TransportStatus.setRequest((byte) 0)); - Header handshakeHeader = new Header(randomInt(), randomNonNegativeLong(), handshakeStatus, Version.CURRENT); + Header handshakeHeader = new Header(randomInt(), randomNonNegativeLong(), handshakeStatus, TransportVersion.CURRENT); handshakeHeader.headers = new Tuple<>(Collections.emptyMap(), Collections.emptyMap()); handshakeHeader.actionName = "handshake"; // Initiate Message @@ -184,7 +195,7 @@ public void testCircuitBreak() throws IOException { public void testCloseWillCloseContent() { long requestId = randomNonNegativeLong(); - Header header = new Header(randomInt(), requestId, TransportStatus.setRequest((byte) 0), Version.CURRENT); + Header header = new Header(randomInt(), requestId, TransportStatus.setRequest((byte) 0), TransportVersion.CURRENT); header.headers = new Tuple<>(Collections.emptyMap(), Collections.emptyMap()); header.actionName = "action_name"; // Initiate Message @@ -224,7 +235,7 @@ public void testFinishAggregationWillFinishHeader() throws IOException { } else { actionName = "action_name"; } - Header header = new Header(randomInt(), requestId, TransportStatus.setRequest((byte) 0), Version.CURRENT); + Header header = new Header(randomInt(), requestId, TransportStatus.setRequest((byte) 0), TransportVersion.CURRENT); // Initiate Message aggregator.headerReceived(header); diff --git a/server/src/test/java/org/elasticsearch/transport/InboundDecoderTests.java b/server/src/test/java/org/elasticsearch/transport/InboundDecoderTests.java index 65e3cb1ad4325..1475474a6b9da 100644 --- a/server/src/test/java/org/elasticsearch/transport/InboundDecoderTests.java +++ b/server/src/test/java/org/elasticsearch/transport/InboundDecoderTests.java @@ -8,6 +8,7 @@ package org.elasticsearch.transport; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.ReleasableBytesReference; @@ -17,7 +18,7 @@ import org.elasticsearch.common.util.MockPageCacheRecycler; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.VersionUtils; +import org.elasticsearch.test.TransportVersionUtils; import java.io.IOException; import java.util.ArrayList; @@ -53,7 +54,7 @@ public void testDecode() throws IOException { message = new OutboundMessage.Request( threadContext, new TestRequest(randomAlphaOfLength(100)), - Version.CURRENT, + TransportVersion.CURRENT, action, requestId, false, @@ -63,7 +64,7 @@ public void testDecode() throws IOException { message = new OutboundMessage.Response( threadContext, new TestResponse(randomAlphaOfLength(100)), - Version.CURRENT, + TransportVersion.CURRENT, requestId, false, null @@ -72,10 +73,12 @@ public void testDecode() throws IOException { try (RecyclerBytesStreamOutput os = new RecyclerBytesStreamOutput(recycler)) { final BytesReference totalBytes = message.serialize(os); - int totalHeaderSize = TcpHeader.headerSize(Version.CURRENT) + totalBytes.getInt(TcpHeader.VARIABLE_HEADER_SIZE_POSITION); + int totalHeaderSize = TcpHeader.headerSize(TransportVersion.CURRENT) + totalBytes.getInt( + TcpHeader.VARIABLE_HEADER_SIZE_POSITION + ); final BytesReference messageBytes = totalBytes.slice(totalHeaderSize, totalBytes.length() - totalHeaderSize); - InboundDecoder decoder = new InboundDecoder(Version.CURRENT, recycler); + InboundDecoder decoder = new InboundDecoder(TransportVersion.CURRENT, recycler); final ArrayList fragments = new ArrayList<>(); final ReleasableBytesReference releasable1 = ReleasableBytesReference.wrap(totalBytes); int bytesConsumed = decoder.decode(releasable1, fragments::add); @@ -122,7 +125,7 @@ public void testDecodePreHeaderSizeVariableInt() throws IOException { Compression.Scheme compressionScheme = randomFrom(Compression.Scheme.DEFLATE, Compression.Scheme.DEFLATE, null); String action = "test-request"; long requestId = randomNonNegativeLong(); - final Version preHeaderVariableInt = Version.V_7_5_0; + final TransportVersion preHeaderVariableInt = TransportVersion.V_7_5_0; final String contentValue = randomAlphaOfLength(100); // 8.0 is only compatible with handshakes on a pre-variable int version final OutboundMessage message = new OutboundMessage.Request( @@ -139,7 +142,7 @@ public void testDecodePreHeaderSizeVariableInt() throws IOException { final BytesReference totalBytes = message.serialize(os); int partialHeaderSize = TcpHeader.headerSize(preHeaderVariableInt); - InboundDecoder decoder = new InboundDecoder(Version.CURRENT, recycler); + InboundDecoder decoder = new InboundDecoder(TransportVersion.CURRENT, recycler); final ArrayList fragments = new ArrayList<>(); final ReleasableBytesReference releasable1 = ReleasableBytesReference.wrap(totalBytes); int bytesConsumed = decoder.decode(releasable1, fragments::add); @@ -181,7 +184,7 @@ public void testDecodeHandshakeCompatibility() throws IOException { final String headerKey = randomAlphaOfLength(10); final String headerValue = randomAlphaOfLength(20); threadContext.putHeader(headerKey, headerValue); - Version handshakeCompat = Version.CURRENT.minimumCompatibilityVersion().minimumCompatibilityVersion(); + TransportVersion handshakeCompat = TransportVersion.CURRENT.minimumCompatibilityVersion().minimumCompatibilityVersion(); OutboundMessage message = new OutboundMessage.Request( threadContext, new TestRequest(randomAlphaOfLength(100)), @@ -196,7 +199,7 @@ public void testDecodeHandshakeCompatibility() throws IOException { final BytesReference bytes = message.serialize(os); int totalHeaderSize = TcpHeader.headerSize(handshakeCompat); - InboundDecoder decoder = new InboundDecoder(Version.CURRENT, recycler); + InboundDecoder decoder = new InboundDecoder(TransportVersion.CURRENT, recycler); final ArrayList fragments = new ArrayList<>(); final ReleasableBytesReference releasable1 = ReleasableBytesReference.wrap(bytes); int bytesConsumed = decoder.decode(releasable1, fragments::add); @@ -232,10 +235,18 @@ public void testCompressedDecode() throws IOException { Compression.Scheme scheme = randomFrom(Compression.Scheme.DEFLATE, Compression.Scheme.LZ4); if (isRequest) { transportMessage = new TestRequest(randomAlphaOfLength(100)); - message = new OutboundMessage.Request(threadContext, transportMessage, Version.CURRENT, action, requestId, false, scheme); + message = new OutboundMessage.Request( + threadContext, + transportMessage, + TransportVersion.CURRENT, + action, + requestId, + false, + scheme + ); } else { transportMessage = new TestResponse(randomAlphaOfLength(100)); - message = new OutboundMessage.Response(threadContext, transportMessage, Version.CURRENT, requestId, false, scheme); + message = new OutboundMessage.Response(threadContext, transportMessage, TransportVersion.CURRENT, requestId, false, scheme); } try (RecyclerBytesStreamOutput os = new RecyclerBytesStreamOutput(recycler)) { @@ -243,9 +254,11 @@ public void testCompressedDecode() throws IOException { final BytesStreamOutput out = new BytesStreamOutput(); transportMessage.writeTo(out); final BytesReference uncompressedBytes = out.bytes(); - int totalHeaderSize = TcpHeader.headerSize(Version.CURRENT) + totalBytes.getInt(TcpHeader.VARIABLE_HEADER_SIZE_POSITION); + int totalHeaderSize = TcpHeader.headerSize(TransportVersion.CURRENT) + totalBytes.getInt( + TcpHeader.VARIABLE_HEADER_SIZE_POSITION + ); - InboundDecoder decoder = new InboundDecoder(Version.CURRENT, recycler); + InboundDecoder decoder = new InboundDecoder(TransportVersion.CURRENT, recycler); final ArrayList fragments = new ArrayList<>(); final ReleasableBytesReference releasable1 = ReleasableBytesReference.wrap(totalBytes); int bytesConsumed = decoder.decode(releasable1, fragments::add); @@ -294,7 +307,7 @@ public void testCompressedDecodeHandshakeCompatibility() throws IOException { final String headerKey = randomAlphaOfLength(10); final String headerValue = randomAlphaOfLength(20); threadContext.putHeader(headerKey, headerValue); - Version handshakeCompat = Version.CURRENT.minimumCompatibilityVersion().minimumCompatibilityVersion(); + TransportVersion handshakeCompat = TransportVersion.CURRENT.minimumCompatibilityVersion().minimumCompatibilityVersion(); OutboundMessage message = new OutboundMessage.Request( threadContext, new TestRequest(randomAlphaOfLength(100)), @@ -309,7 +322,7 @@ public void testCompressedDecodeHandshakeCompatibility() throws IOException { final BytesReference bytes = message.serialize(os); int totalHeaderSize = TcpHeader.headerSize(handshakeCompat); - InboundDecoder decoder = new InboundDecoder(Version.CURRENT, recycler); + InboundDecoder decoder = new InboundDecoder(TransportVersion.CURRENT, recycler); final ArrayList fragments = new ArrayList<>(); final ReleasableBytesReference releasable1 = ReleasableBytesReference.wrap(bytes); int bytesConsumed = decoder.decode(releasable1, fragments::add); @@ -331,7 +344,7 @@ public void testCompressedDecodeHandshakeCompatibility() throws IOException { public void testVersionIncompatibilityDecodeException() throws IOException { String action = "test-request"; long requestId = randomNonNegativeLong(); - Version incompatibleVersion = Version.CURRENT.minimumCompatibilityVersion().minimumCompatibilityVersion(); + TransportVersion incompatibleVersion = TransportVersion.CURRENT.minimumCompatibilityVersion().minimumCompatibilityVersion(); OutboundMessage message = new OutboundMessage.Request( threadContext, new TestRequest(randomAlphaOfLength(100)), @@ -346,7 +359,7 @@ public void testVersionIncompatibilityDecodeException() throws IOException { try (RecyclerBytesStreamOutput os = new RecyclerBytesStreamOutput(recycler)) { final BytesReference bytes = message.serialize(os); - InboundDecoder decoder = new InboundDecoder(Version.CURRENT, recycler); + InboundDecoder decoder = new InboundDecoder(TransportVersion.CURRENT, recycler); final ArrayList fragments = new ArrayList<>(); try (ReleasableBytesReference r = ReleasableBytesReference.wrap(bytes)) { releasable1 = r; @@ -359,31 +372,35 @@ public void testVersionIncompatibilityDecodeException() throws IOException { public void testEnsureVersionCompatibility() throws IOException { IllegalStateException ise = InboundDecoder.ensureVersionCompatibility( - VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT), - Version.CURRENT, + TransportVersionUtils.randomVersionBetween( + random(), + TransportVersion.CURRENT.minimumCompatibilityVersion(), + TransportVersion.CURRENT + ), + TransportVersion.CURRENT, randomBoolean() ); assertNull(ise); - final Version version = Version.fromString("7.0.0"); - ise = InboundDecoder.ensureVersionCompatibility(Version.fromString("6.0.0"), version, true); + TransportVersion version = TransportVersion.V_8_0_0; + ise = InboundDecoder.ensureVersionCompatibility(TransportVersion.V_7_0_0, version, true); assertNull(ise); - ise = InboundDecoder.ensureVersionCompatibility(Version.fromString("6.0.0"), version, false); + ise = InboundDecoder.ensureVersionCompatibility(TransportVersion.V_7_0_0, version, false); assertEquals( - "Received message from unsupported version: [6.0.0] minimal compatible version is: [" + "Received message from unsupported version: [7.0.0] minimal compatible version is: [" + version.minimumCompatibilityVersion() + "]", ise.getMessage() ); // For handshake we are compatible with N-2 - ise = InboundDecoder.ensureVersionCompatibility(Version.fromString("5.6.0"), version, true); + ise = InboundDecoder.ensureVersionCompatibility(Version.fromString("6.0.0").transportVersion, version, true); assertNull(ise); - ise = InboundDecoder.ensureVersionCompatibility(Version.fromString("5.6.0"), version, false); + ise = InboundDecoder.ensureVersionCompatibility(Version.fromString("6.0.0").transportVersion, version, false); assertEquals( - "Received message from unsupported version: [5.6.0] minimal compatible version is: [" + "Received message from unsupported version: [6.0.0] minimal compatible version is: [" + version.minimumCompatibilityVersion() + "]", ise.getMessage() diff --git a/server/src/test/java/org/elasticsearch/transport/OutboundHandlerTests.java b/server/src/test/java/org/elasticsearch/transport/OutboundHandlerTests.java index 460ba850d4b62..69e14b2fdc370 100644 --- a/server/src/test/java/org/elasticsearch/transport/OutboundHandlerTests.java +++ b/server/src/test/java/org/elasticsearch/transport/OutboundHandlerTests.java @@ -12,6 +12,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.PlainActionFuture; @@ -72,10 +73,18 @@ public void setUp() throws Exception { node = new DiscoveryNode("", transportAddress, Version.CURRENT); StatsTracker statsTracker = new StatsTracker(); compressionScheme = randomFrom(Compression.Scheme.DEFLATE, Compression.Scheme.LZ4); - handler = new OutboundHandler("node", Version.CURRENT, statsTracker, threadPool, recycler, new HandlingTimeTracker(), false); + handler = new OutboundHandler( + "node", + TransportVersion.CURRENT, + statsTracker, + threadPool, + recycler, + new HandlingTimeTracker(), + false + ); final LongSupplier millisSupplier = () -> TimeValue.nsecToMSec(System.nanoTime()); - final InboundDecoder decoder = new InboundDecoder(Version.CURRENT, this.recycler); + final InboundDecoder decoder = new InboundDecoder(TransportVersion.CURRENT, this.recycler); final Supplier breaker = () -> new NoopCircuitBreaker("test"); final InboundAggregator aggregator = new InboundAggregator(breaker, (Predicate) action -> true); pipeline = new InboundPipeline(statsTracker, millisSupplier, decoder, aggregator, (c, m) -> { @@ -120,7 +129,7 @@ public void testSendRawBytes() { public void testSendRequest() throws IOException { ThreadContext threadContext = threadPool.getThreadContext(); - Version version = randomFrom(Version.CURRENT, Version.CURRENT.minimumCompatibilityVersion()); + TransportVersion version = randomFrom(TransportVersion.CURRENT, TransportVersion.CURRENT.minimumCompatibilityVersion()); String action = "handshake"; long requestId = randomLongBetween(0, 300); boolean isHandshake = randomBoolean(); @@ -193,7 +202,7 @@ public void onRequestSent( public void testSendResponse() throws IOException { ThreadContext threadContext = threadPool.getThreadContext(); - Version version = randomFrom(Version.CURRENT, Version.CURRENT.minimumCompatibilityVersion()); + TransportVersion version = randomFrom(TransportVersion.CURRENT, TransportVersion.CURRENT.minimumCompatibilityVersion()); String action = "handshake"; long requestId = randomLongBetween(0, 300); boolean isHandshake = randomBoolean(); @@ -260,7 +269,7 @@ public void onResponseSent(long requestId, String action, TransportResponse resp public void testErrorResponse() throws IOException { ThreadContext threadContext = threadPool.getThreadContext(); - Version version = randomFrom(Version.CURRENT, Version.CURRENT.minimumCompatibilityVersion()); + TransportVersion version = randomFrom(TransportVersion.CURRENT, TransportVersion.CURRENT.minimumCompatibilityVersion()); String action = "handshake"; long requestId = randomLongBetween(0, 300); threadContext.putHeader("header", "header_value"); diff --git a/server/src/test/java/org/elasticsearch/transport/RemoteConnectionManagerTests.java b/server/src/test/java/org/elasticsearch/transport/RemoteConnectionManagerTests.java index a0a9d1ac21d4e..3e8b36455b9d1 100644 --- a/server/src/test/java/org/elasticsearch/transport/RemoteConnectionManagerTests.java +++ b/server/src/test/java/org/elasticsearch/transport/RemoteConnectionManagerTests.java @@ -7,7 +7,6 @@ */ package org.elasticsearch.transport; -import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.PlainActionFuture; diff --git a/server/src/test/java/org/elasticsearch/transport/TcpTransportTests.java b/server/src/test/java/org/elasticsearch/transport/TcpTransportTests.java index 72941da7ceb19..2afe43f4f6ed4 100644 --- a/server/src/test/java/org/elasticsearch/transport/TcpTransportTests.java +++ b/server/src/test/java/org/elasticsearch/transport/TcpTransportTests.java @@ -11,7 +11,7 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.component.Lifecycle; @@ -227,7 +227,7 @@ private void testDefaultSeedAddresses(final Settings settings, MatcherminVersion and maxVersion (inclusive). */ + public static TransportVersion randomVersionBetween( + Random random, + @Nullable TransportVersion minVersion, + @Nullable TransportVersion maxVersion + ) { + int minVersionIndex = 0; + if (minVersion != null) { + minVersionIndex = ALL_VERSIONS.indexOf(minVersion); + } + int maxVersionIndex = ALL_VERSIONS.size() - 1; + if (maxVersion != null) { + maxVersionIndex = ALL_VERSIONS.indexOf(maxVersion); + } + if (minVersionIndex == -1) { + throw new IllegalArgumentException("minVersion [" + minVersion + "] does not exist."); + } else if (maxVersionIndex == -1) { + throw new IllegalArgumentException("maxVersion [" + maxVersion + "] does not exist."); + } else if (minVersionIndex > maxVersionIndex) { + throw new IllegalArgumentException("maxVersion [" + maxVersion + "] cannot be less than minVersion [" + minVersion + "]"); + } else { + // minVersionIndex is inclusive so need to add 1 to this index + int range = maxVersionIndex + 1 - minVersionIndex; + return ALL_VERSIONS.get(minVersionIndex + random.nextInt(range)); + } + } + public static TransportVersion getPreviousVersion() { TransportVersion version = getPreviousVersion(TransportVersion.CURRENT); assert version.before(TransportVersion.CURRENT); @@ -56,4 +84,10 @@ public static TransportVersion getPreviousVersion(TransportVersion version) { } return ALL_VERSIONS.get(place - 1); } + + /** Returns a random {@link Version} from all available versions, that is compatible with the given version. */ + public static TransportVersion randomCompatibleVersion(Random random, TransportVersion version) { + final List compatible = ALL_VERSIONS.stream().filter(version::isCompatible).collect(Collectors.toList()); + return compatible.get(random.nextInt(compatible.size())); + } } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/core/security/transport/netty4/SecurityNetty4Transport.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/core/security/transport/netty4/SecurityNetty4Transport.java index 9b63e5e63a3fb..6263568e14e61 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/core/security/transport/netty4/SecurityNetty4Transport.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/core/security/transport/netty4/SecurityNetty4Transport.java @@ -17,7 +17,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.TransportVersion; -import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.network.NetworkService; diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java index 9e27bbd81c0df..1a0c4d2fca753 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java @@ -10,7 +10,6 @@ import org.apache.logging.log4j.Logger; import org.apache.lucene.util.SetOnce; import org.elasticsearch.TransportVersion; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4ServerTransport.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4ServerTransport.java index 579bd710cb426..ffd7437eab2e5 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4ServerTransport.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4ServerTransport.java @@ -10,7 +10,6 @@ import io.netty.channel.ChannelHandler; import org.elasticsearch.TransportVersion; -import org.elasticsearch.Version; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.settings.Settings; diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/ServerTransportFilterTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/ServerTransportFilterTests.java index ac804d8bae279..7e9c785651faf 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/ServerTransportFilterTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/ServerTransportFilterTests.java @@ -7,7 +7,7 @@ package org.elasticsearch.xpack.security.transport; import org.elasticsearch.ElasticsearchSecurityException; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.MockIndicesRequest; import org.elasticsearch.action.admin.indices.close.CloseIndexAction; @@ -65,7 +65,7 @@ public void init() throws Exception { authzService = mock(AuthorizationService.class); channel = mock(TransportChannel.class); when(channel.getProfileName()).thenReturn(TransportSettings.DEFAULT_PROFILE); - when(channel.getVersion()).thenReturn(Version.CURRENT); + when(channel.getVersion()).thenReturn(TransportVersion.CURRENT); failDestructiveOperations = randomBoolean(); Settings settings = Settings.builder().put(DestructiveOperations.REQUIRES_NAME_SETTING.getKey(), failDestructiveOperations).build(); destructiveOperations = new DestructiveOperations( From 7f865ad3674ca1094cb173c8ac2d3f9d525a49ad Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Tue, 17 Jan 2023 13:16:34 +0000 Subject: [PATCH 17/22] Add full compatibility method to get things working --- .../org/elasticsearch/TransportVersion.java | 22 ++++++++++++++++--- .../main/java/org/elasticsearch/Version.java | 22 ++++++++++++++++--- .../transport/InboundDecoder.java | 4 ++-- .../transport/InboundHandler.java | 3 +-- .../transport/TransportHandshaker.java | 6 ++--- .../transport/InboundHandlerTests.java | 3 +-- .../transport/TransportHandshakerTests.java | 4 ++-- .../AbstractSimpleTransportTestCase.java | 12 +++++----- ...pleSecurityNetty4ServerTransportTests.java | 4 ++-- 9 files changed, 55 insertions(+), 25 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/TransportVersion.java b/server/src/main/java/org/elasticsearch/TransportVersion.java index 67181044222d3..55ef0a68f32c3 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersion.java +++ b/server/src/main/java/org/elasticsearch/TransportVersion.java @@ -230,16 +230,32 @@ public static TransportVersion max(TransportVersion version1, TransportVersion v this.uniqueId = Strings.requireNonEmpty(uniqueId, "Each TransportVersion needs a unique string id"); } - /* To help migrate from Version.minimumCompatibilityVersion() */ + /** + * Placeholder method for code compatibility with code calling {@code CURRENT.minimumCompatibilityVersion}. + */ @Deprecated public TransportVersion minimumCompatibilityVersion() { - assert this == CURRENT; + assert this.equals(CURRENT); return MINIMUM_COMPATIBLE; } @Deprecated public boolean isCompatible(TransportVersion version) { - return this.compareTo(MINIMUM_COMPATIBLE) >= 0 && version.compareTo(MINIMUM_COMPATIBLE) >= 0; + return onOrAfter(version.calculateMinimumCompatVersion()) && version.onOrAfter(calculateMinimumCompatVersion()); + } + + private TransportVersion minimumCompatibleVersion; + + /** + * Placeholder for code calling {@code minimumCompatibilityVersion} on arbitrary Version instances. + * Code calling this should be refactored to not do this. + */ + @Deprecated + public TransportVersion calculateMinimumCompatVersion() { + if (minimumCompatibleVersion == null) { + minimumCompatibleVersion = Version.findVersion(this).minimumCompatibilityVersion().transportVersion; + } + return minimumCompatibleVersion; } public boolean after(TransportVersion version) { diff --git a/server/src/main/java/org/elasticsearch/Version.java b/server/src/main/java/org/elasticsearch/Version.java index f5dad1e51a5e5..2afa365b4ef01 100644 --- a/server/src/main/java/org/elasticsearch/Version.java +++ b/server/src/main/java/org/elasticsearch/Version.java @@ -26,7 +26,10 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.NavigableMap; +import java.util.NoSuchElementException; import java.util.Objects; +import java.util.TreeMap; public class Version implements Comparable, ToXContentFragment { /* @@ -134,11 +137,11 @@ public class Version implements Comparable, ToXContentFragment { public static final Version V_8_7_0 = new Version(8_07_00_99, TransportVersion.V_8_7_0, org.apache.lucene.util.Version.LUCENE_9_4_2); public static final Version CURRENT = V_8_7_0; - private static final Map VERSION_IDS; + private static final NavigableMap VERSION_IDS; private static final Map VERSION_STRINGS; static { - final Map builder = new HashMap<>(); + final NavigableMap builder = new TreeMap<>(); final Map builderByString = new HashMap<>(); for (final Field declaredField : Version.class.getFields()) { @@ -180,7 +183,8 @@ public class Version implements Comparable, ToXContentFragment { + "]"; builder.put(V_EMPTY_ID, V_EMPTY); builderByString.put(V_EMPTY.toString(), V_EMPTY); - VERSION_IDS = Map.copyOf(builder); + + VERSION_IDS = Collections.unmodifiableNavigableMap(builder); VERSION_STRINGS = Map.copyOf(builderByString); } @@ -188,6 +192,18 @@ public static Version readVersion(StreamInput in) throws IOException { return fromId(in.readVInt()); } + /** + * Returns the highest Version that has this or a lesser TransportVersion. + */ + static Version findVersion(TransportVersion transportVersion) { + return VERSION_IDS.descendingMap() + .values() + .stream() + .filter(v -> v.transportVersion.compareTo(transportVersion) <= 0) + .findFirst() + .orElseThrow(() -> new NoSuchElementException("No valid Version found")); // only if transportVersion < 0 ????? + } + public static Version fromId(int id) { final Version known = VERSION_IDS.get(id); if (known != null) { diff --git a/server/src/main/java/org/elasticsearch/transport/InboundDecoder.java b/server/src/main/java/org/elasticsearch/transport/InboundDecoder.java index bc573af28eee7..ba399f6936df5 100644 --- a/server/src/main/java/org/elasticsearch/transport/InboundDecoder.java +++ b/server/src/main/java/org/elasticsearch/transport/InboundDecoder.java @@ -212,11 +212,11 @@ static IllegalStateException ensureVersionCompatibility( // since we are compatible with N-1 and N+1 so we always send our minCompatVersion as the initial version in the // handshake. This looks odd but it's required to establish the connection correctly we check for real compatibility // once the connection is established - final TransportVersion compatibilityVersion = isHandshake ? currentVersion.minimumCompatibilityVersion() : currentVersion; + final TransportVersion compatibilityVersion = isHandshake ? currentVersion.calculateMinimumCompatVersion() : currentVersion; if (remoteVersion.isCompatible(compatibilityVersion) == false) { final TransportVersion minCompatibilityVersion = isHandshake ? compatibilityVersion - : compatibilityVersion.minimumCompatibilityVersion(); + : compatibilityVersion.calculateMinimumCompatVersion(); String msg = "Received " + (isHandshake ? "handshake " : "") + "message from unsupported version: ["; return new IllegalStateException(msg + remoteVersion + "] minimal compatible version is: [" + minCompatibilityVersion + "]"); } diff --git a/server/src/main/java/org/elasticsearch/transport/InboundHandler.java b/server/src/main/java/org/elasticsearch/transport/InboundHandler.java index 8995426e22a3f..7c69f1e84d0a0 100644 --- a/server/src/main/java/org/elasticsearch/transport/InboundHandler.java +++ b/server/src/main/java/org/elasticsearch/transport/InboundHandler.java @@ -12,7 +12,6 @@ import org.apache.logging.log4j.Logger; import org.apache.lucene.util.BytesRef; import org.elasticsearch.TransportVersion; -import org.elasticsearch.Version; import org.elasticsearch.common.io.stream.ByteBufferStreamInput; import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -136,7 +135,7 @@ private void messageReceived(TcpChannel channel, InboundMessage message, long st } // ignore if its null, the service logs it if (responseHandler != null) { - if (message.getContentLength() > 0 || header.getVersion().equals(Version.CURRENT) == false) { + if (message.getContentLength() > 0 || header.getVersion().equals(TransportVersion.CURRENT) == false) { final StreamInput streamInput = namedWriteableStream(message.openOrGetStreamInput()); assertRemoteVersion(streamInput, header.getVersion()); if (header.isError()) { diff --git a/server/src/main/java/org/elasticsearch/transport/TransportHandshaker.java b/server/src/main/java/org/elasticsearch/transport/TransportHandshaker.java index 5debf99e81df5..6a405a4b79d5c 100644 --- a/server/src/main/java/org/elasticsearch/transport/TransportHandshaker.java +++ b/server/src/main/java/org/elasticsearch/transport/TransportHandshaker.java @@ -70,7 +70,7 @@ void sendHandshake( // for the request we use the minCompatVersion since we don't know what's the version of the node we talk to // we also have no payload on the request but the response will contain the actual version of the node we talk // to as the payload. - final TransportVersion minCompatVersion = version.minimumCompatibilityVersion(); + TransportVersion minCompatVersion = version.calculateMinimumCompatVersion(); handshakeRequestSender.sendRequest(node, channel, requestId, minCompatVersion); threadPool.schedule( @@ -79,7 +79,7 @@ void sendHandshake( ThreadPool.Names.GENERIC ); success = true; - } catch (Exception e) { + } catch (Throwable e) { handler.handleLocalException(new ConnectTransportException(node, "failure to send " + HANDSHAKE_ACTION_NAME, e)); } finally { if (success == false) { @@ -154,7 +154,7 @@ public void handleResponse(HandshakeResponse response) { "Received message from unsupported version: [" + responseVersion + "] minimal compatible version is: [" - + currentVersion.minimumCompatibilityVersion() + + currentVersion.calculateMinimumCompatVersion() + "]" ) ); diff --git a/server/src/test/java/org/elasticsearch/transport/InboundHandlerTests.java b/server/src/test/java/org/elasticsearch/transport/InboundHandlerTests.java index f24a1e2a9485a..0029191ca7668 100644 --- a/server/src/test/java/org/elasticsearch/transport/InboundHandlerTests.java +++ b/server/src/test/java/org/elasticsearch/transport/InboundHandlerTests.java @@ -13,7 +13,6 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.TransportVersion; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -179,7 +178,7 @@ public TestResponse read(StreamInput in) throws IOException { handler.inboundMessage(channel, requestMessage); TransportChannel transportChannel = channelCaptor.get(); - assertEquals(Version.CURRENT, transportChannel.getVersion()); + assertEquals(TransportVersion.CURRENT, transportChannel.getVersion()); assertEquals("transport", transportChannel.getChannelType()); assertEquals(requestValue, requestCaptor.get().value); diff --git a/server/src/test/java/org/elasticsearch/transport/TransportHandshakerTests.java b/server/src/test/java/org/elasticsearch/transport/TransportHandshakerTests.java index db2d65d099dec..2446d51e37200 100644 --- a/server/src/test/java/org/elasticsearch/transport/TransportHandshakerTests.java +++ b/server/src/test/java/org/elasticsearch/transport/TransportHandshakerTests.java @@ -83,7 +83,7 @@ public void testHandshakeRequestAndResponse() throws IOException { handler.handleResponse((TransportHandshaker.HandshakeResponse) responseFuture.actionGet()); assertTrue(versionFuture.isDone()); - assertEquals(Version.CURRENT, versionFuture.actionGet()); + assertEquals(TransportVersion.CURRENT, versionFuture.actionGet()); } public void testHandshakeRequestFutureVersionsCompatibility() throws IOException { @@ -118,7 +118,7 @@ public void testHandshakeRequestFutureVersionsCompatibility() throws IOException TransportHandshaker.HandshakeResponse response = (TransportHandshaker.HandshakeResponse) responseFuture.actionGet(); - assertEquals(Version.CURRENT, response.getResponseVersion()); + assertEquals(TransportVersion.CURRENT, response.getResponseVersion()); } public void testHandshakeError() throws IOException { diff --git a/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java b/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java index ec5a3ae996224..a17b3168b8ccc 100644 --- a/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java @@ -1532,7 +1532,7 @@ public void testVersionFrom0to1() throws Exception { assertThat(request.value2, equalTo(0)); // not set, coming from service A Version1Response response = new Version1Response(1, 2); channel.sendResponse(response); - assertEquals(version0, channel.getVersion()); + assertEquals(version0.transportVersion, channel.getVersion()); }); Version0Request version0Request = new Version0Request(); @@ -1569,7 +1569,7 @@ public void testVersionFrom1to0() throws Exception { assertThat(request.value1, equalTo(1)); Version0Response response = new Version0Response(1); channel.sendResponse(response); - assertEquals(version0, channel.getVersion()); + assertEquals(version0.transportVersion, channel.getVersion()); }); Version1Request version1Request = new Version1Request(); @@ -1610,7 +1610,7 @@ public void testVersionFrom1to1() throws Exception { assertThat(request.value2, equalTo(2)); Version1Response response = new Version1Response(1, 2); channel.sendResponse(response); - assertEquals(version1, channel.getVersion()); + assertEquals(version1.transportVersion, channel.getVersion()); }); Version1Request version1Request = new Version1Request(); @@ -1650,7 +1650,7 @@ public void testVersionFrom0to0() throws Exception { assertThat(request.value1, equalTo(1)); Version0Response response = new Version0Response(1); channel.sendResponse(response); - assertEquals(version0, channel.getVersion()); + assertEquals(version0.transportVersion, channel.getVersion()); }); Version0Request version0Request = new Version0Request(); @@ -2259,7 +2259,7 @@ public void testHandshakeUpdatesVersion() throws IOException { TransportRequestOptions.Type.STATE ); try (Transport.Connection connection = openConnection(serviceA, node, builder.build())) { - assertEquals(connection.getVersion(), version); + assertEquals(version.transportVersion, connection.getTransportVersion()); } } } @@ -2304,7 +2304,7 @@ public void testTcpHandshake() { PlainActionFuture future = PlainActionFuture.newFuture(); serviceA.getOriginalTransport().openConnection(node, connectionProfile, future); try (Transport.Connection connection = future.actionGet()) { - assertEquals(connection.getVersion(), Version.CURRENT); + assertEquals(TransportVersion.CURRENT, connection.getTransportVersion()); } } } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SimpleSecurityNetty4ServerTransportTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SimpleSecurityNetty4ServerTransportTests.java index bae7f95a392f6..14d8e94eb9e0b 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SimpleSecurityNetty4ServerTransportTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SimpleSecurityNetty4ServerTransportTests.java @@ -117,7 +117,7 @@ public void executeHandshake( if (doHandshake) { super.executeHandshake(node, channel, profile, listener); } else { - listener.onResponse(version.minimumCompatibilityVersion()); + listener.onResponse(version.calculateMinimumCompatVersion()); } } }; @@ -196,7 +196,7 @@ public void testTcpHandshake() { PlainActionFuture future = PlainActionFuture.newFuture(); originalTransport.openConnection(node, connectionProfile, future); try (TcpTransport.NodeChannels connection = (TcpTransport.NodeChannels) future.actionGet()) { - assertEquals(connection.getVersion(), Version.CURRENT); + assertEquals(TransportVersion.CURRENT, connection.getTransportVersion()); } } } From 2b40f4b28c880f18b1f22449f861198ec57f17bd Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Tue, 17 Jan 2023 14:57:28 +0000 Subject: [PATCH 18/22] Spread calculateMinimumCompatVersion around --- .../transport/netty4/SimpleNetty4TransportTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/SimpleNetty4TransportTests.java b/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/SimpleNetty4TransportTests.java index 60e90d42debda..d57d28d0ea9db 100644 --- a/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/SimpleNetty4TransportTests.java +++ b/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/SimpleNetty4TransportTests.java @@ -69,7 +69,7 @@ public void executeHandshake( if (doHandshake) { super.executeHandshake(node, channel, profile, listener); } else { - listener.onResponse(version.minimumCompatibilityVersion()); + listener.onResponse(version.calculateMinimumCompatVersion()); } } }; From ea1d7293abb56f55327c20eeceb7c7d86a8d44f4 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Tue, 17 Jan 2023 15:21:41 +0000 Subject: [PATCH 19/22] More test fixes --- .../transport/InboundAggregatorTests.java | 2 +- .../transport/InboundDecoderTests.java | 28 +++++++++---------- .../transport/InboundPipelineTests.java | 3 +- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/transport/InboundAggregatorTests.java b/server/src/test/java/org/elasticsearch/transport/InboundAggregatorTests.java index 43d7219fbdaca..58691d29e3617 100644 --- a/server/src/test/java/org/elasticsearch/transport/InboundAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/transport/InboundAggregatorTests.java @@ -90,7 +90,7 @@ public void testInboundAggregation() throws IOException { assertFalse(aggregated.isPing()); assertTrue(aggregated.getHeader().isRequest()); assertThat(aggregated.getHeader().getRequestId(), equalTo(requestId)); - assertThat(aggregated.getHeader().getVersion(), equalTo(Version.CURRENT)); + assertThat(aggregated.getHeader().getVersion(), equalTo(TransportVersion.CURRENT)); for (ReleasableBytesReference reference : references) { assertTrue(reference.hasReferences()); } diff --git a/server/src/test/java/org/elasticsearch/transport/InboundDecoderTests.java b/server/src/test/java/org/elasticsearch/transport/InboundDecoderTests.java index 1475474a6b9da..b676947cf1126 100644 --- a/server/src/test/java/org/elasticsearch/transport/InboundDecoderTests.java +++ b/server/src/test/java/org/elasticsearch/transport/InboundDecoderTests.java @@ -87,7 +87,7 @@ public void testDecode() throws IOException { final Header header = (Header) fragments.get(0); assertEquals(requestId, header.getRequestId()); - assertEquals(Version.CURRENT, header.getVersion()); + assertEquals(TransportVersion.CURRENT, header.getVersion()); assertFalse(header.isCompressed()); assertFalse(header.isHandshake()); if (isRequest) { @@ -184,7 +184,7 @@ public void testDecodeHandshakeCompatibility() throws IOException { final String headerKey = randomAlphaOfLength(10); final String headerValue = randomAlphaOfLength(20); threadContext.putHeader(headerKey, headerValue); - TransportVersion handshakeCompat = TransportVersion.CURRENT.minimumCompatibilityVersion().minimumCompatibilityVersion(); + TransportVersion handshakeCompat = TransportVersion.CURRENT.calculateMinimumCompatVersion().calculateMinimumCompatVersion(); OutboundMessage message = new OutboundMessage.Request( threadContext, new TestRequest(randomAlphaOfLength(100)), @@ -267,7 +267,7 @@ public void testCompressedDecode() throws IOException { final Header header = (Header) fragments.get(0); assertEquals(requestId, header.getRequestId()); - assertEquals(Version.CURRENT, header.getVersion()); + assertEquals(TransportVersion.CURRENT, header.getVersion()); assertTrue(header.isCompressed()); assertFalse(header.isHandshake()); if (isRequest) { @@ -307,7 +307,7 @@ public void testCompressedDecodeHandshakeCompatibility() throws IOException { final String headerKey = randomAlphaOfLength(10); final String headerValue = randomAlphaOfLength(20); threadContext.putHeader(headerKey, headerValue); - TransportVersion handshakeCompat = TransportVersion.CURRENT.minimumCompatibilityVersion().minimumCompatibilityVersion(); + TransportVersion handshakeCompat = TransportVersion.CURRENT.calculateMinimumCompatVersion().calculateMinimumCompatVersion(); OutboundMessage message = new OutboundMessage.Request( threadContext, new TestRequest(randomAlphaOfLength(100)), @@ -344,7 +344,7 @@ public void testCompressedDecodeHandshakeCompatibility() throws IOException { public void testVersionIncompatibilityDecodeException() throws IOException { String action = "test-request"; long requestId = randomNonNegativeLong(); - TransportVersion incompatibleVersion = TransportVersion.CURRENT.minimumCompatibilityVersion().minimumCompatibilityVersion(); + TransportVersion incompatibleVersion = TransportVersion.CURRENT.calculateMinimumCompatVersion().calculateMinimumCompatVersion(); OutboundMessage message = new OutboundMessage.Request( threadContext, new TestRequest(randomAlphaOfLength(100)), @@ -382,26 +382,26 @@ public void testEnsureVersionCompatibility() throws IOException { ); assertNull(ise); - TransportVersion version = TransportVersion.V_8_0_0; - ise = InboundDecoder.ensureVersionCompatibility(TransportVersion.V_7_0_0, version, true); + TransportVersion version = Version.fromString("7.0.0").transportVersion; + ise = InboundDecoder.ensureVersionCompatibility(Version.fromString("6.0.0").transportVersion, version, true); assertNull(ise); - ise = InboundDecoder.ensureVersionCompatibility(TransportVersion.V_7_0_0, version, false); + ise = InboundDecoder.ensureVersionCompatibility(Version.fromString("6.0.0").transportVersion, version, false); assertEquals( - "Received message from unsupported version: [7.0.0] minimal compatible version is: [" - + version.minimumCompatibilityVersion() + "Received message from unsupported version: [6000099] minimal compatible version is: [" + + version.calculateMinimumCompatVersion() + "]", ise.getMessage() ); // For handshake we are compatible with N-2 - ise = InboundDecoder.ensureVersionCompatibility(Version.fromString("6.0.0").transportVersion, version, true); + ise = InboundDecoder.ensureVersionCompatibility(Version.fromString("5.6.0").transportVersion, version, true); assertNull(ise); - ise = InboundDecoder.ensureVersionCompatibility(Version.fromString("6.0.0").transportVersion, version, false); + ise = InboundDecoder.ensureVersionCompatibility(Version.fromString("5.6.0").transportVersion, version, false); assertEquals( - "Received message from unsupported version: [6.0.0] minimal compatible version is: [" - + version.minimumCompatibilityVersion() + "Received message from unsupported version: [5060099] minimal compatible version is: [" + + version.calculateMinimumCompatVersion() + "]", ise.getMessage() ); diff --git a/server/src/test/java/org/elasticsearch/transport/InboundPipelineTests.java b/server/src/test/java/org/elasticsearch/transport/InboundPipelineTests.java index f35984fe42eeb..07f7defe4d625 100644 --- a/server/src/test/java/org/elasticsearch/transport/InboundPipelineTests.java +++ b/server/src/test/java/org/elasticsearch/transport/InboundPipelineTests.java @@ -217,7 +217,8 @@ public void testDecodeExceptionIsPropagated() throws IOException { try (RecyclerBytesStreamOutput streamOutput = new RecyclerBytesStreamOutput(recycler)) { String actionName = "actionName"; - final TransportVersion invalidVersion = TransportVersion.CURRENT.minimumCompatibilityVersion().minimumCompatibilityVersion(); + final TransportVersion invalidVersion = TransportVersion.CURRENT + .calculateMinimumCompatVersion().calculateMinimumCompatVersion(); final String value = randomAlphaOfLength(1000); final boolean isRequest = randomBoolean(); final long requestId = randomNonNegativeLong(); From 4de6681e49183f555f5fc54f6da810ac82108b8d Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Tue, 17 Jan 2023 15:36:11 +0000 Subject: [PATCH 20/22] Splotless --- .../org/elasticsearch/transport/InboundAggregatorTests.java | 1 - .../org/elasticsearch/transport/InboundPipelineTests.java | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/transport/InboundAggregatorTests.java b/server/src/test/java/org/elasticsearch/transport/InboundAggregatorTests.java index 58691d29e3617..30ce676a36e80 100644 --- a/server/src/test/java/org/elasticsearch/transport/InboundAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/transport/InboundAggregatorTests.java @@ -9,7 +9,6 @@ package org.elasticsearch.transport; import org.elasticsearch.TransportVersion; -import org.elasticsearch.Version; import org.elasticsearch.common.breaker.CircuitBreakingException; import org.elasticsearch.common.breaker.TestCircuitBreaker; import org.elasticsearch.common.bytes.BytesArray; diff --git a/server/src/test/java/org/elasticsearch/transport/InboundPipelineTests.java b/server/src/test/java/org/elasticsearch/transport/InboundPipelineTests.java index 07f7defe4d625..333cbde836810 100644 --- a/server/src/test/java/org/elasticsearch/transport/InboundPipelineTests.java +++ b/server/src/test/java/org/elasticsearch/transport/InboundPipelineTests.java @@ -217,8 +217,8 @@ public void testDecodeExceptionIsPropagated() throws IOException { try (RecyclerBytesStreamOutput streamOutput = new RecyclerBytesStreamOutput(recycler)) { String actionName = "actionName"; - final TransportVersion invalidVersion = TransportVersion.CURRENT - .calculateMinimumCompatVersion().calculateMinimumCompatVersion(); + final TransportVersion invalidVersion = TransportVersion.CURRENT.calculateMinimumCompatVersion() + .calculateMinimumCompatVersion(); final String value = randomAlphaOfLength(1000); final boolean isRequest = randomBoolean(); final long requestId = randomNonNegativeLong(); From e5db29defae4e34d344da1a1b0c4983b63444e70 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Tue, 17 Jan 2023 16:17:55 +0000 Subject: [PATCH 21/22] Some hacks around TcpTransport.getVersion to make some tests pass --- .../java/org/elasticsearch/transport/TcpTransport.java | 4 +++- .../org/elasticsearch/transport/TransportHandshaker.java | 2 +- .../test/java/org/elasticsearch/TransportVersionTests.java | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/transport/TcpTransport.java b/server/src/main/java/org/elasticsearch/transport/TcpTransport.java index a1aab47065c69..e80016a803923 100644 --- a/server/src/main/java/org/elasticsearch/transport/TcpTransport.java +++ b/server/src/main/java/org/elasticsearch/transport/TcpTransport.java @@ -281,7 +281,9 @@ public final class NodeChannels extends CloseableConnection { @Override public Version getVersion() { - return node.getVersion(); + // TODO: this should be the below, but in some cases the node version does not match the passed-in version. + // return node.getVersion(); + return Version.fromId(version.id); } @Override diff --git a/server/src/main/java/org/elasticsearch/transport/TransportHandshaker.java b/server/src/main/java/org/elasticsearch/transport/TransportHandshaker.java index 6a405a4b79d5c..656c7b48c90da 100644 --- a/server/src/main/java/org/elasticsearch/transport/TransportHandshaker.java +++ b/server/src/main/java/org/elasticsearch/transport/TransportHandshaker.java @@ -79,7 +79,7 @@ void sendHandshake( ThreadPool.Names.GENERIC ); success = true; - } catch (Throwable e) { + } catch (Exception e) { handler.handleLocalException(new ConnectTransportException(node, "failure to send " + HANDSHAKE_ACTION_NAME, e)); } finally { if (success == false) { diff --git a/server/src/test/java/org/elasticsearch/TransportVersionTests.java b/server/src/test/java/org/elasticsearch/TransportVersionTests.java index 8549547767d5a..b42ade155e9df 100644 --- a/server/src/test/java/org/elasticsearch/TransportVersionTests.java +++ b/server/src/test/java/org/elasticsearch/TransportVersionTests.java @@ -147,4 +147,11 @@ public void testToString() { assertEquals("2000099", TransportVersion.fromId(2_00_00_99).toString()); assertEquals("5000099", TransportVersion.fromId(5_00_00_99).toString()); } + + public void testMinCompatVersion() { + Version minCompat = Version.fromId(TransportVersion.V_8_0_0.calculateMinimumCompatVersion().id); + assertEquals(7, minCompat.major); + assertEquals("This needs to be updated when 7.18 is released", 17, minCompat.minor); + assertEquals(0, minCompat.revision); + } } From 26b5ce7a57636887be2f7af4e776afa024603684 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Wed, 18 Jan 2023 15:08:16 +0000 Subject: [PATCH 22/22] Convert index-related code to TransportVersion --- .../index/rankeval/RankEvalRequest.java | 6 ++--- .../elasticsearch/cluster/ClusterInfo.java | 4 ++-- .../elasticsearch/index/engine/Segment.java | 8 +++---- .../index/engine/SegmentsStats.java | 10 ++++---- .../elasticsearch/index/get/GetResult.java | 6 ++--- .../query/AbstractGeometryQueryBuilder.java | 6 ++--- .../query/GeoBoundingBoxQueryBuilder.java | 5 ++-- .../index/query/IdsQueryBuilder.java | 5 ++-- .../index/query/InnerHitBuilder.java | 6 ++--- .../index/query/IntervalsSourceProvider.java | 6 ++--- .../query/MatchPhrasePrefixQueryBuilder.java | 5 ++-- .../index/query/MatchQueryBuilder.java | 5 ++-- .../index/query/MoreLikeThisQueryBuilder.java | 5 ++-- .../index/query/MultiMatchQueryBuilder.java | 5 ++-- .../index/query/PrefixQueryBuilder.java | 5 ++-- .../index/query/RegexpQueryBuilder.java | 5 ++-- .../index/query/TermQueryBuilder.java | 5 ++-- .../index/query/TermsQueryBuilder.java | 11 +++++---- .../index/query/WildcardQueryBuilder.java | 5 ++-- .../index/refresh/RefreshStats.java | 6 ++--- .../index/reindex/RemoteInfo.java | 6 ++--- .../index/search/stats/FieldUsageStats.java | 6 ++--- .../index/shard/IndexingStats.java | 12 +++++----- .../index/stats/IndexingPressureStats.java | 6 ++--- .../index/store/StoreFileMetadata.java | 7 +++--- .../elasticsearch/index/store/StoreStats.java | 14 +++++------ .../indices/NodeIndicesStats.java | 8 +++---- .../elasticsearch/indices/TermsLookup.java | 6 ++--- .../indices/recovery/RecoverySettings.java | 3 ++- .../indices/recovery/RecoveryState.java | 8 +++---- .../recovery/StartRecoveryRequest.java | 4 ++-- .../TransportNodesListShardStoreMetadata.java | 8 +++---- .../indices/close/CloseIndexRequestTests.java | 24 +++++++++---------- 33 files changed, 122 insertions(+), 109 deletions(-) diff --git a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalRequest.java b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalRequest.java index bea4d4222fa58..d6a9a25be51f2 100644 --- a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalRequest.java +++ b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalRequest.java @@ -8,7 +8,7 @@ package org.elasticsearch.index.rankeval; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.IndicesRequest; @@ -45,7 +45,7 @@ public RankEvalRequest(RankEvalSpec rankingEvaluationSpec, String[] indices) { rankingEvaluationSpec = new RankEvalSpec(in); indices = in.readStringArray(); indicesOptions = IndicesOptions.readIndicesOptions(in); - if (in.getVersion().onOrAfter(Version.V_7_6_0)) { + if (in.getTransportVersion().onOrAfter(TransportVersion.V_7_6_0)) { searchType = SearchType.fromId(in.readByte()); } } @@ -126,7 +126,7 @@ public void writeTo(StreamOutput out) throws IOException { rankingEvaluationSpec.writeTo(out); out.writeStringArray(indices); indicesOptions.writeIndicesOptions(out); - if (out.getVersion().onOrAfter(Version.V_7_6_0)) { + if (out.getTransportVersion().onOrAfter(TransportVersion.V_7_6_0)) { out.writeByte(searchType.id()); } } diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterInfo.java b/server/src/main/java/org/elasticsearch/cluster/ClusterInfo.java index cd83c596d661f..fede744a3b3db 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterInfo.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterInfo.java @@ -97,7 +97,7 @@ public ClusterInfo(StreamInput in) throws IOException { } else { this.dataPath = in.readImmutableMap(nested -> NodeAndShard.from(new ShardRouting(nested)), StreamInput::readString); } - if (in.getVersion().onOrAfter(StoreStats.RESERVED_BYTES_VERSION)) { + if (in.getTransportVersion().onOrAfter(StoreStats.RESERVED_BYTES_VERSION)) { this.reservedSpace = in.readImmutableMap(NodeAndPath::new, ReservedSpace::new); } else { this.reservedSpace = Map.of(); @@ -117,7 +117,7 @@ public void writeTo(StreamOutput out) throws IOException { } else { out.writeMap(this.dataPath, (o, k) -> createFakeShardRoutingFromNodeAndShard(k).writeTo(o), StreamOutput::writeString); } - if (out.getVersion().onOrAfter(StoreStats.RESERVED_BYTES_VERSION)) { + if (out.getTransportVersion().onOrAfter(StoreStats.RESERVED_BYTES_VERSION)) { out.writeMap(this.reservedSpace); } } diff --git a/server/src/main/java/org/elasticsearch/index/engine/Segment.java b/server/src/main/java/org/elasticsearch/index/engine/Segment.java index 8bff90cf5856c..88dbe7d454a3d 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/Segment.java +++ b/server/src/main/java/org/elasticsearch/index/engine/Segment.java @@ -14,7 +14,7 @@ import org.apache.lucene.search.SortedNumericSortField; import org.apache.lucene.search.SortedSetSelector; import org.apache.lucene.search.SortedSetSortField; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -52,7 +52,7 @@ public Segment(StreamInput in) throws IOException { version = Lucene.parseVersionLenient(in.readOptionalString(), null); compound = in.readOptionalBoolean(); mergeId = in.readOptionalString(); - if (in.getVersion().before(Version.V_8_0_0)) { + if (in.getTransportVersion().before(TransportVersion.V_8_0_0)) { in.readLong(); // memoryInBytes } if (in.readBoolean()) { @@ -159,7 +159,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeOptionalString(version.toString()); out.writeOptionalBoolean(compound); out.writeOptionalString(mergeId); - if (out.getVersion().before(Version.V_8_0_0)) { + if (out.getTransportVersion().before(TransportVersion.V_8_0_0)) { out.writeLong(0); // memoryInBytes } @@ -252,7 +252,7 @@ private static void writeSegmentSort(StreamOutput out, Sort sort) throws IOExcep o.writeBoolean(((SortedNumericSortField) field).getSelector() == SortedNumericSelector.Type.MAX); o.writeBoolean(field.getReverse()); } else if (field.getType().equals(SortField.Type.STRING)) { - if (o.getVersion().before(Version.V_8_5_0)) { + if (o.getTransportVersion().before(TransportVersion.V_8_5_0)) { // The closest supported version before 8.5.0 was SortedSet fields, so we mimic that o.writeByte(SORT_STRING_SET); o.writeOptionalBoolean(field.getMissingValue() == null ? null : field.getMissingValue() == SortField.STRING_FIRST); diff --git a/server/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java b/server/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java index 321effc55730c..5a2edcb059787 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java +++ b/server/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java @@ -8,7 +8,7 @@ package org.elasticsearch.index.engine; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -39,7 +39,7 @@ public SegmentsStats() { public SegmentsStats(StreamInput in) throws IOException { count = in.readVLong(); - if (in.getVersion().before(Version.V_8_0_0)) { + if (in.getTransportVersion().before(TransportVersion.V_8_0_0)) { in.readLong(); // memoryInBytes in.readLong(); // termsMemoryInBytes in.readLong(); // storedFieldsMemoryInBytes @@ -220,7 +220,7 @@ static final class Fields { @Override public void writeTo(StreamOutput out) throws IOException { out.writeVLong(count); - if (out.getVersion().before(Version.V_8_0_0)) { + if (out.getTransportVersion().before(TransportVersion.V_8_0_0)) { out.writeLong(0L); // memoryInBytes out.writeLong(0L); // termsMemoryInBytes out.writeLong(0L); // storedFieldsMemoryInBytes @@ -250,7 +250,7 @@ public static class FileStats implements Writeable, ToXContentFragment { private final long max; FileStats(StreamInput in) throws IOException { - if (in.getVersion().onOrAfter(Version.V_7_13_0)) { + if (in.getTransportVersion().onOrAfter(TransportVersion.V_7_13_0)) { this.ext = in.readString(); this.total = in.readVLong(); this.count = in.readVLong(); @@ -295,7 +295,7 @@ public long getMax() { @Override public void writeTo(StreamOutput out) throws IOException { - if (out.getVersion().onOrAfter(Version.V_7_13_0)) { + if (out.getTransportVersion().onOrAfter(TransportVersion.V_7_13_0)) { out.writeString(ext); out.writeVLong(total); out.writeVLong(count); diff --git a/server/src/main/java/org/elasticsearch/index/get/GetResult.java b/server/src/main/java/org/elasticsearch/index/get/GetResult.java index 2d8b6b0572bdf..acd3cc0e1987a 100644 --- a/server/src/main/java/org/elasticsearch/index/get/GetResult.java +++ b/server/src/main/java/org/elasticsearch/index/get/GetResult.java @@ -9,7 +9,7 @@ package org.elasticsearch.index.get; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.compress.CompressorFactory; @@ -66,7 +66,7 @@ public class GetResult implements Writeable, Iterable, ToXContent public GetResult(StreamInput in) throws IOException { index = in.readString(); - if (in.getVersion().before(Version.V_8_0_0)) { + if (in.getTransportVersion().before(TransportVersion.V_8_0_0)) { in.readOptionalString(); } id = in.readString(); @@ -386,7 +386,7 @@ public static GetResult fromXContent(XContentParser parser) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException { out.writeString(index); - if (out.getVersion().before(Version.V_8_0_0)) { + if (out.getTransportVersion().before(TransportVersion.V_8_0_0)) { out.writeOptionalString(MapperService.SINGLE_MAPPING_NAME); } out.writeString(id); diff --git a/server/src/main/java/org/elasticsearch/index/query/AbstractGeometryQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/AbstractGeometryQueryBuilder.java index 525cc72d74c97..e2b566a88d098 100644 --- a/server/src/main/java/org/elasticsearch/index/query/AbstractGeometryQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/AbstractGeometryQueryBuilder.java @@ -11,7 +11,7 @@ import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.util.SetOnce; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.client.internal.Client; @@ -141,7 +141,7 @@ protected AbstractGeometryQueryBuilder(StreamInput in) throws IOException { } else { shape = null; indexedShapeId = in.readOptionalString(); - if (in.getVersion().before(Version.V_8_0_0)) { + if (in.getTransportVersion().before(TransportVersion.V_8_0_0)) { String type = in.readOptionalString(); assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected type [_doc], got [" + type + "]"; } @@ -166,7 +166,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { GeometryIO.writeGeometry(out, shape); } else { out.writeOptionalString(indexedShapeId); - if (out.getVersion().before(Version.V_8_0_0)) { + if (out.getTransportVersion().before(TransportVersion.V_8_0_0)) { out.writeOptionalString(MapperService.SINGLE_MAPPING_NAME); } out.writeOptionalString(indexedShapeIndex); diff --git a/server/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java index 3b88d00b9769b..9b89a4ece5626 100644 --- a/server/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java @@ -11,6 +11,7 @@ import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.common.Numbers; import org.elasticsearch.common.ParsingException; @@ -76,7 +77,7 @@ public GeoBoundingBoxQueryBuilder(StreamInput in) throws IOException { super(in); fieldName = in.readString(); geoBoundingBox = new GeoBoundingBox(in); - if (in.getVersion().before(Version.V_8_0_0)) { + if (in.getTransportVersion().before(TransportVersion.V_8_0_0)) { in.readVInt(); // ignore value } validationMethod = GeoValidationMethod.readFromStream(in); @@ -87,7 +88,7 @@ public GeoBoundingBoxQueryBuilder(StreamInput in) throws IOException { protected void doWriteTo(StreamOutput out) throws IOException { out.writeString(fieldName); geoBoundingBox.writeTo(out); - if (out.getVersion().before(Version.V_8_0_0)) { + if (out.getTransportVersion().before(TransportVersion.V_8_0_0)) { out.writeVInt(0); } validationMethod.writeTo(out); diff --git a/server/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java index 25fb35801cf40..ceeec7791af9c 100644 --- a/server/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java @@ -9,6 +9,7 @@ package org.elasticsearch.index.query; import org.apache.lucene.search.Query; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; @@ -53,7 +54,7 @@ public IdsQueryBuilder() { */ public IdsQueryBuilder(StreamInput in) throws IOException { super(in); - if (in.getVersion().before(Version.V_8_0_0)) { + if (in.getTransportVersion().before(TransportVersion.V_8_0_0)) { // types no longer relevant so ignore String[] types = in.readStringArray(); if (types.length > 0) { @@ -65,7 +66,7 @@ public IdsQueryBuilder(StreamInput in) throws IOException { @Override protected void doWriteTo(StreamOutput out) throws IOException { - if (out.getVersion().before(Version.V_8_0_0)) { + if (out.getTransportVersion().before(TransportVersion.V_8_0_0)) { // types not supported so send an empty array to previous versions out.writeStringArray(Strings.EMPTY_ARRAY); } diff --git a/server/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java b/server/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java index f3eaf053ce79f..39b62b54bf087 100644 --- a/server/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java @@ -7,7 +7,7 @@ */ package org.elasticsearch.index.query; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -189,7 +189,7 @@ public InnerHitBuilder(StreamInput in) throws IOException { highlightBuilder = in.readOptionalWriteable(HighlightBuilder::new); this.innerCollapseBuilder = in.readOptionalWriteable(CollapseBuilder::new); - if (in.getVersion().onOrAfter(Version.V_7_10_0)) { + if (in.getTransportVersion().onOrAfter(TransportVersion.V_7_10_0)) { if (in.readBoolean()) { fetchFields = in.readList(FieldAndFormat::new); } @@ -229,7 +229,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeOptionalWriteable(highlightBuilder); out.writeOptionalWriteable(innerCollapseBuilder); - if (out.getVersion().onOrAfter(Version.V_7_10_0)) { + if (out.getTransportVersion().onOrAfter(TransportVersion.V_7_10_0)) { out.writeBoolean(fetchFields != null); if (fetchFields != null) { out.writeList(fetchFields); diff --git a/server/src/main/java/org/elasticsearch/index/query/IntervalsSourceProvider.java b/server/src/main/java/org/elasticsearch/index/query/IntervalsSourceProvider.java index 01c5a749caf02..a0ace42c40883 100644 --- a/server/src/main/java/org/elasticsearch/index/query/IntervalsSourceProvider.java +++ b/server/src/main/java/org/elasticsearch/index/query/IntervalsSourceProvider.java @@ -13,7 +13,7 @@ import org.apache.lucene.queries.intervals.Intervals; import org.apache.lucene.queries.intervals.IntervalsSource; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.NamedWriteable; import org.elasticsearch.common.io.stream.StreamInput; @@ -120,7 +120,7 @@ public Match(StreamInput in) throws IOException { this.ordered = in.readBoolean(); this.analyzer = in.readOptionalString(); this.filter = in.readOptionalWriteable(IntervalFilter::new); - if (in.getVersion().onOrAfter(Version.V_7_2_0)) { + if (in.getTransportVersion().onOrAfter(TransportVersion.V_7_2_0)) { this.useField = in.readOptionalString(); } else { this.useField = null; @@ -204,7 +204,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeBoolean(ordered); out.writeOptionalString(analyzer); out.writeOptionalWriteable(filter); - if (out.getVersion().onOrAfter(Version.V_7_2_0)) { + if (out.getTransportVersion().onOrAfter(TransportVersion.V_7_2_0)) { out.writeOptionalString(useField); } } diff --git a/server/src/main/java/org/elasticsearch/index/query/MatchPhrasePrefixQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/MatchPhrasePrefixQueryBuilder.java index 23ef97e1cd593..3963eb1a2dedd 100644 --- a/server/src/main/java/org/elasticsearch/index/query/MatchPhrasePrefixQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/MatchPhrasePrefixQueryBuilder.java @@ -10,6 +10,7 @@ import org.apache.lucene.search.FuzzyQuery; import org.apache.lucene.search.Query; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; @@ -64,7 +65,7 @@ public MatchPhrasePrefixQueryBuilder(StreamInput in) throws IOException { slop = in.readVInt(); maxExpansions = in.readVInt(); analyzer = in.readOptionalString(); - if (in.getVersion().onOrAfter(Version.V_7_10_0)) { + if (in.getTransportVersion().onOrAfter(TransportVersion.V_7_10_0)) { this.zeroTermsQuery = ZeroTermsQueryOption.readFromStream(in); } } @@ -76,7 +77,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeVInt(slop); out.writeVInt(maxExpansions); out.writeOptionalString(analyzer); - if (out.getVersion().onOrAfter(Version.V_7_10_0)) { + if (out.getTransportVersion().onOrAfter(TransportVersion.V_7_10_0)) { zeroTermsQuery.writeTo(out); } } diff --git a/server/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java index 8353063a2cc26..408985a559298 100644 --- a/server/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java @@ -11,6 +11,7 @@ import org.apache.lucene.analysis.core.KeywordAnalyzer; import org.apache.lucene.search.FuzzyQuery; import org.apache.lucene.search.Query; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; @@ -117,7 +118,7 @@ public MatchQueryBuilder(StreamInput in) throws IOException { fuzzyRewrite = in.readOptionalString(); fuzziness = in.readOptionalWriteable(Fuzziness::new); // cutoff_frequency has been removed - if (in.getVersion().before(Version.V_8_0_0)) { + if (in.getTransportVersion().before(TransportVersion.V_8_0_0)) { in.readOptionalFloat(); } autoGenerateSynonymsPhraseQuery = in.readBoolean(); @@ -139,7 +140,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalString(fuzzyRewrite); out.writeOptionalWriteable(fuzziness); // cutoff_frequency has been removed - if (out.getVersion().before(Version.V_8_0_0)) { + if (out.getTransportVersion().before(TransportVersion.V_8_0_0)) { out.writeOptionalFloat(null); } out.writeBoolean(autoGenerateSynonymsPhraseQuery); diff --git a/server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java index 22913f181e1ef..72e709c58b3d2 100644 --- a/server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java @@ -15,6 +15,7 @@ import org.apache.lucene.search.Query; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ExceptionsHelper; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.RoutingMissingException; import org.elasticsearch.action.termvectors.MultiTermVectorsItemResponse; @@ -206,7 +207,7 @@ public Item(@Nullable String index, XContentBuilder doc) { @SuppressWarnings("unchecked") Item(StreamInput in) throws IOException { index = in.readOptionalString(); - if (in.getVersion().before(Version.V_8_0_0)) { + if (in.getTransportVersion().before(TransportVersion.V_8_0_0)) { // types no longer relevant so ignore String type = in.readOptionalString(); if (type != null) { @@ -229,7 +230,7 @@ public Item(@Nullable String index, XContentBuilder doc) { @Override public void writeTo(StreamOutput out) throws IOException { out.writeOptionalString(index); - if (out.getVersion().before(Version.V_8_0_0)) { + if (out.getTransportVersion().before(TransportVersion.V_8_0_0)) { // types not supported so send an empty array to previous versions out.writeOptionalString(null); } diff --git a/server/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java index 27a1b696f156c..ac486096f17e1 100644 --- a/server/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java @@ -11,6 +11,7 @@ import org.apache.lucene.search.FuzzyQuery; import org.apache.lucene.search.Query; import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; @@ -223,7 +224,7 @@ public MultiMatchQueryBuilder(StreamInput in) throws IOException { fuzzyRewrite = in.readOptionalString(); tieBreaker = in.readOptionalFloat(); lenient = in.readOptionalBoolean(); - if (in.getVersion().before(Version.V_8_0_0)) { + if (in.getTransportVersion().before(TransportVersion.V_8_0_0)) { in.readOptionalFloat(); } zeroTermsQuery = ZeroTermsQueryOption.readFromStream(in); @@ -246,7 +247,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalString(fuzzyRewrite); out.writeOptionalFloat(tieBreaker); out.writeOptionalBoolean(lenient); - if (out.getVersion().before(Version.V_8_0_0)) { + if (out.getTransportVersion().before(TransportVersion.V_8_0_0)) { out.writeOptionalFloat(null); } zeroTermsQuery.writeTo(out); diff --git a/server/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java index 8867d91902da7..e9d50f22c6aaa 100644 --- a/server/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java @@ -12,6 +12,7 @@ import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.MultiTermQuery; import org.apache.lucene.search.Query; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; @@ -72,7 +73,7 @@ public PrefixQueryBuilder(StreamInput in) throws IOException { fieldName = in.readString(); value = in.readString(); rewrite = in.readOptionalString(); - if (in.getVersion().onOrAfter(Version.V_7_10_0)) { + if (in.getTransportVersion().onOrAfter(TransportVersion.V_7_10_0)) { caseInsensitive = in.readBoolean(); } } @@ -82,7 +83,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeString(fieldName); out.writeString(value); out.writeOptionalString(rewrite); - if (out.getVersion().onOrAfter(Version.V_7_10_0)) { + if (out.getTransportVersion().onOrAfter(TransportVersion.V_7_10_0)) { out.writeBoolean(caseInsensitive); } } diff --git a/server/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java index f6ee1620a0ead..312878efa1f68 100644 --- a/server/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java @@ -14,6 +14,7 @@ import org.apache.lucene.search.RegexpQuery; import org.apache.lucene.util.automaton.Operations; import org.apache.lucene.util.automaton.RegExp; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; @@ -86,7 +87,7 @@ public RegexpQueryBuilder(StreamInput in) throws IOException { syntaxFlagsValue = in.readVInt(); maxDeterminizedStates = in.readVInt(); rewrite = in.readOptionalString(); - if (in.getVersion().onOrAfter(Version.V_7_10_0)) { + if (in.getTransportVersion().onOrAfter(TransportVersion.V_7_10_0)) { caseInsensitive = in.readBoolean(); } } @@ -98,7 +99,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeVInt(syntaxFlagsValue); out.writeVInt(maxDeterminizedStates); out.writeOptionalString(rewrite); - if (out.getVersion().onOrAfter(Version.V_7_10_0)) { + if (out.getTransportVersion().onOrAfter(TransportVersion.V_7_10_0)) { out.writeBoolean(caseInsensitive); } } diff --git a/server/src/main/java/org/elasticsearch/index/query/TermQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/TermQueryBuilder.java index 0e5084a576ee2..d9d2431a5d5b7 100644 --- a/server/src/main/java/org/elasticsearch/index/query/TermQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/TermQueryBuilder.java @@ -11,6 +11,7 @@ import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; @@ -86,7 +87,7 @@ public boolean caseInsensitive() { */ public TermQueryBuilder(StreamInput in) throws IOException { super(in); - if (in.getVersion().onOrAfter(Version.V_7_10_0)) { + if (in.getTransportVersion().onOrAfter(TransportVersion.V_7_10_0)) { caseInsensitive = in.readBoolean(); } } @@ -94,7 +95,7 @@ public TermQueryBuilder(StreamInput in) throws IOException { @Override protected void doWriteTo(StreamOutput out) throws IOException { super.doWriteTo(out); - if (out.getVersion().onOrAfter(Version.V_7_10_0)) { + if (out.getTransportVersion().onOrAfter(TransportVersion.V_7_10_0)) { out.writeBoolean(caseInsensitive); } } diff --git a/server/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java index c88a0ee73da8a..40e63703ed537 100644 --- a/server/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java @@ -12,6 +12,7 @@ import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.util.SetOnce; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.get.GetRequest; @@ -49,7 +50,7 @@ */ public class TermsQueryBuilder extends AbstractQueryBuilder { public static final String NAME = "terms"; - private static final Version VERSION_STORE_VALUES_AS_BYTES_REFERENCE = Version.V_7_12_0; + private static final TransportVersion VERSION_STORE_VALUES_AS_BYTES_REFERENCE = TransportVersion.V_7_12_0; private final String fieldName; private final Values values; @@ -415,7 +416,7 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) { private abstract static class Values extends AbstractCollection implements Writeable { private static Values readFrom(StreamInput in) throws IOException { - if (in.getVersion().onOrAfter(VERSION_STORE_VALUES_AS_BYTES_REFERENCE)) { + if (in.getTransportVersion().onOrAfter(VERSION_STORE_VALUES_AS_BYTES_REFERENCE)) { return in.readOptionalWriteable(BinaryValues::new); } else { List list = (List) in.readGenericValue(); @@ -424,7 +425,7 @@ private static Values readFrom(StreamInput in) throws IOException { } private static void writeTo(StreamOutput out, Values values) throws IOException { - if (out.getVersion().onOrAfter(VERSION_STORE_VALUES_AS_BYTES_REFERENCE)) { + if (out.getTransportVersion().onOrAfter(VERSION_STORE_VALUES_AS_BYTES_REFERENCE)) { out.writeOptionalWriteable(values); } else { if (values == null) { @@ -561,7 +562,7 @@ public Object next() { @Override public void writeTo(StreamOutput out) throws IOException { - if (out.getVersion().onOrAfter(VERSION_STORE_VALUES_AS_BYTES_REFERENCE)) { + if (out.getTransportVersion().onOrAfter(VERSION_STORE_VALUES_AS_BYTES_REFERENCE)) { out.writeBytesReference(valueRef); } else { valueRef.writeTo(out); @@ -642,7 +643,7 @@ public Object[] toArray(IntFunction generator) { @Override public void writeTo(StreamOutput out) throws IOException { - if (out.getVersion().onOrAfter(VERSION_STORE_VALUES_AS_BYTES_REFERENCE)) { + if (out.getTransportVersion().onOrAfter(VERSION_STORE_VALUES_AS_BYTES_REFERENCE)) { BytesReference bytesRef = serialize(values, false); out.writeBytesReference(bytesRef); } else { diff --git a/server/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java index f0a9d0495c0d2..d77de71f3b3ea 100644 --- a/server/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java @@ -12,6 +12,7 @@ import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.MultiTermQuery; import org.apache.lucene.search.Query; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; @@ -83,7 +84,7 @@ public WildcardQueryBuilder(StreamInput in) throws IOException { fieldName = in.readString(); value = in.readString(); rewrite = in.readOptionalString(); - if (in.getVersion().onOrAfter(Version.V_7_10_0)) { + if (in.getTransportVersion().onOrAfter(TransportVersion.V_7_10_0)) { caseInsensitive = in.readBoolean(); } } @@ -93,7 +94,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeString(fieldName); out.writeString(value); out.writeOptionalString(rewrite); - if (out.getVersion().onOrAfter(Version.V_7_10_0)) { + if (out.getTransportVersion().onOrAfter(TransportVersion.V_7_10_0)) { out.writeBoolean(caseInsensitive); } } diff --git a/server/src/main/java/org/elasticsearch/index/refresh/RefreshStats.java b/server/src/main/java/org/elasticsearch/index/refresh/RefreshStats.java index 58aa34851fe87..5b627e4a77eb8 100644 --- a/server/src/main/java/org/elasticsearch/index/refresh/RefreshStats.java +++ b/server/src/main/java/org/elasticsearch/index/refresh/RefreshStats.java @@ -8,7 +8,7 @@ package org.elasticsearch.index.refresh; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -39,7 +39,7 @@ public RefreshStats() {} public RefreshStats(StreamInput in) throws IOException { total = in.readVLong(); totalTimeInMillis = in.readVLong(); - if (in.getVersion().onOrAfter(Version.V_7_2_0)) { + if (in.getTransportVersion().onOrAfter(TransportVersion.V_7_2_0)) { externalTotal = in.readVLong(); externalTotalTimeInMillis = in.readVLong(); } @@ -50,7 +50,7 @@ public RefreshStats(StreamInput in) throws IOException { public void writeTo(StreamOutput out) throws IOException { out.writeVLong(total); out.writeVLong(totalTimeInMillis); - if (out.getVersion().onOrAfter(Version.V_7_2_0)) { + if (out.getTransportVersion().onOrAfter(TransportVersion.V_7_2_0)) { out.writeVLong(externalTotal); out.writeVLong(externalTotalTimeInMillis); } diff --git a/server/src/main/java/org/elasticsearch/index/reindex/RemoteInfo.java b/server/src/main/java/org/elasticsearch/index/reindex/RemoteInfo.java index f35558ad6a560..f168ef9ec2dcf 100644 --- a/server/src/main/java/org/elasticsearch/index/reindex/RemoteInfo.java +++ b/server/src/main/java/org/elasticsearch/index/reindex/RemoteInfo.java @@ -8,7 +8,7 @@ package org.elasticsearch.index.reindex; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -99,7 +99,7 @@ public RemoteInfo(StreamInput in) throws IOException { port = in.readVInt(); query = in.readBytesReference(); username = in.readOptionalString(); - if (in.getVersion().before(Version.V_8_2_0)) { + if (in.getTransportVersion().before(TransportVersion.V_8_2_0)) { password = new SecureString(in.readOptionalString().toCharArray()); } else { password = in.readOptionalSecureString(); @@ -122,7 +122,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeVInt(port); out.writeBytesReference(query); out.writeOptionalString(username); - if (out.getVersion().before(Version.V_8_2_0)) { + if (out.getTransportVersion().before(TransportVersion.V_8_2_0)) { out.writeOptionalString(password.toString()); } else { out.writeOptionalSecureString(password); diff --git a/server/src/main/java/org/elasticsearch/index/search/stats/FieldUsageStats.java b/server/src/main/java/org/elasticsearch/index/search/stats/FieldUsageStats.java index 0e96fa38b38a9..93d047a87c4da 100644 --- a/server/src/main/java/org/elasticsearch/index/search/stats/FieldUsageStats.java +++ b/server/src/main/java/org/elasticsearch/index/search/stats/FieldUsageStats.java @@ -8,7 +8,7 @@ package org.elasticsearch.index.search.stats; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -210,7 +210,7 @@ public PerFieldUsageStats(StreamInput in) throws IOException { payloads = in.readVLong(); termVectors = in.readVLong(); points = in.readVLong(); - if (in.getVersion().onOrAfter(Version.V_8_1_0)) { + if (in.getTransportVersion().onOrAfter(TransportVersion.V_8_1_0)) { knnVectors = in.readVLong(); } else { knnVectors = 0; @@ -232,7 +232,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeVLong(payloads); out.writeVLong(termVectors); out.writeVLong(points); - if (out.getVersion().onOrAfter(Version.V_8_1_0)) { + if (out.getTransportVersion().onOrAfter(TransportVersion.V_8_1_0)) { out.writeVLong(knnVectors); } } diff --git a/server/src/main/java/org/elasticsearch/index/shard/IndexingStats.java b/server/src/main/java/org/elasticsearch/index/shard/IndexingStats.java index b998b214cef4a..f416178a6b10d 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/IndexingStats.java +++ b/server/src/main/java/org/elasticsearch/index/shard/IndexingStats.java @@ -8,7 +8,7 @@ package org.elasticsearch.index.shard; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -27,7 +27,7 @@ public class IndexingStats implements Writeable, ToXContentFragment { public static class Stats implements Writeable, ToXContentFragment { - private static final Version WRITE_LOAD_AVG_SUPPORTED_VERSION = Version.V_8_6_0; + private static final TransportVersion WRITE_LOAD_AVG_SUPPORTED_VERSION = TransportVersion.V_8_6_0; private long indexCount; private long indexTimeInMillis; @@ -55,7 +55,7 @@ public Stats(StreamInput in) throws IOException { noopUpdateCount = in.readVLong(); isThrottled = in.readBoolean(); throttleTimeInMillis = in.readLong(); - if (in.getVersion().onOrAfter(WRITE_LOAD_AVG_SUPPORTED_VERSION)) { + if (in.getTransportVersion().onOrAfter(WRITE_LOAD_AVG_SUPPORTED_VERSION)) { totalIndexingTimeSinceShardStartedInNanos = in.readLong(); totalActiveTimeInNanos = in.readLong(); } @@ -196,7 +196,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeVLong(noopUpdateCount); out.writeBoolean(isThrottled); out.writeLong(throttleTimeInMillis); - if (out.getVersion().onOrAfter(WRITE_LOAD_AVG_SUPPORTED_VERSION)) { + if (out.getTransportVersion().onOrAfter(WRITE_LOAD_AVG_SUPPORTED_VERSION)) { out.writeLong(totalIndexingTimeSinceShardStartedInNanos); out.writeLong(totalActiveTimeInNanos); } @@ -268,7 +268,7 @@ public IndexingStats() { public IndexingStats(StreamInput in) throws IOException { totalStats = new Stats(in); - if (in.getVersion().before(Version.V_8_0_0)) { + if (in.getTransportVersion().before(TransportVersion.V_8_0_0)) { if (in.readBoolean()) { Map typeStats = in.readMap(StreamInput::readString, Stats::new); assert typeStats.size() == 1; @@ -349,7 +349,7 @@ static final class Fields { @Override public void writeTo(StreamOutput out) throws IOException { totalStats.writeTo(out); - if (out.getVersion().before(Version.V_8_0_0)) { + if (out.getTransportVersion().before(TransportVersion.V_8_0_0)) { out.writeBoolean(false); } } diff --git a/server/src/main/java/org/elasticsearch/index/stats/IndexingPressureStats.java b/server/src/main/java/org/elasticsearch/index/stats/IndexingPressureStats.java index a2de41318b567..e4db6921a44d2 100644 --- a/server/src/main/java/org/elasticsearch/index/stats/IndexingPressureStats.java +++ b/server/src/main/java/org/elasticsearch/index/stats/IndexingPressureStats.java @@ -8,7 +8,7 @@ package org.elasticsearch.index.stats; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -57,7 +57,7 @@ public IndexingPressureStats(StreamInput in) throws IOException { primaryRejections = in.readVLong(); replicaRejections = in.readVLong(); - if (in.getVersion().onOrAfter(Version.V_7_10_0)) { + if (in.getTransportVersion().onOrAfter(TransportVersion.V_7_10_0)) { memoryLimit = in.readVLong(); } else { memoryLimit = -1L; @@ -129,7 +129,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeVLong(primaryRejections); out.writeVLong(replicaRejections); - if (out.getVersion().onOrAfter(Version.V_7_10_0)) { + if (out.getTransportVersion().onOrAfter(TransportVersion.V_7_10_0)) { out.writeVLong(memoryLimit); } } diff --git a/server/src/main/java/org/elasticsearch/index/store/StoreFileMetadata.java b/server/src/main/java/org/elasticsearch/index/store/StoreFileMetadata.java index eadffeeecdca8..d9422c648ef8a 100644 --- a/server/src/main/java/org/elasticsearch/index/store/StoreFileMetadata.java +++ b/server/src/main/java/org/elasticsearch/index/store/StoreFileMetadata.java @@ -15,6 +15,7 @@ import org.apache.lucene.index.SegmentInfos; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -28,7 +29,7 @@ public class StoreFileMetadata implements Writeable { public static final BytesRef UNAVAILABLE_WRITER_UUID = new BytesRef(); - private static final org.elasticsearch.Version WRITER_UUID_MIN_VERSION = org.elasticsearch.Version.V_7_16_0; + private static final TransportVersion WRITER_UUID_MIN_VERSION = TransportVersion.V_7_16_0; private final String name; @@ -68,7 +69,7 @@ public StoreFileMetadata(StreamInput in) throws IOException { checksum = in.readString(); writtenBy = in.readString(); hash = in.readBytesRef(); - if (in.getVersion().onOrAfter(WRITER_UUID_MIN_VERSION)) { + if (in.getTransportVersion().onOrAfter(WRITER_UUID_MIN_VERSION)) { writerUuid = StoreFileMetadata.toWriterUuid(in.readBytesRef()); } else { writerUuid = UNAVAILABLE_WRITER_UUID; @@ -82,7 +83,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeString(checksum); out.writeString(writtenBy); out.writeBytesRef(hash); - if (out.getVersion().onOrAfter(WRITER_UUID_MIN_VERSION)) { + if (out.getTransportVersion().onOrAfter(WRITER_UUID_MIN_VERSION)) { out.writeBytesRef(writerUuid); } } diff --git a/server/src/main/java/org/elasticsearch/index/store/StoreStats.java b/server/src/main/java/org/elasticsearch/index/store/StoreStats.java index e73f8df40ffe4..0820f859355ae 100644 --- a/server/src/main/java/org/elasticsearch/index/store/StoreStats.java +++ b/server/src/main/java/org/elasticsearch/index/store/StoreStats.java @@ -8,7 +8,7 @@ package org.elasticsearch.index.store; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -27,8 +27,8 @@ public class StoreStats implements Writeable, ToXContentFragment { */ public static final long UNKNOWN_RESERVED_BYTES = -1L; - public static final Version RESERVED_BYTES_VERSION = Version.V_7_9_0; - public static final Version TOTAL_DATA_SET_SIZE_SIZE_VERSION = Version.V_7_13_0; + public static final TransportVersion RESERVED_BYTES_VERSION = TransportVersion.V_7_9_0; + public static final TransportVersion TOTAL_DATA_SET_SIZE_SIZE_VERSION = TransportVersion.V_7_13_0; private long sizeInBytes; private long totalDataSetSizeInBytes; @@ -40,12 +40,12 @@ public StoreStats() { public StoreStats(StreamInput in) throws IOException { sizeInBytes = in.readVLong(); - if (in.getVersion().onOrAfter(TOTAL_DATA_SET_SIZE_SIZE_VERSION)) { + if (in.getTransportVersion().onOrAfter(TOTAL_DATA_SET_SIZE_SIZE_VERSION)) { totalDataSetSizeInBytes = in.readVLong(); } else { totalDataSetSizeInBytes = sizeInBytes; } - if (in.getVersion().onOrAfter(RESERVED_BYTES_VERSION)) { + if (in.getTransportVersion().onOrAfter(RESERVED_BYTES_VERSION)) { reservedSize = in.readZLong(); } else { reservedSize = UNKNOWN_RESERVED_BYTES; @@ -118,10 +118,10 @@ public ByteSizeValue getReservedSize() { @Override public void writeTo(StreamOutput out) throws IOException { out.writeVLong(sizeInBytes); - if (out.getVersion().onOrAfter(TOTAL_DATA_SET_SIZE_SIZE_VERSION)) { + if (out.getTransportVersion().onOrAfter(TOTAL_DATA_SET_SIZE_SIZE_VERSION)) { out.writeVLong(totalDataSetSizeInBytes); } - if (out.getVersion().onOrAfter(RESERVED_BYTES_VERSION)) { + if (out.getTransportVersion().onOrAfter(RESERVED_BYTES_VERSION)) { out.writeZLong(reservedSize); } } diff --git a/server/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java b/server/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java index cd3db9e4478b9..43e32ba0b0e10 100644 --- a/server/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java +++ b/server/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java @@ -8,7 +8,7 @@ package org.elasticsearch.indices; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.action.admin.indices.stats.CommonStats; import org.elasticsearch.action.admin.indices.stats.IndexShardStats; import org.elasticsearch.action.admin.indices.stats.ShardStats; @@ -51,7 +51,7 @@ */ public class NodeIndicesStats implements Writeable, ToXContentFragment { - private static final Version VERSION_SUPPORTING_STATS_BY_INDEX = Version.V_8_5_0; + private static final TransportVersion VERSION_SUPPORTING_STATS_BY_INDEX = TransportVersion.V_8_5_0; private final CommonStats stats; private final Map> statsByShard; @@ -72,7 +72,7 @@ public NodeIndicesStats(StreamInput in) throws IOException { statsByShard.put(index, indexShardStats); } - if (in.getVersion().onOrAfter(VERSION_SUPPORTING_STATS_BY_INDEX)) { + if (in.getTransportVersion().onOrAfter(VERSION_SUPPORTING_STATS_BY_INDEX)) { statsByIndex = in.readMap(Index::new, CommonStats::new); } else { statsByIndex = new HashMap<>(); @@ -196,7 +196,7 @@ public NodeMappingStats getNodeMappingStats() { public void writeTo(StreamOutput out) throws IOException { stats.writeTo(out); out.writeMap(statsByShard, (o, k) -> k.writeTo(o), StreamOutput::writeList); - if (out.getVersion().onOrAfter(VERSION_SUPPORTING_STATS_BY_INDEX)) { + if (out.getTransportVersion().onOrAfter(VERSION_SUPPORTING_STATS_BY_INDEX)) { out.writeMap(statsByIndex, (o, k) -> k.writeTo(o), (o, v) -> v.writeTo(o)); } } diff --git a/server/src/main/java/org/elasticsearch/indices/TermsLookup.java b/server/src/main/java/org/elasticsearch/indices/TermsLookup.java index 99a1751dd58fd..b18cf552c6451 100644 --- a/server/src/main/java/org/elasticsearch/indices/TermsLookup.java +++ b/server/src/main/java/org/elasticsearch/indices/TermsLookup.java @@ -8,7 +8,7 @@ package org.elasticsearch.indices; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -56,7 +56,7 @@ public TermsLookup(String index, String id, String path) { * Read from a stream. */ public TermsLookup(StreamInput in) throws IOException { - if (in.getVersion().before(Version.V_8_0_0)) { + if (in.getTransportVersion().before(TransportVersion.V_8_0_0)) { in.readOptionalString(); } id = in.readString(); @@ -67,7 +67,7 @@ public TermsLookup(StreamInput in) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException { - if (out.getVersion().before(Version.V_8_0_0)) { + if (out.getTransportVersion().before(TransportVersion.V_8_0_0)) { out.writeOptionalString(MapperService.SINGLE_MAPPING_NAME); } out.writeString(id); diff --git a/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java b/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java index e433cd21b4c96..8915665ead84e 100644 --- a/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java +++ b/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java @@ -12,6 +12,7 @@ import org.apache.logging.log4j.Logger; import org.apache.lucene.store.RateLimiter; import org.apache.lucene.store.RateLimiter.SimpleRateLimiter; +import org.elasticsearch.TransportVersion; import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; @@ -44,7 +45,7 @@ public class RecoverySettings { public static final Version SNAPSHOT_RECOVERIES_SUPPORTED_VERSION = Version.V_7_15_0; public static final Version SEQ_NO_SNAPSHOT_RECOVERIES_SUPPORTED_VERSION = Version.V_7_16_0; - public static final Version SNAPSHOT_FILE_DOWNLOAD_THROTTLING_SUPPORTED_VERSION = Version.V_7_16_0; + public static final TransportVersion SNAPSHOT_FILE_DOWNLOAD_THROTTLING_SUPPORTED_VERSION = TransportVersion.V_7_16_0; private static final Logger logger = LogManager.getLogger(RecoverySettings.class); diff --git a/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java b/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java index 6f7eee079e41c..dfa726a42cb68 100644 --- a/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java +++ b/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java @@ -631,7 +631,7 @@ public FileDetail(StreamInput in) throws IOException { length = in.readVLong(); recovered = in.readVLong(); reused = in.readBoolean(); - if (in.getVersion().onOrAfter(RecoverySettings.SNAPSHOT_RECOVERIES_SUPPORTED_VERSION)) { + if (in.getTransportVersion().onOrAfter(RecoverySettings.SNAPSHOT_RECOVERIES_SUPPORTED_VERSION.transportVersion)) { recoveredFromSnapshot = in.readLong(); } } @@ -642,7 +642,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeVLong(length); out.writeVLong(recovered); out.writeBoolean(reused); - if (out.getVersion().onOrAfter(RecoverySettings.SNAPSHOT_RECOVERIES_SUPPORTED_VERSION)) { + if (out.getTransportVersion().onOrAfter(RecoverySettings.SNAPSHOT_RECOVERIES_SUPPORTED_VERSION.transportVersion)) { out.writeLong(recoveredFromSnapshot); } } @@ -769,7 +769,7 @@ public RecoveryFilesDetails() { RecoveryFilesDetails(StreamInput in) throws IOException { fileDetails = in.readMapValues(FileDetail::new, FileDetail::name); - if (in.getVersion().onOrAfter(StoreStats.RESERVED_BYTES_VERSION)) { + if (in.getTransportVersion().onOrAfter(StoreStats.RESERVED_BYTES_VERSION)) { complete = in.readBoolean(); } else { // This flag is used by disk-based allocation to decide whether the remaining bytes measurement is accurate or not; if not @@ -783,7 +783,7 @@ public RecoveryFilesDetails() { @Override public void writeTo(StreamOutput out) throws IOException { out.writeCollection(values()); - if (out.getVersion().onOrAfter(StoreStats.RESERVED_BYTES_VERSION)) { + if (out.getTransportVersion().onOrAfter(StoreStats.RESERVED_BYTES_VERSION)) { out.writeBoolean(complete); } } diff --git a/server/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java b/server/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java index a19388ca26126..a60ae14263a31 100644 --- a/server/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java +++ b/server/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java @@ -43,7 +43,7 @@ public StartRecoveryRequest(StreamInput in) throws IOException { metadataSnapshot = Store.MetadataSnapshot.readFrom(in); primaryRelocation = in.readBoolean(); startingSeqNo = in.readLong(); - if (in.getVersion().onOrAfter(RecoverySettings.SNAPSHOT_FILE_DOWNLOAD_THROTTLING_SUPPORTED_VERSION)) { + if (in.getTransportVersion().onOrAfter(RecoverySettings.SNAPSHOT_FILE_DOWNLOAD_THROTTLING_SUPPORTED_VERSION)) { canDownloadSnapshotFiles = in.readBoolean(); } else { canDownloadSnapshotFiles = true; @@ -134,7 +134,7 @@ public void writeTo(StreamOutput out) throws IOException { metadataSnapshot.writeTo(out); out.writeBoolean(primaryRelocation); out.writeLong(startingSeqNo); - if (out.getVersion().onOrAfter(RecoverySettings.SNAPSHOT_FILE_DOWNLOAD_THROTTLING_SUPPORTED_VERSION)) { + if (out.getTransportVersion().onOrAfter(RecoverySettings.SNAPSHOT_FILE_DOWNLOAD_THROTTLING_SUPPORTED_VERSION)) { out.writeBoolean(canDownloadSnapshotFiles); } } diff --git a/server/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetadata.java b/server/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetadata.java index 1da1aeae64844..49fee0a5c6820 100644 --- a/server/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetadata.java +++ b/server/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetadata.java @@ -9,7 +9,7 @@ package org.elasticsearch.indices.store; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.Version; +import org.elasticsearch.TransportVersion; import org.elasticsearch.action.ActionType; import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.support.ActionFilters; @@ -200,7 +200,7 @@ public record StoreFilesMetadata(Store.MetadataSnapshot metadataSnapshot, List