[2/2] phoenix git commit: PHOENIX-2915 Dropping of Index can still leave some non-replayed writes in WAL

2016-06-10 Thread ankit
PHOENIX-2915 Dropping of Index can still leave some non-replayed writes in WAL


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/3c205ac4
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/3c205ac4
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/3c205ac4

Branch: refs/heads/4.x-HBase-0.98
Commit: 3c205ac498e5873541bfcf26dea781a58cc22d3a
Parents: 45e4af5
Author: Ankit Singhal 
Authored: Fri Jun 10 16:50:46 2016 +0530
Committer: Ankit Singhal 
Committed: Fri Jun 10 16:50:46 2016 +0530

--
 .../query/ConnectionQueryServicesImpl.java  | 58 +---
 1 file changed, 39 insertions(+), 19 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/3c205ac4/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index fad79b8..b086113 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -1531,7 +1531,8 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
 }
 
 @Override
-public MetaDataMutationResult dropTable(final List 
tableMetaData, final PTableType tableType, final boolean cascade) throws 
SQLException {
+public MetaDataMutationResult dropTable(final List 
tableMetaData, final PTableType tableType,
+final boolean cascade) throws SQLException {
 byte[][] rowKeyMetadata = new byte[3][];
 SchemaUtil.getVarChars(tableMetaData.get(0).getRow(), rowKeyMetadata);
 byte[] tenantIdBytes = 
rowKeyMetadata[PhoenixDatabaseMetaData.TENANT_ID_INDEX];
@@ -1566,18 +1567,14 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
 case TABLE_ALREADY_EXISTS:
 ReadOnlyProps props = this.getProps();
 boolean dropMetadata = props.getBoolean(DROP_METADATA_ATTRIB, 
DEFAULT_DROP_METADATA);
+PTable table = result.getTable();
 if (dropMetadata) {
+flushParentPhysicalTable(table);
 dropTables(result.getTableNamesToDelete());
 }
 invalidateTables(result.getTableNamesToDelete());
 if (tableType == PTableType.TABLE) {
-boolean isNamespaceMapped = 
result.getTable().isNamespaceMapped();
-byte[] physicalName;
-if (!isNamespaceMapped) {
-physicalName = SchemaUtil.getTableNameAsBytes(schemaBytes, 
tableBytes);
-} else {
-physicalName = TableName.valueOf(schemaBytes, 
tableBytes).getName();
-}
+byte[] physicalName = table.getPhysicalName().getBytes();
 long timestamp = 
MetaDataUtil.getClientTimeStamp(tableMetaData);
 ensureViewIndexTableDropped(physicalName, timestamp);
 ensureLocalIndexTableDropped(physicalName, timestamp);
@@ -1590,6 +1587,25 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
   return result;
 }
 
+/*
+ * PHOENIX-2915 while dropping index, flush data table to avoid stale WAL 
edits of indexes 1. Flush parent table if
+ * dropping view has indexes 2. Dropping table indexes 3. Dropping view 
indexes
+ */
+private void flushParentPhysicalTable(PTable table) throws SQLException {
+byte[] parentPhysicalTableName = null;
+if (PTableType.VIEW == table.getType()) {
+if (!table.getIndexes().isEmpty()) {
+parentPhysicalTableName = table.getPhysicalName().getBytes();
+}
+} else if (PTableType.INDEX == table.getType()) {
+PTable parentTable = getTable(null, 
table.getParentName().getString(), HConstants.LATEST_TIMESTAMP);
+parentPhysicalTableName = parentTable.getPhysicalName().getBytes();
+}
+if (parentPhysicalTableName != null) {
+flushTable(parentPhysicalTableName);
+}
+}
+
 @Override
 public MetaDataMutationResult dropFunction(final List 
functionData, final boolean ifExists) throws SQLException {
 byte[][] rowKeyMetadata = new byte[2][];
@@ -1661,31 +1677,35 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
 
 private void ensureViewIndexTableCreated(PName tenantId, byte[] 
physicalIndexTableName, long timestamp,
 boolean isNamespaceMapped) 

[2/2] phoenix git commit: PHOENIX-2915 Dropping of Index can still leave some non-replayed writes in WAL

2016-06-10 Thread ankit
PHOENIX-2915 Dropping of Index can still leave some non-replayed writes in WAL


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/a747b459
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/a747b459
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/a747b459

Branch: refs/heads/4.x-HBase-1.0
Commit: a747b459a15ed271f536b1b08fab416eb5f03fb7
Parents: 5a5da14
Author: Ankit Singhal 
Authored: Fri Jun 10 16:26:08 2016 +0530
Committer: Ankit Singhal 
Committed: Fri Jun 10 16:26:08 2016 +0530

--
 .../query/ConnectionQueryServicesImpl.java  | 58 +---
 1 file changed, 39 insertions(+), 19 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/a747b459/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index c6d8683..b51be5d 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -1530,7 +1530,8 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
 }
 
 @Override
-public MetaDataMutationResult dropTable(final List 
tableMetaData, final PTableType tableType, final boolean cascade) throws 
SQLException {
+public MetaDataMutationResult dropTable(final List 
tableMetaData, final PTableType tableType,
+final boolean cascade) throws SQLException {
 byte[][] rowKeyMetadata = new byte[3][];
 SchemaUtil.getVarChars(tableMetaData.get(0).getRow(), rowKeyMetadata);
 byte[] tenantIdBytes = 
rowKeyMetadata[PhoenixDatabaseMetaData.TENANT_ID_INDEX];
@@ -1565,18 +1566,14 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
 case TABLE_ALREADY_EXISTS:
 ReadOnlyProps props = this.getProps();
 boolean dropMetadata = props.getBoolean(DROP_METADATA_ATTRIB, 
DEFAULT_DROP_METADATA);
+PTable table = result.getTable();
 if (dropMetadata) {
+flushParentPhysicalTable(table);
 dropTables(result.getTableNamesToDelete());
 }
 invalidateTables(result.getTableNamesToDelete());
 if (tableType == PTableType.TABLE) {
-boolean isNamespaceMapped = 
result.getTable().isNamespaceMapped();
-byte[] physicalName;
-if (!isNamespaceMapped) {
-physicalName = SchemaUtil.getTableNameAsBytes(schemaBytes, 
tableBytes);
-} else {
-physicalName = TableName.valueOf(schemaBytes, 
tableBytes).getName();
-}
+byte[] physicalName = table.getPhysicalName().getBytes();
 long timestamp = 
MetaDataUtil.getClientTimeStamp(tableMetaData);
 ensureViewIndexTableDropped(physicalName, timestamp);
 ensureLocalIndexTableDropped(physicalName, timestamp);
@@ -1589,6 +1586,25 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
   return result;
 }
 
+/*
+ * PHOENIX-2915 while dropping index, flush data table to avoid stale WAL 
edits of indexes 1. Flush parent table if
+ * dropping view has indexes 2. Dropping table indexes 3. Dropping view 
indexes
+ */
+private void flushParentPhysicalTable(PTable table) throws SQLException {
+byte[] parentPhysicalTableName = null;
+if (PTableType.VIEW == table.getType()) {
+if (!table.getIndexes().isEmpty()) {
+parentPhysicalTableName = table.getPhysicalName().getBytes();
+}
+} else if (PTableType.INDEX == table.getType()) {
+PTable parentTable = getTable(null, 
table.getParentName().getString(), HConstants.LATEST_TIMESTAMP);
+parentPhysicalTableName = parentTable.getPhysicalName().getBytes();
+}
+if (parentPhysicalTableName != null) {
+flushTable(parentPhysicalTableName);
+}
+}
+
 @Override
 public MetaDataMutationResult dropFunction(final List 
functionData, final boolean ifExists) throws SQLException {
 byte[][] rowKeyMetadata = new byte[2][];
@@ -1660,31 +1676,35 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
 
 private void ensureViewIndexTableCreated(PName tenantId, byte[] 
physicalIndexTableName, long timestamp,
 boolean isNamespaceMapped) 

[2/2] phoenix git commit: PHOENIX-2915 Dropping of Index can still leave some non-replayed writes in WAL

2016-06-10 Thread ankit
PHOENIX-2915 Dropping of Index can still leave some non-replayed writes in WAL


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/49618c83
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/49618c83
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/49618c83

Branch: refs/heads/master
Commit: 49618c835bf053d7e3846c809b2fba22418c4b26
Parents: 8eba8e2
Author: Ankit Singhal 
Authored: Fri Jun 10 16:00:32 2016 +0530
Committer: Ankit Singhal 
Committed: Fri Jun 10 16:00:32 2016 +0530

--
 .../query/ConnectionQueryServicesImpl.java  | 58 +---
 1 file changed, 39 insertions(+), 19 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/49618c83/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index 03ed549..56bd50c 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -1488,7 +1488,8 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
 }
 
 @Override
-public MetaDataMutationResult dropTable(final List 
tableMetaData, final PTableType tableType, final boolean cascade) throws 
SQLException {
+public MetaDataMutationResult dropTable(final List 
tableMetaData, final PTableType tableType,
+final boolean cascade) throws SQLException {
 byte[][] rowKeyMetadata = new byte[3][];
 SchemaUtil.getVarChars(tableMetaData.get(0).getRow(), rowKeyMetadata);
 byte[] tenantIdBytes = 
rowKeyMetadata[PhoenixDatabaseMetaData.TENANT_ID_INDEX];
@@ -1523,19 +1524,15 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
 case TABLE_ALREADY_EXISTS:
 ReadOnlyProps props = this.getProps();
 boolean dropMetadata = props.getBoolean(DROP_METADATA_ATTRIB, 
DEFAULT_DROP_METADATA);
+PTable table = result.getTable();
 if (dropMetadata) {
+flushParentPhysicalTable(table);
 dropTables(result.getTableNamesToDelete());
 }
 invalidateTables(result.getTableNamesToDelete());
 long timestamp = MetaDataUtil.getClientTimeStamp(tableMetaData);
 if (tableType == PTableType.TABLE) {
-boolean isNamespaceMapped = 
result.getTable().isNamespaceMapped();
-byte[] physicalName;
-if (!isNamespaceMapped) {
-physicalName = SchemaUtil.getTableNameAsBytes(schemaBytes, 
tableBytes);
-} else {
-physicalName = TableName.valueOf(schemaBytes, 
tableBytes).getName();
-}
+byte[] physicalName = table.getPhysicalName().getBytes();
 ensureViewIndexTableDropped(physicalName, timestamp);
 ensureLocalIndexTableDropped(physicalName, timestamp);
 tableStatsCache.invalidate(new 
ImmutableBytesPtr(physicalName));
@@ -1547,6 +1544,25 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
   return result;
 }
 
+/*
+ * PHOENIX-2915 while dropping index, flush data table to avoid stale WAL 
edits of indexes 1. Flush parent table if
+ * dropping view has indexes 2. Dropping table indexes 3. Dropping view 
indexes
+ */
+private void flushParentPhysicalTable(PTable table) throws SQLException {
+byte[] parentPhysicalTableName = null;
+if (PTableType.VIEW == table.getType()) {
+if (!table.getIndexes().isEmpty()) {
+parentPhysicalTableName = table.getPhysicalName().getBytes();
+}
+} else if (PTableType.INDEX == table.getType()) {
+PTable parentTable = getTable(null, 
table.getParentName().getString(), HConstants.LATEST_TIMESTAMP);
+parentPhysicalTableName = parentTable.getPhysicalName().getBytes();
+}
+if (parentPhysicalTableName != null) {
+flushTable(parentPhysicalTableName);
+}
+}
+
 @Override
 public MetaDataMutationResult dropFunction(final List 
functionData, final boolean ifExists) throws SQLException {
 byte[][] rowKeyMetadata = new byte[2][];
@@ -1623,31 +1639,35 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
 
 private void ensureViewIndexTableCreated(PName tenantId, byte[]