PHOENIX-4671 Fix minor size accounting bug for MutationSize.
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/0fa6d947 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/0fa6d947 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/0fa6d947 Branch: refs/heads/4.x-cdh5.11 Commit: 0fa6d947ebfc237e854b206f35af3a558e28a8ee Parents: 235def6 Author: Lars Hofhansl <la...@apache.org> Authored: Thu Mar 29 22:42:53 2018 +0100 Committer: Pedro Boado <pbo...@apache.org> Committed: Fri Mar 30 08:58:50 2018 +0100 ---------------------------------------------------------------------- .../end2end/UpsertSelectAutoCommitIT.java | 28 ++++++++++++++++++++ .../apache/phoenix/execute/MutationState.java | 1 + 2 files changed, 29 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/0fa6d947/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java index 6b781a0..38d48d6 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java @@ -23,15 +23,19 @@ import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.sql.Connection; import java.sql.Date; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; +import org.apache.phoenix.exception.SQLExceptionCode; +import org.apache.phoenix.jdbc.PhoenixConnection; import org.apache.phoenix.query.QueryServices; import org.apache.phoenix.util.PropertiesUtil; import org.junit.Test; @@ -173,4 +177,28 @@ public class UpsertSelectAutoCommitIT extends ParallelStatsDisabledIT { conn.close(); } + @Test + public void testMaxMutationSize() throws Exception { + Properties connectionProperties = new Properties(); + connectionProperties.setProperty(QueryServices.MAX_MUTATION_SIZE_ATTRIB, "3"); + connectionProperties.setProperty(QueryServices.MAX_MUTATION_SIZE_BYTES_ATTRIB, "50000"); + PhoenixConnection connection = + (PhoenixConnection) DriverManager.getConnection(getUrl(), connectionProperties); + connection.setAutoCommit(true); + String fullTableName = generateUniqueName(); + try (Statement stmt = connection.createStatement()) { + stmt.execute( + "CREATE TABLE " + fullTableName + " (pk INTEGER PRIMARY KEY, v1 INTEGER, v2 INTEGER)"); + stmt.execute( + "CREATE SEQUENCE " + fullTableName + "_seq cache 1000"); + stmt.execute("UPSERT INTO " + fullTableName + " VALUES (NEXT VALUE FOR " + fullTableName + "_seq, rand(), rand())"); + } + try (Statement stmt = connection.createStatement()) { + for (int i=0; i<16; i++) { + stmt.execute("UPSERT INTO " + fullTableName + " SELECT NEXT VALUE FOR " + fullTableName + "_seq, rand(), rand() FROM " + fullTableName); + } + } + connection.close(); + } + } http://git-wip-us.apache.org/repos/asf/phoenix/blob/0fa6d947/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java index 727b424..f6d11a0 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java @@ -1563,6 +1563,7 @@ public class MutationState implements SQLCloseable { public void clear(){ rowKeyToRowMutationState.clear(); + estimatedSize = 0; } public Collection<RowMutationState> values() {