Skip to content

Commit

Permalink
[FLINK-33865][runtime][refactor] Refactor the RestartStrategyType to …
Browse files Browse the repository at this point in the history
…reduce repeated magic string
  • Loading branch information
1996fanrui committed Jan 24, 2024
1 parent 533ead6 commit 5c895aa
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<td><h5>restart-strategy.type</h5></td>
<td style="word-wrap: break-word;">(none)</td>
<td>String</td>
<td>Defines the restart strategy to use in case of job failures.<br />Accepted values are:<ul><li><code class="highlighter-rouge">none</code>, <code class="highlighter-rouge">off</code>, <code class="highlighter-rouge">disable</code>: No restart strategy.</li><li><code class="highlighter-rouge">fixeddelay</code>, <code class="highlighter-rouge">fixed-delay</code>: Fixed delay restart strategy. More details can be found <a href="{{.Site.BaseURL}}{{.Site.LanguagePrefix}}/docs/ops/state/task_failure_recovery#fixed-delay-restart-strategy">here</a>.</li><li><code class="highlighter-rouge">failurerate</code>, <code class="highlighter-rouge">failure-rate</code>: Failure rate restart strategy. More details can be found <a href="{{.Site.BaseURL}}{{.Site.LanguagePrefix}}/docs/ops/state/task_failure_recovery#failure-rate-restart-strategy">here</a>.</li><li><code class="highlighter-rouge">exponentialdelay</code>, <code class="highlighter-rouge">exponential-delay</code>: Exponential delay restart strategy. More details can be found <a href="{{.Site.BaseURL}}{{.Site.LanguagePrefix}}/docs/ops/state/task_failure_recovery#exponential-delay-restart-strategy">here</a>.</li></ul>If checkpointing is disabled, the default value is <code class="highlighter-rouge">none</code>. If checkpointing is enabled, the default value is <code class="highlighter-rouge">exponential-delay</code>, and the default values of <code class="highlighter-rouge">exponential-delay</code> related config options will be used.</td>
<td>Defines the restart strategy to use in case of job failures.<br />Accepted values are:<ul><li><code class="highlighter-rouge">disable</code>, <code class="highlighter-rouge">off</code>, <code class="highlighter-rouge">none</code>: No restart strategy.</li><li><code class="highlighter-rouge">fixed-delay</code>, <code class="highlighter-rouge">fixeddelay</code>: Fixed delay restart strategy. More details can be found <a href="{{.Site.BaseURL}}{{.Site.LanguagePrefix}}/docs/ops/state/task_failure_recovery#fixed-delay-restart-strategy">here</a>.</li><li><code class="highlighter-rouge">failure-rate</code>, <code class="highlighter-rouge">failurerate</code>: Failure rate restart strategy. More details can be found <a href="{{.Site.BaseURL}}{{.Site.LanguagePrefix}}/docs/ops/state/task_failure_recovery#failure-rate-restart-strategy">here</a>.</li><li><code class="highlighter-rouge">exponential-delay</code>, <code class="highlighter-rouge">exponentialdelay</code>: Exponential delay restart strategy. More details can be found <a href="{{.Site.BaseURL}}{{.Site.LanguagePrefix}}/docs/ops/state/task_failure_recovery#exponential-delay-restart-strategy">here</a>.</li></ul>If checkpointing is disabled, the default value is <code class="highlighter-rouge">disable</code>. If checkpointing is enabled, the default value is <code class="highlighter-rouge">exponential-delay</code>, and the default values of <code class="highlighter-rouge">exponential-delay</code> related config options will be used.</td>
</tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.flink.api.common.time.Time;
import org.apache.flink.configuration.ReadableConfig;
import org.apache.flink.configuration.RestartStrategyOptions;
import org.apache.flink.configuration.RestartStrategyOptions.RestartStrategyType;

import java.io.Serializable;
import java.time.Duration;
Expand Down Expand Up @@ -543,22 +544,18 @@ public static Optional<RestartStrategyConfiguration> fromConfiguration(

private static RestartStrategyConfiguration parseConfiguration(
String restartstrategyKind, ReadableConfig configuration) {
switch (restartstrategyKind.toLowerCase()) {
case "none":
case "off":
case "disable":
switch (RestartStrategyType.of(restartstrategyKind.toLowerCase())) {
case NO_RESTART_STRATEGY:
return noRestart();
case "fixeddelay":
case "fixed-delay":
case FIXED_DELAY:
int attempts =
configuration.get(
RestartStrategyOptions.RESTART_STRATEGY_FIXED_DELAY_ATTEMPTS);
Duration delay =
configuration.get(
RestartStrategyOptions.RESTART_STRATEGY_FIXED_DELAY_DELAY);
return fixedDelayRestart(attempts, delay.toMillis());
case "exponentialdelay":
case "exponential-delay":
case EXPONENTIAL_DELAY:
Duration initialBackoff =
configuration.get(
RestartStrategyOptions
Expand All @@ -585,8 +582,7 @@ private static RestartStrategyConfiguration parseConfiguration(
backoffMultiplier,
resetBackoffThreshold,
jitter);
case "failurerate":
case "failure-rate":
case FAILURE_RATE:
int maxFailures =
configuration.get(
RestartStrategyOptions
Expand Down
Loading

0 comments on commit 5c895aa

Please sign in to comment.