Skip to content

Commit 8167a8f

Browse files
authored
Add support for a custom transport version check predicate in ElasticsearchException (#126272) (#126520)
Today when we are adding a ElasticsearchException, we specify a versionAdded TransportVersion (the transport version from which we support it); this version is checked by the isRegistered method: return version.onOrAfter(elasticsearchExceptionHandle.versionAdded); This does not play well with backports; when we add a patch version for a backport, normally the procedure would be to change the code above take also the patch into account, like: version.orOnAfter(versionAdded) || version.isPatchFrom(versionPatched) This PR updates ElasticsearchException to have more than just "version added", so that we can do patches as described above.
1 parent 963a0a4 commit 8167a8f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

server/src/main/java/org/elasticsearch/ElasticsearchException.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ public static ElasticsearchException readException(StreamInput input, int id) th
352352
public static boolean isRegistered(Class<? extends Throwable> exception, TransportVersion version) {
353353
ElasticsearchExceptionHandle elasticsearchExceptionHandle = CLASS_TO_ELASTICSEARCH_EXCEPTION_HANDLE.get(exception);
354354
if (elasticsearchExceptionHandle != null) {
355-
return version.onOrAfter(elasticsearchExceptionHandle.versionAdded);
355+
return version.onOrAfter(elasticsearchExceptionHandle.versionAdded)
356+
|| Arrays.stream(elasticsearchExceptionHandle.patchVersions).anyMatch(version::isPatchFrom);
356357
}
357358
return false;
358359
}
@@ -1986,19 +1987,23 @@ private enum ElasticsearchExceptionHandle {
19861987
final Class<? extends ElasticsearchException> exceptionClass;
19871988
final CheckedFunction<StreamInput, ? extends ElasticsearchException, IOException> constructor;
19881989
final int id;
1989-
final TransportVersion versionAdded;
1990+
private final TransportVersion versionAdded;
1991+
private final TransportVersion[] patchVersions;
19901992

19911993
<E extends ElasticsearchException> ElasticsearchExceptionHandle(
19921994
Class<E> exceptionClass,
19931995
CheckedFunction<StreamInput, E, IOException> constructor,
19941996
int id,
1995-
TransportVersion versionAdded
1997+
TransportVersion versionAdded,
1998+
TransportVersion... patchVersions
19961999
) {
19972000
// We need the exceptionClass because you can't dig it out of the constructor reliably.
19982001
this.exceptionClass = exceptionClass;
19992002
this.constructor = constructor;
2000-
this.versionAdded = versionAdded;
2003+
20012004
this.id = id;
2005+
this.versionAdded = versionAdded;
2006+
this.patchVersions = patchVersions;
20022007
}
20032008
}
20042009

0 commit comments

Comments
 (0)