You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ac...@apache.org on 2019/12/20 22:40:11 UTC

[phoenix] branch 4.x-HBase-1.3 updated: PHOENIX-5637 Queries with SCN return expired rows

This is an automated email from the ASF dual-hosted git repository.

achouhan pushed a commit to branch 4.x-HBase-1.3
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/4.x-HBase-1.3 by this push:
     new ac1f97e  PHOENIX-5637 Queries with SCN return expired rows
ac1f97e is described below

commit ac1f97ebbb662a9dd6d5b2158402c0815eeb12dd
Author: Abhishek Singh Chouhan <ac...@apache.org>
AuthorDate: Tue Dec 17 19:33:50 2019 -0800

    PHOENIX-5637 Queries with SCN return expired rows
---
 .../it/java/org/apache/phoenix/end2end/SCNIT.java  | 109 +++++++++++++++++++++
 .../hadoop/hbase/regionserver/ScanInfoUtil.java    |   2 +-
 2 files changed, 110 insertions(+), 1 deletion(-)

diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SCNIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SCNIT.java
new file mode 100644
index 0000000..6c45b06
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SCNIT.java
@@ -0,0 +1,109 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.Test;
+
+public class SCNIT extends ParallelStatsDisabledIT {
+
+	@Test
+	public void testReadBeforeDelete() throws Exception {
+		String schemaName = generateUniqueName();
+		String tableName = generateUniqueName();
+		String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
+		long timeBeforeDelete;
+		long timeAfterDelete;
+		try (Connection conn = DriverManager.getConnection(getUrl())) {
+			conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v VARCHAR)");
+			conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','aa')");
+			conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('b','bb')");
+			conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('c','cc')");
+			conn.commit();
+			timeBeforeDelete = EnvironmentEdgeManager.currentTime() + 1;
+			Thread.sleep(2);
+			conn.createStatement().execute("DELETE FROM " + fullTableName + " WHERE k = 'b'");
+			conn.commit();
+			timeAfterDelete = EnvironmentEdgeManager.currentTime() + 1;
+		}
+
+		Properties props = new Properties();
+		props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(timeBeforeDelete));
+		try (Connection connscn = DriverManager.getConnection(getUrl(), props)) {
+			ResultSet rs = connscn.createStatement().executeQuery("select * from " + fullTableName);
+			assertTrue(rs.next());
+			assertEquals("a", rs.getString(1));
+			assertTrue(rs.next());
+			assertEquals("b", rs.getString(1));
+			assertTrue(rs.next());
+			assertEquals("c", rs.getString(1));
+			assertFalse(rs.next());
+			rs.close();
+		}
+		props.clear();
+		props.setProperty("CurrentSCN", Long.toString(timeAfterDelete));
+		try (Connection connscn = DriverManager.getConnection(getUrl(), props)) {
+			ResultSet rs = connscn.createStatement().executeQuery("select * from " + fullTableName);
+			assertTrue(rs.next());
+			assertEquals("a", rs.getString(1));
+			assertTrue(rs.next());
+			assertEquals("c", rs.getString(1));
+			assertFalse(rs.next());
+			rs.close();
+		}
+
+	}
+
+	@Test
+	public void testSCNWithTTL() throws Exception {
+		String schemaName = generateUniqueName();
+		String tableName = generateUniqueName();
+		String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
+		try (Connection conn = DriverManager.getConnection(getUrl())) {
+			conn.createStatement()
+					.execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v VARCHAR) TTL=2");
+			conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','aa')");
+			conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('b','bb')");
+			conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('c','cc')");
+			conn.commit();
+			// TTL is 2 sec
+			Thread.sleep(3000);
+		}
+
+		Properties props = new Properties();
+		props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
+				Long.toString(EnvironmentEdgeManager.currentTime() - 1000));
+		try (Connection connscn = DriverManager.getConnection(getUrl(), props)) {
+			ResultSet rs = connscn.createStatement().executeQuery("select * from " + fullTableName);
+			assertFalse(rs.next());
+			rs.close();
+		}
+	}
+
+}
diff --git a/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/ScanInfoUtil.java b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/ScanInfoUtil.java
index 0725e05..e0d62a2 100644
--- a/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/ScanInfoUtil.java
+++ b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/ScanInfoUtil.java
@@ -32,7 +32,7 @@ public class ScanInfoUtil {
     }
     
     public static ScanInfo cloneScanInfoWithKeepDeletedCells(ScanInfo scanInfo) {
-        return new ScanInfo(scanInfo.getConfiguration(), scanInfo.getFamily(), Math.max(scanInfo.getMinVersions(), 1),
+        return new ScanInfo(scanInfo.getConfiguration(), scanInfo.getFamily(), scanInfo.getMinVersions(),
                     scanInfo.getMaxVersions(), scanInfo.getTtl(), KeepDeletedCells.TRUE,
                     scanInfo.getTimeToPurgeDeletes(), scanInfo.getComparator());
     }