Skip to content

Commit

Permalink
Check length of providers in the constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
yiyuaner committed May 26, 2021
1 parent f554b83 commit ddb8f39
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,24 @@ public WrapperException(Throwable cause) {
private RetryPolicy retryPolicy = null;

public LoadBalancingKMSClientProvider(URI providerUri,
KMSClientProvider[] providers, Configuration conf) {
KMSClientProvider[] providers, Configuration conf) throws IOException {
this(providerUri, providers, Time.monotonicNow(), conf);
}

@VisibleForTesting
LoadBalancingKMSClientProvider(KMSClientProvider[] providers, long seed,
Configuration conf) {
Configuration conf) throws IOException {
this(URI.create("kms://testing"), providers, seed, conf);
}

private LoadBalancingKMSClientProvider(URI uri,
KMSClientProvider[] providers, long seed, Configuration conf) {
KMSClientProvider[] providers, long seed, Configuration conf) throws IOException {
super(conf);

if (providers.length == 0) {
throw new IOException("No providers configured !");
}

// uri is the token service so it can be instantiated for renew/cancel.
dtService = KMSClientProvider.getDtService(uri);
// if provider not in conf, new client will alias on uri else addr.
Expand Down Expand Up @@ -165,9 +170,6 @@ public KMSClientProvider[] getProviders() {

private <T> T doOp(ProviderCallable<T> op, int currPos,
boolean isIdempotent) throws IOException {
if (providers.length == 0) {
throw new IOException("No providers configured !");
}
int numFailovers = 0;
for (int i = 0;; i++, numFailovers++) {
KMSClientProvider provider = providers[(currPos + i) % providers.length];
Expand Down Expand Up @@ -233,10 +235,6 @@ private <T> T doOp(ProviderCallable<T> op, int currPos,
}

private int nextIdx() {
if (providers.length == 0) {
throw new IOException("No providers configured !");
}

while (true) {
int current = currentIdx.get();
int next = (current + 1) % providers.length;
Expand Down

0 comments on commit ddb8f39

Please sign in to comment.