szetszwo commented on code in PR #1354: URL: https://github.com/apache/ratis/pull/1354#discussion_r2829452216
########## ratis-docs/src/site/markdown/configurations.md: ########## @@ -509,11 +509,28 @@ The follower's statemachine is responsible for fetching and installing snapshot | **Type** | string | | **Default** | 1ms,10, 1s,20, 5s,1000 | -"1ms,10, 1s,20, 5s,1000" means -The min wait time as 1ms (0 is not allowed) for first 10, -(5 iteration with 2 times grpc client retry), -next wait 1sec for next 20 retry (10 iteration with 2 times grpc client) -further wait for 5sec for max times ((5sec*980)/2 times ~= 40min) +Format: +`<classname>,<params...>` +If `<classname>` is omitted, it defaults to `MultipleLinearRandomRetry` for backward compatibility. + +Examples: +- `MultipleLinearRandomRetry,1ms,10,1s,20,5s,1000` +- `1ms,10,1s,20,5s,1000` (same as above) +- `ExponentialBackoffRetry,100ms,5s,100` + +For `MultipleLinearRandomRetry`, the parameter "1ms,10, 1s,20, 5s,1000" means +that the wait time is 1ms on average for the first 10 retries. +Then, it becomes 1s on average for next 20 retries +and 5s on average for the last 1000 retries. + +For `ExponentialBackoffRetry`, the parameter "100ms,5s,100" means +that the base wait time is 100ms, the maximum wait time is 5s +and the number of attempts is 100. +The wait time is min(2^(n-1) * 100ms, 5s) on average for the n-th retry. +In other words, +the wait time is on average 100ms, 200ms, 400ms, 800ms, 1.6s, 3.2s, 5s, 5s and so on. Review Comment: Sorry, my mistake: it should be "the wait times are ..." ########## ratis-docs/src/site/markdown/configurations.md: ########## @@ -509,11 +509,28 @@ The follower's statemachine is responsible for fetching and installing snapshot | **Type** | string | | **Default** | 1ms,10, 1s,20, 5s,1000 | -"1ms,10, 1s,20, 5s,1000" means -The min wait time as 1ms (0 is not allowed) for first 10, -(5 iteration with 2 times grpc client retry), -next wait 1sec for next 20 retry (10 iteration with 2 times grpc client) -further wait for 5sec for max times ((5sec*980)/2 times ~= 40min) +Format: +`<classname>,<params...>` +If `<classname>` is omitted, it defaults to `MultipleLinearRandomRetry` for backward compatibility. + +Examples: +- `MultipleLinearRandomRetry,1ms,10,1s,20,5s,1000` +- `1ms,10,1s,20,5s,1000` (same as above) +- `ExponentialBackoffRetry,100ms,5s,100` + +For `MultipleLinearRandomRetry`, the parameter "1ms,10, 1s,20, 5s,1000" means +that the wait time is 1ms on average for the first 10 retries. +Then, it becomes 1s on average for next 20 retries +and 5s on average for the last 1000 retries. + +For `ExponentialBackoffRetry`, the parameter "100ms,5s,100" means +that the base wait time is 100ms, the maximum wait time is 5s +and the number of attempts is 100. +The wait time is min(2^(n-1) * 100ms, 5s) on average for the n-th retry. Review Comment: Good catch that it is `min` but not `max`. BTW, github supports LaTeX. - https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/writing-mathematical-expressions Since using plain md also looks good in this case, I am fine if we do not use LaTeX here. 😀 ########## ratis-common/src/main/java/org/apache/ratis/retry/RetryPolicy.java: ########## @@ -95,7 +96,31 @@ static RetryPolicy parse(String commaSeparated) { .setMaxAttempts(Integer.parseInt(args[3].trim())) .build(); } + if (classname.equals(MultipleLinearRandomRetry.class.getSimpleName())) { + if (args.length == 1) { + throw new IllegalArgumentException("Failed to parse MultipleLinearRandomRetry: args.length = " + + args.length + " <= 1 for " + commaSeparated); + } + final String params = String.join(",", Arrays.copyOfRange(args, 1, args.length)); + return MultipleLinearRandomRetry.parseCommaSeparated(params); + } + // Backward compatibility: legacy config omits class name and starts with a duration (e.g. "1ms"). + if (isLegacyMultipleLinearRandomRetryParams(classname)) { + return MultipleLinearRandomRetry.parseCommaSeparated(commaSeparated); + } + // If a class name is present but unknown, fail fast to surface config errors. throw new IllegalArgumentException("Failed to parse RetryPolicy: unknown class " + args[0] + " for " + commaSeparated); } + + static boolean isLegacyMultipleLinearRandomRetryParams(String firstElement) { + // The legacy format starts with a duration token, not a class name. + final String trimmed = firstElement.trim().replace("_", ""); Review Comment: This line is still here. -- 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]
