From 50868a4b95ed34d67c5dca988cd3736529a63fa7 Mon Sep 17 00:00:00 2001 From: lukasz-stec Date: Mon, 20 Apr 2026 10:07:15 +0200 Subject: [PATCH 1/3] Ignore already commited transaction The connector metrics collection can fail if the transaction was committed after the check to see if the transaction is active. This is expected, and we should not log an error in this case. --- .../src/main/java/io/trino/execution/QueryStateMachine.java | 4 +++- .../io/trino/transaction/InMemoryTransactionManager.java | 5 +++-- .../src/main/java/io/trino/spi/StandardErrorCode.java | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/execution/QueryStateMachine.java b/core/trino-main/src/main/java/io/trino/execution/QueryStateMachine.java index d82fe58d405d..8e0aff4ca78d 100644 --- a/core/trino-main/src/main/java/io/trino/execution/QueryStateMachine.java +++ b/core/trino-main/src/main/java/io/trino/execution/QueryStateMachine.java @@ -115,6 +115,7 @@ import static io.trino.server.DynamicFilterService.DynamicFiltersStats; import static io.trino.spi.StandardErrorCode.NOT_FOUND; import static io.trino.spi.StandardErrorCode.TRANSACTION_ALREADY_ABORTED; +import static io.trino.spi.StandardErrorCode.TRANSACTION_ALREADY_COMMITED; import static io.trino.spi.StandardErrorCode.USER_CANCELED; import static io.trino.spi.connector.StandardWarningCode.SPOOLING_NOT_SUPPORTED; import static io.trino.spi.resourcegroups.QueryType.SELECT; @@ -431,7 +432,8 @@ private void collectCatalogMetadataMetrics() // the transaction can be committed or aborted concurrently, after the check is done. } catch (RuntimeException e) { - if (!(e instanceof TrinoException trinoException && TRANSACTION_ALREADY_ABORTED.toErrorCode().equals(trinoException.getErrorCode()))) { + if (!(e instanceof TrinoException trinoException && (TRANSACTION_ALREADY_ABORTED.toErrorCode().equals(trinoException.getErrorCode()) || + TRANSACTION_ALREADY_COMMITED.toErrorCode().equals(trinoException.getErrorCode())))) { QUERY_STATE_LOG.error(e, "Error collecting query catalog metadata metrics: %s", queryId); } } diff --git a/core/trino-main/src/main/java/io/trino/transaction/InMemoryTransactionManager.java b/core/trino-main/src/main/java/io/trino/transaction/InMemoryTransactionManager.java index e1395ac3b4ec..499f5a061484 100644 --- a/core/trino-main/src/main/java/io/trino/transaction/InMemoryTransactionManager.java +++ b/core/trino-main/src/main/java/io/trino/transaction/InMemoryTransactionManager.java @@ -63,6 +63,7 @@ import static io.trino.spi.StandardErrorCode.MULTI_CATALOG_WRITE_CONFLICT; import static io.trino.spi.StandardErrorCode.READ_ONLY_VIOLATION; import static io.trino.spi.StandardErrorCode.TRANSACTION_ALREADY_ABORTED; +import static io.trino.spi.StandardErrorCode.TRANSACTION_ALREADY_COMMITED; import static java.util.Objects.requireNonNull; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.stream.Collectors.toList; @@ -384,7 +385,7 @@ public void checkOpenTransaction() if (completedStatus != null) { if (completedStatus) { // Should not happen normally - throw new IllegalStateException("Current transaction already committed"); + throw new TrinoException(TRANSACTION_ALREADY_COMMITED, "Current transaction already committed"); } throw new TrinoException(TRANSACTION_ALREADY_ABORTED, "Current transaction is aborted, commands ignored until end of transaction block"); } @@ -521,7 +522,7 @@ public synchronized ListenableFuture asyncAbort() if (!completedSuccessfully.compareAndSet(null, false)) { if (completedSuccessfully.get()) { // Should not happen normally - return immediateFailedFuture(new IllegalStateException("Current transaction already committed")); + return immediateFailedFuture(new TrinoException(TRANSACTION_ALREADY_COMMITED, "Current transaction already committed")); } // Already done return immediateVoidFuture(); diff --git a/core/trino-spi/src/main/java/io/trino/spi/StandardErrorCode.java b/core/trino-spi/src/main/java/io/trino/spi/StandardErrorCode.java index a4d7aff716b1..8f75da5fcd40 100644 --- a/core/trino-spi/src/main/java/io/trino/spi/StandardErrorCode.java +++ b/core/trino-spi/src/main/java/io/trino/spi/StandardErrorCode.java @@ -160,6 +160,7 @@ public enum StandardErrorCode INVALID_BRANCH_PROPERTY(136, USER_ERROR), INVALID_DEFAULT_COLUMN_VALUE(137, USER_ERROR), INVALID_GRACE_PERIOD(138, USER_ERROR), + TRANSACTION_ALREADY_COMMITED(139, USER_ERROR), GENERIC_INTERNAL_ERROR(65536, INTERNAL_ERROR), TOO_MANY_REQUESTS_FAILED(65537, INTERNAL_ERROR), From 506bb1dc5819427bb81be8d3adc640b86082b471 Mon Sep 17 00:00:00 2001 From: lukasz-stec Date: Mon, 20 Apr 2026 11:59:46 +0200 Subject: [PATCH 2/3] =?UTF-8?q?empty:=20roll=20the=20dice=20=F0=9F=8E=B2'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 3421713db575e55eb54c089c33171182c7be1357 Mon Sep 17 00:00:00 2001 From: lukasz-stec Date: Mon, 20 Apr 2026 13:01:53 +0200 Subject: [PATCH 3/3] =?UTF-8?q?empty:=20roll=20the=20dice=20=F0=9F=8E=B2'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit