HBASE-26905 ReplicationPeerManager#checkPeerExists should throw ReplicationPeerNotFoundException if peer doesn't exists (#4422)

Signed-off-by: Andrew Purtell <apurtell@apache.org>
This commit is contained in:
Rushabh Shah 2022-05-13 18:24:19 -07:00 committed by Andrew Purtell
parent 603f3f5d0c
commit 4ba62c82f8
2 changed files with 17 additions and 1 deletions

View File

@ -32,6 +32,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.ReplicationPeerNotFoundException;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.replication.ReplicationPeerConfigUtil;
@ -116,7 +117,7 @@ public class ReplicationPeerManager {
private ReplicationPeerDescription checkPeerExists(String peerId) throws DoNotRetryIOException {
ReplicationPeerDescription desc = peers.get(peerId);
if (desc == null) {
throw new DoNotRetryIOException("Replication peer " + peerId + " does not exist");
throw new ReplicationPeerNotFoundException(peerId);
}
return desc;
}

View File

@ -40,6 +40,7 @@ import java.util.concurrent.ExecutionException;
import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.ReplicationPeerNotFoundException;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.replication.ReplicationException;
@ -517,4 +518,18 @@ public class TestAsyncReplicationAdminApi extends TestAsyncAdminBase {
assertThat(e.getCause(), instanceOf(DoNotRetryIOException.class));
}
}
/*
* Tests that admin api throws ReplicationPeerNotFoundException if peer doesn't exist.
*/
@Test
public void testReplicationPeerNotFoundException() throws InterruptedException {
String dummyPeer = "dummy_peer";
try {
admin.removeReplicationPeer(dummyPeer).get();
fail();
} catch (ExecutionException e) {
assertThat(e.getCause(), instanceOf(ReplicationPeerNotFoundException.class));
}
}
}