Skip to content
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

Merged
merged 3 commits into from
Jun 25, 2024
Merged

Leader election #93

merged 3 commits into from
Jun 25, 2024

Conversation

erikdubbelboer
Copy link
Member

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.

features/leader.feature Outdated Show resolved Hide resolved
@erikdubbelboer erikdubbelboer force-pushed the leader-election-only branch 4 times, most recently from 24ce927 to 961df49 Compare June 16, 2024 06:43
@erikdubbelboer erikdubbelboer marked this pull request as draft June 16, 2024 12:47
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.
@erikdubbelboer erikdubbelboer marked this pull request as ready for review June 18, 2024 12:17
lib/signaling.ts Outdated Show resolved Hide resolved
internal/signaling/stores/postgres.go Show resolved Hide resolved
internal/signaling/stores/shared.go Outdated Show resolved Hide resolved
internal/signaling/timeout_manager.go Show resolved Hide resolved
@@ -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 {
Copy link
Collaborator

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

lib/signaling.ts Show resolved Hide resolved
@@ -67,6 +67,13 @@ type JoinedPacket struct {
LobbyInfo stores.Lobby `json:"lobbyInfo"`
}

type LeaderPacket struct {
Type string `json:"type"`

Copy link
Collaborator

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?

Copy link
Member Author

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.

Copy link
Collaborator

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

@erikdubbelboer erikdubbelboer merged commit a24c718 into main Jun 25, 2024
1 check passed
@erikdubbelboer erikdubbelboer deleted the leader-election-only branch June 25, 2024 13:33
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants