Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rolling version upgrade support for ignore_unmapped #1770

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/org/opensearch/knn/index/IndexUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ public static boolean isVersionOnOrAfterMinRequiredVersion(Version version, Stri
return version.onOrAfter(minimalRequiredVersion);
}

/**
* Returns the min version required for feature support
*
* @param feature The name of the feature
* @return Min OpenSearch version required for the feature support
*/
public static Version getMinVersionForFeature(String feature) {
return minimalRequiredVersionMap.get(feature);
}

/**
* Checks if index requires shared state
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Objects;

import lombok.extern.log4j.Log4j2;

import org.apache.lucene.search.MatchNoDocsQuery;
import org.opensearch.core.common.Strings;
import org.opensearch.index.mapper.NumberFieldMapper;
Expand Down Expand Up @@ -40,6 +41,7 @@
import static org.opensearch.knn.common.KNNConstants.MAX_DISTANCE;
import static org.opensearch.knn.common.KNNConstants.MIN_SCORE;
import static org.opensearch.knn.common.KNNValidationUtil.validateByteVectorValue;
import static org.opensearch.knn.index.IndexUtil.getMinVersionForFeature;
import static org.opensearch.knn.index.IndexUtil.isClusterOnOrAfterMinRequiredVersion;
import static org.opensearch.knn.index.util.KNNEngine.ENGINES_SUPPORTING_RADIAL_SEARCH;

Expand Down Expand Up @@ -216,7 +218,7 @@ public KNNQueryBuilder(StreamInput in) throws IOException {
vector = in.readFloatArray();
k = in.readInt();
filter = in.readOptionalNamedWriteable(QueryBuilder.class);
if (isClusterOnOrAfterMinRequiredVersion("ignore_unmapped")) {
if (in.getVersion().onOrAfter(getMinVersionForFeature("ignore_unmapped"))) {
ignoreUnmapped = in.readOptionalBoolean();
}
if (isClusterOnOrAfterMinRequiredVersion(KNNConstants.RADIAL_SEARCH_KEY)) {
Expand Down Expand Up @@ -324,7 +326,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
out.writeFloatArray(vector);
out.writeInt(k);
out.writeOptionalNamedWriteable(filter);
if (isClusterOnOrAfterMinRequiredVersion("ignore_unmapped")) {
if (out.getVersion().onOrAfter(getMinVersionForFeature("ignore_unmapped"))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this stream guarantee the min version of the cluster. Just verifying since the previous method has that check

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a historical reason that we look for the cluster version and not the stream version?
It should behave the same - a feature is on only when both the nodes are upgraded.

@jmazanec15 / @navneet1v

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't serialized the stream version when we write KNNQueryBuilder at first. Therefore, we were not able to use stream version. After that, we haven't tried to add stream version because cluster version just worked fine for us.

out.writeOptionalBoolean(ignoreUnmapped);
}
if (isClusterOnOrAfterMinRequiredVersion(KNNConstants.RADIAL_SEARCH_KEY)) {
Expand Down
Loading