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

vjasani pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/master by this push:
     new e876cf7913 PHOENIX-7376 : ViewUtil#findAllDescendantViews should 
provide two versions to differentiate CQSI initiated by clients and servers 
(#1984)
e876cf7913 is described below

commit e876cf79132a5a71dd2246cce5473c0cf651fe9d
Author: Divneet18 <divneet.k...@salesforce.com>
AuthorDate: Mon Mar 24 16:08:53 2025 -0700

    PHOENIX-7376 : ViewUtil#findAllDescendantViews should provide two versions 
to differentiate CQSI initiated by clients and servers (#1984)
---
 .../phoenix/compile/CreateTableCompiler.java       |  2 +-
 .../org/apache/phoenix/schema/MetaDataClient.java  |  2 +-
 .../java/org/apache/phoenix/util/ViewUtil.java     | 22 ++++++++++++----------
 .../phoenix/coprocessor/MetaDataEndpointImpl.java  | 10 +++++-----
 .../PhoenixTransformWithViewsInputFormat.java      |  6 ++++--
 .../phoenix/end2end/BaseRowKeyMatcherTestIT.java   |  2 +-
 .../org/apache/phoenix/end2end/ViewMetadataIT.java |  8 ++++----
 .../org/apache/phoenix/end2end/ViewUtilIT.java     |  8 ++++----
 8 files changed, 32 insertions(+), 28 deletions(-)

diff --git 
a/phoenix-core-client/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
 
b/phoenix-core-client/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
index ccda4659c4..a1cc50c37d 100644
--- 
a/phoenix-core-client/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
+++ 
b/phoenix-core-client/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
@@ -341,7 +341,7 @@ public class CreateTableCompiler {
             List<PTable> legitimateSiblingViewList =
                     ViewUtil.findAllDescendantViews(childLinkTable, config, 
parentTenantIdInBytes,
                             parentSchemaNameInBytes, 
parentToBe.getTableName().getBytes(),
-                            HConstants.LATEST_TIMESTAMP, true).getFirst();
+                            HConstants.LATEST_TIMESTAMP, 
true,false).getFirst();
             if (!legitimateSiblingViewList.isEmpty()) {
                 PTable siblingView = legitimateSiblingViewList.get(0);
                 Expression siblingViewWhere = getWhereFromView(connection, 
siblingView);
diff --git 
a/phoenix-core-client/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
 
b/phoenix-core-client/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index 243b13ff78..6a89052007 100644
--- 
a/phoenix-core-client/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ 
b/phoenix-core-client/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -2156,7 +2156,7 @@ public class MetaDataClient {
                             schemaNameBytes,
                             viewOrTableName,
                             HConstants.LATEST_TIMESTAMP,
-                            false);
+                            false,false);
             List<PTable> legitimateChildViews = descViews.getFirst();
             int dataTableOrViewPkCols = tableOrView.getPKColumns().size();
             if (legitimateChildViews != null && legitimateChildViews.size() > 
0) {
diff --git 
a/phoenix-core-client/src/main/java/org/apache/phoenix/util/ViewUtil.java 
b/phoenix-core-client/src/main/java/org/apache/phoenix/util/ViewUtil.java
index 071bc20769..8d737d219e 100644
--- a/phoenix-core-client/src/main/java/org/apache/phoenix/util/ViewUtil.java
+++ b/phoenix-core-client/src/main/java/org/apache/phoenix/util/ViewUtil.java
@@ -134,26 +134,26 @@ public class ViewUtil {
     public static Pair<List<PTable>, List<TableInfo>> findAllDescendantViews(
             Table sysCatOrsysChildLink, Configuration serverSideConfig, byte[] 
tenantId,
             byte[] schemaName, byte[] tableOrViewName, long clientTimeStamp,
-            boolean findJustOneLegitimateChildView)
+            boolean findJustOneLegitimateChildView, boolean isServerConnection)
             throws IOException, SQLException {
         List<PTable> legitimateChildViews = new ArrayList<>();
         List<TableInfo> orphanChildViews = new ArrayList<>();
 
         return findAllDescendantViews(sysCatOrsysChildLink, serverSideConfig, 
tenantId, schemaName,
                 tableOrViewName, clientTimeStamp, legitimateChildViews, 
orphanChildViews,
-                findJustOneLegitimateChildView);
+                findJustOneLegitimateChildView, isServerConnection);
     }
 
     public static Pair<List<PTable>, List<TableInfo>> 
findAllDescendantViews(Table sysCatOrsysChildLink,
            Configuration serverSideConfig, byte[] parentTenantId, byte[] 
parentSchemaName,
            byte[] parentTableOrViewName, long clientTimeStamp, List<PTable> 
legitimateChildViews,
-           List<TableInfo> orphanChildViews, boolean 
findJustOneLegitimateChildView)
+           List<TableInfo> orphanChildViews, boolean 
findJustOneLegitimateChildView, boolean isServerConnection)
            throws IOException, SQLException{
 
          return findAllDescendantViews(sysCatOrsysChildLink, null, 
serverSideConfig,
                  parentTenantId, parentSchemaName, parentTableOrViewName, 
clientTimeStamp,
                  legitimateChildViews, orphanChildViews, 
findJustOneLegitimateChildView,
-                 new Pair<>(false, false));
+                 new Pair<>(false, false), isServerConnection);
 
     }
 
