You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by GitBox <gi...@apache.org> on 2020/01/15 03:20:35 UTC

[GitHub] [phoenix] abhishek-chouhan opened a new pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

abhishek-chouhan opened a new pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685
 
 
   …ow-expiry

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] swaroopak commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
swaroopak commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685#discussion_r367034019
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
 ##########
 @@ -510,6 +508,72 @@ public void testIndexToolOnlyVerifyOption() throws Exception {
         }
     }
 
+    @Test
+    public void testIndexToolVerifyWithExpiredIndexRows() throws Exception {
+        if (localIndex || transactional || !directApi || useSnapshot) {
+            return;
+        }
+        String schemaName = generateUniqueName();
+        String dataTableName = generateUniqueName();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+        String indexTableName = generateUniqueName();
+        String indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.createStatement().execute("CREATE TABLE " + dataTableFullName
+                    + " (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, CODE VARCHAR) COLUMN_ENCODED_BYTES=0");
+            // Insert a row
+            conn.createStatement()
+                    .execute("upsert into " + dataTableFullName + " values (1, 'Phoenix', 'A')");
+            conn.commit();
+            conn.createStatement()
+                    .execute(String.format("CREATE INDEX %s ON %s (NAME) INCLUDE (CODE) ASYNC",
+                        indexTableName, dataTableFullName));
+            runIndexTool(directApi, useSnapshot, schemaName, dataTableName, indexTableName, null, 0,
+                IndexTool.IndexVerifyType.ONLY);
+            Cell cell =
+                    getErrorMessageFromIndexToolOutputTable(conn, dataTableFullName,
+                        indexTableFullName);
+            byte[] expectedValueBytes = Bytes.toBytes("Missing index rows - Expected: 1 Actual: 0");
+            assertTrue(Bytes.compareTo(cell.getValueArray(), cell.getValueOffset(),
+                cell.getValueLength(), expectedValueBytes, 0, expectedValueBytes.length) == 0);
+
+            // Run the index tool to populate the index while verifying rows
+            runIndexTool(directApi, useSnapshot, schemaName, dataTableName, indexTableName, null, 0,
+                IndexTool.IndexVerifyType.AFTER);
+
+            // Set ttl of index table ridiculously low so that all data is expired
+            Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
+            TableName indexTable = TableName.valueOf(indexTableFullName);
+            HColumnDescriptor desc = admin.getTableDescriptor(indexTable).getColumnFamilies()[0];
+            desc.setTimeToLive(1);
+            admin.modifyColumn(indexTable, desc);
+            Thread.sleep(1000);
 
 Review comment:
   why not use EEM to advance time instead of sleeping?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] swaroopak commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
swaroopak commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685#discussion_r367058132
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/IndexRebuildRegionScanner.java
 ##########
 @@ -465,17 +490,32 @@ private void verifyIndexRows(ArrayList<KeyRange> keys) throws IOException {
                 if (dataPut == null) {
                     exceptionMessage = "Index verify failed - Missing data row - " + indexHTable.getName();
                     String errorMsg = "Missing data row";
-                    logToIndexToolOutputTable(null, result.getRow(), 0, getMaxTimestamp(result), errorMsg);
+                    logToIndexToolOutputTable(null, result.getRow(), 0, getMaxTimestamp(Arrays.asList(result.rawCells())), errorMsg);
                     if (!onlyVerify) {
                         throw new IOException(exceptionMessage);
                     }
                 }
                 verifySingleIndexRow(result, dataPut);
+                indexRowKeys.remove(result.getRow());
                 rowCount++;
             }
         } catch (Throwable t) {
             ServerUtil.throwIOException(indexHTable.getName().toString(), t);
         }
