Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
import org.apache.zookeeper.server.util.SerializeUtils;
import org.apache.zookeeper.server.util.ZxidUtils;
import org.apache.zookeeper.util.SocketUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -435,7 +436,7 @@ public void run() {

// start with the initLimit, once the ack is processed
// in LearnerHandler switch to the syncLimit
s.setSoTimeout(self.tickTime * self.initLimit);
SocketUtils.setSocketOption(s, self.tickTime * self.initLimit);
s.setTcpNoDelay(nodelay);

BufferedInputStream is = new BufferedInputStream(s.getInputStream());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.zookeeper.server.util.ZxidUtils;
import org.apache.zookeeper.txn.SetDataTxn;
import org.apache.zookeeper.txn.TxnHeader;
import org.apache.zookeeper.util.SocketUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -323,7 +324,7 @@ private Socket createSocket() throws X509Exception, IOException {
} else {
sock = new Socket();
}
sock.setSoTimeout(self.tickTime * self.initLimit);
SocketUtils.setSocketOption(sock, self.tickTime * self.initLimit);
return sock;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.zookeeper.server.Request;
import org.apache.zookeeper.server.ZKDatabase;
import org.apache.zookeeper.server.quorum.auth.QuorumAuthServer;
import org.apache.zookeeper.util.SocketUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -463,7 +464,7 @@ public void run() {

// start with the initLimit, once the ack is processed
// in LearnerHandler switch to the syncLimit
s.setSoTimeout(self.tickTime * self.initLimit);
SocketUtils.setSocketOption(s, self.tickTime * self.initLimit);
BufferedInputStream is = new BufferedInputStream(s.getInputStream());
LearnerHandler lh = new LearnerHandler(s, is, this);
lh.start();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.zookeeper.util;

import java.net.Socket;
import java.net.SocketException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Util class used to set the common options on socket.
*/
public class SocketUtils {
private static final Logger LOG = LoggerFactory.getLogger(SocketUtils.class);

public static final String SOCKET_SO_LINGER = "zookeeper.quorum.solinger";
private static int soLinger = 0;

static {
soLinger = Integer.getInteger(SOCKET_SO_LINGER, 0);
LOG.info("{} = {}", SOCKET_SO_LINGER, soLinger);
}

public static void setSocketOption(Socket sock, int soTimeout) throws SocketException {
sock.setSoTimeout(soTimeout);
sock.setSoLinger(true, soLinger);
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no way to turn it off. Is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems soLinger is always useful, and set the value to a big value is kind of turning it off, that's why we didn't add option to set it to false. Do you suggest to add it?

}
}