You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ra...@apache.org on 2018/01/24 10:10:36 UTC

phoenix git commit: PHOENIX-4534 upsert/delete/upsert for the same row corrupts the indexes(Rajeshbabu)

Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 668c36ca6 -> d1b5fd528


PHOENIX-4534 upsert/delete/upsert for the same row corrupts the indexes(Rajeshbabu)


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

Branch: refs/heads/5.x-HBase-2.0
Commit: d1b5fd52885aac904016b38aa5d1ece43b0053ab
Parents: 668c36c
Author: Rajeshbabu Chintaguntla <ra...@apache.org>
Authored: Wed Jan 24 15:40:12 2018 +0530
Committer: Rajeshbabu Chintaguntla <ra...@apache.org>
Committed: Wed Jan 24 15:40:12 2018 +0530

----------------------------------------------------------------------
 .../phoenix/end2end/index/MutableIndexIT.java   | 41 ++++++++++++++++++++
 .../filter/ApplyAndFilterDeletesFilter.java     |  8 ----
 .../index/scanner/FilteredKeyValueScanner.java  |  7 +++-
 3 files changed, 47 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d1b5fd52/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
index a931084..0fbb933 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
@@ -728,6 +728,47 @@ public class MutableIndexIT extends ParallelStatsDisabledIT {
       }
   }
 
+
+  @Test
+  public void testUpsertingDeletedRowShouldGiveProperDataWithIndexes() throws Exception {
+      testUpsertingDeletedRowShouldGiveProperDataWithIndexes(false);
+  }
+
+  @Test
+  public void testUpsertingDeletedRowShouldGiveProperDataWithMultiCFIndexes() throws Exception {
+      testUpsertingDeletedRowShouldGiveProperDataWithIndexes(true);
+  }
+
+  private void testUpsertingDeletedRowShouldGiveProperDataWithIndexes(boolean multiCf) throws Exception {
+      String tableName = "TBL_" + generateUniqueName();
+      String indexName = "IDX_" + generateUniqueName();
+      String columnFamily1 = "cf1";
+      String columnFamily2 = "cf2";
+      String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
+      try (Connection conn = getConnection()) {
+            conn.createStatement().execute(
+                "create table " + fullTableName + " (id integer primary key, "
+                        + (multiCf ? columnFamily1 : "") + "f float, "
+                        + (multiCf ? columnFamily2 : "") + "s varchar)" + tableDDLOptions);
+            conn.createStatement().execute(
+                "create index " + indexName + " on " + fullTableName + " ("
+                        + (multiCf ? columnFamily1 : "") + "f) include ("+(multiCf ? columnFamily2 : "") +"s)");
+            conn.createStatement().execute(
+                "upsert into " + fullTableName + " values (1, 0.5, 'foo')");
+          conn.commit();
+          conn.createStatement().execute("delete from  " + fullTableName + " where id = 1");
+          conn.commit();
+            conn.createStatement().execute(
+                "upsert into  " + fullTableName + " values (1, 0.5, 'foo')");
+          conn.commit();
+          ResultSet rs = conn.createStatement().executeQuery("select * from "+indexName);
+          assertTrue(rs.next());
+          assertEquals(1, rs.getInt(2));
+          assertEquals(0.5F, rs.getFloat(1), 0.0);
+          assertEquals("foo", rs.getString(3));
+      } 
+  }
+
 private void upsertRow(String dml, Connection tenantConn, int i) throws SQLException {
     PreparedStatement stmt = tenantConn.prepareStatement(dml);
       stmt.setString(1, "00000000000000" + String.valueOf(i));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d1b5fd52/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/ApplyAndFilterDeletesFilter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/ApplyAndFilterDeletesFilter.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/ApplyAndFilterDeletesFilter.java
index 67049f5..0fa9487 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/ApplyAndFilterDeletesFilter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/ApplyAndFilterDeletesFilter.java
@@ -53,7 +53,6 @@ import org.apache.phoenix.util.PhoenixKeyValueUtil;
  */
 public class ApplyAndFilterDeletesFilter extends FilterBase {
 
-  private boolean done = false;
   List<ImmutableBytesPtr> families;
   private final DeleteTracker coveringDelete = new DeleteTracker();
   private Hinter currentHint;
@@ -106,11 +105,6 @@ public class ApplyAndFilterDeletesFilter extends FilterBase {
 
   @Override
   public ReturnCode filterKeyValue(Cell next) {
-    // we marked ourselves done, but the END_ROW_KEY didn't manage to seek to the very last key
-    if (this.done) {
-      return ReturnCode.SKIP;
-    }
-
     KeyValue nextKV = PhoenixKeyValueUtil.maybeCopyCell(next);
     switch (KeyValue.Type.codeToType(next.getTypeByte())) {
     /*
@@ -187,8 +181,6 @@ public class ApplyAndFilterDeletesFilter extends FilterBase {
           getNextFamily(new ImmutableBytesPtr(peeked.getFamilyArray(), peeked.getFamilyOffset(),
               peeked.getFamilyLength()));
       if (nextFamily == null) {
-        // no known next family, so we can be completely done
-        done = true;
         return KeyValue.LOWESTKEY;
       }
         // there is a valid family, so we should seek to that

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d1b5fd52/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/scanner/FilteredKeyValueScanner.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/scanner/FilteredKeyValueScanner.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/scanner/FilteredKeyValueScanner.java
index 6359d6c..4bc6b27 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/scanner/FilteredKeyValueScanner.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/scanner/FilteredKeyValueScanner.java
@@ -94,7 +94,12 @@ public class FilteredKeyValueScanner implements ReseekableScanner {
                 break;
             // use a seek hint to find out where we should go
             case SEEK_NEXT_USING_HINT:
-                delegate.seek(PhoenixKeyValueUtil.maybeCopyCell(filter.getNextCellHint(peeked)));
+                Cell nextCellHint = filter.getNextCellHint(peeked);
+                if(nextCellHint == KeyValue.LOWESTKEY) {
+                    delegate.next();
+                } else {
+                    delegate.seek(PhoenixKeyValueUtil.maybeCopyCell(nextCellHint));
+                }
             }
         }
     }