maedhroz commented on code in PR #2660:
URL: https://github.com/apache/cassandra/pull/2660#discussion_r1320042074


##########
src/java/org/apache/cassandra/repair/messages/RepairMessage.java:
##########
@@ -51,48 +65,165 @@ protected RepairMessage(RepairJobDesc desc)
         this.desc = desc;
     }
 
+    public TimeUUID parentRepairSession()
+    {
+        return desc.parentSessionId;
+    }
+
     public interface RepairFailureCallback
     {
         void onFailure(Exception e);
     }
 
-    public static void sendMessageWithFailureCB(RepairMessage request, Verb 
verb, InetAddressAndPort endpoint, RepairFailureCallback failureCallback)
+    private static Backoff backoff(SharedContext.MessagingContext ctx, Verb 
verb)
+    {
+        RepairRetrySpec.Verb configVerb = toConfigVerb(verb);
+        if (configVerb == null)
+            return Backoff.None.INSTANCE;
+        RepairRetrySpec retrySpec = DatabaseDescriptor.getRepairRetrys();
+        RetrySpec spec = retrySpec.get(configVerb);
+        if (!spec.isEnabled())
+            return Backoff.None.INSTANCE;
+        switch (spec.type)
+        {
+            case Expoential:
+                return new Backoff.ExpoentialBackoff(spec.maxAttempts.value, 
spec.baseSleepTime.toMilliseconds(), spec.maxSleepTime.toMilliseconds(), 
ctx.random().get()::nextDouble);
+            default:
+                throw new IllegalArgumentException("Unknown type: " + 
spec.type);
+        }
+    }
+
+    @Nullable
+    private static RepairRetrySpec.Verb toConfigVerb(Verb verb)
     {
-        RequestCallback<?> callback = new RequestCallback<Object>()
+        switch (verb)
+        {
+            case PREPARE_MSG: return RepairRetrySpec.Verb.PREPARE;
+            case VALIDATION_REQ: return RepairRetrySpec.Verb.VALIDATION_REQ;
+            case VALIDATION_RSP: return RepairRetrySpec.Verb.VALIDATION_RSP;
+            case SYNC_REQ: return RepairRetrySpec.Verb.SYNC_REQ;
+            case SYNC_RSP: return RepairRetrySpec.Verb.SYNC_RSP;
+            case SNAPSHOT_MSG: return RepairRetrySpec.Verb.SNAPSHOT;
+            case CLEANUP_MSG: return RepairRetrySpec.Verb.CLEANUP;
+            default: return null;
+        }
+    }
+
+    public static <T> void 
sendMessageWithRetries(SharedContext.MessagingContext ctx, RepairMessage 
request, Verb verb, InetAddressAndPort endpoint, RequestCallback<T> 
finalCallback)
+    {
+        // 0 means no retries

Review Comment:
   ...but a 0 passed as the last argument here just indicates we haven't made 
any retry attempts yet. Perhaps we should clarify that, or ditch the inline 
comment and JavaDoc the private `sendMessageWithRetries()`. Either way...



##########
src/java/org/apache/cassandra/repair/messages/RepairMessage.java:
##########
@@ -51,48 +65,165 @@ protected RepairMessage(RepairJobDesc desc)
         this.desc = desc;
     }
 
+    public TimeUUID parentRepairSession()
+    {
+        return desc.parentSessionId;
+    }
+
     public interface RepairFailureCallback
     {
         void onFailure(Exception e);
     }
 
-    public static void sendMessageWithFailureCB(RepairMessage request, Verb 
verb, InetAddressAndPort endpoint, RepairFailureCallback failureCallback)
+    private static Backoff backoff(SharedContext.MessagingContext ctx, Verb 
verb)
+    {
+        RepairRetrySpec.Verb configVerb = toConfigVerb(verb);
+        if (configVerb == null)
+            return Backoff.None.INSTANCE;
+        RepairRetrySpec retrySpec = DatabaseDescriptor.getRepairRetrys();
+        RetrySpec spec = retrySpec.get(configVerb);
+        if (!spec.isEnabled())
+            return Backoff.None.INSTANCE;
+        switch (spec.type)
+        {
+            case Expoential:
+                return new Backoff.ExpoentialBackoff(spec.maxAttempts.value, 
spec.baseSleepTime.toMilliseconds(), spec.maxSleepTime.toMilliseconds(), 
ctx.random().get()::nextDouble);
+            default:
+                throw new IllegalArgumentException("Unknown type: " + 
spec.type);
+        }
+    }
+
+    @Nullable
+    private static RepairRetrySpec.Verb toConfigVerb(Verb verb)
     {
-        RequestCallback<?> callback = new RequestCallback<Object>()
+        switch (verb)
+        {
+            case PREPARE_MSG: return RepairRetrySpec.Verb.PREPARE;
+            case VALIDATION_REQ: return RepairRetrySpec.Verb.VALIDATION_REQ;
+            case VALIDATION_RSP: return RepairRetrySpec.Verb.VALIDATION_RSP;
+            case SYNC_REQ: return RepairRetrySpec.Verb.SYNC_REQ;
+            case SYNC_RSP: return RepairRetrySpec.Verb.SYNC_RSP;
+            case SNAPSHOT_MSG: return RepairRetrySpec.Verb.SNAPSHOT;
+            case CLEANUP_MSG: return RepairRetrySpec.Verb.CLEANUP;
+            default: return null;
+        }
+    }
+
+    public static <T> void 
sendMessageWithRetries(SharedContext.MessagingContext ctx, RepairMessage 
request, Verb verb, InetAddressAndPort endpoint, RequestCallback<T> 
finalCallback)
+    {
+        // 0 means no retries

Review Comment:
   ...but a 0 passed as the last argument here just indicates we haven't made 
any retry _attempts_ yet. Perhaps we should clarify that, or ditch the inline 
comment and JavaDoc the private `sendMessageWithRetries()`. Either way...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to