public async Task <Task> Recovery(StreamMessage msg) { List <TopologyUnit> units = topology.GetAllTopologyUnits(); msg.barrierOrCommitInfo = new BarrierOrCommitMsgTrackingInfo(Guid.NewGuid(), units.Count); msg.barrierOrCommitInfo.BatchID = msg.BatchID; await batchTracker.TrackingRecoveryMessages(msg); foreach (TopologyUnit unit in units) { if (unit.OperatorType == OperatorType.Source) { IStreamSource source = GrainFactory.GetGrain <IStreamSource>(unit.PrimaryKey); source.Recovery(msg); } else if (unit.OperatorType == OperatorType.Stateful) { IStatefulOperator statefulOperator = GrainFactory.GetGrain <IStatefulOperator>(unit.PrimaryKey, Constants.Stateful_Operator_Prefix); statefulOperator.Recovery(msg); } else if (unit.OperatorType == OperatorType.Stateless) { IStatelessOperator statelessOperator = GrainFactory.GetGrain <IStatelessOperator>(unit.PrimaryKey, Constants.Stateless_Operator_Prefix); statelessOperator.Recovery(msg); } else { throw new ArgumentException("Recovery: The operator type is in valid!"); } } return(Task.CompletedTask); }
public StatelessStreamObserver(ILogger logger, IStatelessOperator statelessStreamOperator, IBatchTracker tracker) { this.statelessStreamOperator = statelessStreamOperator; this.logger = logger; this.tracker = tracker; this.messagesBuffer = new List <StreamMessage>(); }
public Task AddCustomDownStreamOperator(IStatelessOperator statelessOperator) { //Add to local downStreamOperators.Add(statelessOperator); //Add it to global topologyManager.ConnectUnits(topologyUnit.PrimaryKey, statelessOperator.GetPrimaryKey()); return(Task.CompletedTask); }
private async Task <Task> DetectPossibleFailures(object org) { PrettyConsole.Line("Start Detect Failures"); Dictionary <Guid, Task <int> > taskMap = new Dictionary <Guid, Task <int> >(); List <Task <int> > taskList = new List <Task <int> >(); var topologyManager = GrainFactory.GetGrain <ITopology>(Constants.Topology_Manager); var operatorUnits = await topologyManager.GetAllUnits(); foreach (TopologyUnit unit in operatorUnits) { if (unit.OperatorType == OperatorType.Source) { IStreamSource source = GrainFactory.GetGrain <IStreamSource>(unit.PrimaryKey); var task = source.DetectErrors(); taskMap.Add(unit.PrimaryKey, task); } else if (unit.OperatorType == OperatorType.Stateful) { IStatefulOperator statefulOperator = GrainFactory.GetGrain <IStatefulOperator>(unit.PrimaryKey, Constants.Stateful_Operator_Prefix); var task = statefulOperator.DetectErrors(); taskMap.Add(unit.PrimaryKey, task); } else if (unit.OperatorType == OperatorType.Stateless) { IStatelessOperator statelessOperator = GrainFactory.GetGrain <IStatelessOperator>(unit.PrimaryKey, Constants.Stateless_Operator_Prefix); var task = statelessOperator.DetectErrors(); taskMap.Add(unit.PrimaryKey, task); } else { throw new ArgumentException("Commit: The operator type is in valid!"); } } try { await Task.WhenAny(Task.WhenAll(taskMap.Values), Task.Delay(TimeSpan.FromSeconds(2))); } catch (Exception e) { PrettyConsole.Line(e.ToString()); } foreach (var task in taskMap) { if (task.Value.Status != TaskStatus.RanToCompletion) { PrettyConsole.Line("Replace!"); await topologyManager.ReplaceTheOldOperator(task.Key); disposable.Dispose(); break; } } return(Task.CompletedTask); }
private static async Task JoinChannel(IClusterClient client, string channelName) { if (joinedChannel == channelName) { PrettyConsole.Line($"You already joined channel {channelName}. Double joining a channel, which is implemented as a stream, would result in double subscription to the same stream, " + $"which would result in receiving duplicated messages. For more information, please refer to Orleans streaming documentation."); return; } PrettyConsole.Line($"Joining to channel {channelName}"); joinedChannel = channelName; var room = client.GetGrain <IStreamSource>(joinedChannel); var streamId = await room.Join(userName); var stream = client.GetStreamProvider(Constants.ChatRoomStreamProvider) .GetStream <StreamMessage>(streamId, Constants.CharRoomStreamNameSpace); //subscribe to the stream to receiver furthur messages sent to the chatroom statelessOperator = client.GetGrain <IStatelessOperator>("Stateless"); tracker = await room.GetBatchTracker(); await stream.SubscribeAsync(new StatelessStreamObserver(client.ServiceProvider.GetService <ILoggerFactory>() .CreateLogger($"{joinedChannel} channel"), statelessOperator, tracker)); }