+        // Check if any expected rows from index(which we didn't get) are already expired due to TTL
+        // TODO: metrics for expired rows
+        if (!indexRowKeys.isEmpty()) {
+            Iterator<byte[]> itr = indexRowKeys.iterator();
+            long currentTime = EnvironmentEdgeManager.currentTime();
+            while(itr.hasNext()) {
+                byte[] indexKey = itr.next();
+                long ts = getMaxTimestampFromPut(indexKeyToDataPutMap.get(indexKey));
+                if (indexTableTTL != HConstants.FOREVER && ts < (currentTime - (long)indexTableTTL * 1000)) {
 
 Review comment:
   I think "isCellExpired" function can expect "ts" as a parameter and then that will solve the problem.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] abhishek-chouhan commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
abhishek-chouhan commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685#discussion_r367047621
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/IndexRebuildRegionScanner.java
 ##########
 @@ -465,17 +490,32 @@ private void verifyIndexRows(ArrayList<KeyRange> keys) throws IOException {
                 if (dataPut == null) {
                     exceptionMessage = "Index verify failed - Missing data row - " + indexHTable.getName();
                     String errorMsg = "Missing data row";
-                    logToIndexToolOutputTable(null, result.getRow(), 0, getMaxTimestamp(result), errorMsg);
+                    logToIndexToolOutputTable(null, result.getRow(), 0, getMaxTimestamp(Arrays.asList(result.rawCells())), errorMsg);
                     if (!onlyVerify) {
                         throw new IOException(exceptionMessage);
                     }
                 }
                 verifySingleIndexRow(result, dataPut);
+                indexRowKeys.remove(result.getRow());
                 rowCount++;
             }
         } catch (Throwable t) {
             ServerUtil.throwIOException(indexHTable.getName().toString(), t);
         }
+        // Check if any expected rows from index(which we didn't get) are already expired due to TTL
+        // TODO: metrics for expired rows
+        if (!indexRowKeys.isEmpty()) {
+            Iterator<byte[]> itr = indexRowKeys.iterator();
+            long currentTime = EnvironmentEdgeManager.currentTime();
+            while(itr.hasNext()) {
+                byte[] indexKey = itr.next();
+                long ts = getMaxTimestampFromPut(indexKeyToDataPutMap.get(indexKey));
+                if (indexTableTTL != HConstants.FOREVER && ts < (currentTime - (long)indexTableTTL * 1000)) {
 
 Review comment:
   The logic was a little different from checking a cellTs directly, in the sense that it requires finding the max ts first amongst different cells in the put, just that the comparison part is common. Didn't feel very strongly about creating a different function for that.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] swaroopak commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
swaroopak commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685#discussion_r367040313
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/IndexRebuildRegionScanner.java
 ##########
 @@ -465,17 +490,32 @@ private void verifyIndexRows(ArrayList<KeyRange> keys) throws IOException {
                 if (dataPut == null) {
                     exceptionMessage = "Index verify failed - Missing data row - " + indexHTable.getName();
                     String errorMsg = "Missing data row";
-                    logToIndexToolOutputTable(null, result.getRow(), 0, getMaxTimestamp(result), errorMsg);
+                    logToIndexToolOutputTable(null, result.getRow(), 0, getMaxTimestamp(Arrays.asList(result.rawCells())), errorMsg);
                     if (!onlyVerify) {
                         throw new IOException(exceptionMessage);
                     }
                 }
                 verifySingleIndexRow(result, dataPut);
+                indexRowKeys.remove(result.getRow());
                 rowCount++;
             }
         } catch (Throwable t) {
             ServerUtil.throwIOException(indexHTable.getName().toString(), t);
         }
+        // Check if any expected rows from index(which we didn't get) are already expired due to TTL
+        // TODO: metrics for expired rows
+        if (!indexRowKeys.isEmpty()) {
+            Iterator<byte[]> itr = indexRowKeys.iterator();
+            long currentTime = EnvironmentEdgeManager.currentTime();
+            while(itr.hasNext()) {
+                byte[] indexKey = itr.next();
+                long ts = getMaxTimestampFromPut(indexKeyToDataPutMap.get(indexKey));
+                if (indexTableTTL != HConstants.FOREVER && ts < (currentTime - (long)indexTableTTL * 1000)) {
 
 Review comment:
   This can be replaced with the function call to "isCellExpired" defined at line 530

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] swaroopak commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
swaroopak commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685#discussion_r367058959
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/IndexRebuildRegionScanner.java
 ##########
 @@ -465,17 +490,32 @@ private void verifyIndexRows(ArrayList<KeyRange> keys) throws IOException {
                 if (dataPut == null) {
                     exceptionMessage = "Index verify failed - Missing data row - " + indexHTable.getName();
                     String errorMsg = "Missing data row";
-                    logToIndexToolOutputTable(null, result.getRow(), 0, getMaxTimestamp(result), errorMsg);
+                    logToIndexToolOutputTable(null, result.getRow(), 0, getMaxTimestamp(Arrays.asList(result.rawCells())), errorMsg);
                     if (!onlyVerify) {
                         throw new IOException(exceptionMessage);
                     }
                 }
                 verifySingleIndexRow(result, dataPut);
+                indexRowKeys.remove(result.getRow());
                 rowCount++;
             }
         } catch (Throwable t) {
             ServerUtil.throwIOException(indexHTable.getName().toString(), t);
         }
+        // Check if any expected rows from index(which we didn't get) are already expired due to TTL
+        // TODO: metrics for expired rows
 
 Review comment:
   It would be nice to link it to the code's comment.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] abhishek-chouhan commented on issue #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
abhishek-chouhan commented on issue #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685#issuecomment-575017828
 
 
   Thanks for the reviews!

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] gjacoby126 commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
gjacoby126 commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685#discussion_r367061845
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
 ##########
 @@ -510,6 +508,72 @@ public void testIndexToolOnlyVerifyOption() throws Exception {
         }
     }
 
+    @Test
+    public void testIndexToolVerifyWithExpiredIndexRows() throws Exception {
+        if (localIndex || transactional || !directApi || useSnapshot) {
+            return;
+        }
+        String schemaName = generateUniqueName();
+        String dataTableName = generateUniqueName();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+        String indexTableName = generateUniqueName();
+        String indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.createStatement().execute("CREATE TABLE " + dataTableFullName
+                    + " (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, CODE VARCHAR) COLUMN_ENCODED_BYTES=0");
+            // Insert a row
+            conn.createStatement()
+                    .execute("upsert into " + dataTableFullName + " values (1, 'Phoenix', 'A')");
+            conn.commit();
+            conn.createStatement()
+                    .execute(String.format("CREATE INDEX %s ON %s (NAME) INCLUDE (CODE) ASYNC",
+                        indexTableName, dataTableFullName));
+            runIndexTool(directApi, useSnapshot, schemaName, dataTableName, indexTableName, null, 0,
+                IndexTool.IndexVerifyType.ONLY);
+            Cell cell =
+                    getErrorMessageFromIndexToolOutputTable(conn, dataTableFullName,
+                        indexTableFullName);
+            byte[] expectedValueBytes = Bytes.toBytes("Missing index rows - Expected: 1 Actual: 0");
+            assertTrue(Bytes.compareTo(cell.getValueArray(), cell.getValueOffset(),
+                cell.getValueLength(), expectedValueBytes, 0, expectedValueBytes.length) == 0);
+
+            // Run the index tool to populate the index while verifying rows
+            runIndexTool(directApi, useSnapshot, schemaName, dataTableName, indexTableName, null, 0,
+                IndexTool.IndexVerifyType.AFTER);
+
+            // Set ttl of index table ridiculously low so that all data is expired
+            Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
+            TableName indexTable = TableName.valueOf(indexTableFullName);
+            HColumnDescriptor desc = admin.getTableDescriptor(indexTable).getColumnFamilies()[0];
+            desc.setTimeToLive(1);
+            admin.modifyColumn(indexTable, desc);
+            Thread.sleep(1000);
 
 Review comment:
   1. Why do you need the first sleep for 1s if you're going to loop to wait later anyway?
   2. Why is each sleep so long (2s) rather than something short, like 10 or 100ms?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] swaroopak commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
swaroopak commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685#discussion_r367040313
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/IndexRebuildRegionScanner.java
 ##########
 @@ -465,17 +490,32 @@ private void verifyIndexRows(ArrayList<KeyRange> keys) throws IOException {
                 if (dataPut == null) {
                     exceptionMessage = "Index verify failed - Missing data row - " + indexHTable.getName();
                     String errorMsg = "Missing data row";
-                    logToIndexToolOutputTable(null, result.getRow(), 0, getMaxTimestamp(result), errorMsg);
+                    logToIndexToolOutputTable(null, result.getRow(), 0, getMaxTimestamp(Arrays.asList(result.rawCells())), errorMsg);
                     if (!onlyVerify) {
                         throw new IOException(exceptionMessage);
                     }
                 }
                 verifySingleIndexRow(result, dataPut);
+                indexRowKeys.remove(result.getRow());
                 rowCount++;
             }
         } catch (Throwable t) {
             ServerUtil.throwIOException(indexHTable.getName().toString(), t);
         }
+        // Check if any expected rows from index(which we didn't get) are already expired due to TTL
+        // TODO: metrics for expired rows
+        if (!indexRowKeys.isEmpty()) {
+            Iterator<byte[]> itr = indexRowKeys.iterator();
+            long currentTime = EnvironmentEdgeManager.currentTime();
+            while(itr.hasNext()) {
+                byte[] indexKey = itr.next();
+                long ts = getMaxTimestampFromPut(indexKeyToDataPutMap.get(indexKey));
+                if (indexTableTTL != HConstants.FOREVER && ts < (currentTime - (long)indexTableTTL * 1000)) {
 
 Review comment:
   This can be replaced with the function at line 530

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] abhishek-chouhan commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
abhishek-chouhan commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685#discussion_r367141985
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
 ##########
 @@ -510,6 +508,72 @@ public void testIndexToolOnlyVerifyOption() throws Exception {
         }
     }
 
+    @Test
+    public void testIndexToolVerifyWithExpiredIndexRows() throws Exception {
+        if (localIndex || transactional || !directApi || useSnapshot) {
+            return;
+        }
+        String schemaName = generateUniqueName();
+        String dataTableName = generateUniqueName();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+        String indexTableName = generateUniqueName();
+        String indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.createStatement().execute("CREATE TABLE " + dataTableFullName
+                    + " (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, CODE VARCHAR) COLUMN_ENCODED_BYTES=0");
+            // Insert a row
+            conn.createStatement()
+                    .execute("upsert into " + dataTableFullName + " values (1, 'Phoenix', 'A')");
+            conn.commit();
+            conn.createStatement()
+                    .execute(String.format("CREATE INDEX %s ON %s (NAME) INCLUDE (CODE) ASYNC",
+                        indexTableName, dataTableFullName));
+            runIndexTool(directApi, useSnapshot, schemaName, dataTableName, indexTableName, null, 0,
+                IndexTool.IndexVerifyType.ONLY);
+            Cell cell =
+                    getErrorMessageFromIndexToolOutputTable(conn, dataTableFullName,
+                        indexTableFullName);
+            byte[] expectedValueBytes = Bytes.toBytes("Missing index rows - Expected: 1 Actual: 0");
+            assertTrue(Bytes.compareTo(cell.getValueArray(), cell.getValueOffset(),
+                cell.getValueLength(), expectedValueBytes, 0, expectedValueBytes.length) == 0);
+
+            // Run the index tool to populate the index while verifying rows
+            runIndexTool(directApi, useSnapshot, schemaName, dataTableName, indexTableName, null, 0,
+                IndexTool.IndexVerifyType.AFTER);
+
+            // Set ttl of index table ridiculously low so that all data is expired
+            Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
+            TableName indexTable = TableName.valueOf(indexTableFullName);
+            HColumnDescriptor desc = admin.getTableDescriptor(indexTable).getColumnFamilies()[0];
+            desc.setTimeToLive(1);
+            admin.modifyColumn(indexTable, desc);
+            Thread.sleep(1000);
 
 Review comment:
   The first sleep was handling both the things of ttl expiry as well as giving reasonable time for most cases of the admin operation to succeed. The alternative is to use edge just for the ttl of 1 second but still have the retries in place since we actually need to wait for the admin operation. No particular reason of having the retry interval large, thought 40 seconds overall for the test should be enough to have it running reasonably deterministic on the most flaky of hardwares. Let me know if you strongly feel about changing these and i can work on them.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] abhishek-chouhan commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
abhishek-chouhan commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685#discussion_r367041875
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
 ##########
 @@ -510,6 +508,72 @@ public void testIndexToolOnlyVerifyOption() throws Exception {
         }
     }
 
+    @Test
+    public void testIndexToolVerifyWithExpiredIndexRows() throws Exception {
+        if (localIndex || transactional || !directApi || useSnapshot) {
+            return;
+        }
+        String schemaName = generateUniqueName();
+        String dataTableName = generateUniqueName();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+        String indexTableName = generateUniqueName();
+        String indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.createStatement().execute("CREATE TABLE " + dataTableFullName
+                    + " (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, CODE VARCHAR) COLUMN_ENCODED_BYTES=0");
+            // Insert a row
+            conn.createStatement()
+                    .execute("upsert into " + dataTableFullName + " values (1, 'Phoenix', 'A')");
+            conn.commit();
+            conn.createStatement()
+                    .execute(String.format("CREATE INDEX %s ON %s (NAME) INCLUDE (CODE) ASYNC",
+                        indexTableName, dataTableFullName));
+            runIndexTool(directApi, useSnapshot, schemaName, dataTableName, indexTableName, null, 0,
+                IndexTool.IndexVerifyType.ONLY);
+            Cell cell =
+                    getErrorMessageFromIndexToolOutputTable(conn, dataTableFullName,
+                        indexTableFullName);
+            byte[] expectedValueBytes = Bytes.toBytes("Missing index rows - Expected: 1 Actual: 0");
+            assertTrue(Bytes.compareTo(cell.getValueArray(), cell.getValueOffset(),
+                cell.getValueLength(), expectedValueBytes, 0, expectedValueBytes.length) == 0);
+
+            // Run the index tool to populate the index while verifying rows
+            runIndexTool(directApi, useSnapshot, schemaName, dataTableName, indexTableName, null, 0,
+                IndexTool.IndexVerifyType.AFTER);
+
+            // Set ttl of index table ridiculously low so that all data is expired
+            Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
+            TableName indexTable = TableName.valueOf(indexTableFullName);
+            HColumnDescriptor desc = admin.getTableDescriptor(indexTable).getColumnFamilies()[0];
+            desc.setTimeToLive(1);
+            admin.modifyColumn(indexTable, desc);
+            Thread.sleep(1000);
 
 Review comment:
   modify is async operation, which needs to actually disable/enable regions. Faking a skip in time would not help.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] swaroopak commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
swaroopak commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685#discussion_r367039589
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/IndexRebuildRegionScanner.java
 ##########
 @@ -465,17 +490,32 @@ private void verifyIndexRows(ArrayList<KeyRange> keys) throws IOException {
                 if (dataPut == null) {
                     exceptionMessage = "Index verify failed - Missing data row - " + indexHTable.getName();
                     String errorMsg = "Missing data row";
-                    logToIndexToolOutputTable(null, result.getRow(), 0, getMaxTimestamp(result), errorMsg);
+                    logToIndexToolOutputTable(null, result.getRow(), 0, getMaxTimestamp(Arrays.asList(result.rawCells())), errorMsg);
                     if (!onlyVerify) {
                         throw new IOException(exceptionMessage);
                     }
                 }
                 verifySingleIndexRow(result, dataPut);
+                indexRowKeys.remove(result.getRow());
                 rowCount++;
             }
         } catch (Throwable t) {
             ServerUtil.throwIOException(indexHTable.getName().toString(), t);
         }
+        // Check if any expected rows from index(which we didn't get) are already expired due to TTL
+        // TODO: metrics for expired rows
 
 Review comment:
   Could you please also create a jira for this so that we don't lose it in the comments? Thanks.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] swaroopak commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
swaroopak commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685#discussion_r367056891
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
 ##########
 @@ -510,6 +508,72 @@ public void testIndexToolOnlyVerifyOption() throws Exception {
         }
     }
 
+    @Test
+    public void testIndexToolVerifyWithExpiredIndexRows() throws Exception {
+        if (localIndex || transactional || !directApi || useSnapshot) {
+            return;
+        }
+        String schemaName = generateUniqueName();
+        String dataTableName = generateUniqueName();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+        String indexTableName = generateUniqueName();
+        String indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.createStatement().execute("CREATE TABLE " + dataTableFullName
+                    + " (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, CODE VARCHAR) COLUMN_ENCODED_BYTES=0");
+            // Insert a row
+            conn.createStatement()
+                    .execute("upsert into " + dataTableFullName + " values (1, 'Phoenix', 'A')");
+            conn.commit();
+            conn.createStatement()
+                    .execute(String.format("CREATE INDEX %s ON %s (NAME) INCLUDE (CODE) ASYNC",
+                        indexTableName, dataTableFullName));
+            runIndexTool(directApi, useSnapshot, schemaName, dataTableName, indexTableName, null, 0,
+                IndexTool.IndexVerifyType.ONLY);
+            Cell cell =
+                    getErrorMessageFromIndexToolOutputTable(conn, dataTableFullName,
+                        indexTableFullName);
+            byte[] expectedValueBytes = Bytes.toBytes("Missing index rows - Expected: 1 Actual: 0");
+            assertTrue(Bytes.compareTo(cell.getValueArray(), cell.getValueOffset(),
+                cell.getValueLength(), expectedValueBytes, 0, expectedValueBytes.length) == 0);
+
+            // Run the index tool to populate the index while verifying rows
+            runIndexTool(directApi, useSnapshot, schemaName, dataTableName, indexTableName, null, 0,
+                IndexTool.IndexVerifyType.AFTER);
+
+            // Set ttl of index table ridiculously low so that all data is expired
+            Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
+            TableName indexTable = TableName.valueOf(indexTableFullName);
+            HColumnDescriptor desc = admin.getTableDescriptor(indexTable).getColumnFamilies()[0];
+            desc.setTimeToLive(1);
+            admin.modifyColumn(indexTable, desc);
+            Thread.sleep(1000);
 
 Review comment:
   is it not sleeping because the test would want to expire the row? 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] abhishek-chouhan closed pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
abhishek-chouhan closed pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] abhishek-chouhan commented on issue #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
abhishek-chouhan commented on issue #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685#issuecomment-574534652
 
 
   Sorry for that miss. Have updated to use TreeSet with appropriate comparator @kadirozde and verified the expected behavior.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] abhishek-chouhan commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
abhishek-chouhan commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685#discussion_r367042035
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/IndexRebuildRegionScanner.java
 ##########
 @@ -465,17 +490,32 @@ private void verifyIndexRows(ArrayList<KeyRange> keys) throws IOException {
                 if (dataPut == null) {
                     exceptionMessage = "Index verify failed - Missing data row - " + indexHTable.getName();
                     String errorMsg = "Missing data row";
-                    logToIndexToolOutputTable(null, result.getRow(), 0, getMaxTimestamp(result), errorMsg);
+                    logToIndexToolOutputTable(null, result.getRow(), 0, getMaxTimestamp(Arrays.asList(result.rawCells())), errorMsg);
                     if (!onlyVerify) {
                         throw new IOException(exceptionMessage);
                     }
                 }
                 verifySingleIndexRow(result, dataPut);
+                indexRowKeys.remove(result.getRow());
                 rowCount++;
             }
         } catch (Throwable t) {
             ServerUtil.throwIOException(indexHTable.getName().toString(), t);
         }
+        // Check if any expected rows from index(which we didn't get) are already expired due to TTL
+        // TODO: metrics for expired rows
 
 Review comment:
   Sure, will do.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] kadirozde commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
kadirozde commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685#discussion_r366688528
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/IndexRebuildRegionScanner.java
 ##########
 @@ -584,16 +633,19 @@ public boolean next(List<Cell> results) throws IOException {
             if (onlyVerify) {
                 addToBeVerifiedIndexRows();
             }
-            ArrayList<KeyRange> keys = new ArrayList<>(rowCountPerTask);
+            ArrayList<KeyRange> keyRanges = new ArrayList<>(rowCountPerTask);
+            Set<byte[]> indexRowKeys = new HashSet<>(rowCountPerTask);
 
 Review comment:
   A byte array hash set would not work here. The byte array needs to be wrapped with equals and hashCode, or Map<byte[], Put> created with Maps.newTreeMap(Bytes.BYTES_COMPARATOR) can be used instead.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [phoenix] abhishek-chouhan commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…

Posted by GitBox <gi...@apache.org>.
abhishek-chouhan commented on a change in pull request #685: PHOENIX-5676 Inline-verification from IndexTool does not handle TTL/r…
URL: https://github.com/apache/phoenix/pull/685#discussion_r367060090
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
 ##########
 @@ -510,6 +508,72 @@ public void testIndexToolOnlyVerifyOption() throws Exception {
         }
     }
 
