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

refactor: Remove dependency on concrete datastore implementations from db package #51

Merged
merged 5 commits into from
Nov 22, 2021

Conversation

AndrewSisley
Copy link
Contributor

Closes #50

Hands control over datastore implementations to consumers of the db package, removing the dependency on badger-db (and MapDatabase) from the core code.

Did some manual testing to make sure it wouldn't complain about dropping the inMemory Size option. Some public function/types definitions have changed.

Protects against accidental change, and allows the db config struct to be modified without impacting end users
@AndrewSisley AndrewSisley self-assigned this Nov 22, 2021
@AndrewSisley AndrewSisley linked an issue Nov 22, 2021 that may be closed by this pull request
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 really like the refactor here, and removing the tight dependency on implementation will make things easier in the future for some of our deployment environment work.

My only requested change would be to keep the options struct (in some way) accessible and passed into the NewDB construcutor. At the moment the options are pretty stright forward, but as things progress, additional opts will be added, and itll be good to just have an always accessible struct of provided options within the DB object itself.

@@ -32,7 +32,6 @@ type BadgerOptions struct {

// MemoryOptions for the memory instance of the backing datastore
type MemoryOptions struct {
Size uint64
Copy link
Member

Choose a reason for hiding this comment

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

Also might want to keep this in, not used at the moment cus there was no way to include this within the current memory store, but as we talk through #40 itll probably prove helpful

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 easy to add back in as/when we need it, and if it exists without being used it just adds confusion. Although as I write this - this is a config struct and leaving it in preserves the name/structure. Will put it back in unless you say otherwise (I have no strong feelings here).

@AndrewSisley
Copy link
Contributor Author

I really like the refactor here, and removing the tight dependency on implementation will make things easier in the future for some of our deployment environment work.

My only requested change would be to keep the options struct (in some way) accessible and passed into the NewDB construcutor. At the moment the options are pretty stright forward, but as things progress, additional opts will be added, and itll be good to just have an always accessible struct of provided options within the DB object itself.

Would you be alright with an interface (of some sort, maybe named maybe interface{}) for that (probs wrapped by a concrete struct Options {foo: interface{}})? Problem with the options struct is that it is defined in the badger package and it would be nice to keep db clean of that if we can. Also dislike having both the IM and badger on the same options instance (fine for a cmd/web config record, but not in a library)...

@AndrewSisley AndrewSisley force-pushed the sisley/refactore/I50-break-badger-db-dependency branch from 7064a97 to 735e9eb Compare November 22, 2021 21:12
@AndrewSisley
Copy link
Contributor Author

Added selected options via interface{} back onto the db struct via FIXUP commit (will squash before merging), let me know if you want the original object (via the interface) with both IM and Badger defined.

Also removed the removal of the IM.Size property

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.

The options looks fine for now. We might need to further investigate an options approach, but that will depend what ends up in the generalized opts stuct, and how its used.

The most pressing one I am imagining is LogLevels. Since at the moment we aren't tracking that, and everything is dumped into the logger, but only the default level (I think Info) is used.

@AndrewSisley AndrewSisley force-pushed the sisley/refactore/I50-break-badger-db-dependency branch from 735e9eb to 57c8298 Compare November 22, 2021 23:08
@AndrewSisley
Copy link
Contributor Author

The options looks fine for now. We might need to further investigate an options approach, but that will depend what ends up in the generalized opts stuct, and how its used.

The most pressing one I am imagining is LogLevels. Since at the moment we aren't tracking that, and everything is dumped into the logger, but only the default level (I think Info) is used.

Ah okay I see - should hopefully be nice and easy to sort out when we get round to it :)

I cleaned up the commits - guess you want to do the merging?

@AndrewSisley AndrewSisley merged commit 7f76e60 into develop Nov 22, 2021
@orpheuslummis orpheuslummis mentioned this pull request Jan 29, 2022
@AndrewSisley AndrewSisley deleted the sisley/refactore/I50-break-badger-db-dependency branch February 7, 2022 21:05
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
…m db package (sourcenetwork#51)

* Go mod tidy

* Remove unhelpful comment

* Use owned concrete type for cmd config

Protects against accidental change, and allows the db config struct to be modified without impacting end users

* Remove unhelpful code branch on db close

* Move datastore init out of db package
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.

Remove badger as a dependency from the db package
2 participants