// these are messages from some other node in the cluster public Task <IMessage> ReceiveMessage(ISubscriber sender, IMessage message, object?context, CancellationToken token) { if (message.Name == server.ShardAssignment.Name) { if (_cluster.Leader.IsRemote) { // shard assignment requests should always be sent to the leader, so we if get one as // a follower then something went wrong _logger.LogWarning("Got shard assignment message as a follower"); } // if we have a current shardAssignment, and one that was sent in that are different // we should check membership for new servers, or missing servers. // if we have new servers, .... // if we have missing servers ... // if we have same servers, but different assignments, then we will want to either keep it the same // or determine if we should balance some things around. var sa = new ShardAssignment(_cluster.Members.Count * 4, _cluster.Members); this._currentShardAssignment = sa; return(Task.FromResult(sa.ToBinaryMessage() as IMessage)); } throw new NotImplementedException(); }
public async void Startup() { var shardAssignment = await _clusterBus.LeaderRouter.SendMessageAsync(new ShardAssignment(_cluster.Members.Count * 4, _cluster.Members).ToBinaryMessage(), (resp, token) => new ValueTask <ShardAssignment>(new ShardAssignment(resp)), CancellationToken.None); this._currentShardAssignment = shardAssignment; }
public static Ekati.Protocol.Grpc.ShardAssignment ToGrpcShardAssignment(ShardAssignment sa) { var respSA = new Ekati.Protocol.Grpc.ShardAssignment(); respSA.Leaders.AddRange(sa.Leaders); for (int i = 0; i < sa.Followers.GetLength(0); i++) { var fo = new Followers(); fo.Follower.AddRange(sa.Followers[i]); respSA.Followers.Add(fo); } return(respSA); }