forked from apache/ranger
-
Notifications
You must be signed in to change notification settings - Fork 1
ADPS-1428 Ranger RMM crashes when Hive is restarted #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
evgenii-tregubov
wants to merge
1
commit into
develop/2.2.0/2.6.0.7
Choose a base branch
from
feature/ADPS-1428
base: develop/2.2.0/2.6.0.7
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
...ager/src/main/java/org/apache/ranger/resource/mapper/event/retry/BackoffRetrySupport.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.ranger.resource.mapper.event.retry; | ||
|
|
||
| import java.util.concurrent.ThreadLocalRandom; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.apache.ranger.resource.mapper.utils.ThrowingRunnable; | ||
|
|
||
| /** | ||
| * Retry helper that never gives up. It runs the action and, if it fails, waits and tries | ||
| * again until the action works or the thread is interrupted. The wait grows after each | ||
| * failure (exponential backoff), but it is capped at a maximum, and a small random jitter | ||
| * is added so many clients do not retry at the same moment. | ||
| */ | ||
| @Slf4j | ||
| public class BackoffRetrySupport implements RetrySupport { | ||
|
|
||
| private final long baseIntervalMs; | ||
| private final long maxIntervalMs; | ||
| private final RetrySleeper retrySleeper; | ||
|
|
||
| /** | ||
| * The config values are already checked in the config class. Here we only keep a safe floor | ||
| * (base at least 1 ms, max not smaller than base), so this helper can never break on a wrong | ||
| * wait time, even if it is created with bad values from some other place. | ||
| * | ||
| * @param baseIntervalMs wait time for the first retry, in milliseconds | ||
| * @param maxIntervalMs the biggest possible wait time, in milliseconds | ||
| * @param retrySleeper how to wait between the tries (usually {@code Thread::sleep}) | ||
| */ | ||
| public BackoffRetrySupport(long baseIntervalMs, long maxIntervalMs, RetrySleeper retrySleeper) { | ||
| this.baseIntervalMs = Math.max(1, baseIntervalMs); | ||
| this.maxIntervalMs = Math.max(this.baseIntervalMs, maxIntervalMs); | ||
| this.retrySleeper = retrySleeper; | ||
| } | ||
|
|
||
| /** | ||
| * Runs the action. If the action throws, it waits (see {@link #backoffWithJitterMs(int)}) | ||
| * and runs the action one more time. It repeats this forever until the action does not throw. | ||
| * | ||
| * @param action the work to run; it can throw any exception | ||
| * @throws RetryException only when the thread is interrupted during the wait. Before it throws, | ||
| * it sets the interrupt flag again, so the caller can also see the interrupt. | ||
| */ | ||
| @Override | ||
| public void withRetries(ThrowingRunnable<?> action) throws RetryException { | ||
| int attempt = 0; | ||
| while (true) { | ||
| try { | ||
| action.run(); | ||
| return; | ||
| } catch (Exception e) { | ||
| long delayMs = backoffWithJitterMs(attempt++); | ||
| log.warn("Attempt failed, retrying in {} ms", delayMs, e); | ||
| try { | ||
| retrySleeper.sleepForMs(delayMs); | ||
| } catch (InterruptedException interrupted) { | ||
| Thread.currentThread().interrupt(); | ||
| throw new RetryException("Interrupted while backing off before retry", interrupted); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Calculates how long to wait before the next try. | ||
| * | ||
| * <p>The base value is doubled one time for every attempt (base, base*2, base*4 ...), but the | ||
| * result is never bigger than the maximum. After that a random jitter is added: the returned | ||
| * value is between the half of the capped value and the full capped value.</p> | ||
| * | ||
| * @param attempt how many times we already failed (the first call uses 0) | ||
| * @return the wait time in milliseconds | ||
| */ | ||
| private long backoffWithJitterMs(int attempt) { | ||
| long delay = baseIntervalMs; | ||
| for (int i = 0; i < attempt && delay < maxIntervalMs; i++) { | ||
| delay <<= 1; | ||
| } | ||
| long capped = Math.min(delay, maxIntervalMs); | ||
| long half = capped / 2; | ||
| return half + ThreadLocalRandom.current().nextLong(half + 1); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we also add the new reconnect properties to
ranger-rmm-default.xml? Right now, when passed only via-D, they are ignored byloadSystemProperties()and silently remain at the1000/300000defaults.