@ -28,10 +28,11 @@ func NewRecoveryOrchestrator() *RecoveryOrchestrator {
// ProcessAssignment applies an assignment intent and logs the result.
// ProcessAssignment applies an assignment intent and logs the result.
// Detects endpoint-change invalidations automatically.
// Detects endpoint-change invalidations automatically.
func ( o * RecoveryOrchestrator ) ProcessAssignment ( intent AssignmentIntent ) AssignmentResult {
func ( o * RecoveryOrchestrator ) ProcessAssignment ( intent AssignmentIntent ) AssignmentResult {
// Snapshot pre-assignment session s tate for invalidation detection.
// Snapshot pre-assignment state for invalidation detection.
type preState struct {
type preState struct {
hadSession bool
hadSession bool
sessionID uint64
sessionID uint64
endpoint Endpoint
}
}
pre := map [ string ] preState { }
pre := map [ string ] preState { }
for _ , ra := range intent . Replicas {
for _ , ra := range intent . Replicas {
@ -39,6 +40,7 @@ func (o *RecoveryOrchestrator) ProcessAssignment(intent AssignmentIntent) Assign
pre [ ra . ReplicaID ] = preState {
pre [ ra . ReplicaID ] = preState {
hadSession : s . HasActiveSession ( ) ,
hadSession : s . HasActiveSession ( ) ,
sessionID : s . SessionID ( ) ,
sessionID : s . SessionID ( ) ,
endpoint : s . Endpoint ( ) ,
}
}
}
}
}
}
@ -52,12 +54,12 @@ func (o *RecoveryOrchestrator) ProcessAssignment(intent AssignmentIntent) Assign
o . Log . Record ( id , 0 , "sender_removed" , "" )
o . Log . Record ( id , 0 , "sender_removed" , "" )
}
}
// Detect endpoint-change invalidations: if the session ID changed
// (old session was invalidated and possibly replaced), log the old on e.
// Detect endpoint-change invalidations: only log "endpoint_changed" when
// the endpoint actually changed, not on normal session supersed e.
for id , p := range pre {
for id , p := range pre {
if p . hadSession {
if p . hadSession {
s := o . Registry . Sender ( id )
s := o . Registry . Sender ( id )
if s != nil && s . SessionID ( ) != p . sessionID {
if s != nil && s . SessionID ( ) != p . sessionID && s . Endpoint ( ) . Changed ( p . endpoint ) {
o . Log . Record ( id , p . sessionID , "session_invalidated" , "endpoint_changed" )
o . Log . Record ( id , p . sessionID , "session_invalidated" , "endpoint_changed" )
}
}
}
}