-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Leader election #93
Leader election #93
Conversation
24ce927
to
961df49
Compare
961df49
to
c8612a4
Compare
Give each lobby a leader. A leader is a useful concept to have in many game types. Implementing leader election in the game itself is much harder. After this we can add support for the leader to be able to change the lobby data. For example making it private when a game starts.
c8612a4
to
f2e5f33
Compare
@@ -88,6 +86,28 @@ func (i *TimeoutManager) Disconnected(ctx context.Context, p *Peer) { | |||
err := i.Store.TimeoutPeer(ctx, p.ID, p.Secret, p.Game, lobbies) | |||
if err != nil { | |||
logger.Error("failed to record timeout peer", zap.Error(err)) | |||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we maybe wanna do leaderElection anyway, even if the TimeoutPeer failed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If TimeoutPeer
fails, the peer won't have been inserted into timeouts
and DoLeaderElection
will just keep it as the current leader if it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And most likely if TimeoutPeer
the database has issues and DoLeaderElection
will also fail.
61ba7ee
to
7af5491
Compare
@@ -67,6 +67,13 @@ type JoinedPacket struct { | |||
LobbyInfo stores.Lobby `json:"lobbyInfo"` | |||
} | |||
|
|||
type LeaderPacket struct { | |||
Type string `json:"type"` | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea: Should this packet also contain the lobby it's about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you can currently only be in 1 lobby that wouldn't make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, I figured it would make it forward compatible. But I guess we can always add it
Give each lobby a leader. A leader is a useful concept to have in many game types. Implementing leader election in the game itself is much harder.
After this we can add support for the leader to be able to change the lobby data. For example making it private when a game starts.