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),