@@ -208,7 +208,7 @@ public class ViewUtil {
             byte[] parentTenantId, byte[] parentSchemaName, byte[] 
parentTableOrViewName,
             long clientTimeStamp, List<PTable> legitimateChildViews,
             List<TableInfo> orphanChildViews, boolean 
findJustOneLegitimateChildView,
-            Pair<Boolean, Boolean> scanSysCatForTTLDefinedOnAnyChildPair)
+            Pair<Boolean, Boolean> scanSysCatForTTLDefinedOnAnyChildPair, 
boolean isServerConnection)
             throws IOException, SQLException {
         TableViewFinderResult currentResult =
                 findImmediateRelatedViews(sysCatOrsysChildLink, sysCat, 
parentTenantId,
@@ -226,9 +226,11 @@ public class ViewUtil {
             if (clientTimeStamp != HConstants.LATEST_TIMESTAMP) {
                 props.setProperty(CURRENT_SCN_ATTRIB, 
Long.toString(clientTimeStamp));
             }
-            try (PhoenixConnection connection =
-                    QueryUtil.getConnectionOnServer(props, serverSideConfig)
-                            .unwrap(PhoenixConnection.class)) {
+            try (PhoenixConnection connection = ((isServerConnection) ?
+                            QueryUtil.getConnectionOnServer(props, 
serverSideConfig)
+                            .unwrap(PhoenixConnection.class) :
+                            QueryUtil.getConnection(props, serverSideConfig)
+                            .unwrap(PhoenixConnection.class))){
                 try {
                     view = connection.getTableNoCache(
                             SchemaUtil.getTableName(viewSchemaName, viewName));
@@ -257,7 +259,7 @@ public class ViewUtil {
                             viewInfo.getTenantId(), viewInfo.getSchemaName(),
                             viewInfo.getTableName(), clientTimeStamp, 
legitimateChildViews,
                             orphanChildViews, findJustOneLegitimateChildView,
-                            scanSysCatForTTLDefinedOnAnyChildPair);
+                            scanSysCatForTTLDefinedOnAnyChildPair, 
isServerConnection);
                 } else {
                     logger.error("Found an orphan parent->child link keyed by 
this parent."
                             + " Parent Tenant Id: '" + 
Bytes.toString(parentTenantId)
@@ -285,7 +287,7 @@ public class ViewUtil {
      * Returns relatives in a breadth-first fashion. Note that this is not 
resilient to orphan
      * linking rows and we also do not try to resolve any of the views to 
ensure they are valid.
      * Use {@link ViewUtil#findAllDescendantViews(Table, Configuration, 
byte[], byte[], byte[],
-     * long, boolean)} if you are only interested in {@link 
LinkType#CHILD_TABLE} and need to be
+     * long, boolean, boolean)} if you are only interested in {@link 
LinkType#CHILD_TABLE} and need to be
      * resilient to orphan linking rows.
      *
      * @param sysCatOrsysChildLink Table corresponding to either 
SYSTEM.CATALOG or SYSTEM.CHILD_LINK
diff --git 
a/phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
 
b/phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index 49a55d78af..72680a1927 100644
--- 
a/phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ 
b/phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -3016,7 +3016,7 @@ TABLE_FAMILY_BYTES, TABLE_SEQ_NUM_BYTES);
                     Pair<List<PTable>, List<TableInfo>> descendantViews =
                             findAllDescendantViews(hTable, 
env.getConfiguration(),
                                     tenantIdBytes, schemaName, 
tableOrViewName, clientTimeStamp,
-                                    true);
+                                    true, true);
                     List<PTable> legitimateChildViews = 
descendantViews.getFirst();
                     List<TableInfo> orphanChildViews = 
descendantViews.getSecond();
                     if (!legitimateChildViews.isEmpty()) {
@@ -3406,16 +3406,16 @@ TABLE_FAMILY_BYTES, TABLE_SEQ_NUM_BYTES);
      * @param childViews child views of table or parent view. Usually this is 
an empty list
      *     passed to this method, and this method will add child views 
retrieved using
      *     {@link ViewUtil#findAllDescendantViews(Table, Configuration, 
byte[], byte[], byte[],
-     *     long, boolean)}
+     *     long, boolean, boolean)}
      * @param clientVersion client version, used to determine if mutation is 
allowed.
      * @return Optional.empty() if mutation is allowed on parent table/view. 
If not allowed,
      *     returned Optional object will contain metaDataMutationResult with 
MutationCode.
      * @throws IOException if something goes wrong while retrieving child 
views using
      *     {@link ViewUtil#findAllDescendantViews(Table, Configuration, 
byte[], byte[], byte[],
-     *     long, boolean)}
+     *     long, boolean, boolean)}
      * @throws SQLException if something goes wrong while retrieving child 
