Skip to content

Commit

Permalink
Merge pull request #13743 from jerrinot/fixes/reduce-chattiness/master
Browse files Browse the repository at this point in the history
Reduce chattiness when starting Hazelcast
  • Loading branch information
pveentjer committed Sep 12, 2018
2 parents d111fd6 + 32492ab commit 770eee7
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void printNodeInfo() {
systemLogger.info("Hazelcast " + buildInfo.getVersion()
+ " (" + build + ") starting at " + node.getThisAddress());
systemLogger.info("Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved.");
systemLogger.info("Configured Hazelcast Serialization version: " + buildInfo.getSerializationVersion());
systemLogger.fine("Configured Hazelcast Serialization version: " + buildInfo.getSerializationVersion());
}

@Override
Expand Down Expand Up @@ -345,7 +345,9 @@ public void onMemberListChange() {

@Override
public void onClusterVersionChange(Version newVersion) {
systemLogger.info("Cluster version set to " + newVersion);
if (!node.getVersion().asVersion().isEqualTo(newVersion)) {
systemLogger.info("Cluster version set to " + newVersion);
}
ServiceManager serviceManager = node.getNodeEngine().getServiceManager();
List<ClusterVersionListener> listeners = serviceManager.getServices(ClusterVersionListener.class);
for (ClusterVersionListener listener : listeners) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ public void commitClusterState(ClusterStateChange stateChange, Address initiator
}
} else if (stateChange.isOfType(Version.class)) {
// version is validated on cluster-state-lock, thus we can commit without checking compatibility
doSetClusterVersion((Version) stateChange.getNewState());
Version newVersion = (Version) stateChange.getNewState();
logger.info("Cluster version set to " + newVersion);
doSetClusterVersion(newVersion);
node.getClusterService().getMembershipManager().scheduleMemberListVersionIncrement();
} else {
throw new IllegalArgumentException("Illegal ClusterStateChange of type " + stateChange.getType() + ".");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ private void acceptSocket() {

if (channel != null) {
final Channel theChannel = channel;
logger.info("Accepting socket connection from " + theChannel.socket().getRemoteSocketAddress());
if (logger.isFineEnabled()) {
logger.fine("Accepting socket connection from " + theChannel.socket().getRemoteSocketAddress());
}
if (ioService.isSocketInterceptorEnabled()) {
ioService.executeAsync(new Runnable() {
@Override
Expand Down
50 changes: 37 additions & 13 deletions hazelcast/src/main/java/com/hazelcast/nio/tcp/TcpIpConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
import java.net.InetSocketAddress;
import java.nio.channels.CancelledKeyException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;

import static com.hazelcast.nio.ConnectionType.MEMBER;
import static com.hazelcast.nio.ConnectionType.NONE;

/**
* The Tcp/Ip implementation of the {@link com.hazelcast.nio.Connection}.
Expand Down Expand Up @@ -59,7 +63,7 @@ public class TcpIpConnection implements Connection {

private TcpIpConnectionErrorHandler errorHandler;

private volatile ConnectionType type = ConnectionType.NONE;
private volatile ConnectionType type = NONE;

private volatile Throwable closeCause;

Expand Down Expand Up @@ -87,8 +91,14 @@ public ConnectionType getType() {

@Override
public void setType(ConnectionType type) {
if (this.type == ConnectionType.NONE) {
this.type = type;
if (this.type != NONE) {
return;
}

this.type = type;
if (type == MEMBER) {
logger.info("Initialized new cluster connection between "
+ channel.localSocketAddress() + " and " + channel.remoteSocketAddress());
}
}

Expand Down Expand Up @@ -152,7 +162,7 @@ public int getConnectionId() {
@Override
public boolean isClient() {
ConnectionType t = type;
return t != null && t != ConnectionType.NONE && t.isClient();
return t != null && t != NONE && t.isClient();
}

@Override
Expand Down Expand Up @@ -210,6 +220,11 @@ public void close(String reason, Throwable cause) {
}

private void logClose() {
Level logLevel = resolveLogLevelOnClose();
if (!logger.isLoggable(logLevel)) {
return;
}

String message = toString() + " closed. Reason: ";
if (closeReason != null) {
message += closeReason;
Expand All @@ -219,18 +234,27 @@ private void logClose() {
message += "Socket explicitly closed";
}

if (ioService.isActive()) {
if (closeCause == null || closeCause instanceof EOFException || closeCause instanceof CancelledKeyException) {
logger.info(message);
} else {
logger.warning(message, closeCause);
}
if (closeCause == null) {
logger.log(logLevel, message);
} else {
if (closeCause == null) {
logger.finest(message);
logger.log(logLevel, message, closeCause);
}
}

private Level resolveLogLevelOnClose() {
if (!ioService.isActive()) {
return Level.FINEST;
}

if (closeCause == null || closeCause instanceof EOFException || closeCause instanceof CancelledKeyException) {
if (type == ConnectionType.REST_CLIENT || type == ConnectionType.MEMCACHE_CLIENT) {
// text-based clients are expected to come and go frequently.
return Level.FINE;
} else {
logger.finest(message, closeCause);
return Level.INFO;
}
} else {
return Level.WARNING;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,10 @@ synchronized TcpIpConnection newConnection(Channel channel, Address endpoint) {
connection.setEndPoint(endpoint);
activeConnections.add(connection);

logger.info("Established socket connection between "
+ channel.localSocketAddress() + " and " + channel.remoteSocketAddress());
if (logger.isFineEnabled()) {
logger.fine("Established socket connection between "
+ channel.localSocketAddress() + " and " + channel.remoteSocketAddress());
}
openedCount.inc();

channel.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ protected MutableInteger initialValue() {
throw new IllegalArgumentException(RESPONSE_THREAD_COUNT.getName() + " can't be smaller than 0");
}

logger.info("Running with " + responseThreadCount + " response threads");
if (logger.isFineEnabled()) {
logger.fine("Running with " + responseThreadCount + " response threads");
}

this.responseThreads = new ResponseThread[responseThreadCount];
if (responseThreadCount == 0) {
Expand Down

0 comments on commit 770eee7

Please sign in to comment.