Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Prefix child db by threadid when starting #422

Closed
wants to merge 1 commit into from

Conversation

carsonfarmer
Copy link
Member

Signed-off-by: Carson Farmer [email protected]

Description

This PR changes the internals of how we "start" Databases. Now, the actual "opening" of the database is deferred until it is actually "started". Additionally, while we can "create" a database and its underlying components (dispatcher, event handler, etc) at construction time, none of this stuff is turned on until we actually start it. Additionally, all DB keys are prefixed by the threadid in a transparent way. So that, in theory, a user doesn't really need to worry about threadid at all. Additionally, this makes the database "name" (which is really just sugar for the developer) default to "thread.db". For developer who want to "sandbox" their db from other user dbs, they can specify their own name.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

All existing tests should pass. Additionally, some previous behavior that was expected to fail, should no longer fail, so some checks for this were actually removed. With that in mind, some additional tests should be applied here.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

This PR template comes from https://github.com/embeddedartistry/templates

@carsonfarmer carsonfarmer added bug Something isn't working enhancement New feature or request dependencies Pull requests that update a dependency file chore Things that need doing labels Jul 22, 2020
@carsonfarmer carsonfarmer added this to the Sprint 41 milestone Jul 22, 2020
@carsonfarmer carsonfarmer requested a review from andrewxhill July 22, 2020 22:56
@carsonfarmer carsonfarmer self-assigned this Jul 22, 2020
const threadID = opts.threadID ?? this.threadID ?? ThreadID.fromRandom()
let info: ThreadInfo
try {
// DANGER: If we don't have the key info locally here already, we're out of luck!
Copy link
Member Author

Choose a reason for hiding this comment

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

This is actually a fundamental issue with our current Database implementation. The key info is likely not recoverable at this point. Right now, we assume this isn't the case, and that we have the thread info cached locally. Moving to #414 will fix this issue, so it might not be worth worry about this too much right now.

new Key(this.threadID.toString())
)
// Open "new" store, which may in fact already exist
await this.child.open()
Copy link
Member Author

Choose a reason for hiding this comment

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

We've deferred start until the last minute here, this makes it possible to prefix all our keys since we might not know the thread id until now.

throw new Error("Unable to obtain thread id")
// Replace default child store with store prefixed by thread id
this.child = new DomainDatastore(
this.child,
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this'll be an issue :P

@carsonfarmer carsonfarmer deleted the carson/threadid-prefixing branch July 28, 2020 23:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working chore Things that need doing dependencies Pull requests that update a dependency file enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant