[ 
https://issues.apache.org/jira/browse/IGNITE-23430?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Maksim Zhuravkov reassigned IGNITE-23430:
-----------------------------------------

    Assignee: Maksim Zhuravkov

> Sql. Provide an ability to cancel query before first page ready
> ---------------------------------------------------------------
>
>                 Key: IGNITE-23430
>                 URL: https://issues.apache.org/jira/browse/IGNITE-23430
>             Project: Ignite
>          Issue Type: Improvement
>          Components: sql
>            Reporter: Konstantin Orlov
>            Assignee: Maksim Zhuravkov
>            Priority: Major
>              Labels: ignite-3
>
> Currently, the only possible way to cancel a query prematurely is by invoking 
> {{cancel()}} on a {{ResultSet}} object. The problem is the result set is 
> returned only when first page is ready. For statements like DML and DDL this 
> means that result set will be returned only when operation is complete.
> Proposed solution is to introduce new pair of entities to public API:
> {code:java}
> /**
>  * A handle which may be used to request the cancellation of execution.
>  */
> public interface CancelHandle {
>     /** A factory method to create a handle. */
>     static CancelHandle create() {}
>     /**
>      * Abruptly terminates an execution of an associated process.
>      *
>      * <p>Control flow will return after the process has been terminated and 
> the resources associated with that process have been freed.
>      */
>     void cancel();
>     /**
>      * Abruptly terminates an execution of a associated process.
>      *
>      * @return A future that will be completed after the process has been 
> terminated and the resources associated with that process have
>      *         been freed.
>      */
>     CompletableFuture<Void> cancelAsync();
>     /**
>      * Flag indicating whether cancellation was requested or not.
>      *
>      * <p>This method will return true even if cancellation has not been 
> completed yet.
>      *
>      * @return {@code true} when cancellation was requested.
>      */
>     boolean isCancelled();
>     /**
>      * Issue a token associated with this handle.
>      * 
>      * <p>Token is reusable, meaning the same token may be used to link 
> several executions into a single cancellable.
>      */
>     CancellationToken token();
> }
> public interface CancellationToken { }
> {code}
> Also, a new group of {{execute<*>}} methods accepting optional 
> {{CancellationToken}} parameter must be introduced to sql facade: 
> {code:java}
> public interface IgniteSql {
>     <...>
>     
>     ResultSet<SqlRow> execute(
>         @Nullable Transaction transaction,
>         @Nullable CancellationToken cancellationToken,
>         String query,
>         @Nullable Object... arguments
>     );
>     
>     <...>
> }
> {code}
> When user need a better control over query lifecycle, they should create 
> handle and propagate token to the execution:
> {code:java}
> IgniteSql sql = <acquire sql api>;
> // create cancellation handle
> CancelHandle handle = CancelHandle.create();
> // propagate cancellation token to an execution
> sql.executeAsync(null, handle.token(), "<query text>");
> // propagate token from the same handle to more executions, if needed
> sql.executeAsync(null, handle.token(), "<query text>");
> // cancel everything at once
> handle.cancel();
> {code}
> Definition of Done: new entities are introduced to public API and integrated 
> with single statement execution flow from embedded API.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to