zhuzhurk commented on code in PR #22506:
URL: https://github.com/apache/flink/pull/22506#discussion_r1192155460
##########
flink-core/src/main/java/org/apache/flink/util/concurrent/FutureUtils.java:
##########
@@ -1289,4 +1293,59 @@ public static <T> CompletableFuture<T> switchExecutor(
},
executor);
}
+
+ /**
+ * A serializable implementation of CompletableFuture.
+ *
+ * <p>This class extends CompletableFuture and implements the Serializable
interface to allow it
+ * to be serialized and deserialized. The result of the CompletableFuture
is extracted and
+ * serialized when the object is written to a stream, and the result is
set using the complete()
+ * method when the object is read from a stream.
+ *
+ * @param <T> the type of the result of the CompletableFuture
+ */
+ public static class SerializableCompletableFuture<T> extends
CompletableFuture<T>
+ implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private transient T result;
+
+ public SerializableCompletableFuture(T value) {
+ this.result = value;
+ this.complete(value);
+ }
+
+ /**
+ * Writes this object to the given OutputStream. The result of the
CompletableFuture is
+ * extracted and serialized along with the object.
+ *
+ * @param out the ObjectOutputStream to write to
+ * @throws IOException if an I/O error occurs
+ */
+ private void writeObject(ObjectOutputStream out)
+ throws IOException, ExecutionException, InterruptedException {
+ out.defaultWriteObject();
+ if (result == null) {
+ result = this.get();
Review Comment:
This `get()` is possible to block the main thread. Maybe we do not need to
introduce a `SerializableCompletableFuture`, but instead modify the ErrorInfo
to achieve the goal. e.g.
* introduce two fields to ErrorInfo: `transient
CompletableFuture<Map<String, String>> labelsFuture` as well as a `Map<String,
String> labels`
* the `labels` will be set as soon as `labelsFuture` is completed
* `ErrorInfo#getLabels()` returns a `Map<String, String>`, which can be
empty if `labels` is null and `labelsFuture` is not completed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]