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: Update datastore packages to allow use of context #48

Merged
merged 3 commits into from
Nov 19, 2021

Conversation

AndrewSisley
Copy link
Contributor

Closes #44

Most of the changes are just passing around a context object, however there are some more risky changes dotted around due to changes made to some of the dependencies:

  • dshelp.DsKeyToCid(key) was replaced with a function that converted to a V1 Cid, there is no helper for the V0 CIDs that we use in the headstore, this is probably the riskiest change, as our key versioning seems to be a bit messy (constructing v1 prefixes and then using then to construct v0 keys - e.g. collection.go ln 297-309), and there are fewer unit tests covering the commit queries - I changed the heads_test.go tests to reflect the use of v0 keys - this should be the only test change besides context handling
  • Similar to the above dshelp.CidToDsKey(cid) was replaced by dshelp.MultihashToDsKey(cid.Hash())
  • I deleted a public function as I got too lazy to maintain it, let me know if we want to keep it

We use v0 in the prod code and the tests should reflect this
@AndrewSisley AndrewSisley added feature New feature or request area/datastore Related to the datastore / storage engine system labels Nov 18, 2021
@AndrewSisley AndrewSisley self-assigned this Nov 18, 2021
@AndrewSisley AndrewSisley linked an issue Nov 18, 2021 that may be closed by this pull request
@jsimnz
Copy link
Member

jsimnz commented Nov 18, 2021 via email

Copy link
Member

@jsimnz jsimnz left a comment

Choose a reason for hiding this comment

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

Wow that's quite an overhaul.

I really hate to do this to you, but the standard practise for using the context package is to use the code:

ctx := context.Background()

So, the instantiated context variable is ctx. The current way your doing it means we are overwriting the symbol for the context package with the specific instance of the context variable.

Sorry :)

Copy link
Member

@jsimnz jsimnz left a comment

Choose a reason for hiding this comment

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

I think you might have got lost in translation with respect to the Cid and DocKey versioning. I like that you updated dshelp package since I was using a pretty outdated version.

We use the CidV1 exclusively, but we have a defined version system for the DocKey as well, which is the DocKeyV0. The versions are independant of one another.

So with that being said, the upgrade to the newer dshelp package, you use the NewCidV0 function but we should instead be using

bk, err := dshelp.BinaryFromDsKey(key)
k := cid.NewCidV1(cid.Raw, bk)
...

@AndrewSisley
Copy link
Contributor Author

Wow that's quite an overhaul.

I really hate to do this to you, but the standard practise for using the context package is to use the code:

ctx := context.Background()

So, the instantiated context variable is ctx. The current way your doing it means we are overwriting the symbol for the context package with the specific instance of the context variable.

Sorry :)

Ah no worries - I wondered if you'd flag that - I do prefer the long name, but will make the change :)

@AndrewSisley
Copy link
Contributor Author

I think you might have got lost in translation with respect to the Cid and DocKey versioning. I like that you updated dshelp package since I was using a pretty outdated version.

We use the CidV1 exclusively, but we have a defined version system for the DocKey as well, which is the DocKeyV0. The versions are independant of one another.

So with that being said, the upgrade to the newer dshelp package, you use the NewCidV0 function but we should instead be using

bk, err := dshelp.BinaryFromDsKey(key)
k := cid.NewCidV1(cid.Raw, bk)
...

The newer dshelp was required when using the newer datastore packages - code didn't compile without it (there were a couple I had to update manually). I think I understand what you mean - will give it a go and then read up Dockey versions :)

@AndrewSisley
Copy link
Contributor Author

AndrewSisley commented Nov 18, 2021

Flipped it back to V1, and the commit query tests started failing again - maybe we can have a quick call about this?

V1 cids seem to look like this:
bafkreifvdqhkkvurzwphw27gwhyazybqajqtwrntfacpwfziy3tdo7v5hi

But the Headstore is used to:
QmaXdKKsc5GRWXtMytZj4PEf5hFgFxjZaKToQpDY8cAocV

Yesterday I ended up comparing the bytes and different serializations - it does look like the 'new' V1 code is adding a new identifier at the start, which I assumed was the new version id (not present in v0?)

EDIT: I've pushed a new commit showing the problem (tests fail)

@jsimnz
Copy link
Member

jsimnz commented Nov 18, 2021

Flipped it back to V1, and the commit query tests started failing again - maybe we can have a quick call about this?

V1 cids seem to look like this: bafkreifvdqhkkvurzwphw27gwhyazybqajqtwrntfacpwfziy3tdo7v5hi

But the Headstore is used to: QmaXdKKsc5GRWXtMytZj4PEf5hFgFxjZaKToQpDY8cAocV

Yesterday I ended up comparing the bytes and different serializations - it does look like the 'new' V1 code is adding a new identifier at the start, which I assumed was the new version id (not present in v0?)

EDIT: I've pushed a new commit showing the problem (tests fail)

You are correct regarding the CID version issue. Lets revert the last commit to as you had it. The older dshelp package got me mixed up with respect to the version structure.

Yes, for now lets keep things using CidV0.

As for the context vs ctx, its just very standard Go practise, and beyond that we don't want to overwrite the context package.

IE:

import "context" // context refers to package 
func main() {
    context := context.Background() // create a context from the package, called context
    
    // this next line will fail to build, since "context.WithTimeout" is trying to 
    // refer to the global WithTimeout function defined in the context 
    // package, but context refers to the variable we created above.
    context = context.WithTimeout(context, time.Second) 
    someFunc(context)
}

vs

import "context" // context refers to package 
func main() {
    ctx := context.Background() // create a context from the package, called context
    
    // now it builds and is clear whats happening
    ctx = context.WithTimeout(ctx, time.Second) 
    someFunc(context)
}

@AndrewSisley AndrewSisley force-pushed the sisley/chore/I44-update-datastore-version branch 2 times, most recently from f8b3934 to 49ada0f Compare November 18, 2021 23:00
@AndrewSisley AndrewSisley force-pushed the sisley/chore/I44-update-datastore-version branch from 49ada0f to a84cd9d Compare November 18, 2021 23:15
@AndrewSisley
Copy link
Contributor Author

Variables renamed to ctx - think I was being unfairly grumpy+stubborn with Go, I don't think C#/Rust would let you compile at all with a name clash (although collisions are rarer due to casing/import styles...) :) I need to keep an eye out for that unfairness perhaps.

Temp commit that explained the cid/ds.Key issue dropped.

Ready for re-review/merge when you are.

@jsimnz jsimnz merged commit 77f6bc6 into develop Nov 19, 2021
@AndrewSisley AndrewSisley deleted the sisley/chore/I44-update-datastore-version branch November 19, 2021 16:27
@jsimnz jsimnz restored the sisley/chore/I44-update-datastore-version branch November 22, 2021 23:15
@jsimnz jsimnz added the sred/merged SR&ED activity: Merged label Nov 22, 2021
@AndrewSisley AndrewSisley deleted the sisley/chore/I44-update-datastore-version branch November 22, 2021 23:47
@orpheuslummis orpheuslummis mentioned this pull request Jan 29, 2022
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
…k#48)

* Remove deprecated function

* Use cid v0 in tests

* Update datastore packages to handle context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/datastore Related to the datastore / storage engine system feature New feature or request sred/merged SR&ED activity: Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade Datastore to support context
2 participants