phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pbo...@apache.org
Subject [4/9] phoenix git commit: PHOENIX-4698 Tolerate orphaned views (Maddineni Sukumar)
Date Thu, 26 Apr 2018 21:43:56 GMT
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/67093243
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/67093243
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/67093243

Branch: refs/heads/4.x-cdh5.13
Commit: 67093243cbe95daef07e8b47fbe8f06f6c035d3d
Parents: 1725728
Author: James Taylor <jtaylor@salesforce.com>
Authored: Thu Apr 19 14:42:24 2018 -0700
Committer: James Taylor <jtaylor@salesforce.com>
Committed: Thu Apr 26 10:00:16 2018 -0700

----------------------------------------------------------------------
 .../coprocessor/MetaDataEndpointImpl.java       | 50 +++++++++++++-------
 1 file changed, 33 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/67093243/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);
         }
     }


Mime
View raw message