Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Be less aggressive when pruning peers from session #276

Merged
merged 12 commits into from
Mar 6, 2020

Conversation

dirkmc
Copy link
Contributor

@dirkmc dirkmc commented Mar 5, 2020

Currently we prune peers from the session when they send us several DONT_HAVEs in a row.

However if the peer sent us a HAVE for a block that we want, we should not prune the peer.

Depends on #275

@dirkmc dirkmc changed the base branch from feat/peer-timeout to refactor/session-peers March 5, 2020 19:25
@@ -56,7 +56,7 @@ func (sw *sessionWants) GetNextWants(limit int) []cid.Cid {
func (sw *sessionWants) WantsSent(ks []cid.Cid) {
now := time.Now()
for _, c := range ks {
if _, ok := sw.liveWants[c]; !ok {
if _, ok := sw.liveWants[c]; !ok && sw.toFetch.Has(c) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was causing us to sometimes re-broadcast a want for which a block had already been received

internal/session/sessionwantsender.go Show resolved Hide resolved
@dirkmc dirkmc requested a review from Stebalien March 5, 2020 19:52
@Stebalien Stebalien changed the base branch from refactor/session-peers to master March 6, 2020 02:57
// If we already received a block for the want, ignore any HAVE for
// the want
if blkCids.Has(c) {
continue
Copy link
Member

Choose a reason for hiding this comment

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

Would this prevent us from adding this peer to the session?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding the peer to the session happens before processUpdates() gets called. However this does interfere with consecutive DONT_HAVE counting so I refactored to avoid interference.

internal/session/sessionwantsender.go Show resolved Hide resolved
// Before removing the peer from the session, check if the peer
// sent us a HAVE for a block that we want
peerHasWantedBlock := false
for c := range sws.wants {
Copy link
Member

Choose a reason for hiding this comment

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

This is in a goroutine. Is this safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

@Stebalien
Copy link
Member

(rebasing to get the tests working)

@dirkmc
Copy link
Contributor Author

dirkmc commented Mar 6, 2020

Let me take a look at that failed test now...

@@ -340,7 +340,7 @@ func (s *Session) broadcastWantHaves(ctx context.Context, wants []cid.Cid) {
// Search for providers who have the first want in the list.
// Typically if the provider has the first block they will have
// the rest of the blocks also.
log.Warnf("Ses%d: FindMorePeers with want 0 of %d wants", s.id, len(wants))
log.Warnf("Ses%d: FindMorePeers with want %s (1st of %d wants)", s.id, lu.C(wants[0]), len(wants))
Copy link
Member

Choose a reason for hiding this comment

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

OT note: this should be an info at best.

@Stebalien Stebalien merged commit 418d88c into master Mar 6, 2020
Jorropo pushed a commit to Jorropo/go-libipfs that referenced this pull request Jan 26, 2023
Be less aggressive when pruning peers from session

This commit was moved from ipfs/go-bitswap@418d88c
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants