Skip to content

Commit 8e95c1a

Browse files
author
Divneet Kaur
committed
PHOENIX-7376 : ViewUtil#findAllDescendantViews should provide two versions to differentiate CQSI initiated by clients and servers
1 parent b1706df commit 8e95c1a

File tree

8 files changed

+29
-27
lines changed

8 files changed

+29
-27
lines changed

phoenix-core-client/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ private ViewType setViewTypeToBe(final PhoenixConnection connection, final PTabl
341341
List<PTable> legitimateSiblingViewList =
342342
ViewUtil.findAllDescendantViews(childLinkTable, config, parentTenantIdInBytes,
343343
parentSchemaNameInBytes, parentToBe.getTableName().getBytes(),
344-
HConstants.LATEST_TIMESTAMP, true).getFirst();
344+
HConstants.LATEST_TIMESTAMP, true,false).getFirst();
345345
if (!legitimateSiblingViewList.isEmpty()) {
346346
PTable siblingView = legitimateSiblingViewList.get(0);
347347
Expression siblingViewWhere = getWhereFromView(connection, siblingView);

phoenix-core-client/src/main/java/org/apache/phoenix/schema/MetaDataClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2156,7 +2156,7 @@ private void verifyIfDescendentViewsExtendPk(PTable tableOrView, Configuration c
21562156
schemaNameBytes,
21572157
viewOrTableName,
21582158
HConstants.LATEST_TIMESTAMP,
2159-
false);
2159+
false,false);
21602160
List<PTable> legitimateChildViews = descViews.getFirst();
21612161
int dataTableOrViewPkCols = tableOrView.getPKColumns().size();
21622162
if (legitimateChildViews != null && legitimateChildViews.size() > 0) {

phoenix-core-client/src/main/java/org/apache/phoenix/util/ViewUtil.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,26 @@ public class ViewUtil {
134134
public static Pair<List<PTable>, List<TableInfo>> findAllDescendantViews(
135135
Table sysCatOrsysChildLink, Configuration serverSideConfig, byte[] tenantId,
136136
byte[] schemaName, byte[] tableOrViewName, long clientTimeStamp,
137-
boolean findJustOneLegitimateChildView)
137+
boolean findJustOneLegitimateChildView, boolean isServerConnection)
138138
throws IOException, SQLException {
139139
List<PTable> legitimateChildViews = new ArrayList<>();
140140
List<TableInfo> orphanChildViews = new ArrayList<>();
141141

142142
return findAllDescendantViews(sysCatOrsysChildLink, serverSideConfig, tenantId, schemaName,
143143
tableOrViewName, clientTimeStamp, legitimateChildViews, orphanChildViews,
144-
findJustOneLegitimateChildView);
144+
findJustOneLegitimateChildView, isServerConnection);
145145
}
146146

147147
public static Pair<List<PTable>, List<TableInfo>> findAllDescendantViews(Table sysCatOrsysChildLink,
148148
Configuration serverSideConfig, byte[] parentTenantId, byte[] parentSchemaName,
149149
byte[] parentTableOrViewName, long clientTimeStamp, List<PTable> legitimateChildViews,
150-
List<TableInfo> orphanChildViews, boolean findJustOneLegitimateChildView)
150+
List<TableInfo> orphanChildViews, boolean findJustOneLegitimateChildView, boolean isServerConnection)
151151
throws IOException, SQLException{
152152

153153
return findAllDescendantViews(sysCatOrsysChildLink, null, serverSideConfig,
154154
parentTenantId, parentSchemaName, parentTableOrViewName, clientTimeStamp,
155155
legitimateChildViews, orphanChildViews, findJustOneLegitimateChildView,
156-
new Pair<>(false, false));
156+
new Pair<>(false, false), isServerConnection);
157157

158158
}
159159

@@ -208,7 +208,7 @@ public static Pair<List<PTable>, List<TableInfo>> findAllDescendantViews(
208208
byte[] parentTenantId, byte[] parentSchemaName, byte[] parentTableOrViewName,
209209
long clientTimeStamp, List<PTable> legitimateChildViews,
210210
List<TableInfo> orphanChildViews, boolean findJustOneLegitimateChildView,
211-
Pair<Boolean, Boolean> scanSysCatForTTLDefinedOnAnyChildPair)
211+
Pair<Boolean, Boolean> scanSysCatForTTLDefinedOnAnyChildPair, boolean isServerConnection)
212212
throws IOException, SQLException {
213213
TableViewFinderResult currentResult =
214214
findImmediateRelatedViews(sysCatOrsysChildLink, sysCat, parentTenantId,
@@ -226,9 +226,11 @@ public static Pair<List<PTable>, List<TableInfo>> findAllDescendantViews(
226226
if (clientTimeStamp != HConstants.LATEST_TIMESTAMP) {
227227
props.setProperty(CURRENT_SCN_ATTRIB, Long.toString(clientTimeStamp));
228228
}
229-
try (PhoenixConnection connection =
230-
QueryUtil.getConnectionOnServer(props, serverSideConfig)
231-
.unwrap(PhoenixConnection.class)) {
229+
try (PhoenixConnection connection = ((isServerConnection) ?
230+
QueryUtil.getConnectionOnServer(props, serverSideConfig)
231+
.unwrap(PhoenixConnection.class) :
232+
QueryUtil.getConnection(props, serverSideConfig)
233+
.unwrap(PhoenixConnection.class))){
232234
try {
233235
view = connection.getTableNoCache(
234236
SchemaUtil.getTableName(viewSchemaName, viewName));
@@ -257,7 +259,7 @@ public static Pair<List<PTable>, List<TableInfo>> findAllDescendantViews(
257259
viewInfo.getTenantId(), viewInfo.getSchemaName(),
258260
viewInfo.getTableName(), clientTimeStamp, legitimateChildViews,
259261
orphanChildViews, findJustOneLegitimateChildView,
260-
scanSysCatForTTLDefinedOnAnyChildPair);
262+
scanSysCatForTTLDefinedOnAnyChildPair, isServerConnection);
261263
} else {
262264
logger.error("Found an orphan parent->child link keyed by this parent."
263265
+ " Parent Tenant Id: '" + Bytes.toString(parentTenantId)
@@ -285,7 +287,7 @@ private static boolean isLegitimateChildView(PTable view, byte[] parentSchemaNam
285287
* Returns relatives in a breadth-first fashion. Note that this is not resilient to orphan
286288
* linking rows and we also do not try to resolve any of the views to ensure they are valid.
287289
* Use {@link ViewUtil#findAllDescendantViews(Table, Configuration, byte[], byte[], byte[],
288-
* long, boolean)} if you are only interested in {@link LinkType#CHILD_TABLE} and need to be
290+
* long, boolean, boolean)} if you are only interested in {@link LinkType#CHILD_TABLE} and need to be
289291
* resilient to orphan linking rows.
290292
*
291293
* @param sysCatOrsysChildLink Table corresponding to either SYSTEM.CATALOG or SYSTEM.CHILD_LINK

phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -3016,7 +3016,7 @@ public void dropTable(RpcController controller, DropTableRequest request,
30163016
Pair<List<PTable>, List<TableInfo>> descendantViews =
30173017
findAllDescendantViews(hTable, env.getConfiguration(),
30183018
tenantIdBytes, schemaName, tableOrViewName, clientTimeStamp,
3019-
true);
3019+
true,true);
30203020
List<PTable> legitimateChildViews = descendantViews.getFirst();
30213021
List<TableInfo> orphanChildViews = descendantViews.getSecond();
30223022
if (!legitimateChildViews.isEmpty()) {
@@ -3406,16 +3406,16 @@ private MetaDataMutationResult doDropTable(byte[] key, byte[] tenantId, byte[] s
34063406
* @param childViews child views of table or parent view. Usually this is an empty list
34073407
* passed to this method, and this method will add child views retrieved using
34083408
* {@link ViewUtil#findAllDescendantViews(Table, Configuration, byte[], byte[], byte[],
3409-
* long, boolean)}
3409+
* long, boolean, boolean)}
34103410
* @param clientVersion client version, used to determine if mutation is allowed.
34113411
* @return Optional.empty() if mutation is allowed on parent table/view. If not allowed,
34123412
* returned Optional object will contain metaDataMutationResult with MutationCode.
34133413
* @throws IOException if something goes wrong while retrieving child views using
34143414
* {@link ViewUtil#findAllDescendantViews(Table, Configuration, byte[], byte[], byte[],
3415-
* long, boolean)}
3415+
* long, boolean, boolean)}
34163416
* @throws SQLException if something goes wrong while retrieving child views using
34173417
* {@link ViewUtil#findAllDescendantViews(Table, Configuration, byte[], byte[], byte[],
3418-
* long, boolean)}
3418+
* long, boolean, boolean)}
34193419
*/
34203420
private Optional<MetaDataMutationResult> validateIfMutationAllowedOnParent(
34213421
final PTable parentTable,
@@ -3438,7 +3438,7 @@ private Optional<MetaDataMutationResult> validateIfMutationAllowedOnParent(
34383438
childViews.addAll(findAllDescendantViews(hTable, sysCat, env.getConfiguration(),
34393439
tenantId, schemaName, tableOrViewName, clientTimeStamp, new ArrayList<>(),
34403440
new ArrayList<>(), false,
3441-
scanSysCatForTTLDefinedOnAnyChildPair)
3441+
scanSysCatForTTLDefinedOnAnyChildPair,true)
34423442
.getFirst());
34433443
}
34443444

phoenix-core-server/src/main/java/org/apache/phoenix/mapreduce/transform/PhoenixTransformWithViewsInputFormat.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public List<InputSplit> getSplits(JobContext context) throws IOException, Interr
7272
String tableName = SchemaUtil.getTableNameFromFullName(oldDataTableFullName);
7373
byte[] schemaNameBytes = Strings.isNullOrEmpty(schemaName) ? null : schemaName.getBytes();
7474
Pair<List<PTable>, List<TableInfo>> allDescendantViews = ViewUtil.findAllDescendantViews(hTable, configuration, null, schemaNameBytes,
75-
tableName.getBytes(), EnvironmentEdgeManager.currentTimeMillis(), false);
75+
tableName.getBytes(), EnvironmentEdgeManager.currentTimeMillis(), false,true);
7676
List<PTable> legitimateDecendants = allDescendantViews.getFirst();
7777

7878
List<InputSplit> inputSplits = new ArrayList<>();

phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseRowKeyMatcherTestIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ private Map<String, byte[]> assertRowKeyMatchersForTable(String url, String pare
592592
ViewUtil.findAllDescendantViews(childLinkTable, cqs.getConfiguration(),
593593
EMPTY_BYTE_ARRAY, parentSchemaName.getBytes(),
594594
parentTableName.getBytes(),
595-
HConstants.LATEST_TIMESTAMP, false);
595+
HConstants.LATEST_TIMESTAMP, false,true);
596596
for (PTable view : allDescendants.getFirst()) {
597597
PName tenantId = view.getTenantId();
598598
String viewName = view.getName().getString();

phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewMetadataIT.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ public void testViewHierarchyWithOrphanLinks() throws Exception {
597597
cqs.getConfiguration(),
598598
EMPTY_BYTE_ARRAY, BASE_TABLE_SCHEMA.getBytes(),
599599
parent1TableName.getBytes(),
600-
HConstants.LATEST_TIMESTAMP, false);
600+
HConstants.LATEST_TIMESTAMP, false,true);
601601
List<PTable> legitChildViews = allDescendants.getFirst();
602602
List<TableInfo> orphanViews = allDescendants.getSecond();
603603
// All of the orphan links are legit views of the other parent
@@ -610,7 +610,7 @@ public void testViewHierarchyWithOrphanLinks() throws Exception {
610610
cqs.getConfiguration(), EMPTY_BYTE_ARRAY,
611611
BASE_TABLE_SCHEMA.getBytes(),
612612
parent2TableName.getBytes(),
613-
HConstants.LATEST_TIMESTAMP, false);
613+
HConstants.LATEST_TIMESTAMP, false,true);
614614
legitChildViews = allDescendants.getFirst();
615615
orphanViews = allDescendants.getSecond();
616616
// All of the orphan links are legit views of the other parent
@@ -642,7 +642,7 @@ public void testViewHierarchyWithOrphanLinks() throws Exception {
642642
cqs.getConfiguration(), EMPTY_BYTE_ARRAY,
643643
BASE_TABLE_SCHEMA.getBytes(),
644644
parent1TableName.getBytes(),
645-
HConstants.LATEST_TIMESTAMP, false);
645+
HConstants.LATEST_TIMESTAMP, false,true);
646646
legitChildViews = allDescendants.getFirst();
647647
orphanViews = allDescendants.getSecond();
648648
assertLegitChildViews(expectedLegitChildViewsListForParent1,
@@ -653,7 +653,7 @@ public void testViewHierarchyWithOrphanLinks() throws Exception {
653653
cqs.getConfiguration(), EMPTY_BYTE_ARRAY,
654654
BASE_TABLE_SCHEMA.getBytes(),
655655
parent2TableName.getBytes(),
656-
HConstants.LATEST_TIMESTAMP, false);
656+
HConstants.LATEST_TIMESTAMP, false,true);
657657
legitChildViews = allDescendants.getFirst();
658658
orphanViews = allDescendants.getSecond();
659659

phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewUtilIT.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public void testFindLegitChildViews() throws Exception {
371371
Pair<List<PTable>, List<TableInfo>> allDescendants =
372372
ViewUtil.findAllDescendantViews(childLinkTable, cqs.getConfiguration(),
373373
EMPTY_BYTE_ARRAY, BASE_TABLE_SCHEMA.getBytes(),
374-
parentTable.getBytes(), HConstants.LATEST_TIMESTAMP, true);
374+
parentTable.getBytes(), HConstants.LATEST_TIMESTAMP, true,true);
375375
assertTrue("No orphan views expected", allDescendants.getSecond().isEmpty());
376376
List<PTable> childViews = allDescendants.getFirst();
377377
assertEquals("Just 1 legit child view expected", 1, childViews.size());
@@ -386,7 +386,7 @@ public void testFindLegitChildViews() throws Exception {
386386

387387
allDescendants = ViewUtil.findAllDescendantViews(childLinkTable,
388388
cqs.getConfiguration(), EMPTY_BYTE_ARRAY, BASE_TABLE_SCHEMA.getBytes(),
389-
parentTable.getBytes(), HConstants.LATEST_TIMESTAMP, false);
389+
parentTable.getBytes(), HConstants.LATEST_TIMESTAMP, false,true);
390390
assertTrue("No orphan views expected", allDescendants.getSecond().isEmpty());
391391
childViews = allDescendants.getFirst();
392392
assertEquals("All child views expected", childViewNames.size(), childViews.size());
@@ -418,7 +418,7 @@ public void testOrphanViewDetection() throws Exception {
418418
Pair<List<PTable>, List<TableInfo>> allDescendants =
419419
ViewUtil.findAllDescendantViews(childLinkTable, cqs.getConfiguration(),
420420
EMPTY_BYTE_ARRAY, BASE_TABLE_SCHEMA.getBytes(),
421-
parent2TableName.getBytes(), HConstants.LATEST_TIMESTAMP, false);
421+
parent2TableName.getBytes(), HConstants.LATEST_TIMESTAMP, false,true);
422422
assertTrue("No orphan views expected", allDescendants.getSecond().isEmpty());
423423
assertTrue("No legitimate views expected", allDescendants.getFirst().isEmpty());
424424

@@ -431,7 +431,7 @@ public void testOrphanViewDetection() throws Exception {
431431
// orphan parent2->view link should show up as an orphan view of parent2
432432
allDescendants = ViewUtil.findAllDescendantViews(childLinkTable,
433433
cqs.getConfiguration(), EMPTY_BYTE_ARRAY, BASE_TABLE_SCHEMA.getBytes(),
434-
parent2TableName.getBytes(), HConstants.LATEST_TIMESTAMP, false);
434+
parent2TableName.getBytes(), HConstants.LATEST_TIMESTAMP, false,true);
435435
assertTrue("No legitimate views expected", allDescendants.getFirst().isEmpty());
436436
List<TableInfo> orphanViews = allDescendants.getSecond();
437437
assertEquals("1 orphan view expected", 1, orphanViews.size());

0 commit comments

Comments
 (0)