Skip to content
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

[ISSUE#1815]Adding lifecycle interface and resolve the service downtime caused by thread leak #2927

Merged
merged 23 commits into from
Jun 11, 2020

Conversation

zongtanghu
Copy link
Collaborator

@zongtanghu zongtanghu commented May 31, 2020

Please do not create a Pull Request without creating an issue first.

What is the purpose of the change

The related issue is [ISSUE #1815 ]
(1)Adding lifecycle interface and resolve the service downtime caused by thread leak .

Brief changelog

(1)Define and implement the lifecycle interface and related abstract class codes.
(2)Add lifecycle related codes.
(3)Adjust the ServerHttpAgent and MetricsHttpAgent class to implement the lifecycle interface.

Verifying this change

I have already add the unit test codes.

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

@zongtanghu
Copy link
Collaborator Author

@chuntaojun @yanlinly @wangweizZZ please help to review this pr's codes.


@Override
public void doStart() throws Exception {
this.serverHttpAgent.doStart();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use this.serverHttpAgent.start()


@Override
public void doStop() throws Exception {
this.serverHttpAgent.doStop();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use this.serverHttpAgent.stop()

public void register(AbstractLifeCycle instance) {
if (!lifeCycleResources.contains(instance)) {
synchronized(this) {
lockers.put(instance, new Object());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe need double check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you can see @chuntaojun 's review comments above.

@yfh0918
Copy link
Contributor

yfh0918 commented Jun 1, 2020

提一个建议
ResourceLifeCycleManager中关于lifycycle的注册,可以放到abstractlifycycle的构造函数中进行
或者,载新建个abstractlifycyclewithManager,继承abstractlifycycle做lifycycle的自动注册

@zongtanghu
Copy link
Collaborator Author

提一个建议
ResourceLifeCycleManager中关于lifycycle的注册,可以放到abstractlifycycle的构造函数中进行
或者,载新建个abstractlifycyclewithManager,继承abstractlifycycle做lifycycle的自动注册

Okay, good advice, I will optimize this pr's codes.Thanks.

@yfh0918
Copy link
Contributor

yfh0918 commented Jun 1, 2020

漏了一个建议,是不是可以弄个startable和closable,让lifecycle继承它们

@zongtanghu
Copy link
Collaborator Author

漏了一个建议,是不是可以弄个startable和closable,让lifecycle继承它们

In last new commit code, I have already defined the closeable interface.

@yfh0918
Copy link
Contributor

yfh0918 commented Jun 1, 2020

Ok节日快乐

@zongtanghu zongtanghu changed the title Adding lifecycle interface and resolve the service downtime caused by thread leak [ISSUE#1815]Adding lifecycle interface and resolve the service downtime caused by thread leak Jun 3, 2020
@zongtanghu
Copy link
Collaborator Author

I adjust and optimize some codes, please help to review this pr again, thanks. @chuntaojun @yanlinly @wangweizZZ

@yanlinly yanlinly requested a review from KomachiSion June 3, 2020 03:24
@yfh0918
Copy link
Contributor

yfh0918 commented Jun 3, 2020

I'm sorry to have made so many suggestions,
The shutdown method is defined in the closeable. Other interfaces, such as configservice, also have the shutdown method. Whether the shutdown can be extends closeable
In addition, there is only destroy method in the lifecycle interface. Can add init method in the lifecycle interface ,the purpose is to reflect the true meaning of lifecycle

@zongtanghu
Copy link
Collaborator Author

I'm sorry to have made so many suggestions,
The shutdown method is defined in the closeable. Other interfaces, such as configservice, also have the shutdown method. Whether the shutdown can be extends closeable
In addition, there is only destroy method in the lifecycle interface. Can add init method in the lifecycle interface ,the purpose is to reflect the true meaning of lifecycle

I optimzie original pr's codes, and think it's too complex.Because, Closeable interface is located in detailed implment class level, and lifecycle interface is aimed to be defined and implemented in configservice and namingservice.We put init logical codes in claas constructor method.

@yfh0918
Copy link
Contributor

yfh0918 commented Jun 3, 2020

I'm sorry to have made so many suggestions,
The shutdown method is defined in the closeable. Other interfaces, such as configservice, also have the shutdown method. Whether the shutdown can be extends closeable
In addition, there is only destroy method in the lifecycle interface. Can add init method in the lifecycle interface ,the purpose is to reflect the true meaning of lifecycle

I optimzie original pr's codes, and think it's too complex.Because, Closeable interface is located in detailed implment class level, and lifecycle interface is aimed to be defined and implemented in configservice and namingservice.We put init logical codes in claas constructor method.

This PR is really complicated, and it's a big change. I'm a Virgo. Maybe I'm a little picky. Smile

Copy link
Collaborator

@KomachiSion KomachiSion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some suggestion for this PR.

  1. I think there no need to add this when using member normally. It's ok for used this in the set method and constructor uniformly.
  2. Why add destroyXXXService in factory? I think that it's enough for calling shutdown or destory method directly. It is same as call factory.destoryXXXService(XXXService)

@zongtanghu
Copy link
Collaborator Author

I have some suggestion for this PR.

  1. I think there no need to add this when using member normally. It's ok for used this in the set method and constructor uniformly.
  2. Why add destroyXXXService in factory? I think that it's enough for calling shutdown or destory method directly. It is same as call factory.destoryXXXService(XXXService)

My answer:
(1)"this" keywords aims to keep strong unified coding style.
(2)The destroyXXXService in factory can provide user a direct method call to destroy specific configservice/namingservice exhibitly.

Copy link
Collaborator

@KomachiSion KomachiSion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems no large issues. Just one unused import.

import com.alibaba.nacos.common.utils.JacksonUtils;

import com.alibaba.nacos.common.utils.ThreadUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.*;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't import *

@chuntaojun chuntaojun requested review from TsingLiang and yanlinly June 9, 2020 04:37
@@ -482,12 +499,21 @@ public void run() {

private void init(Properties properties) {

timeout = Math.max(NumberUtils.toInt(properties.getProperty(PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT),
this.timeout = Math.max(ConvertUtils.toInt(properties.getProperty(PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConvertUtils 这块为什么要改呢

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

再下一次提交中修改回原来的NumberUtils

Copy link
Collaborator

@yanlinly yanlinly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@yanlinly yanlinly merged commit 4c38fe1 into alibaba:develop Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants