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/04/01 00:10:36 UTC

[GitHub] [phoenix] gjacoby126 opened a new pull request #750: PHOENIX-5799 - Inline Index Verification Output API

gjacoby126 opened a new pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750
 
 
   … 5748 rebase

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
gjacoby126 commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r402744294
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexVerificationOutputRepositoryTest.java
 ##########
 @@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end.index;
+
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.mapreduce.index.IndexVerificationOutputRepository;
+import org.apache.phoenix.mapreduce.index.IndexVerificationOutputRow;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.phoenix.mapreduce.index.IndexVerificationOutputRepository.PHASE_AFTER_VALUE;
+import static org.apache.phoenix.mapreduce.index.IndexVerificationOutputRepository.PHASE_BEFORE_VALUE;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class IndexVerificationOutputRepositoryTest extends ParallelStatsDisabledIT {
 
 Review comment:
   Fixed

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
abhishek-chouhan commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r403383368
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRepository.java
 ##########
 @@ -0,0 +1,285 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.mapreduce.index;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.coprocessor.MetaDataProtocol;
+import org.apache.phoenix.hbase.index.table.HTableFactory;
+import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.query.ConnectionQueryServices;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.util.ByteUtil;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class IndexVerificationOutputRepository {
+    public static final byte[] ROW_KEY_SEPARATOR_BYTE = Bytes.toBytes("|");
+    private Table indexHTable;
+    private byte[] indexName;
+    private Table outputHTable;
+    public final static String OUTPUT_TABLE_NAME = "PHOENIX_INDEX_TOOL";
+    public final static byte[] OUTPUT_TABLE_NAME_BYTES = Bytes.toBytes(OUTPUT_TABLE_NAME);
+    public final static byte[] OUTPUT_TABLE_COLUMN_FAMILY = QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES;
+
+    public final static String DATA_TABLE_NAME = "DTName";
+    public final static byte[] DATA_TABLE_NAME_BYTES = Bytes.toBytes(DATA_TABLE_NAME);
+    public static String INDEX_TABLE_NAME = "ITName";
+    public final static byte[] INDEX_TABLE_NAME_BYTES = Bytes.toBytes(INDEX_TABLE_NAME);
+    public static String DATA_TABLE_ROW_KEY = "DTRowKey";
+    public final static byte[] DATA_TABLE_ROW_KEY_BYTES = Bytes.toBytes(DATA_TABLE_ROW_KEY);
+    public static String INDEX_TABLE_ROW_KEY = "ITRowKey";
+    public final static byte[] INDEX_TABLE_ROW_KEY_BYTES = Bytes.toBytes(INDEX_TABLE_ROW_KEY);
+    public static String DATA_TABLE_TS = "DTTS";
+    public final static byte[] DATA_TABLE_TS_BYTES = Bytes.toBytes(DATA_TABLE_TS);
+    public static String INDEX_TABLE_TS = "ITTS";
+    public final static byte[] INDEX_TABLE_TS_BYTES = Bytes.toBytes(INDEX_TABLE_TS);
+    public static String ERROR_MESSAGE = "Error";
+    public final static byte[] ERROR_MESSAGE_BYTES = Bytes.toBytes(ERROR_MESSAGE);
+
+    public static String  VERIFICATION_PHASE = "Phase";
+    public final static byte[] VERIFICATION_PHASE_BYTES = Bytes.toBytes(VERIFICATION_PHASE);
+    public final static String EXPECTED_VALUE = "ExpectedValue";
+    public final static byte[] EXPECTED_VALUE_BYTES = Bytes.toBytes(EXPECTED_VALUE);
+    public final static String ACTUAL_VALUE = "ActualValue";
+    public final static byte[] ACTUAL_VALUE_BYTES = Bytes.toBytes(ACTUAL_VALUE);
+    public static final byte[] E_VALUE_PREFIX_BYTES = Bytes.toBytes(" E:");
+    public static final byte[] A_VALUE_PREFIX_BYTES = Bytes.toBytes(" A:");
+    public static final int PREFIX_LENGTH = 3;
+    public static final int TOTAL_PREFIX_LENGTH = 6;
+    public static final byte[] PHASE_BEFORE_VALUE = Bytes.toBytes("BEFORE");
+    public static final byte[] PHASE_AFTER_VALUE = Bytes.toBytes("AFTER");
+
+    /**
+     * Only usable for the read path or for testing
+     */
+    public IndexVerificationOutputRepository(){
 
 Review comment:
   Do we need this constructor? I see that read (non static)methods make use of outputHTable which would not work with an instance created through this.

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
gjacoby126 commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r404312606
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRepository.java
 ##########
 @@ -0,0 +1,285 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.mapreduce.index;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.coprocessor.MetaDataProtocol;
+import org.apache.phoenix.hbase.index.table.HTableFactory;
+import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.query.ConnectionQueryServices;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.util.ByteUtil;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class IndexVerificationOutputRepository {
+    public static final byte[] ROW_KEY_SEPARATOR_BYTE = Bytes.toBytes("|");
+    private Table indexHTable;
+    private byte[] indexName;
+    private Table outputHTable;
+    public final static String OUTPUT_TABLE_NAME = "PHOENIX_INDEX_TOOL";
+    public final static byte[] OUTPUT_TABLE_NAME_BYTES = Bytes.toBytes(OUTPUT_TABLE_NAME);
+    public final static byte[] OUTPUT_TABLE_COLUMN_FAMILY = QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES;
+
+    public final static String DATA_TABLE_NAME = "DTName";
+    public final static byte[] DATA_TABLE_NAME_BYTES = Bytes.toBytes(DATA_TABLE_NAME);
+    public static String INDEX_TABLE_NAME = "ITName";
+    public final static byte[] INDEX_TABLE_NAME_BYTES = Bytes.toBytes(INDEX_TABLE_NAME);
+    public static String DATA_TABLE_ROW_KEY = "DTRowKey";
+    public final static byte[] DATA_TABLE_ROW_KEY_BYTES = Bytes.toBytes(DATA_TABLE_ROW_KEY);
+    public static String INDEX_TABLE_ROW_KEY = "ITRowKey";
+    public final static byte[] INDEX_TABLE_ROW_KEY_BYTES = Bytes.toBytes(INDEX_TABLE_ROW_KEY);
+    public static String DATA_TABLE_TS = "DTTS";
+    public final static byte[] DATA_TABLE_TS_BYTES = Bytes.toBytes(DATA_TABLE_TS);
+    public static String INDEX_TABLE_TS = "ITTS";
+    public final static byte[] INDEX_TABLE_TS_BYTES = Bytes.toBytes(INDEX_TABLE_TS);
+    public static String ERROR_MESSAGE = "Error";
+    public final static byte[] ERROR_MESSAGE_BYTES = Bytes.toBytes(ERROR_MESSAGE);
+
+    public static String  VERIFICATION_PHASE = "Phase";
+    public final static byte[] VERIFICATION_PHASE_BYTES = Bytes.toBytes(VERIFICATION_PHASE);
+    public final static String EXPECTED_VALUE = "ExpectedValue";
+    public final static byte[] EXPECTED_VALUE_BYTES = Bytes.toBytes(EXPECTED_VALUE);
+    public final static String ACTUAL_VALUE = "ActualValue";
+    public final static byte[] ACTUAL_VALUE_BYTES = Bytes.toBytes(ACTUAL_VALUE);
+    public static final byte[] E_VALUE_PREFIX_BYTES = Bytes.toBytes(" E:");
+    public static final byte[] A_VALUE_PREFIX_BYTES = Bytes.toBytes(" A:");
+    public static final int PREFIX_LENGTH = 3;
+    public static final int TOTAL_PREFIX_LENGTH = 6;
+    public static final byte[] PHASE_BEFORE_VALUE = Bytes.toBytes("BEFORE");
+    public static final byte[] PHASE_AFTER_VALUE = Bytes.toBytes("AFTER");
+
+    /**
+     * Only usable for the read path or for testing
+     */
+    public IndexVerificationOutputRepository(){
 
 Review comment:
   The constructor's needed for a case in IndexTool where we're just creating the tables but not reading or writing the tables. I've added setters so that a developer can use the default constructor and still write after using the setters. Is that sufficient? 

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
gjacoby126 commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r404310670
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationResultRepository.java
 ##########
 @@ -0,0 +1,209 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.mapreduce.index;
+
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.coprocessor.IndexToolVerificationResult;
+import org.apache.phoenix.coprocessor.MetaDataProtocol;
+import org.apache.phoenix.hbase.index.table.HTableFactory;
+import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.mapreduce.index.IndexTool;
+import org.apache.phoenix.query.ConnectionQueryServices;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.util.ByteUtil;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+public class IndexVerificationResultRepository {
+    private Table resultHTable;
+    private Table indexHTable;
+    public static final byte[] ROW_KEY_SEPARATOR_BYTE = Bytes.toBytes("|");
+    public final static String RESULT_TABLE_NAME = "PHOENIX_INDEX_TOOL_RESULT";
+    public final static byte[] RESULT_TABLE_NAME_BYTES = Bytes.toBytes(RESULT_TABLE_NAME);
+    public final static byte[] RESULT_TABLE_COLUMN_FAMILY = QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES;
+    public static String SCANNED_DATA_ROW_COUNT = "ScannedDataRowCount";
+    public final static byte[] SCANNED_DATA_ROW_COUNT_BYTES = Bytes.toBytes(SCANNED_DATA_ROW_COUNT);
+    public static String REBUILT_INDEX_ROW_COUNT = "RebuiltIndexRowCount";
+    public final static byte[] REBUILT_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(REBUILT_INDEX_ROW_COUNT);
+    public static String BEFORE_REBUILD_VALID_INDEX_ROW_COUNT = "BeforeRebuildValidIndexRowCount";
+    public final static byte[] BEFORE_REBUILD_VALID_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(BEFORE_REBUILD_VALID_INDEX_ROW_COUNT);
+    public static String BEFORE_REBUILD_EXPIRED_INDEX_ROW_COUNT = "BeforeRebuildExpiredIndexRowCount";
+    public final static byte[] BEFORE_REBUILD_EXPIRED_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(BEFORE_REBUILD_EXPIRED_INDEX_ROW_COUNT);
+    public static String BEFORE_REBUILD_MISSING_INDEX_ROW_COUNT = "BeforeRebuildMissingIndexRowCount";
+    public final static byte[] BEFORE_REBUILD_MISSING_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(BEFORE_REBUILD_MISSING_INDEX_ROW_COUNT);
+    public static String BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT = "BeforeRebuildInvalidIndexRowCount";
+    public final static byte[] BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT);
+    public static String AFTER_REBUILD_VALID_INDEX_ROW_COUNT = "AfterValidExpiredIndexRowCount";
+    public final static byte[] AFTER_REBUILD_VALID_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(AFTER_REBUILD_VALID_INDEX_ROW_COUNT);
+    public static String AFTER_REBUILD_EXPIRED_INDEX_ROW_COUNT = "AfterRebuildExpiredIndexRowCount";
+    public final static byte[] AFTER_REBUILD_EXPIRED_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(AFTER_REBUILD_EXPIRED_INDEX_ROW_COUNT);
+    public static String AFTER_REBUILD_MISSING_INDEX_ROW_COUNT = "AfterRebuildMissingIndexRowCount";
+    public final static byte[] AFTER_REBUILD_MISSING_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(AFTER_REBUILD_MISSING_INDEX_ROW_COUNT);
+    public static String AFTER_REBUILD_INVALID_INDEX_ROW_COUNT = "AfterRebuildInvalidIndexRowCount";
+    public final static byte[] AFTER_REBUILD_INVALID_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(AFTER_REBUILD_INVALID_INDEX_ROW_COUNT);
+    /***
+     * Only usable for read methods
+     */
+    public IndexVerificationResultRepository(){
+
+    }
+
+    public IndexVerificationResultRepository(Connection conn, byte[] indexNameBytes) throws SQLException {
+        resultHTable = getTable(conn, RESULT_TABLE_NAME_BYTES);
+        indexHTable = getTable(conn, indexNameBytes);
+    }
+
+    public IndexVerificationResultRepository(byte[] indexName,
+                                             HTableFactory hTableFactory) throws IOException {
+        resultHTable = hTableFactory.getTable(new ImmutableBytesPtr(RESULT_TABLE_NAME_BYTES));
+        indexHTable = hTableFactory.getTable(new ImmutableBytesPtr(indexName));
+    }
+
+    public void createResultTable(Connection connection) throws IOException, SQLException {
+        ConnectionQueryServices queryServices = connection.unwrap(PhoenixConnection.class).getQueryServices();
+        Admin admin = queryServices.getAdmin();
+
+        if (!admin.tableExists(TableName.valueOf(RESULT_TABLE_NAME))) {
+            HTableDescriptor tableDescriptor = new
+                HTableDescriptor(TableName.valueOf(RESULT_TABLE_NAME));
+            tableDescriptor.setValue(HColumnDescriptor.TTL, String.valueOf(MetaDataProtocol.DEFAULT_LOG_TTL));
+            HColumnDescriptor columnDescriptor = new HColumnDescriptor(RESULT_TABLE_COLUMN_FAMILY);
+            tableDescriptor.addFamily(columnDescriptor);
+            admin.createTable(tableDescriptor);
+        }
+    }
+    public static byte[] generateResultTableRowKey(long ts, byte[] indexTableName,  byte [] regionName,
+                                                    byte[] startRow, byte[] stopRow) {
+        byte[] keyPrefix = Bytes.toBytes(Long.toString(ts));
+        int targetOffset = 0;
+        // The row key for the result table : timestamp | index table name | datable table region name |
+        //                                    scan start row | scan stop row
+        byte[] rowKey = new byte[keyPrefix.length + ROW_KEY_SEPARATOR_BYTE.length + indexTableName.length +
+            ROW_KEY_SEPARATOR_BYTE.length + regionName.length + ROW_KEY_SEPARATOR_BYTE.length +
+            startRow.length + ROW_KEY_SEPARATOR_BYTE.length + stopRow.length];
+        Bytes.putBytes(rowKey, targetOffset, keyPrefix, 0, keyPrefix.length);
+        targetOffset += keyPrefix.length;
+        Bytes.putBytes(rowKey, targetOffset, ROW_KEY_SEPARATOR_BYTE, 0, ROW_KEY_SEPARATOR_BYTE.length);
+        targetOffset += ROW_KEY_SEPARATOR_BYTE.length;
+        Bytes.putBytes(rowKey, targetOffset, indexTableName, 0, indexTableName.length);
+        targetOffset += indexTableName.length;
+        Bytes.putBytes(rowKey, targetOffset, ROW_KEY_SEPARATOR_BYTE, 0, ROW_KEY_SEPARATOR_BYTE.length);
+        targetOffset += ROW_KEY_SEPARATOR_BYTE.length;
+        Bytes.putBytes(rowKey, targetOffset, regionName, 0, regionName.length);
+        targetOffset += regionName.length;
+        Bytes.putBytes(rowKey, targetOffset, ROW_KEY_SEPARATOR_BYTE, 0, ROW_KEY_SEPARATOR_BYTE.length);
+        targetOffset += ROW_KEY_SEPARATOR_BYTE.length;
+        Bytes.putBytes(rowKey, targetOffset, startRow, 0, startRow.length);
+        targetOffset += startRow.length;
+        Bytes.putBytes(rowKey, targetOffset, ROW_KEY_SEPARATOR_BYTE, 0, ROW_KEY_SEPARATOR_BYTE.length);
+        targetOffset += ROW_KEY_SEPARATOR_BYTE.length;
+        Bytes.putBytes(rowKey, targetOffset, stopRow, 0, stopRow.length);
+        return rowKey;
+    }
+
+    public void logToIndexToolResultTable(IndexToolVerificationResult verificationResult,
+                                          IndexTool.IndexVerifyType verifyType, byte[] region) throws IOException {
+        long scanMaxTs = verificationResult.getScanMaxTs();
+        byte[] rowKey = generateResultTableRowKey(scanMaxTs, indexHTable.getName().toBytes(),
+            region, verificationResult.getStartRow(),
+            verificationResult.getStopRow());
+        Put put = new Put(rowKey);
+        put.addColumn(RESULT_TABLE_COLUMN_FAMILY, SCANNED_DATA_ROW_COUNT_BYTES,
+            scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getScannedDataRowCount())));
+        put.addColumn(RESULT_TABLE_COLUMN_FAMILY, REBUILT_INDEX_ROW_COUNT_BYTES,
+            scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getRebuiltIndexRowCount())));
+        if (verifyType == IndexTool.IndexVerifyType.BEFORE || verifyType == IndexTool.IndexVerifyType.BOTH ||
+            verifyType == IndexTool.IndexVerifyType.ONLY) {
+            put.addColumn(RESULT_TABLE_COLUMN_FAMILY, BEFORE_REBUILD_VALID_INDEX_ROW_COUNT_BYTES,
+                scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getBeforeRebuildValidIndexRowCount())));
+            put.addColumn(RESULT_TABLE_COLUMN_FAMILY, BEFORE_REBUILD_EXPIRED_INDEX_ROW_COUNT_BYTES,
+                scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getBeforeRebuildExpiredIndexRowCount())));
+            put.addColumn(RESULT_TABLE_COLUMN_FAMILY, BEFORE_REBUILD_MISSING_INDEX_ROW_COUNT_BYTES,
+                scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getBeforeRebuildMissingIndexRowCount())));
+            put.addColumn(RESULT_TABLE_COLUMN_FAMILY, BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT_BYTES,
+                scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getBeforeRebuildInvalidIndexRowCount())));
+        }
+        if (verifyType == IndexTool.IndexVerifyType.AFTER || verifyType == IndexTool.IndexVerifyType.BOTH) {
+            put.addColumn(RESULT_TABLE_COLUMN_FAMILY, AFTER_REBUILD_VALID_INDEX_ROW_COUNT_BYTES,
+                scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getAfterRebuildValidIndexRowCount())));
+            put.addColumn(RESULT_TABLE_COLUMN_FAMILY, AFTER_REBUILD_EXPIRED_INDEX_ROW_COUNT_BYTES,
+                scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getAfterRebuildExpiredIndexRowCount())));
+            put.addColumn(RESULT_TABLE_COLUMN_FAMILY, AFTER_REBUILD_MISSING_INDEX_ROW_COUNT_BYTES,
+                scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getAfterRebuildMissingIndexRowCount())));
+            put.addColumn(RESULT_TABLE_COLUMN_FAMILY, AFTER_REBUILD_INVALID_INDEX_ROW_COUNT_BYTES,
+                scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getAfterRebuildInvalidIndexRowCount())));
+        }
+        resultHTable.put(put);
+    }
+
+    public IndexToolVerificationResult getVerificationResult(Connection conn, long ts) throws IOException, SQLException {
+        Table hTable = getTable(conn, RESULT_TABLE_NAME_BYTES);
+        return getVerificationResult(hTable, ts);
+    }
+
+    public Table getTable(Connection conn, byte[] tableName) throws SQLException {
+        return conn.unwrap(PhoenixConnection.class).getQueryServices()
+                .getTable(tableName);
+    }
+
+    public IndexToolVerificationResult getVerificationResult(Table htable, long ts)
+        throws IOException {
+        byte[] startRowKey = Bytes.toBytes(Long.toString(ts));
+        byte[] stopRowKey = ByteUtil.calculateTheClosestNextRowKeyForPrefix(startRowKey);
+        IndexToolVerificationResult verificationResult = new IndexToolVerificationResult(ts);
+        Scan scan = new Scan();
+        scan.withStartRow(startRowKey);
+        scan.withStopRow(stopRowKey);
+        ResultScanner scanner = htable.getScanner(scan);
+        for (Result result = scanner.next(); result != null; result = scanner.next()) {
+            boolean isFirst = true;
+            for (Cell cell : result.rawCells()) {
+                if (isFirst){
+                    byte[][] rowKeyParts = ByteUtil.splitArrayBySeparator(result.getRow(),
+                        ROW_KEY_SEPARATOR_BYTE[0]);
+                    verificationResult.setStartRow(rowKeyParts[3]);
+                    verificationResult.setStopRow(rowKeyParts[4]);
+                    isFirst = false;
+                }
+                verificationResult.update(cell);
+            }
+        }
+        return verificationResult;
+    }
+
+    public void close() throws IOException {
+        if (resultHTable != null) {
 
 Review comment:
   Done. 

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
gjacoby126 commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r404310809
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRow.java
 ##########
 @@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.mapreduce.index;
+
+import org.apache.hadoop.hbase.util.Bytes;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+public class IndexVerificationOutputRow {
+    private String dataTableName;
+    private String indexTableName;
+    private Long scanMaxTimestamp;
+    private byte[] dataTableRowKey;
+    private byte[] indexTableRowKey;
+    private Long dataTableRowTimestamp;
+    private Long indexTableRowTimestamp;
+    private String errorMessage;
+    private byte[] expectedValue;
+    private byte[] actualValue;
+    private byte[] phaseValue;
+
+    private IndexVerificationOutputRow(String dataTableName, String indexTableName,
+                                       byte[] dataTableRowKey, Long scanMaxTimestamp,
+                                      byte[] indexTableRowKey,
+                                       long dataTableRowTimestamp, long indexTableRowTimestamp,
+                                      String errorMessage, byte[] expectedValue, byte[] actualValue,
+                                      byte[] phaseValue) {
+        this.dataTableName = dataTableName;
+        this.indexTableName = indexTableName;
+        this.scanMaxTimestamp = scanMaxTimestamp;
+        this.dataTableRowKey = dataTableRowKey;
+        this.indexTableRowKey = indexTableRowKey;
+        this.dataTableRowTimestamp = dataTableRowTimestamp;
+        this.indexTableRowTimestamp = indexTableRowTimestamp;
+        this.errorMessage = errorMessage;
+        this.expectedValue = expectedValue;
+        this.actualValue = actualValue;
+        this.phaseValue = phaseValue;
+    }
+
+    public String getDataTableName() {
+        return dataTableName;
+    }
+
+    public String getIndexTableName() {
+        return indexTableName;
+    }
+
+    public Long getScanMaxTimestamp() {
+        return scanMaxTimestamp;
+    }
+
+    public byte[] getIndexTableRowKey() {
+        return indexTableRowKey;
+    }
+
+    public long getIndexTableRowTimestamp() {
+        return indexTableRowTimestamp;
+    }
+
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public byte[] getExpectedValue() {
+        return expectedValue;
+    }
+
+    public byte[] getActualValue() {
+        return actualValue;
+    }
+
+    public byte[] getPhaseValue() {
+        return phaseValue;
+    }
+
+    public byte[] getDataTableRowKey() {
+        return dataTableRowKey;
+    }
+
+    public Long getDataTableRowTimestamp() {
+        return dataTableRowTimestamp;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o == null ) {
+            return false;
+        }
+        if (!(o instanceof  IndexVerificationOutputRow)) {
+            return false;
+        }
+        IndexVerificationOutputRow otherRow = (IndexVerificationOutputRow) o;
+
+        return Objects.equals(dataTableName, otherRow.getDataTableName()) &&
+            Objects.equals(indexTableName, otherRow.getIndexTableName()) &&
+            Objects.equals(scanMaxTimestamp, otherRow.getScanMaxTimestamp()) &&
+            Arrays.equals(dataTableRowKey, otherRow.getDataTableRowKey()) &&
+            Arrays.equals(indexTableRowKey, otherRow.getIndexTableRowKey()) &&
+            Objects.equals(dataTableRowTimestamp, otherRow.getDataTableRowTimestamp()) &&
+            Objects.equals(indexTableRowTimestamp, otherRow.getIndexTableRowTimestamp()) &&
+            Objects.equals(errorMessage, otherRow.getErrorMessage()) &&
+            Arrays.equals(expectedValue, otherRow.getExpectedValue()) &&
+            Arrays.equals(actualValue, otherRow.getActualValue()) &&
+            Arrays.equals(phaseValue, otherRow.getPhaseValue());
+    }
+
+    @Override
+    public int hashCode(){
+        return Objects.hashCode(scanMaxTimestamp) ^ Objects.hashCode(indexTableName) ^
+            Arrays.hashCode(dataTableRowKey);
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("DataTableName: ").append(dataTableName).append(",");
 
 Review comment:
   Good idea. Done.

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
swaroopak commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r401950870
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/IndexRebuildRegionScanner.java
 ##########
 @@ -154,6 +143,8 @@
     private int  singleRowRebuildReturnCode;
     private Map<byte[], NavigableSet<byte[]>> familyMap;
     private byte[][] viewConstants;
+    private IndexVerificationResultRepository verificationResultRepository;
 
 Review comment:
   How these two repositories differ from each other? Could the names be more explicit?  

----------------------------------------------------------------
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 merged pull request #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
gjacoby126 merged pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750
 
 
   

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
abhishek-chouhan commented on issue #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#issuecomment-609972156
 
 
   LGTM +1

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
kadirozde commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r402652508
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRow.java
 ##########
 @@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.mapreduce.index;
+
+import org.apache.hadoop.hbase.util.Bytes;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+public class IndexVerificationOutputRow {
 
 Review comment:
   Is this class is used only for IT? If so, it should not be under src/main, should it?

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
gjacoby126 commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r404310582
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRepository.java
 ##########
 @@ -0,0 +1,285 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.mapreduce.index;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.coprocessor.MetaDataProtocol;
+import org.apache.phoenix.hbase.index.table.HTableFactory;
+import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.query.ConnectionQueryServices;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.util.ByteUtil;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class IndexVerificationOutputRepository {
+    public static final byte[] ROW_KEY_SEPARATOR_BYTE = Bytes.toBytes("|");
+    private Table indexHTable;
+    private byte[] indexName;
+    private Table outputHTable;
+    public final static String OUTPUT_TABLE_NAME = "PHOENIX_INDEX_TOOL";
+    public final static byte[] OUTPUT_TABLE_NAME_BYTES = Bytes.toBytes(OUTPUT_TABLE_NAME);
+    public final static byte[] OUTPUT_TABLE_COLUMN_FAMILY = QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES;
+
+    public final static String DATA_TABLE_NAME = "DTName";
+    public final static byte[] DATA_TABLE_NAME_BYTES = Bytes.toBytes(DATA_TABLE_NAME);
+    public static String INDEX_TABLE_NAME = "ITName";
+    public final static byte[] INDEX_TABLE_NAME_BYTES = Bytes.toBytes(INDEX_TABLE_NAME);
+    public static String DATA_TABLE_ROW_KEY = "DTRowKey";
+    public final static byte[] DATA_TABLE_ROW_KEY_BYTES = Bytes.toBytes(DATA_TABLE_ROW_KEY);
+    public static String INDEX_TABLE_ROW_KEY = "ITRowKey";
+    public final static byte[] INDEX_TABLE_ROW_KEY_BYTES = Bytes.toBytes(INDEX_TABLE_ROW_KEY);
+    public static String DATA_TABLE_TS = "DTTS";
+    public final static byte[] DATA_TABLE_TS_BYTES = Bytes.toBytes(DATA_TABLE_TS);
+    public static String INDEX_TABLE_TS = "ITTS";
+    public final static byte[] INDEX_TABLE_TS_BYTES = Bytes.toBytes(INDEX_TABLE_TS);
+    public static String ERROR_MESSAGE = "Error";
+    public final static byte[] ERROR_MESSAGE_BYTES = Bytes.toBytes(ERROR_MESSAGE);
+
+    public static String  VERIFICATION_PHASE = "Phase";
+    public final static byte[] VERIFICATION_PHASE_BYTES = Bytes.toBytes(VERIFICATION_PHASE);
+    public final static String EXPECTED_VALUE = "ExpectedValue";
+    public final static byte[] EXPECTED_VALUE_BYTES = Bytes.toBytes(EXPECTED_VALUE);
+    public final static String ACTUAL_VALUE = "ActualValue";
+    public final static byte[] ACTUAL_VALUE_BYTES = Bytes.toBytes(ACTUAL_VALUE);
+    public static final byte[] E_VALUE_PREFIX_BYTES = Bytes.toBytes(" E:");
+    public static final byte[] A_VALUE_PREFIX_BYTES = Bytes.toBytes(" A:");
+    public static final int PREFIX_LENGTH = 3;
+    public static final int TOTAL_PREFIX_LENGTH = 6;
+    public static final byte[] PHASE_BEFORE_VALUE = Bytes.toBytes("BEFORE");
+    public static final byte[] PHASE_AFTER_VALUE = Bytes.toBytes("AFTER");
+
+    /**
+     * Only usable for the read path or for testing
+     */
+    public IndexVerificationOutputRepository(){
+
+    }
+
+    @VisibleForTesting
+    public IndexVerificationOutputRepository(byte[] indexName, Connection conn) throws SQLException {
+        ConnectionQueryServices queryServices =
+            conn.unwrap(PhoenixConnection.class).getQueryServices();
+        outputHTable = queryServices.getTable(OUTPUT_TABLE_NAME_BYTES);
+        indexHTable = queryServices.getTable(indexName);
+    }
+
+    public IndexVerificationOutputRepository(byte[] indexName, HTableFactory hTableFactory) throws IOException {
+        this.indexName = indexName;
+        outputHTable = hTableFactory.getTable(new ImmutableBytesPtr(OUTPUT_TABLE_NAME_BYTES));
+        indexHTable = hTableFactory.getTable(new ImmutableBytesPtr(indexName));
+    }
+
+    public static byte[] generateOutputTableRowKey(long ts, byte[] indexTableName, byte[] dataRowKey ) {
+        byte[] keyPrefix = Bytes.toBytes(Long.toString(ts));
+        byte[] rowKey;
+        int targetOffset = 0;
+        // The row key for the output table : timestamp | index table name | data row key
+        rowKey = new byte[keyPrefix.length + ROW_KEY_SEPARATOR_BYTE.length + indexTableName.length +
+            ROW_KEY_SEPARATOR_BYTE.length + dataRowKey.length];
+        Bytes.putBytes(rowKey, targetOffset, keyPrefix, 0, keyPrefix.length);
+        targetOffset += keyPrefix.length;
+        Bytes.putBytes(rowKey, targetOffset, ROW_KEY_SEPARATOR_BYTE, 0, ROW_KEY_SEPARATOR_BYTE.length);
+        targetOffset += ROW_KEY_SEPARATOR_BYTE.length;
+        Bytes.putBytes(rowKey, targetOffset, indexTableName, 0, indexTableName.length);
+        targetOffset += indexTableName.length;
+        Bytes.putBytes(rowKey, targetOffset, ROW_KEY_SEPARATOR_BYTE, 0, ROW_KEY_SEPARATOR_BYTE.length);
+        targetOffset += ROW_KEY_SEPARATOR_BYTE.length;
+        Bytes.putBytes(rowKey, targetOffset, dataRowKey, 0, dataRowKey.length);
+        return rowKey;
+    }
+
+    /**
+     * Generates partial row key for use in a Scan to get all rows for an index verification
+     */
+    private static byte[] generatePartialOutputTableRowKey(long ts, byte[] indexTableName){
+        byte[] keyPrefix = Bytes.toBytes(Long.toString(ts));
+        byte[] partialRowKey;
+        int targetOffset = 0;
+        // The row key for the output table : timestamp | index table name | data row key
+        partialRowKey = new byte[keyPrefix.length + ROW_KEY_SEPARATOR_BYTE.length + indexTableName.length];
+        Bytes.putBytes(partialRowKey, targetOffset, keyPrefix, 0, keyPrefix.length);
+        targetOffset += keyPrefix.length;
+        Bytes.putBytes(partialRowKey, targetOffset, ROW_KEY_SEPARATOR_BYTE, 0, ROW_KEY_SEPARATOR_BYTE.length);
+        targetOffset += ROW_KEY_SEPARATOR_BYTE.length;
+        Bytes.putBytes(partialRowKey, targetOffset, indexTableName, 0, indexTableName.length);
+        return partialRowKey;
+    }
+
+    public void createOutputTable(Connection connection) throws IOException, SQLException {
+        ConnectionQueryServices queryServices = connection.unwrap(PhoenixConnection.class).getQueryServices();
+        Admin admin = queryServices.getAdmin();
+        if (!admin.tableExists(TableName.valueOf(OUTPUT_TABLE_NAME))) {
+            HTableDescriptor tableDescriptor = new
+                HTableDescriptor(TableName.valueOf(OUTPUT_TABLE_NAME));
+            tableDescriptor.setValue(HColumnDescriptor.TTL,
+                String.valueOf(MetaDataProtocol.DEFAULT_LOG_TTL));
+            HColumnDescriptor columnDescriptor = new HColumnDescriptor(OUTPUT_TABLE_COLUMN_FAMILY);
+            tableDescriptor.addFamily(columnDescriptor);
+            admin.createTable(tableDescriptor);
+        }
+    }
+        
+    @VisibleForTesting
+    public void logToIndexToolOutputTable(byte[] dataRowKey, byte[] indexRowKey, long dataRowTs,
+                                          long indexRowTs,
+                                          String errorMsg, byte[] expectedValue, byte[] actualValue,
+                                          long scanMaxTs, byte[] tableName, boolean isBeforeRebuild)
+        throws IOException {
+        byte[] rowKey = generateOutputTableRowKey(scanMaxTs, indexHTable.getName().toBytes(), dataRowKey);
+        Put put = new Put(rowKey);
+        put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, DATA_TABLE_NAME_BYTES,
+            scanMaxTs, tableName);
+        put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, INDEX_TABLE_NAME_BYTES,
+            scanMaxTs, indexName);
+        put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, DATA_TABLE_TS_BYTES,
+            scanMaxTs, Bytes.toBytes(Long.toString(dataRowTs)));
+
+        put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, INDEX_TABLE_ROW_KEY_BYTES,
+            scanMaxTs, indexRowKey);
+        put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, INDEX_TABLE_TS_BYTES,
+            scanMaxTs, Bytes.toBytes(Long.toString(indexRowTs)));
+        byte[] errorMessageBytes;
+        if (expectedValue != null) {
+            errorMessageBytes = getErrorMessageBytes(errorMsg, expectedValue, actualValue);
+            put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, EXPECTED_VALUE_BYTES, expectedValue);
+            put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, ACTUAL_VALUE_BYTES, actualValue);
+        } else {
+            errorMessageBytes = Bytes.toBytes(errorMsg);
+        }
+        put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, ERROR_MESSAGE_BYTES, scanMaxTs, errorMessageBytes);
+        if (isBeforeRebuild) {
+            put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, VERIFICATION_PHASE_BYTES, scanMaxTs, PHASE_BEFORE_VALUE);
+        } else {
+            put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, VERIFICATION_PHASE_BYTES, scanMaxTs, PHASE_AFTER_VALUE);
+        }
+        outputHTable.put(put);
+    }
+
+    public static byte[] getErrorMessageBytes(String errorMsg, byte[] expectedValue, byte[] actualValue) {
+        byte[] errorMessageBytes;
+        errorMessageBytes = new byte[errorMsg.length() + expectedValue.length + actualValue.length +
+            TOTAL_PREFIX_LENGTH];
+        Bytes.putBytes(errorMessageBytes, 0, Bytes.toBytes(errorMsg), 0, errorMsg.length());
+        int length = errorMsg.length();
+        Bytes.putBytes(errorMessageBytes, length, E_VALUE_PREFIX_BYTES, 0, PREFIX_LENGTH);
+        length += PREFIX_LENGTH;
+        Bytes.putBytes(errorMessageBytes, length, expectedValue, 0, expectedValue.length);
+        length += expectedValue.length;
+        Bytes.putBytes(errorMessageBytes, length, A_VALUE_PREFIX_BYTES, 0, PREFIX_LENGTH);
+        length += PREFIX_LENGTH;
+        Bytes.putBytes(errorMessageBytes, length, actualValue, 0, actualValue.length);
+        return errorMessageBytes;
+    }
+
+    public List<IndexVerificationOutputRow> getOutputRows(long ts, byte[] indexName)
+        throws IOException {
+        Iterator<IndexVerificationOutputRow> iter = getOutputRowIterator(ts, indexName);
+        List<IndexVerificationOutputRow> outputRowList = new ArrayList<IndexVerificationOutputRow>();
+        while (iter.hasNext()){
+            outputRowList.add(iter.next());
+        }
+        return outputRowList;
+    }
+
+    public Iterator<IndexVerificationOutputRow> getOutputRowIterator(long ts, byte[] indexName)
+        throws IOException {
+        Scan scan = new Scan();
+        byte[] partialKey = generatePartialOutputTableRowKey(ts, indexName);
+        scan.withStartRow(partialKey);
+        scan.withStopRow(ByteUtil.calculateTheClosestNextRowKeyForPrefix(partialKey));
+        ResultScanner scanner = outputHTable.getScanner(scan);
+        return new IndexVerificationOutputRowIterator(scanner.iterator());
+    }
+
+    public static IndexVerificationOutputRow getOutputRowFromResult(Result result) {
+        IndexVerificationOutputRow.IndexVerificationOutputRowBuilder builder =
+            new IndexVerificationOutputRow.IndexVerificationOutputRowBuilder();
+        byte[] rowKey = result.getRow();
+        //rowkey is scanTs + SEPARATOR_BYTE + indexTableName + SEPARATOR_BYTE + dataTableRowKey
+        byte[][] rowKeySplit = ByteUtil.splitArrayBySeparator(rowKey, ROW_KEY_SEPARATOR_BYTE[0]);
+        builder.setScanMaxTimestamp(Long.parseLong(Bytes.toString(rowKeySplit[0])));
+        builder.setIndexTableName(Bytes.toString(rowKeySplit[1]));
+        builder.setDataTableRowKey(rowKeySplit[2]);
+
+        builder.setDataTableName(Bytes.toString(result.getValue(OUTPUT_TABLE_COLUMN_FAMILY,
+            DATA_TABLE_NAME_BYTES)));
+        builder.setIndexTableRowKey(result.getValue(OUTPUT_TABLE_COLUMN_FAMILY,
+            INDEX_TABLE_ROW_KEY_BYTES));
+        builder.setDataTableRowTimestamp(Long.parseLong(Bytes.toString(result.getValue(OUTPUT_TABLE_COLUMN_FAMILY,
+            DATA_TABLE_TS_BYTES))));
+        builder.setIndexTableRowTimestamp(Long.parseLong(Bytes.toString(result.getValue(OUTPUT_TABLE_COLUMN_FAMILY,
+            INDEX_TABLE_TS_BYTES))));
+        builder.setErrorMessage(Bytes.toString(result.getValue(OUTPUT_TABLE_COLUMN_FAMILY,
+            ERROR_MESSAGE_BYTES)));
+        //actual and expected value might not be present, but will just set to null if not
+        builder.setExpectedValue(result.getValue(OUTPUT_TABLE_COLUMN_FAMILY, EXPECTED_VALUE_BYTES));
+        builder.setActualValue(result.getValue(OUTPUT_TABLE_COLUMN_FAMILY, ACTUAL_VALUE_BYTES));
+        builder.setPhaseValue(result.getValue(OUTPUT_TABLE_COLUMN_FAMILY, VERIFICATION_PHASE_BYTES));
+        return builder.build();
+    }
+
+    public void close() throws IOException {
+        if (outputHTable != null) {
+            outputHTable.close();
+        }
 
 Review comment:
   Good catch, thanks. Done. 

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
gjacoby126 commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r402657252
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRow.java
 ##########
 @@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.mapreduce.index;
+
+import org.apache.hadoop.hbase.util.Bytes;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+public class IndexVerificationOutputRow {
 
 Review comment:
   The purpose of the patch is to expose the output row and repo classes so they can be used both for tests and also externally in tools that programmatically query and analyze the output table. So it needs to be in main. 

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
gjacoby126 commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r402656754
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexVerificationResultRepositoryTest.java
 ##########
 @@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end.index;
+
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.coprocessor.IndexToolVerificationResult;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
+import org.apache.phoenix.mapreduce.index.IndexTool;
+import org.apache.phoenix.mapreduce.index.IndexVerificationResultRepository;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.Collections;
+import java.util.Map;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+public class IndexVerificationResultRepositoryTest extends ParallelStatsDisabledIT {
 
 Review comment:
   Fair point. It's sort of between a true unit test and an IT, because it needs a minicluster but is exercising a particular class rather than something broader. I'll change the names. 

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
kadirozde commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r402644744
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexVerificationOutputRepositoryTest.java
 ##########
 @@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end.index;
+
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.mapreduce.index.IndexVerificationOutputRepository;
+import org.apache.phoenix.mapreduce.index.IndexVerificationOutputRow;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.phoenix.mapreduce.index.IndexVerificationOutputRepository.PHASE_AFTER_VALUE;
+import static org.apache.phoenix.mapreduce.index.IndexVerificationOutputRepository.PHASE_BEFORE_VALUE;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class IndexVerificationOutputRepositoryTest extends ParallelStatsDisabledIT {
 
 Review comment:
   Should not this be called IndexVerificationOutputRepositoryIT?

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
kadirozde commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r402643700
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexVerificationResultRepositoryTest.java
 ##########
 @@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end.index;
+
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.coprocessor.IndexToolVerificationResult;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
+import org.apache.phoenix.mapreduce.index.IndexTool;
+import org.apache.phoenix.mapreduce.index.IndexVerificationResultRepository;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.Collections;
+import java.util.Map;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+public class IndexVerificationResultRepositoryTest extends ParallelStatsDisabledIT {
 
 Review comment:
   Should not this be called IndexVerificationResultRepositoryIT?

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
swaroopak commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r403404730
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRow.java
 ##########
 @@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.mapreduce.index;
+
+import org.apache.hadoop.hbase.util.Bytes;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+public class IndexVerificationOutputRow {
+    private String dataTableName;
+    private String indexTableName;
+    private Long scanMaxTimestamp;
+    private byte[] dataTableRowKey;
+    private byte[] indexTableRowKey;
+    private Long dataTableRowTimestamp;
+    private Long indexTableRowTimestamp;
+    private String errorMessage;
+    private byte[] expectedValue;
+    private byte[] actualValue;
+    private byte[] phaseValue;
+
+    private IndexVerificationOutputRow(String dataTableName, String indexTableName,
+                                       byte[] dataTableRowKey, Long scanMaxTimestamp,
+                                      byte[] indexTableRowKey,
+                                       long dataTableRowTimestamp, long indexTableRowTimestamp,
+                                      String errorMessage, byte[] expectedValue, byte[] actualValue,
+                                      byte[] phaseValue) {
+        this.dataTableName = dataTableName;
+        this.indexTableName = indexTableName;
+        this.scanMaxTimestamp = scanMaxTimestamp;
+        this.dataTableRowKey = dataTableRowKey;
+        this.indexTableRowKey = indexTableRowKey;
+        this.dataTableRowTimestamp = dataTableRowTimestamp;
+        this.indexTableRowTimestamp = indexTableRowTimestamp;
+        this.errorMessage = errorMessage;
+        this.expectedValue = expectedValue;
+        this.actualValue = actualValue;
+        this.phaseValue = phaseValue;
+    }
+
+    public String getDataTableName() {
+        return dataTableName;
+    }
+
+    public String getIndexTableName() {
+        return indexTableName;
+    }
+
+    public Long getScanMaxTimestamp() {
+        return scanMaxTimestamp;
+    }
+
+    public byte[] getIndexTableRowKey() {
+        return indexTableRowKey;
+    }
+
+    public long getIndexTableRowTimestamp() {
+        return indexTableRowTimestamp;
+    }
+
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public byte[] getExpectedValue() {
+        return expectedValue;
+    }
+
+    public byte[] getActualValue() {
+        return actualValue;
+    }
+
+    public byte[] getPhaseValue() {
+        return phaseValue;
+    }
+
+    public byte[] getDataTableRowKey() {
+        return dataTableRowKey;
+    }
+
+    public Long getDataTableRowTimestamp() {
+        return dataTableRowTimestamp;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o == null ) {
+            return false;
+        }
+        if (!(o instanceof  IndexVerificationOutputRow)) {
+            return false;
+        }
+        IndexVerificationOutputRow otherRow = (IndexVerificationOutputRow) o;
+
+        return Objects.equals(dataTableName, otherRow.getDataTableName()) &&
+            Objects.equals(indexTableName, otherRow.getIndexTableName()) &&
+            Objects.equals(scanMaxTimestamp, otherRow.getScanMaxTimestamp()) &&
+            Arrays.equals(dataTableRowKey, otherRow.getDataTableRowKey()) &&
+            Arrays.equals(indexTableRowKey, otherRow.getIndexTableRowKey()) &&
+            Objects.equals(dataTableRowTimestamp, otherRow.getDataTableRowTimestamp()) &&
+            Objects.equals(indexTableRowTimestamp, otherRow.getIndexTableRowTimestamp()) &&
+            Objects.equals(errorMessage, otherRow.getErrorMessage()) &&
+            Arrays.equals(expectedValue, otherRow.getExpectedValue()) &&
+            Arrays.equals(actualValue, otherRow.getActualValue()) &&
+            Arrays.equals(phaseValue, otherRow.getPhaseValue());
+    }
+
+    @Override
+    public int hashCode(){
+        return Objects.hashCode(scanMaxTimestamp) ^ Objects.hashCode(indexTableName) ^
+            Arrays.hashCode(dataTableRowKey);
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("DataTableName: ").append(dataTableName).append(",");
 
 Review comment:
   Why not reuse the same strings from table values? like DTName, ITName. Would be easier to track and reuse. 

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
gjacoby126 commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r402744260
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexVerificationResultRepositoryTest.java
 ##########
 @@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end.index;
+
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.coprocessor.IndexToolVerificationResult;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
+import org.apache.phoenix.mapreduce.index.IndexTool;
+import org.apache.phoenix.mapreduce.index.IndexVerificationResultRepository;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.Collections;
+import java.util.Map;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+public class IndexVerificationResultRepositoryTest extends ParallelStatsDisabledIT {
 
 Review comment:
   Fixed

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
abhishek-chouhan commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r403387007
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationResultRepository.java
 ##########
 @@ -0,0 +1,209 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.mapreduce.index;
+
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.coprocessor.IndexToolVerificationResult;
+import org.apache.phoenix.coprocessor.MetaDataProtocol;
+import org.apache.phoenix.hbase.index.table.HTableFactory;
+import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.mapreduce.index.IndexTool;
+import org.apache.phoenix.query.ConnectionQueryServices;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.util.ByteUtil;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+public class IndexVerificationResultRepository {
+    private Table resultHTable;
+    private Table indexHTable;
+    public static final byte[] ROW_KEY_SEPARATOR_BYTE = Bytes.toBytes("|");
+    public final static String RESULT_TABLE_NAME = "PHOENIX_INDEX_TOOL_RESULT";
+    public final static byte[] RESULT_TABLE_NAME_BYTES = Bytes.toBytes(RESULT_TABLE_NAME);
+    public final static byte[] RESULT_TABLE_COLUMN_FAMILY = QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES;
+    public static String SCANNED_DATA_ROW_COUNT = "ScannedDataRowCount";
+    public final static byte[] SCANNED_DATA_ROW_COUNT_BYTES = Bytes.toBytes(SCANNED_DATA_ROW_COUNT);
+    public static String REBUILT_INDEX_ROW_COUNT = "RebuiltIndexRowCount";
+    public final static byte[] REBUILT_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(REBUILT_INDEX_ROW_COUNT);
+    public static String BEFORE_REBUILD_VALID_INDEX_ROW_COUNT = "BeforeRebuildValidIndexRowCount";
+    public final static byte[] BEFORE_REBUILD_VALID_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(BEFORE_REBUILD_VALID_INDEX_ROW_COUNT);
+    public static String BEFORE_REBUILD_EXPIRED_INDEX_ROW_COUNT = "BeforeRebuildExpiredIndexRowCount";
+    public final static byte[] BEFORE_REBUILD_EXPIRED_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(BEFORE_REBUILD_EXPIRED_INDEX_ROW_COUNT);
+    public static String BEFORE_REBUILD_MISSING_INDEX_ROW_COUNT = "BeforeRebuildMissingIndexRowCount";
+    public final static byte[] BEFORE_REBUILD_MISSING_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(BEFORE_REBUILD_MISSING_INDEX_ROW_COUNT);
+    public static String BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT = "BeforeRebuildInvalidIndexRowCount";
+    public final static byte[] BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT);
+    public static String AFTER_REBUILD_VALID_INDEX_ROW_COUNT = "AfterValidExpiredIndexRowCount";
+    public final static byte[] AFTER_REBUILD_VALID_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(AFTER_REBUILD_VALID_INDEX_ROW_COUNT);
+    public static String AFTER_REBUILD_EXPIRED_INDEX_ROW_COUNT = "AfterRebuildExpiredIndexRowCount";
+    public final static byte[] AFTER_REBUILD_EXPIRED_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(AFTER_REBUILD_EXPIRED_INDEX_ROW_COUNT);
+    public static String AFTER_REBUILD_MISSING_INDEX_ROW_COUNT = "AfterRebuildMissingIndexRowCount";
+    public final static byte[] AFTER_REBUILD_MISSING_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(AFTER_REBUILD_MISSING_INDEX_ROW_COUNT);
+    public static String AFTER_REBUILD_INVALID_INDEX_ROW_COUNT = "AfterRebuildInvalidIndexRowCount";
+    public final static byte[] AFTER_REBUILD_INVALID_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(AFTER_REBUILD_INVALID_INDEX_ROW_COUNT);
+    /***
+     * Only usable for read methods
+     */
+    public IndexVerificationResultRepository(){
+
+    }
+
+    public IndexVerificationResultRepository(Connection conn, byte[] indexNameBytes) throws SQLException {
+        resultHTable = getTable(conn, RESULT_TABLE_NAME_BYTES);
+        indexHTable = getTable(conn, indexNameBytes);
+    }
+
+    public IndexVerificationResultRepository(byte[] indexName,
+                                             HTableFactory hTableFactory) throws IOException {
+        resultHTable = hTableFactory.getTable(new ImmutableBytesPtr(RESULT_TABLE_NAME_BYTES));
+        indexHTable = hTableFactory.getTable(new ImmutableBytesPtr(indexName));
+    }
+
+    public void createResultTable(Connection connection) throws IOException, SQLException {
+        ConnectionQueryServices queryServices = connection.unwrap(PhoenixConnection.class).getQueryServices();
+        Admin admin = queryServices.getAdmin();
+
+        if (!admin.tableExists(TableName.valueOf(RESULT_TABLE_NAME))) {
+            HTableDescriptor tableDescriptor = new
+                HTableDescriptor(TableName.valueOf(RESULT_TABLE_NAME));
+            tableDescriptor.setValue(HColumnDescriptor.TTL, String.valueOf(MetaDataProtocol.DEFAULT_LOG_TTL));
+            HColumnDescriptor columnDescriptor = new HColumnDescriptor(RESULT_TABLE_COLUMN_FAMILY);
+            tableDescriptor.addFamily(columnDescriptor);
+            admin.createTable(tableDescriptor);
+        }
+    }
+    public static byte[] generateResultTableRowKey(long ts, byte[] indexTableName,  byte [] regionName,
+                                                    byte[] startRow, byte[] stopRow) {
+        byte[] keyPrefix = Bytes.toBytes(Long.toString(ts));
+        int targetOffset = 0;
+        // The row key for the result table : timestamp | index table name | datable table region name |
+        //                                    scan start row | scan stop row
+        byte[] rowKey = new byte[keyPrefix.length + ROW_KEY_SEPARATOR_BYTE.length + indexTableName.length +
+            ROW_KEY_SEPARATOR_BYTE.length + regionName.length + ROW_KEY_SEPARATOR_BYTE.length +
+            startRow.length + ROW_KEY_SEPARATOR_BYTE.length + stopRow.length];
+        Bytes.putBytes(rowKey, targetOffset, keyPrefix, 0, keyPrefix.length);
+        targetOffset += keyPrefix.length;
+        Bytes.putBytes(rowKey, targetOffset, ROW_KEY_SEPARATOR_BYTE, 0, ROW_KEY_SEPARATOR_BYTE.length);
+        targetOffset += ROW_KEY_SEPARATOR_BYTE.length;
+        Bytes.putBytes(rowKey, targetOffset, indexTableName, 0, indexTableName.length);
+        targetOffset += indexTableName.length;
+        Bytes.putBytes(rowKey, targetOffset, ROW_KEY_SEPARATOR_BYTE, 0, ROW_KEY_SEPARATOR_BYTE.length);
+        targetOffset += ROW_KEY_SEPARATOR_BYTE.length;
+        Bytes.putBytes(rowKey, targetOffset, regionName, 0, regionName.length);
+        targetOffset += regionName.length;
+        Bytes.putBytes(rowKey, targetOffset, ROW_KEY_SEPARATOR_BYTE, 0, ROW_KEY_SEPARATOR_BYTE.length);
+        targetOffset += ROW_KEY_SEPARATOR_BYTE.length;
+        Bytes.putBytes(rowKey, targetOffset, startRow, 0, startRow.length);
+        targetOffset += startRow.length;
+        Bytes.putBytes(rowKey, targetOffset, ROW_KEY_SEPARATOR_BYTE, 0, ROW_KEY_SEPARATOR_BYTE.length);
+        targetOffset += ROW_KEY_SEPARATOR_BYTE.length;
+        Bytes.putBytes(rowKey, targetOffset, stopRow, 0, stopRow.length);
+        return rowKey;
+    }
+
+    public void logToIndexToolResultTable(IndexToolVerificationResult verificationResult,
+                                          IndexTool.IndexVerifyType verifyType, byte[] region) throws IOException {
+        long scanMaxTs = verificationResult.getScanMaxTs();
+        byte[] rowKey = generateResultTableRowKey(scanMaxTs, indexHTable.getName().toBytes(),
+            region, verificationResult.getStartRow(),
+            verificationResult.getStopRow());
+        Put put = new Put(rowKey);
+        put.addColumn(RESULT_TABLE_COLUMN_FAMILY, SCANNED_DATA_ROW_COUNT_BYTES,
+            scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getScannedDataRowCount())));
+        put.addColumn(RESULT_TABLE_COLUMN_FAMILY, REBUILT_INDEX_ROW_COUNT_BYTES,
+            scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getRebuiltIndexRowCount())));
+        if (verifyType == IndexTool.IndexVerifyType.BEFORE || verifyType == IndexTool.IndexVerifyType.BOTH ||
+            verifyType == IndexTool.IndexVerifyType.ONLY) {
+            put.addColumn(RESULT_TABLE_COLUMN_FAMILY, BEFORE_REBUILD_VALID_INDEX_ROW_COUNT_BYTES,
+                scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getBeforeRebuildValidIndexRowCount())));
+            put.addColumn(RESULT_TABLE_COLUMN_FAMILY, BEFORE_REBUILD_EXPIRED_INDEX_ROW_COUNT_BYTES,
+                scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getBeforeRebuildExpiredIndexRowCount())));
+            put.addColumn(RESULT_TABLE_COLUMN_FAMILY, BEFORE_REBUILD_MISSING_INDEX_ROW_COUNT_BYTES,
+                scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getBeforeRebuildMissingIndexRowCount())));
+            put.addColumn(RESULT_TABLE_COLUMN_FAMILY, BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT_BYTES,
+                scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getBeforeRebuildInvalidIndexRowCount())));
+        }
+        if (verifyType == IndexTool.IndexVerifyType.AFTER || verifyType == IndexTool.IndexVerifyType.BOTH) {
+            put.addColumn(RESULT_TABLE_COLUMN_FAMILY, AFTER_REBUILD_VALID_INDEX_ROW_COUNT_BYTES,
+                scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getAfterRebuildValidIndexRowCount())));
+            put.addColumn(RESULT_TABLE_COLUMN_FAMILY, AFTER_REBUILD_EXPIRED_INDEX_ROW_COUNT_BYTES,
+                scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getAfterRebuildExpiredIndexRowCount())));
+            put.addColumn(RESULT_TABLE_COLUMN_FAMILY, AFTER_REBUILD_MISSING_INDEX_ROW_COUNT_BYTES,
+                scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getAfterRebuildMissingIndexRowCount())));
+            put.addColumn(RESULT_TABLE_COLUMN_FAMILY, AFTER_REBUILD_INVALID_INDEX_ROW_COUNT_BYTES,
+                scanMaxTs, Bytes.toBytes(Long.toString(verificationResult.getAfterRebuildInvalidIndexRowCount())));
+        }
+        resultHTable.put(put);
+    }
+
+    public IndexToolVerificationResult getVerificationResult(Connection conn, long ts) throws IOException, SQLException {
+        Table hTable = getTable(conn, RESULT_TABLE_NAME_BYTES);
+        return getVerificationResult(hTable, ts);
+    }
+
+    public Table getTable(Connection conn, byte[] tableName) throws SQLException {
+        return conn.unwrap(PhoenixConnection.class).getQueryServices()
+                .getTable(tableName);
+    }
+
+    public IndexToolVerificationResult getVerificationResult(Table htable, long ts)
+        throws IOException {
+        byte[] startRowKey = Bytes.toBytes(Long.toString(ts));
+        byte[] stopRowKey = ByteUtil.calculateTheClosestNextRowKeyForPrefix(startRowKey);
+        IndexToolVerificationResult verificationResult = new IndexToolVerificationResult(ts);
+        Scan scan = new Scan();
+        scan.withStartRow(startRowKey);
+        scan.withStopRow(stopRowKey);
+        ResultScanner scanner = htable.getScanner(scan);
+        for (Result result = scanner.next(); result != null; result = scanner.next()) {
+            boolean isFirst = true;
+            for (Cell cell : result.rawCells()) {
+                if (isFirst){
+                    byte[][] rowKeyParts = ByteUtil.splitArrayBySeparator(result.getRow(),
+                        ROW_KEY_SEPARATOR_BYTE[0]);
+                    verificationResult.setStartRow(rowKeyParts[3]);
+                    verificationResult.setStopRow(rowKeyParts[4]);
+                    isFirst = false;
+                }
+                verificationResult.update(cell);
+            }
+        }
+        return verificationResult;
+    }
+
+    public void close() throws IOException {
+        if (resultHTable != null) {
 
 Review comment:
   Check for indexHtable and close here too?

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
kadirozde commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r402693138
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRow.java
 ##########
 @@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.mapreduce.index;
+
+import org.apache.hadoop.hbase.util.Bytes;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+public class IndexVerificationOutputRow {
 
 Review comment:
   It makes sense. Thx

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
abhishek-chouhan commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r403384713
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRepository.java
 ##########
 @@ -0,0 +1,285 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.mapreduce.index;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.coprocessor.MetaDataProtocol;
+import org.apache.phoenix.hbase.index.table.HTableFactory;
+import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.query.ConnectionQueryServices;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.util.ByteUtil;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class IndexVerificationOutputRepository {
+    public static final byte[] ROW_KEY_SEPARATOR_BYTE = Bytes.toBytes("|");
+    private Table indexHTable;
+    private byte[] indexName;
+    private Table outputHTable;
+    public final static String OUTPUT_TABLE_NAME = "PHOENIX_INDEX_TOOL";
+    public final static byte[] OUTPUT_TABLE_NAME_BYTES = Bytes.toBytes(OUTPUT_TABLE_NAME);
+    public final static byte[] OUTPUT_TABLE_COLUMN_FAMILY = QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES;
+
+    public final static String DATA_TABLE_NAME = "DTName";
+    public final static byte[] DATA_TABLE_NAME_BYTES = Bytes.toBytes(DATA_TABLE_NAME);
+    public static String INDEX_TABLE_NAME = "ITName";
+    public final static byte[] INDEX_TABLE_NAME_BYTES = Bytes.toBytes(INDEX_TABLE_NAME);
+    public static String DATA_TABLE_ROW_KEY = "DTRowKey";
+    public final static byte[] DATA_TABLE_ROW_KEY_BYTES = Bytes.toBytes(DATA_TABLE_ROW_KEY);
+    public static String INDEX_TABLE_ROW_KEY = "ITRowKey";
+    public final static byte[] INDEX_TABLE_ROW_KEY_BYTES = Bytes.toBytes(INDEX_TABLE_ROW_KEY);
+    public static String DATA_TABLE_TS = "DTTS";
+    public final static byte[] DATA_TABLE_TS_BYTES = Bytes.toBytes(DATA_TABLE_TS);
+    public static String INDEX_TABLE_TS = "ITTS";
+    public final static byte[] INDEX_TABLE_TS_BYTES = Bytes.toBytes(INDEX_TABLE_TS);
+    public static String ERROR_MESSAGE = "Error";
+    public final static byte[] ERROR_MESSAGE_BYTES = Bytes.toBytes(ERROR_MESSAGE);
+
+    public static String  VERIFICATION_PHASE = "Phase";
+    public final static byte[] VERIFICATION_PHASE_BYTES = Bytes.toBytes(VERIFICATION_PHASE);
+    public final static String EXPECTED_VALUE = "ExpectedValue";
+    public final static byte[] EXPECTED_VALUE_BYTES = Bytes.toBytes(EXPECTED_VALUE);
+    public final static String ACTUAL_VALUE = "ActualValue";
+    public final static byte[] ACTUAL_VALUE_BYTES = Bytes.toBytes(ACTUAL_VALUE);
+    public static final byte[] E_VALUE_PREFIX_BYTES = Bytes.toBytes(" E:");
+    public static final byte[] A_VALUE_PREFIX_BYTES = Bytes.toBytes(" A:");
+    public static final int PREFIX_LENGTH = 3;
+    public static final int TOTAL_PREFIX_LENGTH = 6;
+    public static final byte[] PHASE_BEFORE_VALUE = Bytes.toBytes("BEFORE");
+    public static final byte[] PHASE_AFTER_VALUE = Bytes.toBytes("AFTER");
+
+    /**
+     * Only usable for the read path or for testing
+     */
+    public IndexVerificationOutputRepository(){
+
+    }
+
+    @VisibleForTesting
+    public IndexVerificationOutputRepository(byte[] indexName, Connection conn) throws SQLException {
+        ConnectionQueryServices queryServices =
+            conn.unwrap(PhoenixConnection.class).getQueryServices();
+        outputHTable = queryServices.getTable(OUTPUT_TABLE_NAME_BYTES);
+        indexHTable = queryServices.getTable(indexName);
+    }
+
+    public IndexVerificationOutputRepository(byte[] indexName, HTableFactory hTableFactory) throws IOException {
+        this.indexName = indexName;
+        outputHTable = hTableFactory.getTable(new ImmutableBytesPtr(OUTPUT_TABLE_NAME_BYTES));
+        indexHTable = hTableFactory.getTable(new ImmutableBytesPtr(indexName));
+    }
+
+    public static byte[] generateOutputTableRowKey(long ts, byte[] indexTableName, byte[] dataRowKey ) {
+        byte[] keyPrefix = Bytes.toBytes(Long.toString(ts));
+        byte[] rowKey;
+        int targetOffset = 0;
+        // The row key for the output table : timestamp | index table name | data row key
+        rowKey = new byte[keyPrefix.length + ROW_KEY_SEPARATOR_BYTE.length + indexTableName.length +
+            ROW_KEY_SEPARATOR_BYTE.length + dataRowKey.length];
+        Bytes.putBytes(rowKey, targetOffset, keyPrefix, 0, keyPrefix.length);
+        targetOffset += keyPrefix.length;
+        Bytes.putBytes(rowKey, targetOffset, ROW_KEY_SEPARATOR_BYTE, 0, ROW_KEY_SEPARATOR_BYTE.length);
+        targetOffset += ROW_KEY_SEPARATOR_BYTE.length;
+        Bytes.putBytes(rowKey, targetOffset, indexTableName, 0, indexTableName.length);
+        targetOffset += indexTableName.length;
+        Bytes.putBytes(rowKey, targetOffset, ROW_KEY_SEPARATOR_BYTE, 0, ROW_KEY_SEPARATOR_BYTE.length);
+        targetOffset += ROW_KEY_SEPARATOR_BYTE.length;
+        Bytes.putBytes(rowKey, targetOffset, dataRowKey, 0, dataRowKey.length);
+        return rowKey;
+    }
+
+    /**
+     * Generates partial row key for use in a Scan to get all rows for an index verification
+     */
+    private static byte[] generatePartialOutputTableRowKey(long ts, byte[] indexTableName){
+        byte[] keyPrefix = Bytes.toBytes(Long.toString(ts));
+        byte[] partialRowKey;
+        int targetOffset = 0;
+        // The row key for the output table : timestamp | index table name | data row key
+        partialRowKey = new byte[keyPrefix.length + ROW_KEY_SEPARATOR_BYTE.length + indexTableName.length];
+        Bytes.putBytes(partialRowKey, targetOffset, keyPrefix, 0, keyPrefix.length);
+        targetOffset += keyPrefix.length;
+        Bytes.putBytes(partialRowKey, targetOffset, ROW_KEY_SEPARATOR_BYTE, 0, ROW_KEY_SEPARATOR_BYTE.length);
+        targetOffset += ROW_KEY_SEPARATOR_BYTE.length;
+        Bytes.putBytes(partialRowKey, targetOffset, indexTableName, 0, indexTableName.length);
+        return partialRowKey;
+    }
+
+    public void createOutputTable(Connection connection) throws IOException, SQLException {
+        ConnectionQueryServices queryServices = connection.unwrap(PhoenixConnection.class).getQueryServices();
+        Admin admin = queryServices.getAdmin();
+        if (!admin.tableExists(TableName.valueOf(OUTPUT_TABLE_NAME))) {
+            HTableDescriptor tableDescriptor = new
+                HTableDescriptor(TableName.valueOf(OUTPUT_TABLE_NAME));
+            tableDescriptor.setValue(HColumnDescriptor.TTL,
+                String.valueOf(MetaDataProtocol.DEFAULT_LOG_TTL));
+            HColumnDescriptor columnDescriptor = new HColumnDescriptor(OUTPUT_TABLE_COLUMN_FAMILY);
+            tableDescriptor.addFamily(columnDescriptor);
+            admin.createTable(tableDescriptor);
+        }
+    }
+        
+    @VisibleForTesting
+    public void logToIndexToolOutputTable(byte[] dataRowKey, byte[] indexRowKey, long dataRowTs,
+                                          long indexRowTs,
+                                          String errorMsg, byte[] expectedValue, byte[] actualValue,
+                                          long scanMaxTs, byte[] tableName, boolean isBeforeRebuild)
+        throws IOException {
+        byte[] rowKey = generateOutputTableRowKey(scanMaxTs, indexHTable.getName().toBytes(), dataRowKey);
+        Put put = new Put(rowKey);
+        put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, DATA_TABLE_NAME_BYTES,
+            scanMaxTs, tableName);
+        put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, INDEX_TABLE_NAME_BYTES,
+            scanMaxTs, indexName);
+        put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, DATA_TABLE_TS_BYTES,
+            scanMaxTs, Bytes.toBytes(Long.toString(dataRowTs)));
+
+        put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, INDEX_TABLE_ROW_KEY_BYTES,
+            scanMaxTs, indexRowKey);
+        put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, INDEX_TABLE_TS_BYTES,
+            scanMaxTs, Bytes.toBytes(Long.toString(indexRowTs)));
+        byte[] errorMessageBytes;
+        if (expectedValue != null) {
+            errorMessageBytes = getErrorMessageBytes(errorMsg, expectedValue, actualValue);
+            put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, EXPECTED_VALUE_BYTES, expectedValue);
+            put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, ACTUAL_VALUE_BYTES, actualValue);
+        } else {
+            errorMessageBytes = Bytes.toBytes(errorMsg);
+        }
+        put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, ERROR_MESSAGE_BYTES, scanMaxTs, errorMessageBytes);
+        if (isBeforeRebuild) {
+            put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, VERIFICATION_PHASE_BYTES, scanMaxTs, PHASE_BEFORE_VALUE);
+        } else {
+            put.addColumn(OUTPUT_TABLE_COLUMN_FAMILY, VERIFICATION_PHASE_BYTES, scanMaxTs, PHASE_AFTER_VALUE);
+        }
+        outputHTable.put(put);
+    }
+
+    public static byte[] getErrorMessageBytes(String errorMsg, byte[] expectedValue, byte[] actualValue) {
+        byte[] errorMessageBytes;
+        errorMessageBytes = new byte[errorMsg.length() + expectedValue.length + actualValue.length +
+            TOTAL_PREFIX_LENGTH];
+        Bytes.putBytes(errorMessageBytes, 0, Bytes.toBytes(errorMsg), 0, errorMsg.length());
+        int length = errorMsg.length();
+        Bytes.putBytes(errorMessageBytes, length, E_VALUE_PREFIX_BYTES, 0, PREFIX_LENGTH);
+        length += PREFIX_LENGTH;
+        Bytes.putBytes(errorMessageBytes, length, expectedValue, 0, expectedValue.length);
+        length += expectedValue.length;
+        Bytes.putBytes(errorMessageBytes, length, A_VALUE_PREFIX_BYTES, 0, PREFIX_LENGTH);
+        length += PREFIX_LENGTH;
+        Bytes.putBytes(errorMessageBytes, length, actualValue, 0, actualValue.length);
+        return errorMessageBytes;
+    }
+
+    public List<IndexVerificationOutputRow> getOutputRows(long ts, byte[] indexName)
+        throws IOException {
+        Iterator<IndexVerificationOutputRow> iter = getOutputRowIterator(ts, indexName);
+        List<IndexVerificationOutputRow> outputRowList = new ArrayList<IndexVerificationOutputRow>();
+        while (iter.hasNext()){
+            outputRowList.add(iter.next());
+        }
+        return outputRowList;
+    }
+
+    public Iterator<IndexVerificationOutputRow> getOutputRowIterator(long ts, byte[] indexName)
+        throws IOException {
+        Scan scan = new Scan();
+        byte[] partialKey = generatePartialOutputTableRowKey(ts, indexName);
+        scan.withStartRow(partialKey);
+        scan.withStopRow(ByteUtil.calculateTheClosestNextRowKeyForPrefix(partialKey));
+        ResultScanner scanner = outputHTable.getScanner(scan);
+        return new IndexVerificationOutputRowIterator(scanner.iterator());
+    }
+
+    public static IndexVerificationOutputRow getOutputRowFromResult(Result result) {
+        IndexVerificationOutputRow.IndexVerificationOutputRowBuilder builder =
+            new IndexVerificationOutputRow.IndexVerificationOutputRowBuilder();
+        byte[] rowKey = result.getRow();
+        //rowkey is scanTs + SEPARATOR_BYTE + indexTableName + SEPARATOR_BYTE + dataTableRowKey
+        byte[][] rowKeySplit = ByteUtil.splitArrayBySeparator(rowKey, ROW_KEY_SEPARATOR_BYTE[0]);
+        builder.setScanMaxTimestamp(Long.parseLong(Bytes.toString(rowKeySplit[0])));
+        builder.setIndexTableName(Bytes.toString(rowKeySplit[1]));
+        builder.setDataTableRowKey(rowKeySplit[2]);
+
+        builder.setDataTableName(Bytes.toString(result.getValue(OUTPUT_TABLE_COLUMN_FAMILY,
+            DATA_TABLE_NAME_BYTES)));
+        builder.setIndexTableRowKey(result.getValue(OUTPUT_TABLE_COLUMN_FAMILY,
+            INDEX_TABLE_ROW_KEY_BYTES));
+        builder.setDataTableRowTimestamp(Long.parseLong(Bytes.toString(result.getValue(OUTPUT_TABLE_COLUMN_FAMILY,
+            DATA_TABLE_TS_BYTES))));
+        builder.setIndexTableRowTimestamp(Long.parseLong(Bytes.toString(result.getValue(OUTPUT_TABLE_COLUMN_FAMILY,
+            INDEX_TABLE_TS_BYTES))));
+        builder.setErrorMessage(Bytes.toString(result.getValue(OUTPUT_TABLE_COLUMN_FAMILY,
+            ERROR_MESSAGE_BYTES)));
+        //actual and expected value might not be present, but will just set to null if not
+        builder.setExpectedValue(result.getValue(OUTPUT_TABLE_COLUMN_FAMILY, EXPECTED_VALUE_BYTES));
+        builder.setActualValue(result.getValue(OUTPUT_TABLE_COLUMN_FAMILY, ACTUAL_VALUE_BYTES));
+        builder.setPhaseValue(result.getValue(OUTPUT_TABLE_COLUMN_FAMILY, VERIFICATION_PHASE_BYTES));
+        return builder.build();
+    }
+
+    public void close() throws IOException {
+        if (outputHTable != null) {
+            outputHTable.close();
+        }
 
 Review comment:
   Should we close indexHTable too?

----------------------------------------------------------------
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 #750: PHOENIX-5799 - Inline Index Verification Output API

Posted by GitBox <gi...@apache.org>.
gjacoby126 commented on a change in pull request #750: PHOENIX-5799 - Inline Index Verification Output API
URL: https://github.com/apache/phoenix/pull/750#discussion_r401978569
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/IndexRebuildRegionScanner.java
 ##########
 @@ -154,6 +143,8 @@
     private int  singleRowRebuildReturnCode;
     private Map<byte[], NavigableSet<byte[]>> familyMap;
     private byte[][] viewConstants;
+    private IndexVerificationResultRepository verificationResultRepository;
 
 Review comment:
   Each repo controls insert/select operations for a particular table: the result table (PHOENIX_INDEX_TOOL_RESULT) that stores summary information about the run (counters, etc), and the output table (PHOENIX_INDEX_TOOL) that contains the row-level information about the failed rows. 
   
   Please let me know if you have suggestions on clearer names. 
   
   (The word "Repository", btw, is the name of the design pattern being used -- https://martinfowler.com/eaaCatalog/repository.html , from Martin Fowler's Patterns of Enterprise Architecture and Eric Evans' Domain Driven Design)

----------------------------------------------------------------
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