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

Support Asynchronous Writing Datastores #140

Merged
merged 3 commits into from
Dec 3, 2019
Merged

Support Asynchronous Writing Datastores #140

merged 3 commits into from
Dec 3, 2019

Conversation

aschmahmann
Copy link
Contributor

@aschmahmann aschmahmann commented Nov 26, 2019

Per #137 we would like to support Datastores that internally have asynchronous writes. We are doing this by adding a Sync(prefix ds.Key) function to the Datastore interface.

The plan is:

  1. Get this PR reviewed for a sanity check
  2. Get the datastore PRs submitted and reviewed and ready to be accepted (their go.mod files will reference this PR's branch)
  3. Merge this PR
  4. Update and merge the other PRs
  5. Update some areas of go-ipfs to use the Sync() command on their datastores
  6. Switch the default datastore in go-ipfs to be an asynchronous one (i.e. Badger with Async writes enabled)

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

The mount datastore needs a small fix and a test but otherwise LGTM.

examples/fs.go Show resolved Hide resolved
mount/mount.go Outdated Show resolved Hide resolved
mount/mount.go Outdated Show resolved Hide resolved
mount/mount.go Outdated Show resolved Hide resolved
@bonedaddy
Copy link
Contributor

After this PR is merged can we have a version bump according to semver practices since this is a breaking change to the Datastore interface?

@Stebalien
Copy link
Member

After this PR is merged can we have a version bump according to semver practices since this is a breaking change to the Datastore interface?

We will bump the minor version because the package version is sub-zero.

@bonedaddy
Copy link
Contributor

After this PR is merged can we have a version bump according to semver practices since this is a breaking change to the Datastore interface?

We will bump the minor version because the package version is sub-zero.

Won't break go get -u=patch so 🚀


if mountPts[i].Equal(prefix) || suffix.String() != "/" {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Hm. This looks like a bug in lookupAll. lookupAll should only return mounts that can contain descendents of key.

Copy link
Member

Choose a reason for hiding this comment

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

We can merge this as-is and fix it later or move this logic into lookupAll now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you clarify what you think the bug is here? It looks like the documented behavior for lookupAll.

Copy link
Member

Choose a reason for hiding this comment

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

lookupAll is supposed to return all datastores that might contain keys that are descendants of the given key. That means we should be calling Sync on all datastores returned by lookupAll datastores and we shouldn't have this extra check.

However, if we have ["/foo", "/foo/bar"], "/foo" should "cover" "/foo/bar" given that lookup will always return "/foo". However, when given the prefix "/foo", lookupAll will return both.

Note: this is only technically a bug. Nobody would ever mount "/foo" over "/foo/bar".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nobody would ever mount "/foo" over "/foo/bar"

I thought it was expected behavior that we might mount "/" and also "/foo", or is the root a special case?

Copy link
Member

Choose a reason for hiding this comment

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

My first example was bad: order matters. If we mount "/" over "/foo", "/" will win (I think? check me here). In go-ipfs, we mount "/blocks" over "/".

Copy link
Member

@Stebalien Stebalien Dec 3, 2019

Choose a reason for hiding this comment

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

I say "nobody would ever mount "/foo" over "/foo/bar" because "/foo" is a prefix of "/foo/bar" (and we check mounts in-order).

Copy link
Member

Choose a reason for hiding this comment

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

I was wrong. We reverse-sort datastores so "/foo/bar" always comes before "/foo".

However, the bug was valid. Fix in #141.

@aschmahmann aschmahmann marked this pull request as ready for review December 2, 2019 23:26
@Stebalien
Copy link
Member

LGTM but let's merge this tomorrow. Hitting merge then going to bed is a bad idea (I mean, it's one of my favorite bad ideas but I think it's time to call it a day).

@Stebalien Stebalien merged commit 8b79466 into master Dec 3, 2019
@Stebalien Stebalien deleted the feat/async-ds branch December 3, 2019 14:58
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.

3 participants