Skip to content

Commit ae2139d

Browse files
authored
HBASE-30069:Instead of generic DoNotRetryIOException send specific Exception (#8059)
1 parent b3df7c5 commit ae2139d

File tree

7 files changed

+520
-285
lines changed

7 files changed

+520
-285
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase;
19+
20+
import org.apache.yetus.audience.InterfaceAudience;
21+
22+
/**
23+
* Thrown when a write is attempted on a read-only HBase cluster.
24+
*/
25+
@InterfaceAudience.Public
26+
public class WriteAttemptedOnReadOnlyClusterException extends DoNotRetryIOException {
27+
28+
private static final long serialVersionUID = 1L;
29+
30+
public WriteAttemptedOnReadOnlyClusterException() {
31+
super();
32+
}
33+
34+
/**
35+
* @param message the message for this exception
36+
*/
37+
public WriteAttemptedOnReadOnlyClusterException(String message) {
38+
super(message);
39+
}
40+
41+
/**
42+
* @param message the message for this exception
43+
* @param throwable the {@link Throwable} to use for this exception
44+
*/
45+
public WriteAttemptedOnReadOnlyClusterException(String message, Throwable throwable) {
46+
super(message, throwable);
47+
}
48+
49+
/**
50+
* @param throwable the {@link Throwable} to use for this exception
51+
*/
52+
public WriteAttemptedOnReadOnlyClusterException(Throwable throwable) {
53+
super(throwable);
54+
}
55+
}

hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AbstractReadOnlyController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
import org.apache.hadoop.hbase.ActiveClusterSuffix;
2727
import org.apache.hadoop.hbase.Coprocessor;
2828
import org.apache.hadoop.hbase.CoprocessorEnvironment;
29-
import org.apache.hadoop.hbase.DoNotRetryIOException;
3029
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
3130
import org.apache.hadoop.hbase.HConstants;
3231
import org.apache.hadoop.hbase.TableName;
32+
import org.apache.hadoop.hbase.WriteAttemptedOnReadOnlyClusterException;
3333
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
3434
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
3535
import org.apache.hadoop.hbase.exceptions.DeserializationException;
@@ -56,8 +56,8 @@ public static boolean isWritableInReadOnlyMode(final TableName tableName) {
5656
return writableTables.contains(tableName);
5757
}
5858

59-
protected void internalReadOnlyGuard() throws DoNotRetryIOException {
60-
throw new DoNotRetryIOException("Operation not allowed in Read-Only Mode");
59+
protected void internalReadOnlyGuard() throws WriteAttemptedOnReadOnlyClusterException {
60+
throw new WriteAttemptedOnReadOnlyClusterException("Operation not allowed in Read-Only Mode");
6161
}
6262

6363
@Override

hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerBulkLoadObserver.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
*/
1818
package org.apache.hadoop.hbase.security.access;
1919

20+
import static org.junit.Assert.assertThrows;
2021
import static org.mockito.Mockito.mock;
2122

22-
import java.io.IOException;
23-
import org.apache.hadoop.hbase.DoNotRetryIOException;
2423
import org.apache.hadoop.hbase.HBaseClassTestRule;
24+
import org.apache.hadoop.hbase.WriteAttemptedOnReadOnlyClusterException;
2525
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
2626
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
2727
import org.apache.hadoop.hbase.testclassification.SecurityTests;
@@ -58,13 +58,17 @@ public void tearDown() throws Exception {
5858

5959
}
6060

61-
@Test(expected = DoNotRetryIOException.class)
62-
public void testPrePrepareBulkLoadReadOnlyException() throws IOException {
63-
bulkLoadReadOnlyController.prePrepareBulkLoad(ctx);
61+
@Test
62+
public void testPrePrepareBulkLoadReadOnlyException() {
63+
assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> {
64+
bulkLoadReadOnlyController.prePrepareBulkLoad(ctx);
65+
});
6466
}
6567

66-
@Test(expected = DoNotRetryIOException.class)
67-
public void testPreCleanupBulkLoadReadOnlyException() throws IOException {
68-
bulkLoadReadOnlyController.preCleanupBulkLoad(ctx);
68+
@Test
69+
public void testPreCleanupBulkLoadReadOnlyException() {
70+
assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> {
71+
bulkLoadReadOnlyController.preCleanupBulkLoad(ctx);
72+
});
6973
}
7074
}

hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyControllerEndpointObserver.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
*/
1818
package org.apache.hadoop.hbase.security.access;
1919

20+
import static org.junit.Assert.assertThrows;
2021
import static org.mockito.Mockito.mock;
2122

22-
import java.io.IOException;
23-
import org.apache.hadoop.hbase.DoNotRetryIOException;
2423
import org.apache.hadoop.hbase.HBaseClassTestRule;
24+
import org.apache.hadoop.hbase.WriteAttemptedOnReadOnlyClusterException;
2525
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
2626
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
2727
import org.apache.hadoop.hbase.testclassification.SecurityTests;
@@ -68,8 +68,10 @@ public void tearDown() throws Exception {
6868

6969
}
7070

71-
@Test(expected = DoNotRetryIOException.class)
72-
public void testPreEndpointInvocationReadOnlyException() throws IOException {
73-
endpointReadOnlyController.preEndpointInvocation(ctx, service, methodName, request);
71+
@Test
72+
public void testPreEndpointInvocationReadOnlyException() {
73+
assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> {
74+
endpointReadOnlyController.preEndpointInvocation(ctx, service, methodName, request);
75+
});
7476
}
7577
}

0 commit comments

Comments
 (0)