private async Task <BitMachineIdSet> CallHeartbeatAsync( OperationContext context, ClusterState clusterState, RedisBatch batch, string key, MachineState state) { var heartbeatResults = await Task.WhenAll(clusterState.LocalMachineMappings.Select(async machineMapping => { (MachineState priorState, BitMachineIdSet inactiveMachineIdSet) = await batch.HeartbeatAsync( key, machineMapping.Id.Index, state, _clock.UtcNow, _configuration.RecomputeInactiveMachinesExpiry, _configuration.MachineExpiry); if (priorState != state) { Tracer.Debug(context, $"Machine {machineMapping} state changed from {priorState} to {state}"); } if (priorState == MachineState.Unavailable || priorState == MachineState.Expired) { clusterState.LastInactiveTime = _clock.UtcNow; } return(inactiveMachineIdSet); }).ToList()); return(heartbeatResults.FirstOrDefault() ?? BitMachineIdSet.EmptyInstance); }
private async Task <(MachineState priorState, BitMachineIdSet inactiveMachineIdSet, BitMachineIdSet closedMachineIdSet)> CallHeartbeatAsync( OperationContext context, ClusterState clusterState, RedisBatch batch, string key, MachineState state) { var heartbeatResults = await Task.WhenAll(clusterState.LocalMachineMappings.Select(async machineMapping => { (MachineState priorState, BitMachineIdSet inactiveMachineIdSet, BitMachineIdSet closedMachineIdSet) = await batch.HeartbeatAsync( key, machineMapping.Id.Index, // When readonly, specify Unknown which does not update state Configuration.DistributedContentConsumerOnly ? MachineState.Unknown : state, _clock.UtcNow, Configuration.MachineStateRecomputeInterval, Configuration.MachineActiveToClosedInterval, Configuration.MachineActiveToExpiredInterval); if (priorState != state) { Tracer.Debug(context, $"Machine {machineMapping} state changed from {priorState} to {state}"); } if (priorState == MachineState.DeadUnavailable || priorState == MachineState.DeadExpired) { clusterState.LastInactiveTime = _clock.UtcNow; } return(priorState, inactiveMachineIdSet, closedMachineIdSet); }).ToList()); return(heartbeatResults.Any() ? heartbeatResults.First() : (priorState : MachineState.Unknown, inactiveMachineIdSet : BitMachineIdSet.EmptyInstance, closedMachineIdSet : BitMachineIdSet.EmptyInstance)); }
private async Task <(MachineState priorState, BitMachineIdSet inactiveMachineIdSet)> CallHeartbeatAsync(OperationContext context, RedisBatch batch, string key, MachineState state) { var heartbeatResult = await batch.HeartbeatAsync( key, LocalMachineId.Index, state, _clock.UtcNow, _configuration.RecomputeInactiveMachinesExpiry, _configuration.MachineExpiry); if (heartbeatResult.priorState != state) { Tracer.Debug(context, $"Machine state changed from {heartbeatResult.priorState} to {state}"); } return(heartbeatResult); }