You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ya...@apache.org on 2020/11/04 03:53:17 UTC

[phoenix] branch 4.x updated: PHOENIX-6126 : All createViewAddChildLink requests should go to corresponding region of SYSTEM.CHILD_LINK

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

yanxinyi 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 519da9a  PHOENIX-6126 : All createViewAddChildLink requests should go to corresponding region of SYSTEM.CHILD_LINK
519da9a is described below

commit 519da9ae7bae9a3b12670ee92a9adb95409b6ea8
Author: Viraj Jasani <vj...@apache.org>
AuthorDate: Fri Oct 30 00:21:39 2020 +0530

    PHOENIX-6126 : All createViewAddChildLink requests should go to corresponding region of SYSTEM.CHILD_LINK
    
    Signed-off-by: Xinyi Yan <ya...@apache.org>
---
 .../query/ChildLinkMetaDataServiceCallBack.java    | 68 ++++++++++++++++++++++
 .../phoenix/query/ConnectionQueryServicesImpl.java | 35 ++++-------
 .../java/org/apache/phoenix/util/SchemaUtil.java   |  6 --
 3 files changed, 79 insertions(+), 30 deletions(-)

diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ChildLinkMetaDataServiceCallBack.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ChildLinkMetaDataServiceCallBack.java
new file mode 100644
index 0000000..b5736f4
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ChildLinkMetaDataServiceCallBack.java
@@ -0,0 +1,68 @@
+/*
+ * 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.phoenix.query;
+
+import org.apache.hadoop.hbase.client.Mutation;
+import org.apache.hadoop.hbase.client.coprocessor.Batch;
+import org.apache.hadoop.hbase.ipc.BlockingRpcCallback;
+import org.apache.hadoop.hbase.ipc.ServerRpcController;
+import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto;
+import org.apache.phoenix.coprocessor.generated.ChildLinkMetaDataProtos
+    .ChildLinkMetaDataService;
+import org.apache.phoenix.coprocessor.generated.ChildLinkMetaDataProtos
+    .CreateViewAddChildLinkRequest;
+import org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataResponse;
+import org.apache.phoenix.protobuf.ProtobufUtil;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Callable implementation for coprocessor endpoint associated with
+ * SYSTEM.CHILD_LINK
+ */
+class ChildLinkMetaDataServiceCallBack
+    implements Batch.Call<ChildLinkMetaDataService, MetaDataResponse> {
+
+    private final List<Mutation> childLinkMutations;
+
+    public ChildLinkMetaDataServiceCallBack(List<Mutation> childLinkMutations) {
+        this.childLinkMutations = childLinkMutations;
+    }
+
+    @Override
+    public MetaDataResponse call(ChildLinkMetaDataService instance)
+            throws IOException {
+        ServerRpcController controller = new ServerRpcController();
+        BlockingRpcCallback<MetaDataResponse> rpcCallback =
+            new BlockingRpcCallback<>();
+        CreateViewAddChildLinkRequest.Builder builder =
+            CreateViewAddChildLinkRequest.newBuilder();
+        for (Mutation mutation : childLinkMutations) {
+            MutationProto mp = ProtobufUtil.toProto(mutation);
+            builder.addTableMetadataMutations(mp.toByteString());
+        }
+        CreateViewAddChildLinkRequest build = builder.build();
+        instance.createViewAddChildLink(controller, build, rpcCallback);
+        if (controller.getFailedOn() != null) {
+            throw controller.getFailedOn();
+        }
+        return rpcCallback.get();
+    }
+}
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index 62c7b03..c6dc006 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -83,6 +83,7 @@ import java.lang.ref.WeakReference;
 import java.sql.PreparedStatement;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.sql.Types;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -1889,28 +1890,12 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         // Avoid the client-server RPC if this is not a view creation
         if (!childLinkMutations.isEmpty()) {
             // Send mutations for parent-child links to SYSTEM.CHILD_LINK
-            // We invoke this using the parent table's key since child links are keyed by parent
-            final MetaDataMutationResult result = childLinkMetaDataCoprocessorExec(SchemaUtil.getTableKey(parentTable),
-                    new Batch.Call<ChildLinkMetaDataService, MetaDataResponse>() {
-                        @Override
-                        public MetaDataResponse call(ChildLinkMetaDataService instance) throws IOException {
-                            ServerRpcController controller = new ServerRpcController();
-                            BlockingRpcCallback<MetaDataResponse> rpcCallback =
-                                    new BlockingRpcCallback<>();
-                            CreateViewAddChildLinkRequest.Builder builder =
-                                    CreateViewAddChildLinkRequest.newBuilder();
-                            for (Mutation m: childLinkMutations) {
-                                MutationProto mp = ProtobufUtil.toProto(m);
-                                builder.addTableMetadataMutations(mp.toByteString());
-                            }
-                            CreateViewAddChildLinkRequest build = builder.build();
-                            instance.createViewAddChildLink(controller, build, rpcCallback);
-                            if (controller.getFailedOn() != null) {
-                                throw controller.getFailedOn();
-                            }
-                            return rpcCallback.get();
-                        }
-                    } );
+            // We invoke this using rowKey available in the first element
+            // of childLinkMutations.
+            final byte[] rowKey = childLinkMutations.get(0).getRow();
+            final MetaDataMutationResult result =
+                childLinkMetaDataCoprocessorExec(rowKey,
+                    new ChildLinkMetaDataServiceCallBack(childLinkMutations));
 
             switch (result.getMutationCode()) {
                 case UNABLE_TO_CREATE_CHILD_LINK:
@@ -3202,9 +3187,11 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                             String globalUrl = JDBCUtil.removeProperty(url, PhoenixRuntime.TENANT_ID_ATTRIB);
                             try (PhoenixConnection metaConnection = new PhoenixConnection(ConnectionQueryServicesImpl.this, globalUrl,
                                          scnProps, newEmptyMetaData())) {
-                                try {
+                                try (Statement statement =
+                                        metaConnection.createStatement()) {
                                     metaConnection.setRunningUpgrade(true);
-                                    metaConnection.createStatement().executeUpdate(getSystemCatalogTableDDL());
+                                    statement.executeUpdate(
+                                        getSystemCatalogTableDDL());
                                 } catch (NewerTableAlreadyExistsException ignore) {
                                     // Ignore, as this will happen if the SYSTEM.CATALOG already exists at this fixed
                                     // timestamp. A TableAlreadyExistsException is not thrown, since the table only exists
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
index 3f1f0bb..d17ef96 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
@@ -1054,12 +1054,6 @@ public class SchemaUtil {
     	return table.getRowTimestampColPos()>0;
     }
 
-    public static byte[] getTableKey(PTable dataTable) {
-        PName tenantId = dataTable.getTenantId();
-        PName schemaName = dataTable.getSchemaName();
-        return getTableKey(tenantId == null ? ByteUtil.EMPTY_BYTE_ARRAY : tenantId.getBytes(), schemaName == null ? ByteUtil.EMPTY_BYTE_ARRAY : schemaName.getBytes(), dataTable.getTableName().getBytes());
-    }
-
     public static byte[] getSchemaKey(String schemaName) {
         return SchemaUtil.getTableKey(null, schemaName, MetaDataClient.EMPTY_TABLE);
     }