Skip to content

Commit

Permalink
add support for onCancel and Cancellable for BatchedJob in lib:arrow …
Browse files Browse the repository at this point in the history
…module

Signed-off-by: Rishabh Maurya <[email protected]>
  • Loading branch information
rishabhmaurya committed Nov 20, 2024
1 parent d053e4a commit b7612f6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions libs/arrow/src/main/java/org/opensearch/arrow/StreamProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.opensearch.common.annotation.ExperimentalApi;
import org.opensearch.core.tasks.TaskId;

import java.io.Closeable;

/**
* Represents a producer of Arrow streams. The producer first needs to define the job by implementing this interface and
* then register the job with the {@link StreamManager#registerStream(StreamProducer, TaskId)}, which will return {@link StreamTicket}
Expand Down Expand Up @@ -75,7 +77,7 @@
* @see StreamIterator
*/
@ExperimentalApi
public interface StreamProducer {
public interface StreamProducer extends Closeable {

/**
* Creates a VectorSchemaRoot that defines the schema for this stream. This schema will be used
Expand Down Expand Up @@ -127,13 +129,21 @@ interface BatchedJob {
void run(VectorSchemaRoot root, FlushSignal flushSignal);

/**
* Called when the job is canceled.
* Called to signal producer when the job is canceled.
* This method is used to clean up resources or cancel ongoing operations.
* This maybe called from a different thread than the one used for run(). It might be possible that run()
* thread is busy when onCancel() is called and wakes up later. In such cases, ensure that run() terminates early
* and should clean up resources.
*/
void onCancel();

/**
* Producers can set isCancelled flag to true to indicate that the job is canceled.
* This will ensure the stream is closed and no more data is produced from next Batch onwards.
*
* @return true if the job is canceled, false otherwise
*/
boolean isCancelled();
}

/**
Expand Down

0 comments on commit b7612f6

Please sign in to comment.