-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
[CCR] Add time since last auto follow fetch to auto follow stats #36542
Merged
martijnvg
merged 11 commits into
elastic:master
from
martijnvg:ccr_add_time_since_last_auto_follow_fetch
Dec 17, 2018
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e356483
[CCR] Add time since last auto follow fetch to auto follow stats
martijnvg 7b2bd3c
iter
martijnvg 6dcd88d
added `lastSeenMetadataVersion` and added serialization version checks
martijnvg 8f08cb5
renamed `tracking_remote_clusters` to `auto_followed_clusters` and
martijnvg ff0724f
fixed docs
martijnvg b9aa581
Merge remote-tracking branch 'es/master' into ccr_add_time_since_last…
martijnvg 29d4645
fixed hlrc
martijnvg e99790f
fixed serialization bug
martijnvg c0c0e83
iter
martijnvg ae5fa2f
Merge remote-tracking branch 'es/master' into ccr_add_time_since_last…
martijnvg c196e01
rename
martijnvg 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
This file contains 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 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 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 |
---|---|---|
|
@@ -49,9 +49,11 @@ | |
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.TreeMap; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.function.LongSupplier; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
|
||
|
@@ -67,6 +69,7 @@ public class AutoFollowCoordinator implements ClusterStateListener { | |
private final Client client; | ||
private final ClusterService clusterService; | ||
private final CcrLicenseChecker ccrLicenseChecker; | ||
private final LongSupplier relativeTimeProvider; | ||
|
||
private volatile Map<String, AutoFollower> autoFollowers = Collections.emptyMap(); | ||
|
||
|
@@ -79,10 +82,13 @@ public class AutoFollowCoordinator implements ClusterStateListener { | |
public AutoFollowCoordinator( | ||
Client client, | ||
ClusterService clusterService, | ||
CcrLicenseChecker ccrLicenseChecker) { | ||
CcrLicenseChecker ccrLicenseChecker, | ||
LongSupplier relativeTimeProvider) { | ||
|
||
this.client = client; | ||
this.clusterService = clusterService; | ||
this.ccrLicenseChecker = Objects.requireNonNull(ccrLicenseChecker, "ccrLicenseChecker"); | ||
this.relativeTimeProvider = relativeTimeProvider; | ||
clusterService.addListener(this); | ||
this.recentAutoFollowErrors = new LinkedHashMap<String, ElasticsearchException>() { | ||
@Override | ||
|
@@ -93,11 +99,25 @@ protected boolean removeEldestEntry(final Map.Entry<String, ElasticsearchExcepti | |
} | ||
|
||
public synchronized AutoFollowStats getStats() { | ||
final Map<String, AutoFollower> autoFollowers = this.autoFollowers; | ||
final TreeMap<String, Long> timesSinceLastAutoFollowPerRemoteCluster = new TreeMap<>(); | ||
for (Map.Entry<String, AutoFollower> entry : autoFollowers.entrySet()) { | ||
long timeSinceLastAutoFollow = entry.getValue().lastAutoFollowTime; | ||
if (timeSinceLastAutoFollow != -1) { | ||
long timeSinceLastAutoFollowInMillis = | ||
TimeUnit.NANOSECONDS.toMillis(relativeTimeProvider.getAsLong() - timeSinceLastAutoFollow); | ||
timesSinceLastAutoFollowPerRemoteCluster.put(entry.getKey(), timeSinceLastAutoFollowInMillis); | ||
} else { | ||
timesSinceLastAutoFollowPerRemoteCluster.put(entry.getKey(), -1L); | ||
} | ||
} | ||
|
||
return new AutoFollowStats( | ||
numberOfFailedIndicesAutoFollowed, | ||
numberOfFailedRemoteClusterStateRequests, | ||
numberOfSuccessfulIndicesAutoFollowed, | ||
new TreeMap<>(recentAutoFollowErrors) | ||
new TreeMap<>(recentAutoFollowErrors), | ||
timesSinceLastAutoFollowPerRemoteCluster | ||
); | ||
} | ||
|
||
|
@@ -146,7 +166,7 @@ void updateAutoFollowers(ClusterState followerClusterState) { | |
|
||
Map<String, AutoFollower> newAutoFollowers = new HashMap<>(newRemoteClusters.size()); | ||
for (String remoteCluster : newRemoteClusters) { | ||
AutoFollower autoFollower = new AutoFollower(remoteCluster, this::updateStats, clusterService::state) { | ||
AutoFollower autoFollower = new AutoFollower(remoteCluster, this::updateStats, clusterService::state, relativeTimeProvider) { | ||
|
||
@Override | ||
void getRemoteClusterState(final String remoteCluster, | ||
|
@@ -239,20 +259,25 @@ abstract static class AutoFollower { | |
private final String remoteCluster; | ||
private final Consumer<List<AutoFollowResult>> statsUpdater; | ||
private final Supplier<ClusterState> followerClusterStateSupplier; | ||
private final LongSupplier relativeTimeProvider; | ||
|
||
private volatile long lastAutoFollowTime = -1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add the time unit to the variable names (relativeTimeProvider and lastAutoFollowTime)? |
||
private volatile long metadataVersion = 0; | ||
private volatile CountDown autoFollowPatternsCountDown; | ||
private volatile AtomicArray<AutoFollowResult> autoFollowResults; | ||
|
||
AutoFollower(final String remoteCluster, | ||
final Consumer<List<AutoFollowResult>> statsUpdater, | ||
final Supplier<ClusterState> followerClusterStateSupplier) { | ||
final Supplier<ClusterState> followerClusterStateSupplier, | ||
LongSupplier relativeTimeProvider) { | ||
this.remoteCluster = remoteCluster; | ||
this.statsUpdater = statsUpdater; | ||
this.followerClusterStateSupplier = followerClusterStateSupplier; | ||
this.relativeTimeProvider = relativeTimeProvider; | ||
} | ||
|
||
void start() { | ||
lastAutoFollowTime = relativeTimeProvider.getAsLong(); | ||
final ClusterState clusterState = followerClusterStateSupplier.get(); | ||
final AutoFollowMetadata autoFollowMetadata = clusterState.metaData().custom(AutoFollowMetadata.TYPE); | ||
if (autoFollowMetadata == null) { | ||
|
This file contains 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 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 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.
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.
Maybe use
ThreadPool::relativeTimeInMillis
.