views using
      *     {@link ViewUtil#findAllDescendantViews(Table, Configuration, 
byte[], byte[], byte[],
-     *     long, boolean)}
+     *     long, boolean, boolean)}
      */
     private Optional<MetaDataMutationResult> validateIfMutationAllowedOnParent(
             final PTable parentTable,
@@ -3438,7 +3438,7 @@ TABLE_FAMILY_BYTES, TABLE_SEQ_NUM_BYTES);
                 childViews.addAll(findAllDescendantViews(hTable, sysCat, 
env.getConfiguration(),
                         tenantId, schemaName, tableOrViewName, 
clientTimeStamp, new ArrayList<>(),
                         new ArrayList<>(), false,
-                        scanSysCatForTTLDefinedOnAnyChildPair)
+                        scanSysCatForTTLDefinedOnAnyChildPair, true)
                         .getFirst());
             }
 
diff --git 
a/phoenix-core-server/src/main/java/org/apache/phoenix/mapreduce/transform/PhoenixTransformWithViewsInputFormat.java
 
b/phoenix-core-server/src/main/java/org/apache/phoenix/mapreduce/transform/PhoenixTransformWithViewsInputFormat.java
index 6410b8cf72..13ae4c62c9 100644
--- 
a/phoenix-core-server/src/main/java/org/apache/phoenix/mapreduce/transform/PhoenixTransformWithViewsInputFormat.java
+++ 
b/phoenix-core-server/src/main/java/org/apache/phoenix/mapreduce/transform/PhoenixTransformWithViewsInputFormat.java
@@ -71,8 +71,10 @@ public class PhoenixTransformWithViewsInputFormat<T extends 
DBWritable> extends
                 String schemaName = 
