mattcasters commented on code in PR #9106:
URL: https://github.com/apache/hop/pull/9106#discussion_r4435545676
##########
plugins/transforms/delete/src/main/java/org/apache/hop/pipeline/transforms/delete/Delete.java:
##########
@@ -244,7 +278,14 @@ public boolean init() {
logDetailed(BaseMessages.getString(PKG, "Delete.Log.ConnectedToDB"));
}
- data.db.setCommit(meta.getCommitSize(this));
+ data.commitSize = meta.getCommitSize(this);
+ data.db.setCommit(data.commitSize);
+ data.useSavepoints =
+ getTransformMeta().isDoingErrorHandling()
+ && databaseMeta.getIDatabase().isUseSafePoints()
+ && !data.db.isAutoCommit()
+ && !data.db.getUseBatchInsert(meta.isUseBatchUpdate());
Review Comment:
**[suggestion]** Savepoints are turned off whenever batch updates are
actually used. On PostgreSQL that is the combination that aborts the
transaction, so an error hop with "Use batch update" still sends every later
row to the error hop and loses the uncommitted commit window. There is no log
line. Table Output does the opposite: it disables batch mode when savepoints
are required and warns that error handling is not fully supported with
batching. Update has the same guard.
**Suggestion:** When the transform is doing error handling and the database
uses savepoints, force batch off for this run and log why, instead of skipping
the savepoint.
##########
plugins/transforms/delete/src/test/java/org/apache/hop/pipeline/transforms/delete/DeletePostgresIT.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.pipeline.transforms.delete;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Deque;
+import java.util.List;
+import org.apache.hop.core.HopClientEnvironment;
+import org.apache.hop.core.database.Database;
+import org.apache.hop.core.database.DatabaseMeta;
+import org.apache.hop.core.database.DatabasePluginType;
+import org.apache.hop.core.logging.LoggingObject;
+import org.apache.hop.core.row.IRowMeta;
+import org.apache.hop.core.row.RowMeta;
+import org.apache.hop.core.row.value.ValueMetaInteger;
+import org.apache.hop.core.row.value.ValueMetaString;
+import org.apache.hop.core.variables.Variables;
+import org.apache.hop.databases.postgresql.PostgreSqlDatabaseMeta;
+import org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider;
+import org.apache.hop.pipeline.PipelineHopMeta;
+import org.apache.hop.pipeline.PipelineMeta;
+import org.apache.hop.pipeline.engines.local.LocalPipelineEngine;
+import org.apache.hop.pipeline.transform.TransformErrorMeta;
+import org.apache.hop.pipeline.transform.TransformMeta;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import org.testcontainers.DockerClientFactory;
+import org.testcontainers.containers.PostgreSQLContainer;
+
+/**
+ * Delete with an error hop on PostgreSQL, where a failed statement aborts the
transaction: only the
+ * failing row may go to the error hop, the rows after it must still be
deleted.
+ */
+class DeletePostgresIT {
Review Comment:
**[suggestion]** This class, and the sibling `UpdatePostgresIT`,
`InsertUpdatePostgresIT`, `DimensionLookupPostgresIT`, and
`ExecSqlRowPostgresIT`, match Failsafe's `*IT` pattern, not Surefire's. The
parent build does not bind Failsafe, and these module poms do not add an
execution the way `plugins/tech/age/pom.xml` does, so `mvn verify` never runs
the Testcontainers tests. They already skip themselves when Docker is absent.
**Suggestion:** Bind the failsafe `integration-test` and `verify` goals in
each of these poms. The `main-0048` workflow does not run these classes.
##########
plugins/transforms/execsqlrow/src/main/java/org/apache/hop/pipeline/transforms/execsqlrow/ExecSqlRow.java:
##########
@@ -184,6 +190,13 @@ public boolean processRow() throws HopException {
setOutputDone(); // signal end to receiver(s)
return false;
}
+ if (data.useSavepoints) {
+ // Undo this row only, so the next rows can still run in this
transaction.
+ data.db.rollback(data.savepoint);
Review Comment:
**[bug]** The savepoint is released on line 157, and `commit()` on lines
170–174 may already have run, before this catch. Any later `HopException` (a
failed commit, or `putRow`) still calls `rollback(data.savepoint)`. On
PostgreSQL that savepoint is gone, so the rollback fails with "savepoint does
not exist" and aborts the transaction. The original error is replaced, this row
never reaches the error hop, and every following statement fails with "current
transaction is aborted" — the bug this pull request is fixing. Delete, Update,
Insert/Update, and Dimension lookup/update do the same thing: `endRow()`
releases the savepoint, then `putRow` stays in the same `try`, and the catch
always calls `undoRow()`.
**Suggestion:** Roll back only while the savepoint is still open. After the
row's SQL succeeds, release it and set `data.savepoint` to null; skip the
rollback when it is null. Keep `commit()` and `putRow` outside that catch, or
catch only `HopDatabaseException` around the SQL, as Table Output does.
--
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]