palashc commented on code in PR #2075:
URL: https://github.com/apache/phoenix/pull/2075#discussion_r1978189303
##########
phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HighAvailabilityGroup.java:
##########
@@ -49,14 +49,7 @@
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Properties;
-import java.util.Set;
+import java.util.*;
Review Comment:
Remove wildcard import
##########
phoenix-core-client/src/main/java/org/apache/phoenix/cache/ServerMetadataCache.java:
##########
@@ -24,5 +24,7 @@
public interface ServerMetadataCache {
long getLastDDLTimestampForTable(byte[] tenantID, byte[] schemaName,
byte[] tableName)
throws SQLException;
- void invalidate(byte[] tenantID, byte[] schemaName, byte[] tableName);
+ void invalidateLastDDLTimestampForTable(byte[] tenantID, byte[]
schemaName, byte[] tableName);
+ boolean isMutationBlocked() throws Exception;
Review Comment:
Does `isMutationBlocked` need to be in this interface? Should the signature
have a more specific Exception type like SQLException?
##########
phoenix-core/src/it/java/org/apache/phoenix/cache/ServerMetadataCacheIT.java:
##########
@@ -138,6 +131,82 @@ private ServerMetadataCacheTestImpl
getServerMetadataCache() {
return (ServerMetadataCacheTestImpl)cache;
}
+ /**
+ * This test checks the mutation block enabled feature
+ * 1. Initialize Cache
+ * 2. Create new CRR records with ACTIVE_TO_STANDBY and STANDBY states
+ * 3. Check CRR records are picked up and mutation is blocked
+ * 4. Delete the CRR records
+ * 5. Check now that mutation is NOT blocked
+ * 6. Create CRR records again with ACTIVE and STANDBY states
+ * 7. Check now that mutation is NOT blocked
+ * 8. Update CRR records with ACTIVE_TO_STANDBY and STANDBY states
+ * 9. Check new CRR records mutation is blocked
+ * 10. Delete the CRRs
+ * 11. Check now that mutation is NOT blocked
+ *
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testCacheForMutationBlockEnabled() throws Exception {
+ PhoenixHAAdmin haAdmin = new PhoenixHAAdmin(config);
+ ServerMetadataCacheTestImpl cache = getServerMetadataCache();;
+
+ ClusterRoleRecord crr1 = new ClusterRoleRecord("failover",
+ HighAvailabilityPolicy.FAILOVER, haAdmin.getZkUrl(),
ClusterRoleRecord.ClusterRole.ACTIVE_TO_STANDBY,
+ "random-zk-url", ClusterRoleRecord.ClusterRole.STANDBY, 2L);
+ ClusterRoleRecord crr2 = new ClusterRoleRecord("parallel",
+ HighAvailabilityPolicy.PARALLEL, haAdmin.getZkUrl(),
ClusterRoleRecord.ClusterRole.ACTIVE,
+ "random-zk-url", ClusterRoleRecord.ClusterRole.STANDBY, 2L);
+ haAdmin.createOrUpdateDataOnZookeeper(crr1);
+ haAdmin.createOrUpdateDataOnZookeeper(crr2);
+
+ Thread.sleep(1000L);
Review Comment:
Why is sleep required for this test? Are we sure 1s is enough and this will
not cause the test to be flaky in the future?
##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRegionServerEndpointIT.java:
##########
@@ -158,6 +160,18 @@ public void testValidateLastDDLTimestampWithTenantID()
throws SQLException {
}
}
+ @Test
+ public void testInvalidatePhoenixHACache() throws Exception {
+ HRegionServer regionServer =
utility.getMiniHBaseCluster().getRegionServer(0);
+ PhoenixRegionServerEndpoint coprocessor =
getPhoenixRegionServerEndpoint(regionServer);
+ assertNotNull(coprocessor);
+ ServerRpcController controller = new ServerRpcController();
+ RegionServerEndpointProtos.InvalidatePhoenixHACacheRequest request
+ =
RegionServerEndpointProtos.InvalidatePhoenixHACacheRequest.newBuilder().build();
+ coprocessor.invalidatePhoenixHACache(controller, request, null);
+ assertFalse(controller.failed());
Review Comment:
Should this test verify whether the HA Cache was indeed invalidated?
##########
phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixHACache.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.jdbc;
+
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.api.CuratorWatcher;
+import org.apache.curator.framework.api.GetDataBuilder;
+import org.apache.curator.framework.recipes.cache.NodeCache;
+import org.apache.curator.utils.ZKPaths;
+import org.apache.hadoop.conf.Configuration;
+import
org.apache.phoenix.thirdparty.com.google.common.annotations.VisibleForTesting;
+import org.apache.phoenix.thirdparty.com.google.common.cache.Cache;
+import org.apache.phoenix.thirdparty.com.google.common.cache.CacheBuilder;
+import org.apache.phoenix.thirdparty.com.google.common.cache.RemovalCause;
+import org.apache.phoenix.thirdparty.com.google.common.cache.RemovalListener;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
+
+import static org.apache.phoenix.jdbc.PhoenixHAAdmin.toPath;
+
+/**
+ * Write-through cache for PhoenixHA.
+ * Uses {@link NodeCache} from {@link
org.apache.curator.framework.CuratorFramework}.
+ */
+public class PhoenixHACache implements Closeable {
+
+ private static PhoenixHACache cacheInstance;
+ private final PhoenixHAAdmin phoenixHaAdmin;
+ private Cache<String, ClusterRoleRecord> haGroupClusterRoleRecordMap =
null;
+ private static final Logger LOGGER =
LoggerFactory.getLogger(PhoenixHACache.class);
+ private static final String HA_CACHE_TTL_MS = "phoenix.ha.cache.ttl.ms";
Review Comment:
Can we move this config and its default value to QueryServices and
QueryServicesOptions?
##########
phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HighAvailabilityGroup.java:
##########
@@ -457,7 +450,7 @@ private static CuratorFramework createCurator(String
jdbcUrl, Properties propert
Preconditions.checkArgument(!StringUtils.isEmpty(jdbcUrl), "JDBC url
is empty!");
jdbcUrl = jdbcUrl.replaceAll("\\\\:", "=");
String[] parts = jdbcUrl.split(":");
- if (parts.length == 0 || parts.length > 3) {
+ if (parts.length == 0 || parts.length > 4) {
Review Comment:
Would a comment about why we are changing from 3 to 4 be helpful?
##########
phoenix-core/src/it/java/org/apache/phoenix/cache/ServerMetadataCacheIT.java:
##########
@@ -27,10 +27,7 @@
import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
import org.apache.phoenix.end2end.PhoenixRegionServerEndpointTestImpl;
import org.apache.phoenix.end2end.ServerMetadataCacheTestImpl;
-import org.apache.phoenix.jdbc.PhoenixConnection;
-import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
-import org.apache.phoenix.jdbc.PhoenixResultSet;
-import org.apache.phoenix.jdbc.PhoenixStatement;
+import org.apache.phoenix.jdbc.*;
Review Comment:
Remove wildcard import.
##########
phoenix-core/src/it/java/org/apache/phoenix/cache/ServerMetadataCacheIT.java:
##########
@@ -73,16 +69,12 @@
import static
org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_NAME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_TYPE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TENANT_ID;
+import static org.apache.phoenix.jdbc.PhoenixHAAdmin.toPath;
import static
org.apache.phoenix.query.ConnectionQueryServicesImpl.INVALIDATE_SERVER_METADATA_CACHE_EX_MESSAGE;
import static
org.apache.phoenix.query.QueryServices.PHOENIX_METADATA_INVALIDATE_CACHE_ENABLED;
import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
Review Comment:
Remove wildcard import.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]