private static boolean supportsAbortedFlag(Version version) { // The "aborted" flag was added for 5.5.3 and 5.6.0, but was not in 6.0.0-beta2 return version.after(Version.V_6_0_0_beta2) || (version.major == 5 && version.onOrAfter(Version.V_5_5_3)); }
/** * Returns the minimum compatible version based on the current * version. Ie a node needs to have at least the return version in order * to communicate with a node running the current version. The returned version * is in most of the cases the smallest major version release unless the current version * is a beta or RC release then the version itself is returned. */ public Version minimumCompatibilityVersion() { if (major >= 6) { // all major versions from 6 onwards are compatible with last minor series of the previous major Version bwcVersion = null; for (int i = DeclaredVersionsHolder.DECLARED_VERSIONS.size() - 1; i >= 0; i--) { final Version candidateVersion = DeclaredVersionsHolder.DECLARED_VERSIONS.get(i); if (candidateVersion.major == major - 1 && candidateVersion.isRelease() && after(candidateVersion)) { if (bwcVersion != null && candidateVersion.minor < bwcVersion.minor) { break; } bwcVersion = candidateVersion; } } return bwcVersion == null ? this : bwcVersion; } return Version.min(this, fromId((int) major * 1000000 + 0 * 10000 + 99)); }
@Override public void writeTo(StreamOutput out) throws IOException { if (out.getVersion().before(Version.V_6_0_0_alpha1)) { out.writeShort((short)1); // this maps to InetSocketTransportAddress in 5.x } byte[] bytes = address.getAddress().getAddress(); // 4 bytes (IPv4) or 16 bytes (IPv6) out.writeByte((byte) bytes.length); // 1 byte out.write(bytes, 0, bytes.length); if (out.getVersion().after(Version.V_5_0_2)) { out.writeString(address.getHostString()); } // don't serialize scope ids over the network!!!! // these only make sense with respect to the local machine, and will only formulate // the address incorrectly remotely. out.writeInt(address.getPort()); }
/** * Read from a stream and use the {@code hostString} when creating the InetAddress if the input comes from a version on or prior * {@link Version#V_5_0_2} as the hostString was not serialized */ public TransportAddress(StreamInput in, @Nullable String hostString) throws IOException { if (in.getVersion().before(Version.V_6_0_0_alpha1)) { // bwc layer for 5.x where we had more than one transport address final short i = in.readShort(); if(i != 1) { // we fail hard to ensure nobody tries to use some custom transport address impl even if that is difficult to add throw new AssertionError("illegal transport ID from node of version: " + in.getVersion() + " got: " + i + " expected: 1"); } } final int len = in.readByte(); final byte[] a = new byte[len]; // 4 bytes (IPv4) or 16 bytes (IPv6) in.readFully(a); final InetAddress inetAddress; if (in.getVersion().after(Version.V_5_0_2)) { String host = in.readString(); // the host string was serialized so we can ignore the passed in version inetAddress = InetAddress.getByAddress(host, a); } else { // prior to this version, we did not serialize the host string so we used the passed in version inetAddress = InetAddress.getByAddress(hostString, a); } int port = in.readInt(); this.address = new InetSocketAddress(inetAddress, port); }
this.hostName = in.readString().intern(); this.hostAddress = in.readString().intern(); if (in.getVersion().after(Version.V_5_0_2)) { this.address = new TransportAddress(in); } else {
/** * Ensures that all indices are compatible with the given node version. This will ensure that all indices in the given metadata * will not be created with a newer version of elasticsearch as well as that all indices are newer or equal to the minimum index * compatibility version. * @see Version#minimumIndexCompatibilityVersion() * @throws IllegalStateException if any index is incompatible with the given version */ static void ensureIndexCompatibility(final Version nodeVersion, MetaData metaData) { Version supportedIndexVersion = nodeVersion.minimumIndexCompatibilityVersion(); // we ensure that all indices in the cluster we join are compatible with us no matter if they are // closed or not we can't read mappings of these indices so we need to reject the join... for (IndexMetaData idxMetaData : metaData) { if (idxMetaData.getCreationVersion().after(nodeVersion)) { throw new IllegalStateException("index " + idxMetaData.getIndex() + " version not supported: " + idxMetaData.getCreationVersion() + " the node version is: " + nodeVersion); } if (idxMetaData.getCreationVersion().before(supportedIndexVersion)) { throw new IllegalStateException("index " + idxMetaData.getIndex() + " version not supported: " + idxMetaData.getCreationVersion() + " minimum compatible index version is: " + supportedIndexVersion); } } }
if (result.upgradeVersion().after(versionTuple.v1())) { version = result.upgradeVersion();
private static boolean supportsAbortedFlag(Version version) { // The "aborted" flag was added for 5.5.3 and 5.6.0, but was not in 6.0.0-beta2 return version.after(Version.V_6_0_0_beta2) || (version.major == 5 && version.onOrAfter(Version.V_5_5_3)); }
private static boolean supportsAbortedFlag(Version version) { // The "aborted" flag was added for 5.5.3 and 5.6.0, but was not in 6.0.0-beta2 return version.after(Version.V_6_0_0_beta2) || (version.major == 5 && version.onOrAfter(Version.V_5_5_3)); }
@Override public void writeTo(StreamOutput out) throws IOException { byte[] bytes = address().getAddress().getAddress(); // 4 bytes (IPv4) or 16 bytes (IPv6) out.writeByte((byte) bytes.length); // 1 byte out.write(bytes, 0, bytes.length); if (out.getVersion().after(Version.V_5_0_2)) { out.writeString(address.getHostString()); } // don't serialize scope ids over the network!!!! // these only make sense with respect to the local machine, and will only formulate // the address incorrectly remotely. out.writeInt(address.getPort()); }
/** * Returns the minimum compatible version based on the current * version. Ie a node needs to have at least the return version in order * to communicate with a node running the current version. The returned version * is in most of the cases the smallest major version release unless the current version * is a beta or RC release then the version itself is returned. */ public Version minimumCompatibilityVersion() { if (major >= 6) { // all major versions from 6 onwards are compatible with last minor series of the previous major Version bwcVersion = null; for (int i = DeclaredVersionsHolder.DECLARED_VERSIONS.size() - 1; i >= 0; i--) { final Version candidateVersion = DeclaredVersionsHolder.DECLARED_VERSIONS.get(i); if (candidateVersion.major == major - 1 && candidateVersion.isRelease() && after(candidateVersion)) { if (bwcVersion != null && candidateVersion.minor < bwcVersion.minor) { break; } bwcVersion = candidateVersion; } } return bwcVersion == null ? this : bwcVersion; } return Version.min(this, fromId((int) major * 1000000 + 0 * 10000 + 99)); }
/** * Read from a stream and use the {@code hostString} when creating the InetAddress if the input comes from a version on or prior * {@link Version#V_5_0_2} as the hostString was not serialized */ public InetSocketTransportAddress(StreamInput in, String hostString) throws IOException { final int len = in.readByte(); final byte[] a = new byte[len]; // 4 bytes (IPv4) or 16 bytes (IPv6) in.readFully(a); final InetAddress inetAddress; if (in.getVersion().after(Version.V_5_0_2)) { String host = in.readString(); inetAddress = InetAddress.getByAddress(host, a); // the host string was serialized so we can ignore the passed in value } else { // prior to this version, we did not serialize the host string so we used the passed in value inetAddress = InetAddress.getByAddress(hostString, a); } int port = in.readInt(); this.address = new InetSocketAddress(inetAddress, port); }
@Override public void writeTo(StreamOutput out) throws IOException { if (out.getVersion().before(Version.V_6_0_0_alpha1)) { out.writeShort((short)1); // this maps to InetSocketTransportAddress in 5.x } byte[] bytes = address.getAddress().getAddress(); // 4 bytes (IPv4) or 16 bytes (IPv6) out.writeByte((byte) bytes.length); // 1 byte out.write(bytes, 0, bytes.length); if (out.getVersion().after(Version.V_5_0_2)) { out.writeString(address.getHostString()); } // don't serialize scope ids over the network!!!! // these only make sense with respect to the local machine, and will only formulate // the address incorrectly remotely. out.writeInt(address.getPort()); }
@Override public void writeTo(StreamOutput out) throws IOException { if (out.getVersion().before(Version.V_6_0_0_alpha1)) { out.writeShort((short)1); // this maps to InetSocketTransportAddress in 5.x } byte[] bytes = address.getAddress().getAddress(); // 4 bytes (IPv4) or 16 bytes (IPv6) out.writeByte((byte) bytes.length); // 1 byte out.write(bytes, 0, bytes.length); if (out.getVersion().after(Version.V_5_0_2)) { out.writeString(address.getHostString()); } // don't serialize scope ids over the network!!!! // these only make sense with respect to the local machine, and will only formulate // the address incorrectly remotely. out.writeInt(address.getPort()); }
/** * Read from a stream and use the {@code hostString} when creating the InetAddress if the input comes from a version on or prior * {@link Version#V_5_0_2} as the hostString was not serialized */ public TransportAddress(StreamInput in, @Nullable String hostString) throws IOException { if (in.getVersion().before(Version.V_6_0_0_alpha1)) { // bwc layer for 5.x where we had more than one transport address final short i = in.readShort(); if(i != 1) { // we fail hard to ensure nobody tries to use some custom transport address impl even if that is difficult to add throw new AssertionError("illegal transport ID from node of version: " + in.getVersion() + " got: " + i + " expected: 1"); } } final int len = in.readByte(); final byte[] a = new byte[len]; // 4 bytes (IPv4) or 16 bytes (IPv6) in.readFully(a); final InetAddress inetAddress; if (in.getVersion().after(Version.V_5_0_2)) { String host = in.readString(); // the host string was serialized so we can ignore the passed in version inetAddress = InetAddress.getByAddress(host, a); } else { // prior to this version, we did not serialize the host string so we used the passed in version inetAddress = InetAddress.getByAddress(hostString, a); } int port = in.readInt(); this.address = new InetSocketAddress(inetAddress, port); }
/** * Read from a stream and use the {@code hostString} when creating the InetAddress if the input comes from a version on or prior * {@link Version#V_5_0_2} as the hostString was not serialized */ public TransportAddress(StreamInput in, @Nullable String hostString) throws IOException { if (in.getVersion().before(Version.V_6_0_0_alpha1)) { // bwc layer for 5.x where we had more than one transport address final short i = in.readShort(); if(i != 1) { // we fail hard to ensure nobody tries to use some custom transport address impl even if that is difficult to add throw new AssertionError("illegal transport ID from node of version: " + in.getVersion() + " got: " + i + " expected: 1"); } } final int len = in.readByte(); final byte[] a = new byte[len]; // 4 bytes (IPv4) or 16 bytes (IPv6) in.readFully(a); final InetAddress inetAddress; if (in.getVersion().after(Version.V_5_0_2)) { String host = in.readString(); // the host string was serialized so we can ignore the passed in version inetAddress = InetAddress.getByAddress(host, a); } else { // prior to this version, we did not serialize the host string so we used the passed in version inetAddress = InetAddress.getByAddress(hostString, a); } int port = in.readInt(); this.address = new InetSocketAddress(inetAddress, port); }
/** * Ensures that all indices are compatible with the given node version. This will ensure that all indices in the given metadata * will not be created with a newer version of elasticsearch as well as that all indices are newer or equal to the minimum index * compatibility version. * @see Version#minimumIndexCompatibilityVersion() * @throws IllegalStateException if any index is incompatible with the given version */ static void ensureIndexCompatibility(final Version nodeVersion, MetaData metaData) { Version supportedIndexVersion = nodeVersion.minimumIndexCompatibilityVersion(); // we ensure that all indices in the cluster we join are compatible with us no matter if they are // closed or not we can't read mappings of these indices so we need to reject the join... for (IndexMetaData idxMetaData : metaData) { if (idxMetaData.getCreationVersion().after(nodeVersion)) { throw new IllegalStateException("index " + idxMetaData.getIndex() + " version not supported: " + idxMetaData.getCreationVersion() + " the node version is: " + nodeVersion); } if (idxMetaData.getCreationVersion().before(supportedIndexVersion)) { throw new IllegalStateException("index " + idxMetaData.getIndex() + " version not supported: " + idxMetaData.getCreationVersion() + " minimum compatible index version is: " + supportedIndexVersion); } } }
/** * Ensures that all indices are compatible with the given node version. This will ensure that all indices in the given metadata * will not be created with a newer version of elasticsearch as well as that all indices are newer or equal to the minimum index * compatibility version. * @see Version#minimumIndexCompatibilityVersion() * @throws IllegalStateException if any index is incompatible with the given version */ static void ensureIndexCompatibility(final Version nodeVersion, MetaData metaData) { Version supportedIndexVersion = nodeVersion.minimumIndexCompatibilityVersion(); // we ensure that all indices in the cluster we join are compatible with us no matter if they are // closed or not we can't read mappings of these indices so we need to reject the join... for (IndexMetaData idxMetaData : metaData) { if (idxMetaData.getCreationVersion().after(nodeVersion)) { throw new IllegalStateException("index " + idxMetaData.getIndex() + " version not supported: " + idxMetaData.getCreationVersion() + " the node version is: " + nodeVersion); } if (idxMetaData.getCreationVersion().before(supportedIndexVersion)) { throw new IllegalStateException("index " + idxMetaData.getIndex() + " version not supported: " + idxMetaData.getCreationVersion() + " minimum compatible index version is: " + supportedIndexVersion); } } }
/** * Ensures that all indices are compatible with the given node version. This will ensure that all indices in the given metadata * will not be created with a newer version of elasticsearch as well as that all indices are newer or equal to the minimum index * compatibility version. * @see Version#minimumIndexCompatibilityVersion() * @throws IllegalStateException if any index is incompatible with the given version */ static void ensureIndexCompatibility(final Version nodeVersion, MetaData metaData) { Version supportedIndexVersion = nodeVersion.minimumIndexCompatibilityVersion(); // we ensure that all indices in the cluster we join are compatible with us no matter if they are // closed or not we can't read mappings of these indices so we need to reject the join... for (IndexMetaData idxMetaData : metaData) { if (idxMetaData.getCreationVersion().after(nodeVersion)) { throw new IllegalStateException("index " + idxMetaData.getIndex() + " version not supported: " + idxMetaData.getCreationVersion() + " the node version is: " + nodeVersion); } if (idxMetaData.getCreationVersion().before(supportedIndexVersion)) { throw new IllegalStateException("index " + idxMetaData.getIndex() + " version not supported: " + idxMetaData.getCreationVersion() + " minimum compatible index version is: " + supportedIndexVersion); } } }
public static void assertVersionSerializable(Version version, Streamable streamable) { /* * If possible we fetch the NamedWriteableRegistry from the test cluster. That is the only way to make sure that we properly handle * when plugins register names. If not possible we'll try and set up a registry based on whatever SearchModule registers. But that * is a hack at best - it only covers some things. If you end up with errors below and get to this comment I'm sorry. Please find * a way that sucks less. */ NamedWriteableRegistry registry; if (ESIntegTestCase.isInternalCluster() && ESIntegTestCase.internalCluster().size() > 0) { registry = ESIntegTestCase.internalCluster().getInstance(NamedWriteableRegistry.class); } else { SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList()); registry = new NamedWriteableRegistry(searchModule.getNamedWriteables()); } assertVersionSerializable(version, streamable, registry); }