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

feat: plumb through datastore contexts #753

Merged
merged 1 commit into from
Oct 29, 2021
Merged

feat: plumb through datastore contexts #753

merged 1 commit into from
Oct 29, 2021

Conversation

guseggert
Copy link
Contributor

No description provided.

@@ -125,7 +125,7 @@ func (pm *ProviderManager) run(proc goprocess.Process) {
// don't really care if this fails.
_ = gcQuery.Close()
}
if err := pm.dstore.Flush(); err != nil {
if err := pm.dstore.Flush(context.TODO()); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for a TODO here. You can pass a ctx to run() from NewProviderManager (the only place where it is invoked).

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 tried this when I wrote this, but run() is not called directly, it is called by goprocess which does not provide access to the ctx, and at that point I noped out because of scope creep.

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 can add an issue to thread those through, and we can follow up later. Trying really hard to minimize scope here, b/c it's already huge...

Copy link
Contributor

Choose a reason for hiding this comment

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

func NewProviderManager(ctx context.Context, local peer.ID, ps peerstore.Peerstore, dstore ds.Batching, opts ...Option) (*ProviderManager, error) {
...
pm.proc.Go(func(proc goprocess.Process) { pm.run(ctx, proc) })
...
}

...

func (pm *ProviderManager) run(ctx context.Context, proc goprocess.Process) {
   ...
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I can add an issue to thread those through, and we can follow up later. Trying really hard to minimize scope here, b/c it's already huge...

Adding an issue is fine too. I'll LGTM it then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah that's a fine approach, let me just do it

@@ -242,7 +242,7 @@ func writeProviderEntry(dstore ds.Datastore, k []byte, p peer.ID, t time.Time) e
buf := make([]byte, 16)
n := binary.PutVarint(buf, t.UnixNano())

return dstore.Put(ds.NewKey(dsk), buf[:n])
return dstore.Put(context.TODO(), ds.NewKey(dsk), buf[:n])
Copy link
Contributor

Choose a reason for hiding this comment

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

use the ctx from the AddProvider argument.

@@ -302,7 +302,7 @@ func (pm *ProviderManager) getProviderSetForKey(k []byte) (*providerSet, error)

// loads the ProviderSet out of the datastore
func loadProviderSet(dstore ds.Datastore, k []byte) (*providerSet, error) {
res, err := dstore.Query(dsq.Query{Prefix: mkProvKey(k)})
res, err := dstore.Query(context.TODO(), dsq.Query{Prefix: mkProvKey(k)})
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, if you follow the invocation sequence, it shouldn't be hard to thread through a ctx here, instead of TODO.

@@ -329,7 +329,7 @@ func loadProviderSet(dstore ds.Datastore, k []byte) (*providerSet, error) {
fallthrough
case now.Sub(t) > ProvideValidity:
// or just expired
err = dstore.Delete(ds.RawKey(e.Key))
err = dstore.Delete(context.TODO(), ds.RawKey(e.Key))
Copy link
Contributor

Choose a reason for hiding this comment

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

same

@@ -341,7 +341,7 @@ func loadProviderSet(dstore ds.Datastore, k []byte) (*providerSet, error) {
decstr, err := base32.RawStdEncoding.DecodeString(e.Key[lix+1:])
if err != nil {
log.Error("base32 decoding error: ", err)
err = dstore.Delete(ds.RawKey(e.Key))
err = dstore.Delete(context.TODO(), ds.RawKey(e.Key))
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Copy link
Contributor

@petar petar left a comment

Choose a reason for hiding this comment

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

LGTM.

@guseggert guseggert force-pushed the feat/context branch 2 times, most recently from c1d7c5f to 669b242 Compare October 28, 2021 21:59
@guseggert guseggert merged commit 0b7ac01 into master Oct 29, 2021
@aschmahmann aschmahmann mentioned this pull request Dec 1, 2021
80 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants