kadirozde commented on a change in pull request #702: PHOENIX-5707: Index 
rebuild after truncate incorrectly writes the inc…
URL: https://github.com/apache/phoenix/pull/702#discussion_r374323919
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
 ##########
 @@ -237,6 +237,80 @@ public void testWithSetNull() throws Exception {
         }
     }
 
+    @Test
+    public void testIncorrectRebuild() throws Exception {
+        // This test is for building non-transactional mutable global indexes 
with direct api
+        if (localIndex || transactional || !mutable || !directApi || 
useSnapshot) {
+            return;
+        }
+        String schemaName = generateUniqueName();
+        String dataTableName = generateUniqueName();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, 
dataTableName);
+        String indexTableName = generateUniqueName();
+        String indexTableFullName = SchemaUtil.getTableName(schemaName, 
indexTableName);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.setAutoCommit(true);
+            conn.createStatement().execute("create table " + dataTableFullName 
+
+                    " (id varchar(10) not null primary key, val1 varchar(10), 
val2 varchar(10), val3 varchar(10)) COLUMN_ENCODED_BYTES=0");
+            conn.createStatement().execute("CREATE INDEX " + indexTableName + 
" on " +
+                    dataTableFullName + " (val1) include (val2, val3)" );
+            //insert a full row
+            conn.createStatement().execute("upsert into " + dataTableFullName 
+ " values ('a', 'ab', 'efgh', 'abcd')");
+            Thread.sleep(1000);
+
+            // insert a partial row
+            conn.createStatement().execute("upsert into " + dataTableFullName 
+ " (id, val3) values ('a', 'uvwx')");
+            Thread.sleep(1000);
+            //insert a full row
+            conn.createStatement().execute("upsert into " + dataTableFullName 
+ " values ('a', 'ab', 'efgh', 'yuio')");
+            Thread.sleep(1000);
+            //insert a partial row
+            conn.createStatement().execute("upsert into " + dataTableFullName 
+ " (id, val3) values ('a', 'asdf')");
+
+            //truncate index table
+            ConnectionQueryServices queryServices = 
conn.unwrap(PhoenixConnection.class).getQueryServices();
+            Admin admin = queryServices.getAdmin();
+            TableName tableName = TableName.valueOf(indexTableFullName);
+            admin.disableTable(tableName);
+            admin.truncateTable(tableName, false);
+
+            //rebuild index
+            runIndexTool(true, false, schemaName, dataTableName, 
indexTableName);
+
+            //assert
+            Scan scan = new Scan();
+            scan.setRaw(true);
+            scan.setMaxVersions(10);
+            HTable indexTable = new HTable(getUtility().getConfiguration(), 
indexTableFullName);
+            HTable dataTable = new HTable(getUtility().getConfiguration(), 
dataTableFullName);
+
+            long dataFullRowTS = 0;
 
 Review comment:
   I suggest that we should turn this comparison into a helper method. The 
method should also verify the expected number of rows in the index table, and 
more importantly, it should verify that the row "yuio" exists in the index 
table.  This helper method should be called before truncate 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:
[email protected]


With regards,
Apache Git Services

Reply via email to