Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve hub locking #1694

Merged
merged 28 commits into from
Nov 7, 2023
Merged

Conversation

MariemBaccari
Copy link
Contributor

@MariemBaccari MariemBaccari commented Oct 3, 2023

This PR aims to:

  • Upgrade the go backend to go 1.21
  • Fix a small bug that caused double connections between the client and the server (because of the servers sharing twice the same peers in the greet lao if they have a double connection between each other)
  • Provide new data structures that allow finer-grain locking of the hub. The hub is currently entirely locked very often for processing messages which can be avoided by replacing the maps by thread-safe structs.
  • Creates new package "hub_state" to store the structures that hold the hub's state to improve the main file's readability

@MariemBaccari MariemBaccari requested a review from a team as a code owner October 3, 2023 06:46
@MariemBaccari MariemBaccari marked this pull request as draft October 3, 2023 06:46
@MariemBaccari MariemBaccari changed the title Work be1 mariembaccari fine grain locking hub Improve hub locking Oct 3, 2023
@MariemBaccari MariemBaccari marked this pull request as ready for review October 10, 2023 21:30
@MariemBaccari MariemBaccari added the decentralized Decentralized Communication Project label Oct 11, 2023
Copy link
Contributor

@jbsv jbsv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job. A few questions though.

be1-go/hub/standard_hub/hub_state/ids_by_channel.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/mod.go Show resolved Hide resolved
be1-go/hub/standard_hub/mod.go Outdated Show resolved Hide resolved
Copy link
Contributor

@pierluca pierluca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed about half of it, I still have a few files to go through, but here's the first batch of comments :-)

be1-go/channel/lao/mod.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/hub_state/channels_by_id.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/hub_state/channels_by_id.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/hub_state/ids_by_channel.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/hub_state/ids_by_channel.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/hub_state/channels_by_id.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/hub_state/peers.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/hub_state/queries.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/hub_state/queries.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/message_handling.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/message_handling.go Show resolved Hide resolved
be1-go/hub/standard_hub/mod.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/mod.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/mod_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@pierluca pierluca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better, and it's allowed me to spot a few other issues for future PRs :)
We're on the right path !

be1-go/hub/standard_hub/hub_state/ThreadSafeMap.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/hub_state/ThreadSafeMap.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/mod.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/mod.go Outdated Show resolved Hide resolved
}

if currentState {
return xerrors.Errorf("query with id %d already answered", id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized something, completely outside the scope of this PR.
This error propagates all the way to the socket.
So if another peer (for whatever reason) sends the "answer" message twice, they will get an error in return saying "we've already gotten your answer".
Is this something that would need to be shared with the other peer, or just logged ?
What would the other peer be expected to do - retry ? That would likely make things worse (infinite loop of errors / retries)
It seems manageable (in this case) to implement some degree of idempotency.

Copy link
Contributor Author

@MariemBaccari MariemBaccari Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we should just log it because we wouldn't expect the peer to do anything. I think it could be a nice first issue so I'll add it to the repo (#1709). Regarding idempotency, would that also apply to when we try to create a channel that was already created ? Currently we send a "duplicate resource" error but how do we differentiate between cases that warrant idempotency and those that don't ?

Unrelated to that but I also noticed that we don't always respect the protocol when it comes to sending errors back. Since we have many "levels" of returning in go, the nature of the error gets lost by the time it arrives to the method that's supposed to create the error to send back so we don't have the right code. Thankfully, we already have methods designed to create the right error with the right code but those aren't always used for some reason. I'll investigate the individual cases and open github issues for them. They're easy fixes but also a good way to get to know the codebase so they'll be good first issues as well.

be1-go/hub/standard_hub/hub_state/queries.go Outdated Show resolved Hide resolved
be1-go/hub/standard_hub/hub_state/peers.go Outdated Show resolved Hide resolved
be1-go/channel/lao/mod.go Show resolved Hide resolved
Copy link

sonarcloud bot commented Nov 4, 2023

[PoP - PoPCHA-Web-Client] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link

sonarcloud bot commented Nov 4, 2023

[PoP - Be1-Go] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

88.1% 88.1% Coverage
0.0% 0.0% Duplication

Copy link

sonarcloud bot commented Nov 4, 2023

[PoP - Be2-Scala] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link

sonarcloud bot commented Nov 4, 2023

[PoP - Fe2-Android] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link

sonarcloud bot commented Nov 4, 2023

[PoP - Fe1-Web] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Contributor

@pierluca pierluca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, there are still some performance improvements possible, but this is already so much better than in the past.
Great job !

@pierluca pierluca merged commit f325a91 into master Nov 7, 2023
18 checks passed
@pierluca pierluca deleted the work-be1-mariembaccari-fine-grain-locking-hub branch November 7, 2023 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
be1-go decentralized Decentralized Communication Project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Duplicate resource error when two servers are connected to each other
3 participants