From 1db378579342985431aab9c59dd9d4390e3c176d Mon Sep 17 00:00:00 2001 From: Mikayla Thompson Date: Wed, 20 Nov 2024 08:20:44 -0500 Subject: [PATCH] Sonarqube fixes from subshard work coordination (#1151) * sonarqube fixes from subshard work coordination * switch to sneaky throw for setupShardWorkItems Signed-off-by: Mikayla Thompson --- .../bulkload/workcoordination/OpenSearchWorkCoordinator.java | 4 +++- .../migrations/bulkload/worker/ShardWorkPreparer.java | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/RFS/src/main/java/org/opensearch/migrations/bulkload/workcoordination/OpenSearchWorkCoordinator.java b/RFS/src/main/java/org/opensearch/migrations/bulkload/workcoordination/OpenSearchWorkCoordinator.java index f8ea25f4c..53f230fa9 100644 --- a/RFS/src/main/java/org/opensearch/migrations/bulkload/workcoordination/OpenSearchWorkCoordinator.java +++ b/RFS/src/main/java/org/opensearch/migrations/bulkload/workcoordination/OpenSearchWorkCoordinator.java @@ -161,13 +161,15 @@ private static void retryWithExponentialBackoff( Exception underlyingException = (Exception) e.getCause(); exceptionConsumer.accept(underlyingException); throw new IllegalStateException(underlyingException); + } catch (InterruptedException e) { + throw e; } catch (Exception e) { attempt++; if (attempt > maxRetries) { exceptionConsumer.accept(e); throw new RetriesExceededException(e, attempt); } - Duration sleepDuration = Duration.ofMillis((long) (Math.pow(2.0, attempt - 1) * baseRetryTimeMs)); + Duration sleepDuration = Duration.ofMillis((long) (Math.pow(2.0, attempt - 1.0) * baseRetryTimeMs)); log.atWarn().setCause(e) .setMessage("Couldn't complete action due to exception. Backing off {} and trying again.") .addArgument(sleepDuration).log(); diff --git a/RFS/src/main/java/org/opensearch/migrations/bulkload/worker/ShardWorkPreparer.java b/RFS/src/main/java/org/opensearch/migrations/bulkload/worker/ShardWorkPreparer.java index 6490ad712..5b0d73df2 100644 --- a/RFS/src/main/java/org/opensearch/migrations/bulkload/worker/ShardWorkPreparer.java +++ b/RFS/src/main/java/org/opensearch/migrations/bulkload/worker/ShardWorkPreparer.java @@ -59,6 +59,9 @@ private void setupShardWorkItems( Duration.ofMinutes(5), context::createWorkAcquisitionContext ); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw Lombok.sneakyThrow(e); } catch (Exception e) { throw Lombok.sneakyThrow(e); }