Skip to content

Commit 2c3f687

Browse files
author
Gerd Behrmann
committed
cells: Don't retry send during shutdown
The sendAndWaitToPermanent method allows blocking send to cells we know are usually available. When unavailable we optimistically wait till the cell comes back online or the timeout has expired. This is an excellent strategy, except if our cell is about to shut down. This patch alters the logic so that a NoRouteToCellException during cell shutdown causes the sendAndWaitToPermanent method to return right away. Target: trunk Require-notes: no Require-book: no Acked-by: Dmitry Litvintsev <litvinse@fnal.gov> Acked-by: Paul Millar <paul.millar@desy.de> Patch: http://rb.dcache.org/r/5291/
1 parent 3137ab1 commit 2c3f687

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

modules/cells/src/main/java/dmg/cells/nucleus/CellAdapter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public class CellAdapter
7777
private final CellNucleus _nucleus;
7878
private final Gate _readyGate = new Gate(false);
7979
private final Gate _startGate = new Gate(false);
80+
private final Gate _shutdownGate = new Gate(false);
8081
private final Args _args;
8182
private boolean _useInterpreter = true;
8283
private boolean _returnCommandException = true;
@@ -569,8 +570,11 @@ public CellMessage sendAndWaitToPermanent(CellMessage envelope,
569570
return sendAndWait(envelope, timeUntil(deadline));
570571
} catch (NoRouteToCellException e) {
571572
_log.warn("{}", e.toString());
573+
572574
while (timeUntil(deadline) > RETRY_PERIOD) {
573-
Thread.sleep(RETRY_PERIOD);
575+
if (_shutdownGate.await(RETRY_PERIOD)) {
576+
break;
577+
}
574578
try {
575579
return sendAndWait(envelope, timeUntil(deadline));
576580
} catch (NoRouteToCellException ignored) {
@@ -844,6 +848,7 @@ public void prepareRemoval(KillEvent ce)
844848
{
845849
_log.info("CellAdapter : prepareRemoval : waiting for gate to open");
846850
_readyGate.check();
851+
_shutdownGate.open();
847852
cleanUp();
848853
dumpPinboard();
849854
_log.info("CellAdapter : prepareRemoval : done");

modules/cells/src/main/java/dmg/util/Gate.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,32 @@ public Gate(){}
66
public Gate( boolean isOpen ){
77
_isOpen = isOpen ;
88
}
9+
10+
public synchronized boolean await(long millis) throws InterruptedException
11+
{
12+
long deadline = System.currentTimeMillis() + millis;
13+
while (!_isOpen && deadline > System.currentTimeMillis()) {
14+
wait(deadline - System.currentTimeMillis());
15+
}
16+
return _isOpen;
17+
}
18+
919
public synchronized Object check(){
10-
while( true ){
20+
while( true ){
1121
if( _isOpen ) {
1222
return this;
1323
}
1424
try{ wait() ; }catch( Exception ee ){}
1525
}
16-
26+
1727
}
18-
public synchronized void open(){
28+
public synchronized void open(){
1929
_isOpen = true ;
2030
notifyAll() ;
21-
}
22-
public synchronized void close(){
31+
}
32+
public synchronized void close(){
2333
_isOpen = false ;
2434
notifyAll() ;
25-
}
35+
}
2636

2737
}

0 commit comments

Comments
 (0)