korlov42 commented on code in PR #6889:
URL: https://github.com/apache/ignite-3/pull/6889#discussion_r2503637425
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/fsm/Query.java:
##########
@@ -116,6 +123,64 @@ class Query {
this.parsedResult = parsedResult;
}
+ <ResultT> CompletableFuture<ResultT> runProgram(Program<ResultT> program) {
+ ProgramExecutionState<ResultT> state = program.createState();
+
+ if (!activeProgram.compareAndSet(null, state)) {
+ throw new SqlException(Common.INTERNAL_ERR);
+ }
+
+ program.run(this, state);
+
+ return state.resultHolder;
+ }
+
+ /**
+ * Initiates a graceful termination of the current query.
+ *
+ * <p>If the query is idle, moves it to {@link ExecutionPhase#TERMINATED}
phase immediately. Otherwise, the method waits for the
+ * currently active program to complete before proceeding. Note that
termination may not take effect immediately upon return. To wait
+ * for the actual completion of termination, use {@link
#terminationFuture}.
+ */
+ void terminate() {
+ tryTerminate(1);
+ }
+
+ private void tryTerminate(int attemptNo) {
+ if (attemptNo >= MAX_ATTEMPTS_COUNT) {
Review Comment:
I don't think so. Initially, I got query stuck in an infinite loop because
first implementation was trying to retry after `resultHolder` was completed. I
missed the fact that we complete result earlier as soon as excepting raised.
So, I first added MAX_ATTEMPT_COUNT, and then introduced separate
`programFinished` to notify waiters that program is completed for sure.
Technically, it's still possible to get into this if there is an infinite
loop running different program over the same query, and you are unlucky enough
so your execution attempt lost every single race. But production code runs max
~3 program over the same query object
--
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]