-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Watcher: Mark watcher as started only after loading watches #30403
Changes from 3 commits
ab75984
5754636
1035fb2
28e5ca8
211bec7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,23 +183,40 @@ void reload(ClusterState state, String reason) { | |
// by checking the cluster state version before and after loading the watches we can potentially just exit without applying the | ||
// changes | ||
processedClusterStateVersion.set(state.getVersion()); | ||
pauseExecution(reason); | ||
triggerService.pauseExecution(); | ||
int cancelledTaskCount = executionService.reload(); | ||
logger.info("reloading watcher, reason [{}], cancelled [{}] queued tasks", reason, cancelledTaskCount); | ||
|
||
executor.execute(wrapWatcherService(() -> reloadInner(state, reason, false), | ||
e -> logger.error("error reloading watcher", e))); | ||
} | ||
|
||
public void start(ClusterState state) { | ||
/** | ||
* start the watcher service, load watches in the background | ||
* | ||
* @param state the current cluster state | ||
* @param callback the callback to be triggered, when watches where loaded successfully | ||
*/ | ||
public void start(ClusterState state, Runnable callback) { | ||
executionService.unPause(); | ||
processedClusterStateVersion.set(state.getVersion()); | ||
executor.execute(wrapWatcherService(() -> reloadInner(state, "starting", true), | ||
executor.execute(wrapWatcherService(() -> { | ||
if (reloadInner(state, "starting", true)) { | ||
callback.run(); | ||
} | ||
}, | ||
e -> logger.error("error starting watcher", e))); | ||
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. do we want to do something with is error? (not related to this change) |
||
} | ||
|
||
/** | ||
* reload the watches and start scheduling them | ||
* | ||
* @param state the current cluster state | ||
* @param reason the reason for reloading, will be logged | ||
* @param loadTriggeredWatches should triggered watches be loaded in this run, not needed for reloading, only for starting | ||
* @return true if no other loading of a newer cluster state happened in parallel, false otherwise | ||
*/ | ||
private synchronized void reloadInner(ClusterState state, String reason, boolean loadTriggeredWatches) { | ||
private synchronized boolean reloadInner(ClusterState state, String reason, boolean loadTriggeredWatches) { | ||
// exit early if another thread has come in between | ||
if (processedClusterStateVersion.get() != state.getVersion()) { | ||
logger.debug("watch service has not been reloaded for state [{}], another reload for state [{}] in progress", | ||
|
@@ -221,9 +238,11 @@ private synchronized void reloadInner(ClusterState state, String reason, boolean | |
executionService.executeTriggeredWatches(triggeredWatches); | ||
} | ||
logger.debug("watch service has been reloaded, reason [{}]", reason); | ||
return true; | ||
} else { | ||
logger.debug("watch service has not been reloaded for state [{}], another reload for state [{}] in progress", | ||
state.getVersion(), processedClusterStateVersion.get()); | ||
return false; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,11 +121,19 @@ public void unPause() { | |
} | ||
|
||
/** | ||
* Pause the execution of the watcher executor | ||
* Pause the execution of the watcher executor, and empty the state | ||
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 you unpack the java docs to explain what this does? this seems too terse. For example it doesn't mention reload? |
||
* @return the number of tasks that have been removed | ||
*/ | ||
public int pause() { | ||
paused.set(true); | ||
return reload(); | ||
} | ||
|
||
/** | ||
* Empty the currently queued tasks and wait for current executions to finish | ||
* @return the number of tasks that have been removed | ||
*/ | ||
public int reload() { | ||
int cancelledTaskCount = executor.queue().drainTo(new ArrayList<>()); | ||
this.clearExecutions(); | ||
return cancelledTaskCount; | ||
|
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.
can we call the callback onStarted ? it is not called on error