clintropolis commented on code in PR #19397: URL: https://github.com/apache/druid/pull/19397#discussion_r3205086129
########## processing/src/main/java/org/apache/druid/segment/AsyncCursorHolder.java: ########## @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.segment; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import org.apache.druid.common.guava.FutureUtils; + +import java.io.Closeable; + +/** + * Closeable wrapper around an asynchronously-loaded {@link CursorHolder}, returned by + * {@link CursorFactory#makeCursorHolderAsync}. Designed to make lifecycle management safe even when the holder is + * still loading: callers receive a single Closeable handle and can register it once with their cleanup machinery, + * regardless of where the underlying load is in its lifecycle. + * <p> + * The hazard this exists to avoid: returning a {@code ListenableFuture<CursorHolder>} (or similar future-of-Closeable) + * makes correct cleanup error-prone, where cancelling the future or letting a caller fail before consuming the future + * can orphan the produced holder, leaking the underlying resources. By exposing a Closeable that internally tracks the + * load and disposes whatever has materialized, callers don't have to write that bookkeeping themselves. + * <p> + * Typical usage from a non-blocking caller (e.g. an MSQ frame processor): Review Comment: The example code got a bit weird trying to get rid of `ReturnOrAwait`, so instead of tried to frame it that the example is using 'ReturnOrAwait' to show how you're supposed to use this thing, since the important part is the yield-then-resume when ready pattern, which i think makes it feel less like this is a thing for MSQ than the last iteration did? -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
