Skip to content

Commit

Permalink
info: avoid sending messages too early.
Browse files Browse the repository at this point in the history
Motivation:

The info cell can send messages before the cell is properly registered.
Message sending is randomised, so this does not always happen, but when
it does, it can lead to errors like:

    java.lang.IllegalStateException: Cannot send message with callback in state \{\} \[PRE_STARTUP\]
    	at com.google.common.base.Preconditions.checkState(Preconditions.java:199) ~\[guava-19.0.jar:na\]
    	at dmg.cells.nucleus.CellNucleus.sendMessage(CellNucleus.java:519) ~\[cells-3.0.19-SNAPSHOT.jar:3.0.19-SNAPSHOT\]
    	at dmg.cells.nucleus.CellAdapter.sendMessage(CellAdapter.java:468) ~\[cells-3.0.19-SNAPSHOT.jar:3.0.19-SNAPSHOT\]
    	at org.dcache.services.info.gathers.MessageHandlerChain.sendMessage(MessageHandlerChain.java:129) ~\[dcache-info-3.0.19-SNAPSHOT.jar:3.0.19-SNAPSHOT\]
    	at org.dcache.services.info.gathers.MessageHandlerChain.sendMessage(MessageHandlerChain.java:99) ~\[dcache-info-3.0.19-SNAPSHOT.jar:3.0.19-SNAPSHOT\]
    	at org.dcache.services.info.gathers.SingleMessageDga.trigger(SingleMessageDga.java:83) ~\[dcache-info-3.0.19-SNAPSHOT.jar:3.0.19-SNAPSHOT\]
    	at org.dcache.services.info.gathers.DataGatheringScheduler$RegisteredActivity.checkAndTrigger(DataGatheringScheduler.java:131) ~\[dcache-info-3.0.19-SNAPSHOT.jar:3.0.19-SNAPSHOT\]
    	at org.dcache.services.info.gathers.DataGatheringScheduler.run(DataGatheringScheduler.java:281) ~\[dcache-info-3.0.19-SNAPSHOT.jar:3.0.19-SNAPSHOT\]
    	at java.lang.Thread.run(Thread.java:748) ~\[na:1.8.0_131\]

Modification:

Only start sending messages once the cell nucleus is in POST_STARTUP
phase.

Result:

No more IllegalStateException stack-traces about attempting to send
message with callback in state PRE_STARTUP.

Target: master
Request: 3.1
Request: 3.0
Request: 2.16
Requires-notes: yes
Requires-book: no
Patch: https://rb.dcache.org/r/10234/
Acked-by: Tigran Mkrtchyan
Fixes #3219
  • Loading branch information
paulmillar committed Jun 14, 2017
1 parent e65c4be commit 6407eb9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Expand Up @@ -9,6 +9,7 @@
import java.util.List;
import java.util.Map;

import dmg.cells.nucleus.CellLifeCycleAware;
import dmg.cells.nucleus.EnvironmentAware;
import dmg.cells.nucleus.UOID;

Expand All @@ -30,7 +31,7 @@
* @author Paul Millar <paul.millar@desy.de>
*/

public class DataGatheringScheduler implements Runnable, EnvironmentAware
public class DataGatheringScheduler implements Runnable, EnvironmentAware, CellLifeCycleAware
{
private static final long FIVE_MINUTES = 5*60*1000;
private static final Logger LOGGER_SCHED = LoggerFactory.getLogger(DataGatheringScheduler.class);
Expand Down Expand Up @@ -206,7 +207,8 @@ public String getStatus()
}
}

public synchronized void start()
@Override
public synchronized void afterStart()
{
checkState(_thread == null, "DataGatheringScheduler already started");

Expand Down Expand Up @@ -390,7 +392,8 @@ public String triggerActivity(String name)
* Request that this thread sends no more requests
* for data.
*/
public void shutdown()
@Override
public void beforeStop()
{
LOGGER_SCHED.debug("Requesting DGA Scheduler to shutdown.");
synchronized (_activity) {
Expand Down
Expand Up @@ -62,8 +62,7 @@
</bean>


<bean id="data-gathering-scheduler" class="org.dcache.services.info.gathers.DataGatheringScheduler"
init-method="start" destroy-method="shutdown">
<bean id="data-gathering-scheduler" class="org.dcache.services.info.gathers.DataGatheringScheduler">
<property name="stateUpdateManager" ref="state-update-manager"/>
<property name="messageMetadataRepository" ref="message-handler-chain"/>
<property name="messageSender" ref="message-handler-chain"/>
Expand Down

0 comments on commit 6407eb9

Please sign in to comment.