You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2022/08/03 23:30:20 UTC
[GitHub] [helix] qqu0127 opened a new pull request, #2183: Optimize HelixTaskExecutor reset() in event of shutdown
qqu0127 opened a new pull request, #2183:
URL: https://github.com/apache/helix/pull/2183
### Issues
- [X] My PR addresses the following Helix issues and references them in the PR description:
Resolve https://github.com/apache/helix/issues/2182
### Description
- [X] Here are some details about my PR, including screenshots of any UI changes:
`HelixStateMachineEngine.reset()` is invoked 4 times during participant shutdown and that could take up to a few minutes. Two causes:
1. The above is triggered by `HelixTaskExecutor` twice because the same HelixStateMachineEngine is registered for two different message types.
2. There is also an additional thread doing similar cleanup, from `ZKHelixManager.cleanupCallbackHandlers`
This PR refactor the logic in HelixTaskExecutor to reduce unnecessary method call.
### Tests
- [X] The following tests are written for this issue:
New test case in helix-core/src/test/java/org/apache/helix/messaging/handling/TestHelixTaskExecutor.java
- The following is the result of the "mvn test" command on the appropriate module:
(If CI test fails due to known issue, please specify the issue and test PR locally. Then copy & paste the result of "mvn test" to here.)
### Changes that Break Backward Compatibility (Optional)
- My PR contains changes that break backward compatibility or previous assumptions for certain methods or API. They include:
(Consider including all behavior changes for public methods or API. Also include these changes in merge description so that other developers are aware of these changes. This allows them to make relevant code changes in feature branches accounting for the new method/API behavior.)
### Documentation (Optional)
- In case of new functionality, my PR adds documentation in the following wiki page:
(Link the GitHub wiki you added)
### Commits
- My commits all reference appropriate Apache Helix GitHub issues in their subject lines. In addition, my commits follow the guidelines from "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)":
1. Subject is separated from body by a blank line
1. Subject is limited to 50 characters (not including Jira issue reference)
1. Subject does not end with a period
1. Subject uses the imperative mood ("add", not "adding")
1. Body wraps at 72 characters
1. Body explains "what" and "why", not "how"
### Code Quality
- My diff has been formatted using helix-style.xml
(helix-style-intellij.xml if IntelliJ IDE is used)
--
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: reviews-unsubscribe@helix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] desaikomal commented on a diff in pull request #2183: Optimize HelixTaskExecutor reset() in event of shutdown
Posted by GitBox <gi...@apache.org>.
desaikomal commented on code in PR #2183:
URL: https://github.com/apache/helix/pull/2183#discussion_r937916941
##########
helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java:
##########
@@ -678,52 +680,56 @@ private void syncFactoryState() {
}
void reset() {
- LOG.info("Reset HelixTaskExecutor");
+ synchronized (_resetLock) {
Review Comment:
synchronized method doesn't mean across different methods. only one call to this method.
I agree that you don't need synchronization. reset() method has 3 states: No one has invoked it. it is in progress and it has completed the job and nothing to reset. So if you model as appropriate status enum, you can work around where reset() is called only once in shutdown path. my 2cents
--
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: reviews-unsubscribe@helix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] qqu0127 commented on a diff in pull request #2183: Optimize HelixTaskExecutor reset() in event of shutdown
Posted by GitBox <gi...@apache.org>.
qqu0127 commented on code in PR #2183:
URL: https://github.com/apache/helix/pull/2183#discussion_r937286705
##########
helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java:
##########
@@ -827,7 +833,11 @@ public void onMessage(String instanceName, List<Message> messages,
// and terminate all the thread pools
// TODO: see if we should have a separate notification call for resetting
if (changeContext.getType() == Type.FINALIZE) {
- reset();
+ if (_isShuttingDown) {
Review Comment:
https://github.com/apache/helix/blob/132715785e90803ad8991da491f4621db1668fb8/helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java#L1454
--
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: reviews-unsubscribe@helix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] qqu0127 commented on a diff in pull request #2183: Optimize HelixTaskExecutor reset() in event of shutdown
Posted by GitBox <gi...@apache.org>.
qqu0127 commented on code in PR #2183:
URL: https://github.com/apache/helix/pull/2183#discussion_r938064923
##########
helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java:
##########
@@ -678,52 +680,56 @@ private void syncFactoryState() {
}
void reset() {
- LOG.info("Reset HelixTaskExecutor");
+ synchronized (_resetLock) {
Review Comment:
Thanks for the comment.
I updated a bit to use synchronization and a boolean state, as I find in_progress state is unnecessary. Hope that makes sense.
--
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: reviews-unsubscribe@helix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] qqu0127 commented on a diff in pull request #2183: Optimize HelixTaskExecutor reset() in event of shutdown
Posted by GitBox <gi...@apache.org>.
qqu0127 commented on code in PR #2183:
URL: https://github.com/apache/helix/pull/2183#discussion_r942875946
##########
helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java:
##########
@@ -734,6 +744,7 @@ void init() {
}
_isShuttingDown = false;
+ _isResetComplete = false;
Review Comment:
Correct me if I'm wrong. I think the problem is with `init()`, it initializes threadpools that need to be shutdown in reset(), so reset() should still be run even without state transition.
What `reset()` does should actually be shutdown() or close().
--
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: reviews-unsubscribe@helix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] junkaixue merged pull request #2183: Optimize HelixTaskExecutor reset() in event of shutdown
Posted by GitBox <gi...@apache.org>.
junkaixue merged PR #2183:
URL: https://github.com/apache/helix/pull/2183
--
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: reviews-unsubscribe@helix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] junkaixue commented on a diff in pull request #2183: Optimize HelixTaskExecutor reset() in event of shutdown
Posted by GitBox <gi...@apache.org>.
junkaixue commented on code in PR #2183:
URL: https://github.com/apache/helix/pull/2183#discussion_r942803893
##########
helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java:
##########
@@ -734,6 +744,7 @@ void init() {
}
_isShuttingDown = false;
+ _isResetComplete = false;
Review Comment:
Why not put in onMessage? OnMessage is the place starting STs and changing the states.
##########
helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java:
##########
@@ -827,7 +838,11 @@ public void onMessage(String instanceName, List<Message> messages,
// and terminate all the thread pools
// TODO: see if we should have a separate notification call for resetting
if (changeContext.getType() == Type.FINALIZE) {
- reset();
+ if (_isShuttingDown) {
Review Comment:
Since we already use new flag to protect it. Let's not use this isShutdowning to do another filtering.
There could be race condition happening. The flag started with flag and if there is a session timeout and restart everything. Before this flag set to true in the registryFactory, you get finalize message from ZK server. You will bypass the reset and use the old data.
If we already decide to use lowest component to do dedup, let's not add extra optimization in up layer, which may have potential issues.
##########
helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java:
##########
@@ -237,6 +239,7 @@ private void registerMessageHandlerFactory(String type, MessageHandlerFactory fa
}
_isShuttingDown = false;
+ _isResetComplete = false;
Review Comment:
NIT: this is more like an action flag instead of state flag. Personally, I prefer flag like isCleanState or something else.
##########
helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java:
##########
@@ -694,16 +701,19 @@ void reset() {
LOG.info("Reset executor for msgType: " + msgType + ", pool: " + pool);
shutdownAndAwaitTermination(pool, item);
}
-
- if (item.factory() != null) {
- try {
- item.factory().reset();
- } catch (Exception ex) {
- LOG.error("Failed to reset the factory {} of message type {}.", item.factory().toString(),
- msgType, ex);
- }
- }
}
+ _hdlrFtyRegistry.values()
+ .parallelStream()
+ .map(MsgHandlerFactoryRegistryItem::factory)
+ .distinct()
+ .filter(Objects::nonNull)
+ .forEach(factory -> {
+ try {
+ factory.reset();
+ } catch (Exception ex) {
+ LOG.error("Failed to reset the factory {}.", factory.toString(), ex);
+ }
+ });
Review Comment:
I would suggest to make parallel reset in a different PR. This requires more thinking. 1) we cannot guarantee there is not dependencies and user are not leveraging dependencies because of sequential reset. 2) if there is a problem for parallel reset, you can just revert reset PR instead of entire PR to revert dedup logic.
--
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: reviews-unsubscribe@helix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] qqu0127 commented on a diff in pull request #2183: Optimize HelixTaskExecutor reset() in event of shutdown
Posted by GitBox <gi...@apache.org>.
qqu0127 commented on code in PR #2183:
URL: https://github.com/apache/helix/pull/2183#discussion_r937289799
##########
helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java:
##########
@@ -678,52 +680,56 @@ private void syncFactoryState() {
}
void reset() {
- LOG.info("Reset HelixTaskExecutor");
+ synchronized (_resetLock) {
Review Comment:
Synchronized method is not used since I don't think this has to be mutual exclusive to other methods synchronized on the instance.
Do we need this synchronization at all? Maybe not, I'm still trying staging changes hoping to better improve the reset().
--
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: reviews-unsubscribe@helix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] desaikomal commented on a diff in pull request #2183: Optimize HelixTaskExecutor reset() in event of shutdown
Posted by GitBox <gi...@apache.org>.
desaikomal commented on code in PR #2183:
URL: https://github.com/apache/helix/pull/2183#discussion_r937275820
##########
helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java:
##########
@@ -827,7 +833,11 @@ public void onMessage(String instanceName, List<Message> messages,
// and terminate all the thread pools
// TODO: see if we should have a separate notification call for resetting
if (changeContext.getType() == Type.FINALIZE) {
- reset();
+ if (_isShuttingDown) {
Review Comment:
where is the flag being set?
##########
helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java:
##########
@@ -678,52 +680,56 @@ private void syncFactoryState() {
}
void reset() {
- LOG.info("Reset HelixTaskExecutor");
+ synchronized (_resetLock) {
Review Comment:
do you need to lock the whole method?? if so, why not add synchronized at method itself.
--
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: reviews-unsubscribe@helix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org
[GitHub] [helix] qqu0127 commented on pull request #2183: Optimize HelixTaskExecutor reset() in event of shutdown
Posted by GitBox <gi...@apache.org>.
qqu0127 commented on PR #2183:
URL: https://github.com/apache/helix/pull/2183#issuecomment-1212205819
This PR is ready to merge, approved by @junkaixue
Commit message:
Optimize HelixTaskExecutor reset() in event of shutdown
Some instances maybe reset() multiple times during participant shutdown.
This commit refactor logic in HelixTaskExecutor to reduce unnecessary
method call.
--
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: reviews-unsubscribe@helix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org