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

Refactor SessionInterestManager #384

Merged
merged 2 commits into from
May 1, 2020
Merged

Conversation

dirkmc
Copy link
Contributor

@dirkmc dirkmc commented Apr 27, 2020

Depends on #383

We no longer need the SessionWantList (it used to be used by the WantManager) so we can get rid of it and consolidate functionality into SessionInterestManager.
This also removes a bunch of unnecessary locking.

@dirkmc dirkmc changed the base branch from master to fix/ctx-cancels April 27, 2020 20:30
internal/sessioninterestmanager/sessioninterestmanager.go Outdated Show resolved Hide resolved
}

// When a request is cancelled, the session calls RemoveSessionInterested().
// Returns the keys that no session is interested in any more.
func (sim *SessionInterestManager) RemoveSessionInterested(ses uint64, wants []cid.Cid) []cid.Cid {
func (sim *SessionInterestManager) RemoveSessionInterested(ses uint64, ks []cid.Cid) []cid.Cid {
Copy link
Member

Choose a reason for hiding this comment

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

Something here is very strange. I think the meaning of "session interest" has changed over time. In the past, I believe it included everything the session wanted, but hadn't necessarily asked for.

I prefer the new interpretation "things the session is interested in hearing about", but I think we've made a mistake: we're canceling blocks when we become uninterested in them.

Shouldn't we be canceling blocks when they become unwanted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's true it's a little convoluted. We actually want to do both:

  • When the client calls Session.GetBlocks() the session registers interest in those blocks
  • When we receive blocks / HAVEs / DONT_HAVEs we want to know which sessions are interested in them
  • When the session receives a block it no longer wants the block, and sends a cancel.
    Note that the session is still interested in the block (but doesn't want the block), because the session wants to add peers who had the block to the session, so as to query them for other blocks that the session wants
  • When the client cancels Session.GetBlocks() the session is no longer interested in those blocks, and should also send a cancel for them
  • When the session shuts down, it is no longer interested in the remaining blocks and sends cancels for them

Copy link
Member

Choose a reason for hiding this comment

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

My point is that this function returns CIDs (for cancellation) that no sessions are interested in. However, we really want to return CIDs that no session wants.

I think we're technically fine because:

  1. We cancel blocks when we receive them.
  2. We'll lose interest in blocks when GetBlocks is canceled.

But it's still a bit strange.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see what you're saying, it's a little strange that we don't just cancel something that no one wants.

When we receive a block we send a cancel to the peer, and mark it as unwanted in the SessionInterestManager. We don't remove it entirely from the SessionInterestManager because if other peers subsequently respond with a HAVE or a block, we want to be able to tell the Session so that it can expand its pool of peers who may have blocks its interested in (this is particularly important in the discovery phase).

On the other hand if the request is cancelled, then the Session is not interested at all in hearing about subsequent blocks or HAVEs for the CIDs in the request, so in that case we remove the CIDs entirely from the SessionInterestManager.

Maybe the naming could be a clearer, I'm not sure that wanted / interested fully captures the concepts.

}

// When a request is cancelled, the session calls RemoveSessionInterested().
// Returns the keys that no session is interested in any more.
func (sim *SessionInterestManager) RemoveSessionInterested(ses uint64, wants []cid.Cid) []cid.Cid {
func (sim *SessionInterestManager) RemoveSessionInterested(ses uint64, ks []cid.Cid) []cid.Cid {
Copy link
Member

Choose a reason for hiding this comment

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

My point is that this function returns CIDs (for cancellation) that no sessions are interested in. However, we really want to return CIDs that no session wants.

I think we're technically fine because:

  1. We cancel blocks when we receive them.
  2. We'll lose interest in blocks when GetBlocks is canceled.

But it's still a bit strange.

@dirkmc dirkmc merged commit 9bdf715 into fix/ctx-cancels May 1, 2020
dirkmc added a commit that referenced this pull request May 1, 2020
* fix: send cancel when GetBlocks() is cancelled

* fix: in SessionManager shutdown nil out sessions

* fix: sessionWantSender perf

* make sessionWantSender.SignalAvailability() non-blocking

* Refactor SessionInterestManager (#384)

* refactor: customize SessionInterestManager

* refactor: SessionInterestManager perf
dirkmc added a commit that referenced this pull request May 1, 2020
* fix: use one less go-routine per session

* fix: send cancel when GetBlocks() is cancelled (#383)

* fix: send cancel when GetBlocks() is cancelled

* fix: in SessionManager shutdown nil out sessions

* fix: sessionWantSender perf

* make sessionWantSender.SignalAvailability() non-blocking

* Refactor SessionInterestManager (#384)

* refactor: customize SessionInterestManager

* refactor: SessionInterestManager perf
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