Skip to content

Commit b692d1a

Browse files
authored
Add support for a custom transport version check predicate in ElasticsearchException (#126272)
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 26ae289 commit b692d1a

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ public static ElasticsearchException readException(StreamInput input, int id) th
353353
public static boolean isRegistered(Class<? extends Throwable> exception, TransportVersion version) {
354354
ElasticsearchExceptionHandle elasticsearchExceptionHandle = CLASS_TO_ELASTICSEARCH_EXCEPTION_HANDLE.get(exception);
355355
if (elasticsearchExceptionHandle != null) {
356-
return version.onOrAfter(elasticsearchExceptionHandle.versionAdded);
356+
return version.onOrAfter(elasticsearchExceptionHandle.versionAdded)
357+
|| Arrays.stream(elasticsearchExceptionHandle.patchVersions).anyMatch(version::isPatchFrom);
357358
}
358359
return false;
359360
}
@@ -1983,24 +1984,34 @@ private enum ElasticsearchExceptionHandle {
19831984
183,
19841985
TransportVersions.V_8_16_0
19851986
),
1986-
REMOTE_EXCEPTION(RemoteException.class, RemoteException::new, 184, TransportVersions.REMOTE_EXCEPTION);
1987+
REMOTE_EXCEPTION(
1988+
RemoteException.class,
1989+
RemoteException::new,
1990+
184,
1991+
TransportVersions.REMOTE_EXCEPTION,
1992+
TransportVersions.REMOTE_EXCEPTION_8_19
1993+
);
19871994

19881995
final Class<? extends ElasticsearchException> exceptionClass;
19891996
final CheckedFunction<StreamInput, ? extends ElasticsearchException, IOException> constructor;
19901997
final int id;
1991-
final TransportVersion versionAdded;
1998+
private final TransportVersion versionAdded;
1999+
private final TransportVersion[] patchVersions;
19922000

19932001
<E extends ElasticsearchException> ElasticsearchExceptionHandle(
19942002
Class<E> exceptionClass,
19952003
CheckedFunction<StreamInput, E, IOException> constructor,
19962004
int id,
1997-
TransportVersion versionAdded
2005+
TransportVersion versionAdded,
2006+
TransportVersion... patchVersions
19982007
) {
19992008
// We need the exceptionClass because you can't dig it out of the constructor reliably.
20002009
this.exceptionClass = exceptionClass;
20012010
this.constructor = constructor;
2002-
this.versionAdded = versionAdded;
2011+
20032012
this.id = id;
2013+
this.versionAdded = versionAdded;
2014+
this.patchVersions = patchVersions;
20042015
}
20052016
}
20062017

0 commit comments

Comments
 (0)