=rem #3527 Take actor system uid into consideration in remote watch

* When actor system was restarted quickly the new system replied to
  heartbeats and Terminated was never triggered for actors in old
  system.
* Solved by sending an extra Watch system message when first hearbeat
  is received for an address and when a change of system uid is detected.
This commit is contained in:
Patrik Nordwall 2013-08-19 17:50:15 +02:00
parent d85039c1a6
commit 637598a28b
3 changed files with 130 additions and 1 deletions

View file

@ -17,6 +17,7 @@ import akka.ConfigurationException
import akka.dispatch.{ UnboundedMessageQueueSemantics, RequiresMessageQueue }
import akka.actor.InternalActorRef
import akka.dispatch.sysmsg.DeathWatchNotification
import akka.dispatch.sysmsg.Watch
import akka.actor.Deploy
/**
@ -148,6 +149,8 @@ private[akka] class RemoteWatcher(
log.debug("Received first heartbeat rsp from [{}]", from)
if (watchingNodes(from) && !unreachable(from)) {
if (!addressUids.contains(from) || addressUids(from) != uid)
reWatch(from)
addressUids += (from -> uid)
failureDetector.heartbeat(from)
}
@ -264,4 +267,18 @@ private[akka] class RemoteWatcher(
failureDetector.heartbeat(address)
}
/**
* To ensure that we receive heartbeat messages from the right actor system
* incarnation we send Watch again for the first HeartbeatRsp (containing
* the system UID) and if HeartbeatRsp contains a new system UID.
* Terminated will be triggered if the watchee (including correct Actor UID)
* does not exist.
*/
def reWatch(address: Address): Unit =
watching.foreach {
case (wee: InternalActorRef, wer: InternalActorRef) if wee.path.address == address
log.debug("Re-watch [{} -> {}]", wer, wee)
wee.sendSystemMessage(Watch(wee, wer)) // ➡➡➡ NEVER SEND THE SAME SYSTEM MESSAGE OBJECT TO TWO ACTORS ⬅⬅⬅
}
}