+    @Test
+    public void testIndexToolVerifyWithExpiredIndexRows() throws Exception {
+        if (localIndex || transactional || !directApi || useSnapshot) {
+            return;
+        }
+        String schemaName = generateUniqueName();
+        String dataTableName = generateUniqueName();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+        String indexTableName = generateUniqueName();
+        String indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.createStatement().execute("CREATE TABLE " + dataTableFullName
+                    + " (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, CODE VARCHAR) COLUMN_ENCODED_BYTES=0");
+            // Insert a row
+            conn.createStatement()
+                    .execute("upsert into " + dataTableFullName + " values (1, 'Phoenix', 'A')");
+            conn.commit();
+            conn.createStatement()
+                    .execute(String.format("CREATE INDEX %s ON %s (NAME) INCLUDE (CODE) ASYNC",
+                        indexTableName, dataTableFullName));
+            runIndexTool(directApi, useSnapshot, schemaName, dataTableName, indexTableName, null, 0,
+                IndexTool.IndexVerifyType.ONLY);
+            Cell cell =
+                    getErrorMessageFromIndexToolOutputTable(conn, dataTableFullName,
+                        indexTableFullName);
+            byte[] expectedValueBytes = Bytes.toBytes("Missing index rows - Expected: 1 Actual: 0");
+            assertTrue(Bytes.compareTo(cell.getValueArray(), cell.getValueOffset(),
+                cell.getValueLength(), expectedValueBytes, 0, expectedValueBytes.length) == 0);
+
+            // Run the index tool to populate the index while verifying rows
+            runIndexTool(directApi, useSnapshot, schemaName, dataTableName, indexTableName, null, 0,
+                IndexTool.IndexVerifyType.AFTER);
+
+            // Set ttl of index table ridiculously low so that all data is expired
+            Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
+            TableName indexTable = TableName.valueOf(indexTableFullName);
+            HColumnDescriptor desc = admin.getTableDescriptor(indexTable).getColumnFamilies()[0];
+            desc.setTimeToLive(1);
+            admin.modifyColumn(indexTable, desc);
+            Thread.sleep(1000);
 
 Review comment:
   It is mainly for the admin action but solves both the things. For majority of the cases the admin operation finishes in 1 sec so the retry loop is skipped altogether.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services