[ 
https://issues.apache.org/jira/browse/PHOENIX-6548?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17425282#comment-17425282
 ] 

ASF GitHub Bot commented on PHOENIX-6548:
-----------------------------------------

gjacoby126 commented on a change in pull request #1328:
URL: https://github.com/apache/phoenix/pull/1328#discussion_r723753018



##########
File path: 
phoenix-core/src/test/java/org/apache/phoenix/util/ServerUtilTest.java
##########
@@ -0,0 +1,66 @@
+/**
+ *  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.util;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.client.ClusterConnection;
+import org.apache.hadoop.hbase.regionserver.HRegionServer;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+import org.apache.phoenix.query.HBaseFactoryProvider;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.io.IOException;
+import java.util.concurrent.ExecutorService;
+
+public class ServerUtilTest {
+
+    @Test
+    public void testCoprocessorHConnectionGetTableWithClosedConnection() 
throws Exception {
+        Configuration conf = 
HBaseFactoryProvider.getConfigurationFactory().getConfiguration();
+        HRegionServer server = Mockito.mock(HRegionServer.class);
+        ServerUtil.ConnectionType connectionType = 
ServerUtil.ConnectionType.INDEX_WRITER_CONNECTION;
+
+        // Mock ClusterConnection object to throw IllegalArgumentException.
+        ClusterConnection connection = Mockito.mock(ClusterConnection.class);
+        Mockito.doThrow(new 
IllegalArgumentException()).when(connection).getTable(
+            Mockito.<byte[]>any());
+        Mockito.doThrow(new 
IllegalArgumentException()).when(connection).getTable(
+            Mockito.<byte[]>any(), Mockito.<ExecutorService>any());
+        Mockito.doReturn(true).when(connection).isClosed();
+
+        // Spy CoprocessorHConnectionTableFactory
+        ServerUtil.CoprocessorHConnectionTableFactory coprocHTableFactory =  
new ServerUtil.
+            CoprocessorHConnectionTableFactory(conf, server, connectionType);
+        ServerUtil.CoprocessorHConnectionTableFactory spyedObj = 
Mockito.spy(coprocHTableFactory);
+        Mockito.doReturn(connection).when(spyedObj).getConnection();
+
+        try {
+            spyedObj.getTable(new 
ImmutableBytesPtr(Bytes.toBytes("test_table")));
+            Assert.fail("IOException exception expected as connection was 
closed");
+        }catch (IOException e1) {

Review comment:
       Would be good to have an initial catch block that catches 
DoNotRetryIOException and Assert fails (because DNRIE is a subclass of 
IOException so the current test would pass even if it was thrown)




-- 
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]


> Race condition when triggering index rebuilds as regionserver closes
> --------------------------------------------------------------------
>
>                 Key: PHOENIX-6548
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-6548
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 4.14.3, 4.16.1
>            Reporter: Geoffrey Jacoby
>            Assignee: Ankit Jain
>            Priority: Minor
>
> On each regionserver our coprocs keep a cache of HConnections with custom 
> settings (such as short timeouts) for talking to other regionservers. They're 
> used when coprocs need to make RPCs, such as during index rebuilds. 
> When a regionserver is closed, these HConnections are closed as well. 
> However, we've seen in our test pipelines a race condition where we may have 
> just given out one of the HConnections to a coprocessor, only to have the 
> connection closed just before it's used. 
> This will produce an IllegalArgumentException from the HBase Table object, 
> which (if the index rebuild was caused by a client Scan) will be thrown back 
> to the client as a DoNotRetryIOException.
> In this case we want the client exception to be a normal retriable 
> IOException, because if they try again after the region comes up again 
> somewhere else, the Scan will likely succeed. 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to