SchemaUtil.getSchemaNameFromFullName(oldDataTableFullName);
                 String tableName = 
SchemaUtil.getTableNameFromFullName(oldDataTableFullName);
                 byte[] schemaNameBytes = Strings.isNullOrEmpty(schemaName) ? 
null : schemaName.getBytes();
-                Pair<List<PTable>, List<TableInfo>> allDescendantViews = 
ViewUtil.findAllDescendantViews(hTable, configuration, null, schemaNameBytes,
-                        tableName.getBytes(), 
EnvironmentEdgeManager.currentTimeMillis(), false);
+                Pair<List<PTable>, List<TableInfo>> allDescendantViews =
+                        ViewUtil.findAllDescendantViews(hTable, configuration, 
null, schemaNameBytes,
+                        tableName.getBytes(), 
EnvironmentEdgeManager.currentTimeMillis(),
+                                false, true);
                 List<PTable> legitimateDecendants = 
allDescendantViews.getFirst();
 
                 List<InputSplit> inputSplits = new ArrayList<>();
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseRowKeyMatcherTestIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseRowKeyMatcherTestIT.java
index 0ce628b034..c4072127aa 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseRowKeyMatcherTestIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseRowKeyMatcherTestIT.java
@@ -592,7 +592,7 @@ public abstract class BaseRowKeyMatcherTestIT extends 
ParallelStatsDisabledIT {
                         ViewUtil.findAllDescendantViews(childLinkTable, 
cqs.getConfiguration(),
                                 EMPTY_BYTE_ARRAY, parentSchemaName.getBytes(),
                                 parentTableName.getBytes(),
-                                HConstants.LATEST_TIMESTAMP, false);
+                                HConstants.LATEST_TIMESTAMP, false,true);
                 for (PTable view : allDescendants.getFirst()) {
                     PName tenantId = view.getTenantId();
                     String viewName = view.getName().getString();
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewMetadataIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewMetadataIT.java
index c431a021dd..29c222e3d9 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewMetadataIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewMetadataIT.java
@@ -597,7 +597,7 @@ public class ViewMetadataIT extends SplitSystemCatalogIT {
                                 cqs.getConfiguration(),
                                 EMPTY_BYTE_ARRAY, BASE_TABLE_SCHEMA.getBytes(),
                                 parent1TableName.getBytes(),
-                                HConstants.LATEST_TIMESTAMP, false);
+                                HConstants.LATEST_TIMESTAMP, false,true);
                 List<PTable> legitChildViews = allDescendants.getFirst();
                 List<TableInfo> orphanViews = allDescendants.getSecond();
                 // All of the orphan links are legit views of the other parent
@@ -610,7 +610,7 @@ public class ViewMetadataIT extends SplitSystemCatalogIT {
                         cqs.getConfiguration(), EMPTY_BYTE_ARRAY,
                         BASE_TABLE_SCHEMA.getBytes(),
                         parent2TableName.getBytes(),
-                        HConstants.LATEST_TIMESTAMP, false);
+                        HConstants.LATEST_TIMESTAMP, false,true);
                 legitChildViews = allDescendants.getFirst();
                 orphanViews = allDescendants.getSecond();
                 // All of the orphan links are legit views of the other parent
