You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2018/04/26 16:52:25 UTC
[4/6] phoenix git commit: PHOENIX-4698 Tolerate orphaned views
(Maddineni Sukumar)
PHOENIX-4698 Tolerate orphaned views (Maddineni Sukumar)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/7096a682
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/7096a682
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/7096a682
Branch: refs/heads/4.x-HBase-1.3
Commit: 7096a682c3bd1f6754b8294c706ebb38c00e0af1
Parents: f9369f8
Author: James Taylor <jt...@salesforce.com>
Authored: Thu Apr 19 14:42:24 2018 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Thu Apr 26 09:51:01 2018 -0700
----------------------------------------------------------------------
.../coprocessor/MetaDataEndpointImpl.java | 50 +++++++++++++-------
1 file changed, 33 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/7096a682/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index c28ad3c..ddd3ffe 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -592,7 +592,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
done.run(builder.build());
return;
} catch (Throwable t) {
- logger.error("getTable failed", t);
+ logger.error("getTable failed", t);
ProtobufUtil.setControllerException(controller,
ServerUtil.createIOException(SchemaUtil.getTableName(schemaName, tableName), t));
}
@@ -755,9 +755,9 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
// compatibility.
Cell sortOrderKv = colKeyValues[SORT_ORDER_INDEX];
SortOrder sortOrder =
- sortOrderKv == null ? SortOrder.getDefault() : SortOrder.fromSystemValue(PInteger.INSTANCE
+ sortOrderKv == null ? SortOrder.getDefault() : SortOrder.fromSystemValue(PInteger.INSTANCE
.getCodec().decodeInt(sortOrderKv.getValueArray(),
- sortOrderKv.getValueOffset(), SortOrder.getDefault()));
+ sortOrderKv.getValueOffset(), SortOrder.getDefault()));
Cell arraySizeKv = colKeyValues[ARRAY_SIZE_INDEX];
Integer arraySize = arraySizeKv == null ? null :
@@ -1313,9 +1313,9 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
return table.getName() == null;
}
- private static boolean isSchemaDeleted(PSchema schema) {
- return schema.getSchemaName() == null;
- }
+ private static boolean isSchemaDeleted(PSchema schema) {
+ return schema.getSchemaName() == null;
+ }
private static boolean isFunctionDeleted(PFunction function) {
return function.getFunctionName() == null;
@@ -1827,6 +1827,13 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
byte[] tableKey = SchemaUtil.getTableKey(viewtenantId, viewSchema, viewTable);
ImmutableBytesPtr cacheKey = new ImmutableBytesPtr(tableKey);
PTable view = loadTable(env, tableKey, cacheKey, clientTimeStamp, clientTimeStamp, clientVersion);
+ if (view == null) {
+ logger.warn("Found orphan tenant view row in SYSTEM.CATALOG with tenantId:"
+ + Bytes.toString(tenantId) + ", schema:"
+ + Bytes.toString(viewSchema) + ", table:"
+ + Bytes.toString(viewTable));
+ continue;
+ }
findAllChildViews(region, viewtenantId, view, result, clientTimeStamp, clientVersion);
}
}
@@ -1969,8 +1976,9 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
if (systemCatalog.getTimeStamp() < MIN_SYSTEM_TABLE_TIMESTAMP_4_11_0) {
return findChildViews_deprecated(region, tenantId, table, PHYSICAL_TABLE_BYTES, stopAfterFirst);
} else {
- return findChildViews_4_11(region, tenantId, table.getSchemaName().getBytes(),
- table.getTableName().getBytes(), stopAfterFirst);
+ return findChildViews_4_11(region, tenantId,
+ table.getSchemaName() == null ? ByteUtil.EMPTY_BYTE_ARRAY : table.getSchemaName().getBytes(),
+ table.getTableName().getBytes(), stopAfterFirst);
}
}
@@ -2548,6 +2556,14 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
// lock the rows corresponding to views so that no other thread can modify the view meta-data
RowLock viewRowLock = acquireLock(region, viewKey, locks);
PTable view = doGetTable(viewKey, clientTimeStamp, viewRowLock, clientVersion);
+ if (view == null) {
+ logger.warn("Found orphan tenant view row in SYSTEM.CATALOG with tenantId:"
+ + Bytes.toString(tenantId) + ", schema:"
+ + Bytes.toString(schema) + ", table:"
+ + Bytes.toString(table));
+ continue;
+ }
+
ColumnOrdinalPositionUpdateList ordinalPositionList = new ColumnOrdinalPositionUpdateList();
List<PColumn> viewPkCols = new ArrayList<>(view.getPKColumns());
boolean addingExistingPkCol = false;
@@ -2705,12 +2721,12 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
for (TableProperty tableProp : TableProperty.values()) {
Cell tablePropertyCell = tablePropertyCellMap.get(tableProp);
if ( tablePropertyCell != null) {
- // set this table property on the view :
- // 1. if it is not mutable on a view (which means the property is always the same as the base table)
- // 2. or if it is mutable on a view and if it doesn't exist on the view
- // 3. or if it is mutable on a view and the property value is the same as the base table property (which means it wasn't changed on the view)
+ // set this table property on the view :
+ // 1. if it is not mutable on a view (which means the property is always the same as the base table)
+ // 2. or if it is mutable on a view and if it doesn't exist on the view
+ // 3. or if it is mutable on a view and the property value is the same as the base table property (which means it wasn't changed on the view)
Object viewProp = tableProp.getPTableValue(view);
- if (!tableProp.isMutableOnView() || viewProp==null || viewProp.equals(tableProp.getPTableValue(basePhysicalTable))) {
+ if (!tableProp.isMutableOnView() || viewProp==null || viewProp.equals(tableProp.getPTableValue(basePhysicalTable))) {
viewHeaderRowPut.add(CellUtil.createCell(viewKey, CellUtil.cloneFamily(tablePropertyCell),
CellUtil.cloneQualifier(tablePropertyCell), clientTimeStamp, tablePropertyCell.getTypeByte(),
CellUtil.cloneValue(tablePropertyCell)));
@@ -2800,10 +2816,10 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
// if switching from from non tx to tx
if (!basePhysicalTable.isTransactional() && switchAttribute(basePhysicalTable, basePhysicalTable.isTransactional(), tableMetadata, TRANSACTIONAL_BYTES)) {
- invalidateList.add(new ImmutableBytesPtr(viewKey));
- Put put = new Put(viewKey);
- put.addColumn(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,
- TRANSACTIONAL_BYTES, clientTimeStamp, PBoolean.INSTANCE.toBytes(true));
+ invalidateList.add(new ImmutableBytesPtr(viewKey));
+ Put put = new Put(viewKey);
+ put.add(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,
+ TRANSACTIONAL_BYTES, clientTimeStamp, PBoolean.INSTANCE.toBytes(true));
mutationsForAddingColumnsToViews.add(put);
}
}