Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHOENIX-7376 : ViewUtil#findAllDescendantViews should provide two versions to differentiate CQSI initiated by clients and servers #1984

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private ViewType setViewTypeToBe(final PhoenixConnection connection, final PTabl
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,7 @@ private void verifyIfDescendentViewsExtendPk(PTable tableOrView, Configuration c
schemaNameBytes,
viewOrTableName,
HConstants.LATEST_TIMESTAMP,
false);
false,false);
List<PTable> legitimateChildViews = descViews.getFirst();
int dataTableOrViewPkCols = tableOrView.getPKColumns().size();
if (legitimateChildViews != null && legitimateChildViews.size() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand Down Expand Up @@ -208,7 +208,7 @@ public static Pair<List<PTable>, List<TableInfo>> findAllDescendantViews(
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,
Expand All @@ -226,9 +226,11 @@ public static Pair<List<PTable>, List<TableInfo>> findAllDescendantViews(
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));
Expand Down Expand Up @@ -257,7 +259,7 @@ public static Pair<List<PTable>, List<TableInfo>> findAllDescendantViews(
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)
Expand Down Expand Up @@ -285,7 +287,7 @@ private static boolean isLegitimateChildView(PTable view, byte[] parentSchemaNam
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3016,7 +3016,7 @@ public void dropTable(RpcController controller, DropTableRequest request,
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()) {
Expand Down Expand Up @@ -3406,16 +3406,16 @@ private MetaDataMutationResult doDropTable(byte[] key, byte[] tenantId, byte[] s
* @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,
Expand All @@ -3438,7 +3438,7 @@ private Optional<MetaDataMutationResult> validateIfMutationAllowedOnParent(
childViews.addAll(findAllDescendantViews(hTable, sysCat, env.getConfiguration(),
tenantId, schemaName, tableOrViewName, clientTimeStamp, new ArrayList<>(),
new ArrayList<>(), false,
scanSysCatForTTLDefinedOnAnyChildPair)
scanSysCatForTTLDefinedOnAnyChildPair, true)
.getFirst());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ public List<InputSplit> getSplits(JobContext context) throws IOException, Interr
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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ private Map<String, byte[]> assertRowKeyMatchersForTable(String url, String pare
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ public void testViewHierarchyWithOrphanLinks() throws Exception {
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
Expand All @@ -610,7 +610,7 @@ public void testViewHierarchyWithOrphanLinks() throws Exception {
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
Expand Down Expand Up @@ -642,7 +642,7 @@ public void testViewHierarchyWithOrphanLinks() throws Exception {
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,
Expand All @@ -653,7 +653,7 @@ public void testViewHierarchyWithOrphanLinks() throws Exception {
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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public void testFindLegitChildViews() throws Exception {
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());
Expand All @@ -386,7 +386,7 @@ public void testFindLegitChildViews() throws Exception {

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());
Expand Down Expand Up @@ -418,7 +418,7 @@ public void testOrphanViewDetection() throws Exception {
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());

Expand All @@ -431,7 +431,7 @@ public void testOrphanViewDetection() throws Exception {
// 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());
Expand Down