Skip to content

Conversation

@jhuan31
Copy link

@jhuan31 jhuan31 commented Oct 13, 2019

…utdown stalled by long socket closing time

@jhuan31
Copy link
Author

jhuan31 commented Nov 12, 2019

retest maven build

@jhuan31
Copy link
Author

jhuan31 commented Nov 15, 2019

retest maven build

@asf-ci
Copy link

asf-ci commented Nov 25, 2019

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build-maven/1658/

@asf-ci
Copy link

asf-ci commented Dec 11, 2019

@jhuan31
Copy link
Author

jhuan31 commented Dec 12, 2019

retest maven build

@asf-ci
Copy link

asf-ci commented Dec 12, 2019

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build-maven/1716/

@asf-ci
Copy link

asf-ci commented Dec 17, 2019

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build-maven/1748/

@lvfangmin
Copy link
Contributor

Manually restarted the job on Jenkins and it passed.

Copy link
Contributor

@anmolnar anmolnar left a comment

Choose a reason for hiding this comment

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

Few nitpicks


protected Socket sock;
protected MultipleAddresses leaderAddr;
protected AtomicBoolean sockBeingClosed = new AtomicBoolean(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think socketClosed would be a better name for this variable, because it's not only guarding the "closing" method.

Copy link
Author

Choose a reason for hiding this comment

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

It is ONLY guarding the closing method. When it is set, the socket might not be closed for a long time, e.g. 30 seconds. But I don't want to name it "socketClosed" because it doesn't mean the socket is closed. Thoughts?

void closeSockSync() {
try {
long startTime = Time.currentElapsedTime();
sock.close();
Copy link
Contributor

Choose a reason for hiding this comment

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

You might want to add 2 more things here:

  • double check if sock is still not null
  • make sock = null after the close to prevent further usage of the object and let GC collect it

Copy link
Author

Choose a reason for hiding this comment

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

done.

@belugabehr
Copy link
Contributor

Can you please introduce a CachedThreadPool so that a new thread does not need to be spawned for every socket?

https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool()

@belugabehr
Copy link
Contributor

Also, better than using a conditional statement in the close method:

            if (sockBeingClosed.compareAndSet(false, true)) {
                if (closeSocketAsync) {
                    final Thread closingThread = new Thread(() -> closeSockSync(), "CloseSocketThread(sid:" + zk.getServerId());
                    closingThread.setDaemon(true);
                    closingThread.start();
                } else {
                    closeSockSync();
                }

Always use a ThreadPool, but use a single-thread thread pool or a 'direct' thread pool:

https://guava.dev/releases/19.0/api/docs/com/google/common/util/concurrent/MoreExecutors.html#directExecutor()

@jhuan31
Copy link
Author

jhuan31 commented Feb 26, 2020

Can you please introduce a CachedThreadPool so that a new thread does not need to be spawned for every socket?

https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool()

This is for closing the quorum socket once in a while, not the client sockets. I check the link you provide and it says the thread will be terminated if not being used for 60 seconds--I would expect the life time of a learner much longer than that. So I don't see any benefit of using a thread pool, or do I miss anything?

@jhuan31
Copy link
Author

jhuan31 commented Feb 26, 2020

Also, better than using a conditional statement in the close method:

            if (sockBeingClosed.compareAndSet(false, true)) {
                if (closeSocketAsync) {
                    final Thread closingThread = new Thread(() -> closeSockSync(), "CloseSocketThread(sid:" + zk.getServerId());
                    closingThread.setDaemon(true);
                    closingThread.start();
                } else {
                    closeSockSync();
                }

Always use a ThreadPool, but use a single-thread thread pool or a 'direct' thread pool:

https://guava.dev/releases/19.0/api/docs/com/google/common/util/concurrent/MoreExecutors.html#directExecutor()

The conditional statement is to preserve the current "blocking" behavior in case it's needed. How do I do that using a thread pool?

@jhuan31 jhuan31 force-pushed the ZOOKEEPER-3574 branch 2 times, most recently from ed3a9d5 to c70965a Compare February 26, 2020 22:30
Copy link
Contributor

@lvfangmin lvfangmin left a comment

Choose a reason for hiding this comment

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

+1

Thanks @jhuan31.

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

I will merge soon
Thank you guys!

Copy link
Contributor

@ztzg ztzg left a comment

Choose a reason for hiding this comment

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

LGTM, but 1. untested, and 2. see the documentation question.

Comment on lines +123 to +124
public static final String LEARNER_CLOSE_SOCKET_ASYNC = "learner.closeSocketAsync";
public static final boolean closeSocketAsync = Boolean.getBoolean(LEARNER_CLOSE_SOCKET_ASYNC);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not trying to block this PR, and things can be improved later, but:

I see that such properties, including learner.asyncSending above it, are not documented. Is there a specific policy regarding which properties are to be mentioned in zookeeperAdmin.md? I am wondering how one can learn about all these knobs, and their raison d'être? (I know the corresponding ticket ID can be found via Git, but that incurs some overhead.)

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your comments. I will add the flag to zookeeperAdmin. As for test, I find it is hard to construct a unit test for this. But this feature has been enabled in our production for months.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jhuan31: By "untested," I meant: I have looked into the code, but I haven't tested it :) I understand that it is not always easy to create meaningful tests for socket behavior. Thank you for taking care of the documentation.

Jie Huang added 2 commits April 4, 2020 15:33
Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

@ztzg as rule of thumb we have to document each know.
Usually once we introduce a know we are no more going to drop it.

@jhuan31
Copy link
Author

jhuan31 commented May 3, 2020

I will merge soon
Thank you guys!

@eolivelli Does this PR need more changes? Is it ready for merge? I refer "learner.closeSockeAsync" in a later PR #1301 and @symat points out that he can't find it in the code (since this PR is not merged yet) :)

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

LGTM

Sorry for the delay.
I can merge as soon as I back to work tomorrow

@eolivelli eolivelli closed this in b4f6e82 May 3, 2020
stickyhipp pushed a commit to stickyhipp/zookeeper that referenced this pull request Aug 19, 2020
…utdown stalled by long socket closing time

…utdown stalled by long socket closing time

Author: Jie Huang <[email protected]>

Reviewers: Enrico Olivelli <[email protected]>, Fangmin Lyu <[email protected]>

Closes apache#1115 from jhuan31/ZOOKEEPER-3574
RokLenarcic pushed a commit to RokLenarcic/zookeeper that referenced this pull request Aug 31, 2022
…utdown stalled by long socket closing time

…utdown stalled by long socket closing time

Author: Jie Huang <[email protected]>

Reviewers: Enrico Olivelli <[email protected]>, Fangmin Lyu <[email protected]>

Closes apache#1115 from jhuan31/ZOOKEEPER-3574
RokLenarcic pushed a commit to RokLenarcic/zookeeper that referenced this pull request Aug 31, 2022
…utdown stalled by long socket closing time

…utdown stalled by long socket closing time

Author: Jie Huang <[email protected]>

Reviewers: Enrico Olivelli <[email protected]>, Fangmin Lyu <[email protected]>

Closes apache#1115 from jhuan31/ZOOKEEPER-3574
RokLenarcic pushed a commit to RokLenarcic/zookeeper that referenced this pull request Aug 31, 2022
…utdown stalled by long socket closing time

…utdown stalled by long socket closing time

Author: Jie Huang <[email protected]>

Reviewers: Enrico Olivelli <[email protected]>, Fangmin Lyu <[email protected]>

Closes apache#1115 from jhuan31/ZOOKEEPER-3574
RokLenarcic pushed a commit to RokLenarcic/zookeeper that referenced this pull request Sep 3, 2022
…utdown stalled by long socket closing time

…utdown stalled by long socket closing time

Author: Jie Huang <[email protected]>

Reviewers: Enrico Olivelli <[email protected]>, Fangmin Lyu <[email protected]>

Closes apache#1115 from jhuan31/ZOOKEEPER-3574
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.

7 participants