Skip to content

Commit 147b4e9

Browse files
committed
Fix #170 and #188 by taking @jasonculverhouse 's suggestion and making the
HBaseException#make() method abstract so we enforce it everywhere. Now the multi-action processing won't throw the AssertionError. Signed-off-by: Chris Larsen <clarsen@yahoo-inc.com>
1 parent 89513a5 commit 147b4e9

7 files changed

Lines changed: 68 additions & 14 deletions

src/ConnectionResetException.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2010-2012 The Async HBase Authors. All rights reserved.
2+
* Copyright (C) 2010-2018 The Async HBase Authors. All rights reserved.
33
* This file is part of Async HBase.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -50,7 +50,12 @@ public final class ConnectionResetException extends RecoverableException {
5050
public Channel getChannel() {
5151
return chan;
5252
}
53-
53+
54+
@Override
55+
ConnectionResetException make(final Object msg, final HBaseRpc rpc) {
56+
return new ConnectionResetException(chan);
57+
}
58+
5459
private static final long serialVersionUID = 1280644142;
55-
60+
5661
}

src/HBaseException.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,10 @@ public abstract class HBaseException extends RuntimeException {
5555
* one without having to resort to reflection, which is annoying to use.
5656
* Sub-classes that want to provide this internal functionality should
5757
* implement this method.
58-
* @param arg Some arbitrary parameter to help build the new instance.
58+
* @param msg Some arbitrary parameter to help build the new instance.
5959
* @param rpc The RPC that failed, if any. Can be {@code null}.
6060
*/
61-
HBaseException make(final Object arg, final HBaseRpc rpc) {
62-
throw new AssertionError("Must not be used.");
63-
}
61+
abstract HBaseException make(final Object msg, final HBaseRpc rpc);
6462

6563
private static final long serialVersionUID = 1280638842;
6664

src/HBaseRpc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ public void run(final Timeout time_out) throws Exception {
639639

640640
callback(new RpcTimedOutException("RPC ID [" + rpc_id +
641641
"] timed out waiting for response from HBase on region client [" +
642-
region_client + " ] for over " + timeout + "ms"));
642+
region_client + " ] for over " + timeout + "ms", HBaseRpc.this));
643643
timeout_task = null;
644644
timeout_handle = null;
645645
}

src/NonRecoverableException.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2010-2012 The Async HBase Authors. All rights reserved.
2+
* Copyright (C) 2010-2018 The Async HBase Authors. All rights reserved.
33
* This file is part of Async HBase.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -51,6 +51,20 @@ public class NonRecoverableException extends HBaseException {
5151
super(msg, cause);
5252
}
5353

54+
@Override
55+
NonRecoverableException make(final Object msg, final HBaseRpc rpc) {
56+
// Don't need to keep the RPC here.
57+
if (msg == this || msg instanceof NonRecoverableException) {
58+
final NonRecoverableException e = (NonRecoverableException) msg;
59+
if (e.getCause() != null) {
60+
return new NonRecoverableException(e.getMessage(), e.getCause());
61+
} else {
62+
return new NonRecoverableException(e.getMessage());
63+
}
64+
}
65+
return new NonRecoverableException(msg.toString());
66+
}
67+
5468
private static final long serialVersionUID = 1280638547;
5569

5670
}

src/RegionOfflineException.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2010-2012 The Async HBase Authors. All rights reserved.
2+
* Copyright (C) 2010-2018 The Async HBase Authors. All rights reserved.
33
* This file is part of Async HBase.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -52,6 +52,11 @@ public byte[] getRegion() {
5252
return region;
5353
}
5454

55+
@Override
56+
HBaseException make(final Object msg, final HBaseRpc rpc) {
57+
return new RegionOfflineException(region);
58+
}
59+
5560
private static final long serialVersionUID = 1280641842;
5661

5762
}

src/RpcTimedOutException.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2015 The Async HBase Authors. All rights reserved.
2+
* Copyright (C) 2015-2018 The Async HBase Authors. All rights reserved.
33
* This file is part of Async HBase.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -32,26 +32,53 @@
3232
*/
3333
public class RpcTimedOutException extends HBaseException {
3434

35+
/** The RPC that failed */
36+
final HBaseRpc failed_rpc;
37+
3538
/**
3639
* Constructor.
3740
* @param msg The message of the exception, potentially including a stack
3841
* trace.
42+
* @param rpc The RPC that timed out.
3943
*/
40-
RpcTimedOutException(final String msg) {
44+
RpcTimedOutException(final String msg, final HBaseRpc rpc) {
4145
super(msg);
46+
failed_rpc = rpc;
4247
}
4348

4449
/**
4550
* Constructor.
4651
* @param msg The message of the exception, potentially including a stack
4752
* trace.
4853
* @param cause The exception that caused this one to be thrown.
54+
* @param rpc The RPC that timed out.
4955
*/
50-
RpcTimedOutException(final String msg, final Throwable cause) {
56+
RpcTimedOutException(final String msg,
57+
final Throwable cause,
58+
final HBaseRpc rpc) {
5159
super(msg, cause);
60+
failed_rpc = rpc;
5261
}
5362

63+
/** @return The RPC that timed out. */
64+
public HBaseRpc getFailedRpc() {
65+
return failed_rpc;
66+
}
67+
68+
@Override
69+
RpcTimedOutException make(final Object msg, final HBaseRpc rpc) {
70+
if (msg == this || msg instanceof RpcTimedOutException) {
71+
final RpcTimedOutException e = (RpcTimedOutException) msg;
72+
if (e.getCause() != null) {
73+
return new RpcTimedOutException(e.getMessage(), e.getCause(), rpc);
74+
} else {
75+
return new RpcTimedOutException(e.getMessage(), rpc);
76+
}
77+
}
78+
return new RpcTimedOutException(msg.toString(), rpc);
79+
}
80+
5481
private static final long serialVersionUID = -6245448564580938789L;
55-
82+
5683
}
5784

test/TestRegionClientDecode.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,11 @@ class TestingHBaseException extends HBaseException {
15311531
TestingHBaseException(final String msg) {
15321532
super(msg);
15331533
}
1534+
1535+
@Override
1536+
TestingHBaseException make(Object msg, HBaseRpc rpc) {
1537+
return new TestingHBaseException(getMessage());
1538+
}
15341539
}
15351540

15361541
/** Creates a new mock client that isn't spied. Necessary for the replay

0 commit comments

Comments
 (0)