korlov42 commented on code in PR #5143: URL: https://github.com/apache/ignite-3/pull/5143#discussion_r1939604639
########## modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlCommandHandler.java: ########## @@ -63,35 +65,71 @@ public DdlCommandHandler( this.clockService = clockService; } + /** + * Submits given list of commands at once. + * + * <p>The whole list is submitted atomically. The result of applying of any individual command in case of conditional statements + * may be checked by calling {@link CatalogApplyResult#isApplied(int)} providing 0-based index of command in question. If exception + * is thrown during processing of any command from batch, then none of the commands will be applied. + * + * @param batch A batch of command to execute. + * @return Future containing result of applying a list of commands to catalog. + */ + public CompletableFuture<CatalogApplyResult> handle(List<CatalogCommand> batch) { + CompletableFuture<CatalogApplyResult> fut = catalogManager.execute(batch); + + boolean hasCreateIndexCommand = batch.stream().anyMatch(AbstractCreateIndexCommand.class::isInstance); + + if (!hasCreateIndexCommand) { + return fut; + } + + return fut.thenCompose(applyResult -> + inBusyLock(busyLock, () -> { + List<CompletableFuture<?>> toWait = new ArrayList<>(); + for (int i = 0; i < batch.size(); i++) { + CatalogCommand cmd = batch.get(i); + + if (!(cmd instanceof AbstractCreateIndexCommand) || !applyResult.isApplied(i)) { + continue; + } + + toWait.add(waitTillIndexBecomesAvailableOrRemoved( + ((AbstractCreateIndexCommand) cmd), i, applyResult + )); + } + + return CompletableFutures.allOf(toWait).thenApply(none -> applyResult); + }) + ); + } + /** * Handles ddl commands. * * @param cmd Catalog command. - * @return Future representing pending completion of the operation. If the command execution resulted in a modification of the catalog, - * the result will be the activation timestamp of the new catalog version, if the command did not result in a change of the - * catalog, the result will be {@code null}. + * @return Future containing result of applying a commands to catalog. */ - public CompletableFuture<@Nullable Long> handle(CatalogCommand cmd) { + public CompletableFuture<CatalogApplyResult> handle(CatalogCommand cmd) { CompletableFuture<CatalogApplyResult> fut = catalogManager.execute(cmd); if (cmd instanceof AbstractCreateIndexCommand) { fut = fut.thenCompose(applyResult -> - inBusyLock(busyLock, () -> waitTillIndexBecomesAvailableOrRemoved((AbstractCreateIndexCommand) cmd, applyResult))); + inBusyLock(busyLock, () -> waitTillIndexBecomesAvailableOrRemoved((AbstractCreateIndexCommand) cmd, 0, applyResult))); Review Comment: no, because it works as it should. Index may be dropped before it becomes available, therefore we have to listen for both events in order to release future representing result of index creation -- 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: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org