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

Fixed bug in max reconnection delay initialization. #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/main/java/net/spy/memcached/ConnectionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ MemcachedNode createMemcachedNode(SocketAddress sa, SocketChannel c,
HashAlgorithm getHashAlg();

/**
* Maximum number of milliseconds to wait between reconnect attempts.
* Maximum number of seconds to wait between reconnect attempts.
Copy link

@jhbae jhbae Feb 13, 2017

Choose a reason for hiding this comment

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

I think this should be milliseconds.

Because, in this commit, you just used f.getMaxReconnectDelay()
and as you may already know maxDelay is applied to calculate delay as follows.

long delay = (long) Math.min(maxDelay, Math.pow(2, node.getReconnectCount()) * 1000); long reconnectTime = System.currentTimeMillis() + delay;

As we can see above, delay will be just added to currentTimeMillis()
and the value 1000 is multiplied only to Math.pow(2, node.getReconnectCount()) not to maxDelay.

So I think it should be milliseconds as originally it was.

Copy link

Choose a reason for hiding this comment

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

although maxDelay is in millisecond, maxDelay = TimeUnit.SECONDS.toMillis(f.getMaxReconnectDelay()); MaxReconnectDelay should be in second

*/
long getMaxReconnectDelay();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/spy/memcached/MemcachedConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public MemcachedConnection(final int bufSize, final ConnectionFactory f,
addedQueue = new ConcurrentLinkedQueue<MemcachedNode>();
failureMode = fm;
shouldOptimize = f.shouldOptimize();
maxDelay = TimeUnit.SECONDS.toMillis(f.getMaxReconnectDelay());
maxDelay = f.getMaxReconnectDelay();
opFact = opfactory;
timeoutExceptionThreshold = f.getTimeoutExceptionThreshold();
selector = Selector.open();
Expand Down