phoenix-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [phoenix] gjacoby126 commented on a change in pull request #457: PHOENIX-5190 Implement TaskRegionObserver for Index rebuild
Date Fri, 22 Mar 2019 23:05:05 GMT
gjacoby126 commented on a change in pull request #457:  PHOENIX-5190 Implement TaskRegionObserver
for Index rebuild
URL: https://github.com/apache/phoenix/pull/457#discussion_r268363793
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/schema/task/Task.java
 ##########
 @@ -0,0 +1,314 @@
+package org.apache.phoenix.schema.task;
+
+import org.apache.hadoop.hbase.ipc.RpcCall;
+import org.apache.hadoop.hbase.ipc.RpcUtil;
+import org.apache.hadoop.hbase.security.User;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.schema.PTable;
+
+import java.io.IOException;
+import java.security.PrivilegedExceptionAction;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.List;
+
+public class Task {
+    private static void mutateSystemTaskTable(PhoenixConnection conn, PreparedStatement stmt,
boolean accessCheckEnabled)
+            throws IOException {
+        // we need to mutate SYSTEM.TASK with HBase/login user if access is enabled.
+        if (accessCheckEnabled) {
+            User.runAsLoginUser(new PrivilegedExceptionAction<Void>() {
+                @Override
+                public Void run() throws Exception {
+                    final RpcCall rpcContext = RpcUtil.getRpcContext();
+                    // setting RPC context as null so that user can be reset
+                    try {
+                        RpcUtil.setRpcContext(null);
+                        stmt.execute();
+                        conn.commit();
+                    } catch (SQLException e) {
+                        throw new IOException(e);
+                    } finally {
+                        // setting RPC context back to original context of the RPC
+                        RpcUtil.setRpcContext(rpcContext);
+                    }
+                    return null;
+                }
+            });
+        }
+        else {
+            try {
+                stmt.execute();
+                conn.commit();
+            } catch (SQLException e) {
+                throw new IOException(e);
+            }
+        }
+    }
+
+    private static  PreparedStatement setValuesToAddTaskPS(PreparedStatement stmt, PTable.TaskType
taskType,
+            String tenantId, String schemaName, String tableName) throws SQLException {
+        stmt.setByte(1, taskType.getSerializedValue());
+        if (tenantId != null) {
+            stmt.setString(2, tenantId);
+        } else {
+            stmt.setNull(2, Types.VARCHAR);
+        }
+        if (schemaName != null) {
+            stmt.setString(3, schemaName);
+        } else {
+            stmt.setNull(3, Types.VARCHAR);
+        }
+        stmt.setString(4, tableName);
+        return stmt;
+    }
+
+    public static void addTask(PhoenixConnection conn, PTable.TaskType taskType, String tenantId,
String schemaName,
+            String tableName, boolean accessCheckEnabled)
+            throws IOException {
+        PreparedStatement stmt = null;
+        try {
+            stmt = conn.prepareStatement("UPSERT INTO " +
+                    PhoenixDatabaseMetaData.SYSTEM_TASK_NAME + " ( " +
+                    PhoenixDatabaseMetaData.TASK_TYPE + ", " +
+                    PhoenixDatabaseMetaData.TENANT_ID + ", " +
+                    PhoenixDatabaseMetaData.TABLE_SCHEM + ", " +
+                    PhoenixDatabaseMetaData.TABLE_NAME + " ) VALUES(?,?,?,?)");
+            stmt = setValuesToAddTaskPS(stmt, taskType, tenantId, schemaName, tableName);
+        } catch (SQLException e) {
+            throw new IOException(e);
+        }
+        mutateSystemTaskTable(conn, stmt, accessCheckEnabled);
+    }
+
+    public static void addTask(PhoenixConnection conn, PTable.TaskType taskType, String tenantId,
String schemaName,
+            String tableName, String taskStatus, String data, Integer priority, Timestamp
endTs,
+            boolean accessCheckEnabled)
+            throws IOException {
+        PreparedStatement stmt = null;
+        try {
+            stmt = conn.prepareStatement("UPSERT INTO " +
+                    PhoenixDatabaseMetaData.SYSTEM_TASK_NAME + " ( " +
+                    PhoenixDatabaseMetaData.TASK_TYPE + ", " +
+                    PhoenixDatabaseMetaData.TENANT_ID + ", " +
+                    PhoenixDatabaseMetaData.TABLE_SCHEM + ", " +
+                    PhoenixDatabaseMetaData.TABLE_NAME + ", " +
+                    PhoenixDatabaseMetaData.TASK_STATUS + ", " +
+                    PhoenixDatabaseMetaData.TASK_PRIORITY + ", " +
+                    PhoenixDatabaseMetaData.TASK_END_TS + ", " +
+                    PhoenixDatabaseMetaData.TASK_DATA +
+                    " ) VALUES(?,?,?,?,?,?,?,?)");
+            stmt = setValuesToAddTaskPS(stmt, taskType, tenantId, schemaName, tableName);
+            if (taskStatus != null) {
+                stmt.setString(5, taskStatus);
 
 Review comment:
   Any reason this logic shouldn't be in setValuesToAddTaskPS? (You could have an overload
that took just the original 4 params that calls the full 8 param function)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message