Skip to content

Commit

Permalink
add patch version
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkyle committed Oct 10, 2023
1 parent 29fa10a commit 9562fec
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ static TransportVersion def(int id) {
public static final TransportVersion NODE_INFO_REQUEST_SIMPLIFIED = def(8_510_00_0);
public static final TransportVersion NESTED_KNN_VECTOR_QUERY_V = def(8_511_00_0);
public static final TransportVersion ML_PACKAGE_LOADER_PLATFORM_ADDED = def(8_512_00_0);
public static final TransportVersion ELSER_SERVICE_MODEL_VERSION_ADDED_PATCH = def(8_512_00_1);
public static final TransportVersion PLUGIN_DESCRIPTOR_OPTIONAL_CLASSNAME = def(8_513_00_0);
public static final TransportVersion UNIVERSAL_PROFILING_LICENSE_ADDED = def(8_514_00_0);
public static final TransportVersion ELSER_SERVICE_MODEL_VERSION_ADDED = def(8_515_00_0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,21 @@ public ElserMlNodeServiceSettings(int numAllocations, int numThreads, String var
public ElserMlNodeServiceSettings(StreamInput in) throws IOException {
numAllocations = in.readVInt();
numThreads = in.readVInt();
if (in.getTransportVersion().onOrAfter(TransportVersions.ELSER_SERVICE_MODEL_VERSION_ADDED)) {
if (transportVersionIsCompatibleWithElserModelVersion(in.getTransportVersion())) {
modelVariant = in.readString();
} else {
modelVariant = ElserMlNodeService.ELSER_V1_MODEL;
modelVariant = ElserMlNodeService.ELSER_V2_MODEL;
}
}

static boolean transportVersionIsCompatibleWithElserModelVersion(TransportVersion transportVersion) {
var nextNonPatchVersion = TransportVersions.PLUGIN_DESCRIPTOR_OPTIONAL_CLASSNAME;

if (transportVersion.onOrAfter(TransportVersions.ELSER_SERVICE_MODEL_VERSION_ADDED)) {
return true;
} else {
return transportVersion.onOrAfter(TransportVersions.ELSER_SERVICE_MODEL_VERSION_ADDED_PATCH)
&& transportVersion.before(nextNonPatchVersion);
}
}

Expand Down Expand Up @@ -130,7 +141,7 @@ public TransportVersion getMinimalSupportedVersion() {
public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(numAllocations);
out.writeVInt(numThreads);
if (out.getTransportVersion().onOrAfter(TransportVersions.ELSER_SERVICE_MODEL_VERSION_ADDED)) {
if (transportVersionIsCompatibleWithElserModelVersion(out.getTransportVersion())) {
out.writeString(modelVariant);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package org.elasticsearch.xpack.inference.services.elser;

import org.elasticsearch.TransportVersions;
import org.elasticsearch.common.ValidationException;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.test.AbstractWireSerializingTestCase;
Expand Down Expand Up @@ -85,6 +86,33 @@ public void testFromMapMissingOptions() {
assertThat(e.getMessage(), containsString("[service_settings] does not contain the required setting [num_allocations]"));
}

public void testTransportVersionIsCompatibleWithElserModelVersion() {
assertTrue(
ElserMlNodeServiceSettings.transportVersionIsCompatibleWithElserModelVersion(
TransportVersions.ELSER_SERVICE_MODEL_VERSION_ADDED
)
);
assertTrue(
ElserMlNodeServiceSettings.transportVersionIsCompatibleWithElserModelVersion(
TransportVersions.ELSER_SERVICE_MODEL_VERSION_ADDED_PATCH
)
);

assertFalse(
ElserMlNodeServiceSettings.transportVersionIsCompatibleWithElserModelVersion(TransportVersions.ML_PACKAGE_LOADER_PLATFORM_ADDED)
);
assertFalse(
ElserMlNodeServiceSettings.transportVersionIsCompatibleWithElserModelVersion(
TransportVersions.PLUGIN_DESCRIPTOR_OPTIONAL_CLASSNAME
)
);
assertFalse(
ElserMlNodeServiceSettings.transportVersionIsCompatibleWithElserModelVersion(
TransportVersions.UNIVERSAL_PROFILING_LICENSE_ADDED
)
);
}

public void testFromMapInvalidSettings() {
var settingsMap = new HashMap<String, Object>(
Map.of(ElserMlNodeServiceSettings.NUM_ALLOCATIONS, 0, ElserMlNodeServiceSettings.NUM_THREADS, -1)
Expand Down

0 comments on commit 9562fec

Please sign in to comment.