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

vjasani pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/master by this push:
     new 2dab08504c PHOENIX-6985 Setting server-side masking flag default to 
false (#1629)
2dab08504c is described below

commit 2dab08504c4828119bf55ad69653477ab8085bd1
Author: Lokesh Khurana <[email protected]>
AuthorDate: Tue Jun 27 22:13:49 2023 -0700

    PHOENIX-6985 Setting server-side masking flag default to false (#1629)
---
 .../apache/phoenix/end2end/PhoenixTTLToolIT.java   |  15 +++
 .../java/org/apache/phoenix/end2end/ViewTTLIT.java |  17 ++++
 .../phoenix/end2end/ViewTTLNotEnabledIT.java       | 105 +++++++++++++++++++++
 .../phoenix/query/ConnectionQueryServicesImpl.java |   8 +-
 .../apache/phoenix/query/QueryServicesOptions.java |   2 +-
 5 files changed, 144 insertions(+), 3 deletions(-)

diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixTTLToolIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixTTLToolIT.java
index 8446f3e45d..7b16c145cc 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixTTLToolIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixTTLToolIT.java
@@ -27,10 +27,15 @@ import org.apache.hadoop.hbase.filter.CompareFilter;
 import org.apache.hadoop.hbase.filter.Filter;
 import org.apache.hadoop.hbase.filter.RowFilter;
 import org.apache.hadoop.hbase.filter.RegexStringComparator;
+import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
 import org.apache.phoenix.mapreduce.PhoenixTTLTool;
 import org.apache.phoenix.mapreduce.util.PhoenixMultiInputUtil;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.thirdparty.com.google.common.collect.Maps;
+import org.apache.phoenix.util.ReadOnlyProps;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.TestUtil;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
@@ -38,6 +43,7 @@ import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.Statement;
+import java.util.Map;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
@@ -45,6 +51,15 @@ import static org.junit.Assert.assertTrue;
 @Category(NeedsOwnMiniClusterTest.class)
 public class PhoenixTTLToolIT extends ParallelStatsDisabledIT {
 
+    @BeforeClass
+    public static synchronized void doSetup() throws Exception {
+        Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
+        props.put(BaseScannerRegionObserver.PHOENIX_MAX_LOOKBACK_AGE_CONF_KEY, 
Integer.toString(60*60)); // An hour
+        props.put(QueryServices.USE_STATS_FOR_PARALLELIZATION, 
Boolean.toString(false));
+        props.put(QueryServices.PHOENIX_TTL_SERVER_SIDE_MASKING_ENABLED, 
Boolean.toString(true));
+        setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+    }
+
     private final long PHOENIX_TTL_EXPIRE_IN_A_SECOND = 1;
     private final long MILLISECOND = 1000;
     private final long PHOENIX_TTL_EXPIRE_IN_A_DAY = 1000 * 60 * 60 * 24;
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewTTLIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewTTLIT.java
index 70fd9542a3..77b3ec7ebd 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewTTLIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewTTLIT.java
@@ -60,10 +60,12 @@ import 
org.apache.phoenix.thirdparty.com.google.common.collect.Lists;
 import org.apache.phoenix.thirdparty.com.google.common.collect.Maps;
 import org.apache.phoenix.util.EnvironmentEdgeManager;
 import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.ReadOnlyProps;
 import org.apache.phoenix.util.ScanUtil;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.TestUtil;
 import org.junit.Assert;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.slf4j.Logger;
@@ -76,6 +78,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -119,6 +122,20 @@ public class ViewTTLIT extends ParallelStatsDisabledIT {
     static final String COL8_FMT = "h%05d";
     static final String COL9_FMT = "i%05d";
 
+    protected static void setUpTestDriver(ReadOnlyProps props) throws 
Exception {
+        setUpTestDriver(props, props);
+    }
+
+    @BeforeClass
+    public static final void doSetup() throws Exception {
+        // Turn on the PHOENIX_TTL feature
+        Map<String, String> DEFAULT_PROPERTIES = new HashMap<String, String>() 
{{
+            put(QueryServices.PHOENIX_TTL_SERVER_SIDE_MASKING_ENABLED, 
String.valueOf(true));
+        }};
+
+        setUpTestDriver(new ReadOnlyProps(ReadOnlyProps.EMPTY_PROPS, 
DEFAULT_PROPERTIES.entrySet().iterator()));
+    }
+
     // Scans the HBase rows directly and asserts
     private void assertUsingHBaseRows(byte[] hbaseTableName,
             long minTimestamp, int expectedRows) throws IOException, 
SQLException {
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewTTLNotEnabledIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewTTLNotEnabledIT.java
new file mode 100644
index 0000000000..dfde99b546
--- /dev/null
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewTTLNotEnabledIT.java
@@ -0,0 +1,105 @@
+/*
+ * 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 org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.phoenix.compile.QueryPlan;
+import org.apache.phoenix.coprocessor.PhoenixTTLRegionObserver;
+import org.apache.phoenix.jdbc.PhoenixResultSet;
+import org.apache.phoenix.jdbc.PhoenixStatement;
+import org.apache.phoenix.query.PhoenixTestBuilder;
+import org.apache.phoenix.thirdparty.com.google.common.base.Preconditions;
+import org.apache.phoenix.util.ScanUtil;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.Properties;
+
+import static org.apache.phoenix.util.PhoenixRuntime.TENANT_ID_ATTRIB;
+
+@Category(NeedsOwnMiniClusterTest.class)
+public class ViewTTLNotEnabledIT extends ParallelStatsDisabledIT {
+
+    @Test
+    public void testPhoenixTTLNotEnabled() throws Exception {
+
+        // PHOENIX TTL is set in seconds (for e.g 10 secs)
+        long phoenixTTL = 10;
+        PhoenixTestBuilder.SchemaBuilder.TableOptions
+                tableOptions = 
PhoenixTestBuilder.SchemaBuilder.TableOptions.withDefaults();
+        tableOptions.getTableColumns().clear();
+        tableOptions.getTableColumnTypes().clear();
+
+        PhoenixTestBuilder.SchemaBuilder.TenantViewOptions
+                tenantViewOptions = 
PhoenixTestBuilder.SchemaBuilder.TenantViewOptions.withDefaults();
+        tenantViewOptions.setTableProps(String.format("PHOENIX_TTL=%d", 
phoenixTTL));
+
+        // Define the test schema.
+        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new 
PhoenixTestBuilder.SchemaBuilder(url);
+        schemaBuilder
+                .withTableOptions(tableOptions)
+                .withTenantViewOptions(tenantViewOptions)
+                .build();
+
+        String viewName = schemaBuilder.getEntityTenantViewName();
+
+        Properties props = new Properties();
+        String tenantConnectUrl =
+                url + ';' + TENANT_ID_ATTRIB + '=' + 
schemaBuilder.getDataOptions().getTenantId();
+
+        // Test the coproc is not registered
+        org.apache.hadoop.hbase.client.Connection hconn = 
getUtility().getConnection();
+        Admin admin = hconn.getAdmin();
+        HTableDescriptor tableDescriptor = admin.getTableDescriptor(
+                TableName.valueOf(schemaBuilder.getEntityTableName()));
+        Assert.assertFalse("Coprocessor " + 
PhoenixTTLRegionObserver.class.getName()
+                        + " should not have been added: ",
+                
tableDescriptor.hasCoprocessor(PhoenixTTLRegionObserver.class.getName()));
+
+
+        // Test masking expired rows property are not set
+        try (Connection conn = DriverManager.getConnection(tenantConnectUrl, 
props);
+                final Statement statement = conn.createStatement()) {
+            conn.setAutoCommit(true);
+
+            final String stmtString = String.format("select * from  %s", 
viewName);
+            Preconditions.checkNotNull(stmtString);
+            final PhoenixStatement pstmt = 
statement.unwrap(PhoenixStatement.class);
+            final QueryPlan queryPlan = pstmt.optimizeQuery(stmtString);
+
+            PhoenixResultSet
+                    rs = pstmt.newResultSet(queryPlan.iterator(), 
queryPlan.getProjector(), queryPlan.getContext());
+            Assert.assertFalse("Should not have any rows", rs.next());
+            Assert.assertEquals("Should have at least one element", 1, 
queryPlan.getScans().size());
+            Assert.assertEquals("PhoenixTTL should not be set",
+                    0, 
ScanUtil.getPhoenixTTL(queryPlan.getScans().get(0).get(0)));
+            Assert.assertFalse("Masking attribute should not be set",
+                    
ScanUtil.isMaskTTLExpiredRows(queryPlan.getScans().get(0).get(0)));
+            Assert.assertFalse("Delete Expired attribute should not set",
+                    
ScanUtil.isDeleteTTLExpiredRows(queryPlan.getScans().get(0).get(0)));
+        }
+    }
+
+}
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index 2486ec5d54..c5f5b8fd52 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -1058,6 +1058,9 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
                     
QueryServicesOptions.DEFAULT_INDEX_REGION_OBSERVER_ENABLED);
             boolean isViewIndex = TRUE_BYTES_AS_STRING
                     
.equals(tableProps.get(MetaDataUtil.IS_VIEW_INDEX_TABLE_PROP_NAME));
+            boolean isServerSideMaskingEnabled = config.getBoolean(
+                    QueryServices.PHOENIX_TTL_SERVER_SIDE_MASKING_ENABLED,
+                    QueryServicesOptions.DEFAULT_SERVER_SIDE_MASKING_ENABLED);
 
             boolean isViewBaseTransactional = false;
             if (!isTransactional && isViewIndex) {
@@ -1279,8 +1282,9 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
             // The priority for this co-processor should be set higher than 
the GlobalIndexChecker so that the read repair scans
             // are intercepted by the TTLAwareRegionObserver and only the rows 
that are not ttl-expired are returned.
             if (!SchemaUtil.isSystemTable(tableName)) {
-                if 
(!newDesc.hasCoprocessor(PhoenixTTLRegionObserver.class.getName())) {
-                    builder.setCoprocessor(
+                if 
(!newDesc.hasCoprocessor(PhoenixTTLRegionObserver.class.getName()) &&
+                        isServerSideMaskingEnabled) {
+                        builder.setCoprocessor(
                             CoprocessorDescriptorBuilder
                                     
.newBuilder(PhoenixTTLRegionObserver.class.getName())
                                     .setPriority(priority - 2)
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java 
b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
index 6fac191e68..697554605f 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
@@ -165,7 +165,7 @@ public class QueryServicesOptions {
     public static final int DEFAULT_TRACING_TRACE_BUFFER_SIZE = 1000;
     public static final int DEFAULT_MAX_INDEXES_PER_TABLE = 10;
     public static final int DEFAULT_CLIENT_INDEX_ASYNC_THRESHOLD = 0;
-    public static final boolean DEFAULT_SERVER_SIDE_MASKING_ENABLED = true;
+    public static final boolean DEFAULT_SERVER_SIDE_MASKING_ENABLED = false;
 
     public final static int DEFAULT_MUTATE_BATCH_SIZE = 100; // Batch size for 
UPSERT SELECT and DELETE
     //Batch size in bytes for UPSERT, SELECT and DELETE. By default, 2MB

Reply via email to