[
https://issues.apache.org/jira/browse/PHOENIX-7006?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17800438#comment-17800438
]
ASF GitHub Bot commented on PHOENIX-7006:
-----------------------------------------
sanjeet006py commented on code in PR #1751:
URL: https://github.com/apache/phoenix/pull/1751#discussion_r1436311621
##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java:
##########
@@ -1795,4 +1796,65 @@ public void
testChangePropertiesUpdatesLASTDDLTimestamp() throws Exception {
newLastDDLTimestamp > oldLastDDLTimestamp);
}
}
-}
\ No newline at end of file
+
+ @Test
+ public void testChangeTableLevelMaxLookbackAge() throws Exception {
+ String schemaName = generateUniqueName();
+ String dataTableName = generateUniqueName();
+ String fullTableName = SchemaUtil.getTableName(schemaName,
dataTableName);
+ long baseMaxLookbackAge = 86400000; // 1 day
+ Long maxLookbackAge = baseMaxLookbackAge;
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ String ddl = "CREATE TABLE " + fullTableName +
+ " (a_string varchar not null, a_binary VARCHAR not null,
col1 integer" +
+ " CONSTRAINT pk PRIMARY KEY (a_string, a_binary)) " +
"MAX_LOOKBACK_AGE=" + maxLookbackAge;
+ conn.createStatement().execute(ddl);
+ assertMaxLookbackAge(schemaName, dataTableName, maxLookbackAge);
+ maxLookbackAge = 3L * baseMaxLookbackAge;
+ alterTableLevelMaxLookbackAge(fullTableName,
maxLookbackAge.toString());
+ assertMaxLookbackAge(schemaName, dataTableName, maxLookbackAge);
+ maxLookbackAge = 2L * baseMaxLookbackAge;
+ alterTableLevelMaxLookbackAge(fullTableName,
maxLookbackAge.toString());
+ assertMaxLookbackAge(schemaName, dataTableName, maxLookbackAge);
+ maxLookbackAge = 0L;
+ alterTableLevelMaxLookbackAge(fullTableName,
maxLookbackAge.toString());
+ assertMaxLookbackAge(schemaName, dataTableName, maxLookbackAge);
+ }
+ }
+
+ @Test
+ public void testChangeTableLevelMaxLookbackAgeToInvalid() throws Exception
{
+ String schemaName = generateUniqueName();
+ String dataTableName = generateUniqueName();
+ String fullTableName = SchemaUtil.getTableName(schemaName,
dataTableName);
+ long maxLookbackAge = 86400000L;
+ try(Connection conn = DriverManager.getConnection(getUrl())) {
+ String ddl = "CREATE TABLE " + fullTableName +
+ " (a_string varchar not null, a_binary VARCHAR not null,
col1 integer" +
+ " CONSTRAINT pk PRIMARY KEY (a_string, a_binary)) " +
"MAX_LOOKBACK_AGE=" + maxLookbackAge;
+ conn.createStatement().execute(ddl);
+ }
+ assertThrows(IllegalArgumentException.class, () ->
alterTableLevelMaxLookbackAge(fullTableName, "2309.3"));
+ assertThrows(IllegalArgumentException.class, () ->
alterTableLevelMaxLookbackAge(fullTableName, "forty"));
+ }
+
+ private void assertMaxLookbackAge(String schemaName, String dataTableName,
long expectedMaxLookbackAge) throws Exception {
+ String query = "SELECT MAX_LOOKBACK_AGE FROM \"SYSTEM\".\"CATALOG\"\n"
+ + "WHERE TENANT_ID IS NULL AND\n"
+ + "(TABLE_SCHEM, TABLE_NAME) = ('" + schemaName + "','"+
dataTableName + "') AND\n"
+ + "COLUMN_FAMILY IS NULL AND COLUMN_NAME IS NULL";
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ ResultSet rs = conn.createStatement().executeQuery(query);
+ assertTrue(rs.next());
+ assertEquals(expectedMaxLookbackAge, rs.getLong(1));
+ assertFalse(rs.next());
+ }
+ }
+
+ private void alterTableLevelMaxLookbackAge(String fullTableName, String
maxLookbackAge) throws Exception {
+ try(Connection conn = DriverManager.getConnection(getUrl())) {
+ String ddl = "ALTER TABLE " + fullTableName + " SET
MAX_LOOKBACK_AGE = " + maxLookbackAge;
+ conn.createStatement().execute(ddl);
+ }
+ }
+}
Review Comment:
You mean for indexes? If so then it will be part of next batch of changes.
> Configure maxLookbackAge at table level
> ---------------------------------------
>
> Key: PHOENIX-7006
> URL: https://issues.apache.org/jira/browse/PHOENIX-7006
> Project: Phoenix
> Issue Type: Improvement
> Reporter: Viraj Jasani
> Assignee: Sanjeet Malhotra
> Priority: Major
>
> Phoenix max lookback age feature preserves live or deleted row versions that
> are only visible through the max lookback window, it does not preserve any
> unwanted row versions that should not be visible through the max lookback
> window. More details on the max lookback redesign: PHOENIX-6888
> As of today, maxlookback age is only configurable at the cluster level
> (config key: {_}phoenix.max.lookback.age.seconds{_}), meaning the same value
> is used by all tables. This does not allow individual table level compaction
> scanner to be able to retain data based on the table level maxlookback age.
> Setting max lookback age at the table level can serve multiple purposes e.g.
> change-data-capture (PHOENIX-7001) for individual table should have it's own
> latest data retention period.
> The purpose of this Jira is to allow maxlookback age as a table level
> property:
> * New column in SYSTEM.CATALOG to preserve table level maxlookback age
> * PTable object to read the value of maxlookback from SYSTEM.CATALOG
> * Allow CREATE/ALTER TABLE DDLs to provide maxlookback attribute
> * CompactionScanner should use table level maxlookbackAge, if available,
> else use cluster level config
--
This message was sent by Atlassian Jira
(v8.20.10#820010)