浏览代码

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.
Lorenzo Dematté 6 月之前
父节点
当前提交
b692d1a14e
共有 1 个文件被更改,包括 16 次插入5 次删除
  1. 16 5
      server/src/main/java/org/elasticsearch/ElasticsearchException.java

+ 16 - 5
server/src/main/java/org/elasticsearch/ElasticsearchException.java

@@ -353,7 +353,8 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
     public static boolean isRegistered(Class<? extends Throwable> exception, TransportVersion version) {
         ElasticsearchExceptionHandle elasticsearchExceptionHandle = CLASS_TO_ELASTICSEARCH_EXCEPTION_HANDLE.get(exception);
         if (elasticsearchExceptionHandle != null) {
-            return version.onOrAfter(elasticsearchExceptionHandle.versionAdded);
+            return version.onOrAfter(elasticsearchExceptionHandle.versionAdded)
+                || Arrays.stream(elasticsearchExceptionHandle.patchVersions).anyMatch(version::isPatchFrom);
         }
         return false;
     }
@@ -1983,24 +1984,34 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
             183,
             TransportVersions.V_8_16_0
         ),
-        REMOTE_EXCEPTION(RemoteException.class, RemoteException::new, 184, TransportVersions.REMOTE_EXCEPTION);
+        REMOTE_EXCEPTION(
+            RemoteException.class,
+            RemoteException::new,
+            184,
+            TransportVersions.REMOTE_EXCEPTION,
+            TransportVersions.REMOTE_EXCEPTION_8_19
+        );
 
         final Class<? extends ElasticsearchException> exceptionClass;
         final CheckedFunction<StreamInput, ? extends ElasticsearchException, IOException> constructor;
         final int id;
-        final TransportVersion versionAdded;
+        private final TransportVersion versionAdded;
+        private final TransportVersion[] patchVersions;
 
         <E extends ElasticsearchException> ElasticsearchExceptionHandle(
             Class<E> exceptionClass,
             CheckedFunction<StreamInput, E, IOException> constructor,
             int id,
-            TransportVersion versionAdded
+            TransportVersion versionAdded,
+            TransportVersion... patchVersions
         ) {
             // We need the exceptionClass because you can't dig it out of the constructor reliably.
             this.exceptionClass = exceptionClass;
             this.constructor = constructor;
-            this.versionAdded = versionAdded;
+
             this.id = id;
+            this.versionAdded = versionAdded;
+            this.patchVersions = patchVersions;
         }
     }