Skip to content

Commit 8023a7a

Browse files
authored
Harden gossip consensus (#1911)
* test larger clusters * remove redundant purge
1 parent e7c2608 commit 8023a7a

File tree

5 files changed

+7
-11
lines changed

5 files changed

+7
-11
lines changed

src/Proto.Cluster/Gossip/Gossip.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ public ImmutableList<GossipUpdate> ReceiveState(GossipState remoteState)
9090
}
9191

9292
_state = newState;
93-
94-
//TODO: Optimize
95-
Purge();
93+
9694
CheckConsensus(updatedKeys);
9795

9896
return updates.ToImmutableList();
@@ -253,7 +251,7 @@ private void Purge()
253251
{
254252
//find all members that have sent topology
255253
var members = _getMembers();
256-
254+
257255
foreach (var memberId in _state.Members.Keys.ToArray())
258256
{
259257
if (!members.Contains(memberId))

src/Proto.Cluster/Gossip/GossipActor.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public class GossipActor : IActor
1616
private static readonly ILogger Logger = Log.CreateLogger<GossipActor>();
1717
private readonly TimeSpan _gossipRequestTimeout;
1818
private readonly IGossip _internal;
19-
private readonly ActorSystem _system;
2019

2120
// lookup from state key -> consensus checks
2221

@@ -29,11 +28,10 @@ public GossipActor(
2928
int gossipMaxSend
3029
)
3130
{
32-
_system = system;
3331
_gossipRequestTimeout = gossipRequestTimeout;
3432

3533
_internal = new Gossip(myId, gossipFanout, gossipMaxSend, instanceLogger,
36-
() => _system.Cluster().MemberList.GetMembers());
34+
() => system.Cluster().MemberList.GetMembers());
3735
}
3836

3937
public Task ReceiveAsync(IContext context) =>

src/Proto.Cluster/Gossip/Gossiper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public async Task<ImmutableDictionary<string, GossipKeyValue>> GetStateEntry(str
114114
try
115115
{
116116
var res = await _context.RequestAsync<GetGossipStateEntryResponse>(_pid,
117-
new GetGossipStateEntryRequest(key));
117+
new GetGossipStateEntryRequest(key),CancellationTokens.FromSeconds(5));
118118

119119
return res.State;
120120
}

src/Proto.Cluster/GossipContracts.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ message GossipState {
3232
//we still know when _we_ as in this node, got this data.
3333
//and we can measure time from then til now.
3434
//
35-
//if we got a hear-beat from another node, and X seconds pass, we can assume it to be dead
35+
//if we got a heartbeat from another node, and X seconds pass, we can assume it to be dead
3636
message GossipKeyValue {
3737
int64 sequence_number = 2; //version is local to the owner member
3838
google.protobuf.Any value = 4; //value is any format

tests/Proto.Cluster.Tests/GossipCoreTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public GossipCoreTests(ITestOutputHelper output)
3030
[Fact]
3131
public async Task Large_cluster_should_get_topology_consensus()
3232
{
33-
const int memberCount = 50;
34-
const int fanout = 4;
33+
const int memberCount = 300;
34+
const int fanout = 3;
3535

3636
var members =
3737
Enumerable

0 commit comments

Comments
 (0)