/// <summary> /// Marks that a machine with <paramref name="machineId"/> is Active. /// </summary> public void MarkMachineActive(MachineId machineId) { if (_inactiveMachinesSet[machineId.Index]) { _inactiveMachinesSet = (BitMachineIdSet)_inactiveMachinesSet.Remove(machineId); } }
/// <nodoc /> public BoolResult SetMachineStates(BitMachineIdSet inactiveMachines, BitMachineIdSet closedMachines = null) { bool updateBinManager = false; if (inactiveMachines != null) { _inactiveMachinesSet = inactiveMachines; InactiveMachines = inactiveMachines.EnumerateMachineIds().ToArray(); updateBinManager = true; } if (closedMachines != null) { _closedMachinesSet = closedMachines; ClosedMachines = closedMachines.EnumerateMachineIds().ToArray(); } if (EnableBinManagerUpdates && BinManager != null && updateBinManager) { // Closed machines aren't included in the bin manager's update because they are expected to be back // soon, so it doesn't make much sense to reorganize the stamp because of them. var activeMachines = _idByLocationMap.Values.Except(InactiveMachines).ToArray(); return(BinManager.UpdateAll(activeMachines, InactiveMachines)); } return(BoolResult.Success); }
/// <nodoc /> public void SetInactiveMachines(BitMachineIdSet inactiveMachines) { _inactiveMachinesSet = inactiveMachines; InactiveMachines = inactiveMachines.EnumerateMachineIds().ToArray(); if (BinManager != null) { var activeMachines = _idByLocationMap.Values.Except(InactiveMachines).ToArray(); BinManager.UpdateAll(activeMachines, InactiveMachines); } }
/// <nodoc /> public static MachineIdSet Deserialize(BuildXLReader reader) { var format = (SetFormat)reader.ReadByte(); if (format == SetFormat.Bits) { return(BitMachineIdSet.DeserializeCore(reader)); } else { return(ArrayMachineIdSet.DeserializeCore(reader)); } }
/// <summary> /// Returns true if deserialized instance would have a machine id with a given index. /// </summary> public static bool HasMachineId(BuildXLReader reader, int index) { var format = (SetFormat)reader.ReadByte(); if (format == SetFormat.Bits) { return(BitMachineIdSet.HasMachineIdCore(reader, index)); } else { return(ArrayMachineIdSet.HasMachineIdCore(reader, index)); } }
/// <nodoc /> public void Serialize(BuildXLWriter writer) { MachineIdSet serializableInstance = this; if (Format == SetFormat.Bits) { if (Count <= BitMachineIdSetThreshold) { serializableInstance = new ArrayMachineIdSet(EnumerateMachineIds().Select(id => (ushort)id.Index)); } } else { if (Count > BitMachineIdSetThreshold) { serializableInstance = BitMachineIdSet.Create(EnumerateMachineIds()); } } writer.Write((byte)serializableInstance.Format); serializableInstance.SerializeCore(writer); }
/// <nodoc /> public void SetInactiveMachines(BitMachineIdSet inactiveMachines) { _inactiveMachinesSet = inactiveMachines; InactiveMachines = inactiveMachines.EnumerateMachineIds().ToArray(); }
private async Task <Result <MachineState> > UpdateClusterStateCoreAsync( OperationContext context, ClusterState clusterState, MachineState machineState) { var heartbeatResponse = await CallHeartbeatAsync(context, clusterState, machineState); var updates = await _storage.GetClusterUpdatesAsync(context, new GetClusterUpdatesRequest() { MaxMachineId = clusterState.MaxMachineId }).ThrowIfFailureAsync(); BitMachineIdSet inactiveMachineIdSet = heartbeatResponse.InactiveMachines; BitMachineIdSet closedMachineIdSet = heartbeatResponse.ClosedMachines; Contract.Assert(inactiveMachineIdSet != null, "inactiveMachineIdSet != null"); Contract.Assert(closedMachineIdSet != null, "closedMachineIdSet != null"); if (updates.MaxMachineId != clusterState.MaxMachineId) { Tracer.Debug(context, $"Retrieved unknown machines from ({clusterState.MaxMachineId}, {updates.MaxMachineId}]"); if (updates.UnknownMachines != null) { foreach (var item in updates.UnknownMachines) { context.LogMachineMapping(Tracer, item.Key, item.Value); } } } if (updates.UnknownMachines != null) { clusterState.AddUnknownMachines(updates.MaxMachineId, updates.UnknownMachines); } clusterState.SetMachineStates(inactiveMachineIdSet, closedMachineIdSet).ThrowIfFailure(); Tracer.Debug(context, $"Inactive machines: Count={inactiveMachineIdSet.Count}, [{string.Join(", ", inactiveMachineIdSet)}]"); Tracer.TrackMetric(context, "InactiveMachineCount", inactiveMachineIdSet.Count); if (!_configuration.DistributedContentConsumerOnly) { foreach (var machineMapping in clusterState.LocalMachineMappings) { if (!clusterState.TryResolveMachineId(machineMapping.Location, out var machineId)) { return(Result.FromErrorMessage <MachineState>($"Invalid cluster state on machine {machineMapping}. (Missing location {machineMapping.Location})")); } else if (machineId != machineMapping.Id) { Tracer.Warning(context, $"Machine id mismatch for location {machineMapping.Location}. Registered id: {machineMapping.Id}. Cluster state id: {machineId}. Updating registered id with cluster state id."); machineMapping.Id = machineId; } if (updates.MaxMachineId < machineMapping.Id.Index) { return(Result.FromErrorMessage <MachineState>($"Invalid cluster state on machine {machineMapping} (max machine id={updates.MaxMachineId})")); } } } return(heartbeatResponse.PriorState); }