-
Notifications
You must be signed in to change notification settings - Fork 994
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHOENIX-5881 - Port PHOENIX-5645 (MaxLookbackAge) to 5.x
- Loading branch information
1 parent
aac2633
commit 1aa7d60
Showing
13 changed files
with
1,065 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
423 changes: 423 additions & 0 deletions
423
phoenix-core/src/it/java/org/apache/phoenix/end2end/MaxLookbackIT.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
phoenix-core/src/it/java/org/apache/phoenix/end2end/SCNIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* 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.sql.SQLException; | ||
import java.util.Properties; | ||
|
||
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; | ||
import org.apache.phoenix.compat.hbase.HbaseCompatCapabilities; | ||
import org.apache.phoenix.compat.hbase.coprocessor.CompatBaseScannerRegionObserver; | ||
import org.apache.phoenix.util.PhoenixRuntime; | ||
import org.apache.phoenix.util.SchemaUtil; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class SCNIT extends ParallelStatsDisabledIT { | ||
|
||
@Test | ||
public void testReadBeforeDelete() throws Exception { | ||
//we don't support reading earlier than a delete in HBase 2.0-2.2, only in 1.4+ and 2.3+ | ||
if (!HbaseCompatCapabilities.isLookbackBeyondDeletesSupported()){ | ||
return; | ||
} | ||
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(PhoenixRuntime.CURRENT_SCN_ATTRIB, 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 { | ||
int ttl = 2; | ||
String fullTableName = createTableWithTTL(ttl); | ||
//sleep for one second longer than ttl | ||
Thread.sleep(ttl * 1000 + 1000); | ||
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(); | ||
} | ||
} | ||
|
||
private String createTableWithTTL(int ttl) throws SQLException, InterruptedException { | ||
String schemaName = generateUniqueName(); | ||
String tableName = generateUniqueName(); | ||
StringBuilder optionsBuilder = new StringBuilder(); | ||
if (ttl > 0){ | ||
optionsBuilder.append("TTL="); | ||
optionsBuilder.append(ttl); | ||
} | ||
String ddlOptions = optionsBuilder.toString(); | ||
String fullTableName = SchemaUtil.getTableName(schemaName, tableName); | ||
try (Connection conn = DriverManager.getConnection(getUrl())) { | ||
conn.createStatement() | ||
.execute(String.format("CREATE TABLE %s" + | ||
"(k VARCHAR PRIMARY KEY, f.v VARCHAR) %s", fullTableName, ddlOptions)); | ||
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(); | ||
} | ||
return fullTableName; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...e-compat-2.1.6/src/main/java/org/apache/phoenix/compat/hbase/HbaseCompatCapabilities.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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.compat.hbase; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
|
||
public class HbaseCompatCapabilities { | ||
|
||
public static boolean isMaxLookbackTimeSupported() { | ||
return false; | ||
} | ||
|
||
//In HBase 2.1 and 2.2, a lookback query won't return any results if covered by a future delete | ||
public static boolean isLookbackBeyondDeletesSupported() { return false; } | ||
|
||
} |
Oops, something went wrong.