@@ -642,7 +642,7 @@ public class ViewMetadataIT extends SplitSystemCatalogIT {
                         cqs.getConfiguration(), EMPTY_BYTE_ARRAY,
                         BASE_TABLE_SCHEMA.getBytes(),
                         parent1TableName.getBytes(),
-                        HConstants.LATEST_TIMESTAMP, false);
+                        HConstants.LATEST_TIMESTAMP, false,true);
                 legitChildViews = allDescendants.getFirst();
                 orphanViews = allDescendants.getSecond();
                 assertLegitChildViews(expectedLegitChildViewsListForParent1,
@@ -653,7 +653,7 @@ public class ViewMetadataIT extends SplitSystemCatalogIT {
                         cqs.getConfiguration(), EMPTY_BYTE_ARRAY,
                         BASE_TABLE_SCHEMA.getBytes(),
                         parent2TableName.getBytes(),
-                        HConstants.LATEST_TIMESTAMP, false);
+                        HConstants.LATEST_TIMESTAMP, false,true);
                 legitChildViews = allDescendants.getFirst();
                 orphanViews = allDescendants.getSecond();
 
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewUtilIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewUtilIT.java
index 919a71d306..60150ed202 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewUtilIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewUtilIT.java
@@ -371,7 +371,7 @@ public class ViewUtilIT extends ParallelStatsDisabledIT {
                 Pair<List<PTable>, List<TableInfo>> allDescendants =
                         ViewUtil.findAllDescendantViews(childLinkTable, 
cqs.getConfiguration(),
                                 EMPTY_BYTE_ARRAY, BASE_TABLE_SCHEMA.getBytes(),
-                                parentTable.getBytes(), 
HConstants.LATEST_TIMESTAMP, true);
+                                parentTable.getBytes(), 
HConstants.LATEST_TIMESTAMP, true,true);
                 assertTrue("No orphan views expected", 
allDescendants.getSecond().isEmpty());
                 List<PTable> childViews = allDescendants.getFirst();
                 assertEquals("Just 1 legit child view expected", 1, 
childViews.size());
@@ -386,7 +386,7 @@ public class ViewUtilIT extends ParallelStatsDisabledIT {
 
                 allDescendants = 
ViewUtil.findAllDescendantViews(childLinkTable,
                         cqs.getConfiguration(), EMPTY_BYTE_ARRAY, 
BASE_TABLE_SCHEMA.getBytes(),
-                        parentTable.getBytes(), HConstants.LATEST_TIMESTAMP, 
false);
+                        parentTable.getBytes(), HConstants.LATEST_TIMESTAMP, 
false,true);
                 assertTrue("No orphan views expected", 
allDescendants.getSecond().isEmpty());
                 childViews = allDescendants.getFirst();
                 assertEquals("All child views expected", 
childViewNames.size(), childViews.size());
@@ -418,7 +418,7 @@ public class ViewUtilIT extends ParallelStatsDisabledIT {
                 Pair<List<PTable>, List<TableInfo>> allDescendants =
                         ViewUtil.findAllDescendantViews(childLinkTable, 
cqs.getConfiguration(),
                                 EMPTY_BYTE_ARRAY, BASE_TABLE_SCHEMA.getBytes(),
-                                parent2TableName.getBytes(), 
HConstants.LATEST_TIMESTAMP, false);
+                                parent2TableName.getBytes(), 
HConstants.LATEST_TIMESTAMP, false,true);
                 assertTrue("No orphan views expected", 
allDescendants.getSecond().isEmpty());
                 assertTrue("No legitimate views expected", 
allDescendants.getFirst().isEmpty());
 
@@ -431,7 +431,7 @@ public class ViewUtilIT extends ParallelStatsDisabledIT {
                 // orphan parent2->view link should show up as an orphan view 
of parent2
                 allDescendants = 
ViewUtil.findAllDescendantViews(childLinkTable,
                         cqs.getConfiguration(), EMPTY_BYTE_ARRAY, 
BASE_TABLE_SCHEMA.getBytes(),
-                        parent2TableName.getBytes(), 
HConstants.LATEST_TIMESTAMP, false);
+                        parent2TableName.getBytes(), 
HConstants.LATEST_TIMESTAMP, false,true);
                 assertTrue("No legitimate views expected", 
allDescendants.getFirst().isEmpty());
                 List<TableInfo> orphanViews = allDescendants.getSecond();
                 assertEquals("1 orphan view expected", 1, orphanViews.size());

Reply via email to