You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ac...@apache.org on 2020/03/25 02:37:59 UTC

[phoenix] branch 4.x updated: PHOENIX-5751 Remove redundant IndexUtil#isGlobalIndexCheckEnabled() calls for immutable data tables

This is an automated email from the ASF dual-hosted git repository.

achouhan pushed a commit to branch 4.x
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/4.x by this push:
     new 07f26d5  PHOENIX-5751 Remove redundant IndexUtil#isGlobalIndexCheckEnabled() calls for immutable data tables
07f26d5 is described below

commit 07f26d53a2e1ffb99968822cd54f469dfb74699d
Author: Abhishek <ab...@salesforce.com>
AuthorDate: Tue Mar 24 18:44:15 2020 -0700

    PHOENIX-5751 Remove redundant IndexUtil#isGlobalIndexCheckEnabled() calls for immutable data tables
---
 .../apache/phoenix/end2end/BasePermissionsIT.java  | 75 ++++++++++++++++++++++
 .../org/apache/phoenix/execute/MutationState.java  |  3 +
 2 files changed, 78 insertions(+)

diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BasePermissionsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BasePermissionsIT.java
index 4301ec8..218c6b1 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BasePermissionsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BasePermissionsIT.java
@@ -1217,4 +1217,79 @@ public abstract class BasePermissionsIT extends BaseTest {
             revokeAll();
         }
     }
+
+    @Test
+    public void testUpsertIntoImmutableTable() throws Throwable {
+        final String schema = generateUniqueName();
+        final String tableName = generateUniqueName();
+        final String phoenixTableName = schema + "." + tableName;
+        grantSystemTableAccess();
+        try {
+            superUser1.runAs(new PrivilegedExceptionAction<Void>() {
+                @Override
+                public Void run() throws Exception {
+                    try {
+                        verifyAllowed(createSchema(schema), superUser1);
+                        verifyAllowed(onlyCreateImmutableTable(phoenixTableName), superUser1);
+                    } catch (Throwable e) {
+                        if (e instanceof Exception) {
+                            throw (Exception) e;
+                        } else {
+                            throw new Exception(e);
+                        }
+                    }
+                    return null;
+                }
+            });
+
+            if (isNamespaceMapped) {
+                grantPermissions(unprivilegedUser.getShortName(), schema, Permission.Action.WRITE,
+                    Permission.Action.READ, Permission.Action.EXEC);
+            } else {
+                grantPermissions(unprivilegedUser.getShortName(),
+                    NamespaceDescriptor.DEFAULT_NAMESPACE.getName(), Permission.Action.WRITE,
+                    Permission.Action.READ, Permission.Action.EXEC);
+            }
+            verifyAllowed(upsertRowsIntoTable(phoenixTableName), unprivilegedUser);
+            verifyAllowed(readTable(phoenixTableName), unprivilegedUser);
+        } finally {
+            revokeAll();
+        }
+    }
+
+    AccessTestAction onlyCreateImmutableTable(final String tableName) throws SQLException {
+        return new AccessTestAction() {
+            @Override
+            public Object run() throws Exception {
+                try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) {
+                    assertFalse(stmt.execute("CREATE IMMUTABLE TABLE " + tableName
+                            + "(pk INTEGER not null primary key, data VARCHAR, val integer)"));
+                }
+                return null;
+            }
+        };
+    }
+
+    AccessTestAction upsertRowsIntoTable(final String tableName) throws SQLException {
+        return new AccessTestAction() {
+            @Override
+            public Object run() throws Exception {
+                try (Connection conn = getConnection()) {
+                    try (PreparedStatement pstmt =
+                            conn.prepareStatement(
+                                "UPSERT INTO " + tableName + " values(?, ?, ?)")) {
+                        for (int i = 0; i < NUM_RECORDS; i++) {
+                            pstmt.setInt(1, i);
+                            pstmt.setString(2, Integer.toString(i));
+                            pstmt.setInt(3, i);
+                            assertEquals(1, pstmt.executeUpdate());
+                        }
+                    }
+                    conn.commit();
+                }
+                return null;
+            }
+        };
+    }
+
 }
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 b7c55f3..7088a49 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
@@ -1227,6 +1227,9 @@ public class MutationState implements SQLCloseable {
         while (mapIter.hasNext()) {
             Entry<TableInfo, List<Mutation>> pair = mapIter.next();
             TableInfo tableInfo = pair.getKey();
+            if (!tableInfo.getPTable().getType().equals(PTableType.INDEX)) {
+                continue;
+            }
             PTable logicalTable = tableInfo.getPTable();
             if (tableInfo.getOrigTableRef().getTable()
                     .isImmutableRows() && IndexUtil.isGlobalIndexCheckerEnabled(connection,