@@ -105,6 +105,7 @@ public class MemcachedConnection extends SpyThread {
105
105
private final int timeoutExceptionThreshold ;
106
106
private final Collection <Operation > retryOps ;
107
107
protected final ConcurrentLinkedQueue <MemcachedNode > nodesToShutdown ;
108
+ private final boolean verifyAliveOnConnect ;
108
109
109
110
/**
110
111
* Construct a memcached connection.
@@ -131,6 +132,14 @@ public MemcachedConnection(int bufSize, ConnectionFactory f,
131
132
nodesToShutdown = new ConcurrentLinkedQueue <MemcachedNode >();
132
133
this .bufSize = bufSize ;
133
134
this .connectionFactory = f ;
135
+
136
+ String verifyAlive = System .getProperty ("net.spy.verifyAliveOnConnect" );
137
+ if (verifyAlive != null && verifyAlive .equals ("true" )) {
138
+ verifyAliveOnConnect = true ;
139
+ } else {
140
+ verifyAliveOnConnect = false ;
141
+ }
142
+
134
143
List <MemcachedNode > connections = createConnections (a );
135
144
locator = f .createLocator (connections );
136
145
setName ("Memcached IO over " + this );
@@ -412,47 +421,49 @@ private void handleIO(SelectionKey sk) {
412
421
final SocketChannel channel = node .getChannel ();
413
422
if (channel .finishConnect ()) {
414
423
415
- // Test to see if it's truly alive, could be a hung process, OS
416
- final CountDownLatch latch = new CountDownLatch (1 );
417
- final OperationFuture <Boolean > rv =
418
- new OperationFuture <Boolean >("noop" , latch , 2500 );
419
- NoopOperation testOp = opFact .noop (new OperationCallback () {
420
- public void receivedStatus (OperationStatus status ) {
421
- rv .set (status .isSuccess (), status );
422
- }
424
+ if (verifyAliveOnConnect ) {
425
+ // Test to see if it's truly alive, could be a hung process, OS
426
+ final CountDownLatch latch = new CountDownLatch (1 );
427
+ final OperationFuture <Boolean > rv =
428
+ new OperationFuture <Boolean >("noop" , latch , 2500 );
429
+ NoopOperation testOp = opFact .noop (new OperationCallback () {
430
+ public void receivedStatus (OperationStatus status ) {
431
+ rv .set (status .isSuccess (), status );
432
+ }
423
433
424
- @ Override
425
- public void complete () {
426
- latch .countDown ();
427
- }
428
- });
429
-
430
- testOp .setHandlingNode (node );
431
- testOp .initialize ();
432
-
433
- checkState ();
434
- insertOperation (node , testOp );
435
- node .copyInputQueue ();
436
-
437
- boolean done = false ;
438
- if (sk .isValid ()) {
439
- long timeout = TimeUnit .MILLISECONDS .toNanos (
440
- connectionFactory .getOperationTimeout ());
441
- for (long stop = System .nanoTime () + timeout ;
442
- stop > System .nanoTime ();) {
443
- handleWrites (sk , node );
444
- handleReads (sk , node );
445
- if (done = (latch .getCount () == 0 )) {
446
- break ;
434
+ @ Override
435
+ public void complete () {
436
+ latch .countDown ();
437
+ }
438
+ });
439
+
440
+ testOp .setHandlingNode (node );
441
+ testOp .initialize ();
442
+
443
+ checkState ();
444
+ insertOperation (node , testOp );
445
+ node .copyInputQueue ();
446
+
447
+ boolean done = false ;
448
+ if (sk .isValid ()) {
449
+ long timeout = TimeUnit .MILLISECONDS .toNanos (
450
+ connectionFactory .getOperationTimeout ());
451
+ for (long stop = System .nanoTime () + timeout ;
452
+ stop > System .nanoTime ();) {
453
+ handleWrites (sk , node );
454
+ handleReads (sk , node );
455
+ if (done = (latch .getCount () == 0 )) {
456
+ break ;
457
+ }
447
458
}
448
459
}
449
- }
450
460
451
- if (!done || testOp .isCancelled () || testOp .hasErrored ()
452
- || testOp .isTimedOut ()) {
453
- throw new ConnectException ("Could not send noop upon connect! "
454
- + "This may indicate a running, but not responding memcached "
455
- + "instance." );
461
+ if (!done || testOp .isCancelled () || testOp .hasErrored ()
462
+ || testOp .isTimedOut ()) {
463
+ throw new ConnectException ("Could not send noop upon connect! "
464
+ + "This may indicate a running, but not responding memcached "
465
+ + "instance." );
466
+ }
456
467
}
457
468
458
469
connected (node );
0 commit comments