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

Account Manager #1769

Merged
merged 29 commits into from
Nov 1, 2023
Merged

Account Manager #1769

merged 29 commits into from
Nov 1, 2023

Conversation

dholms
Copy link
Collaborator

@dholms dholms commented Oct 25, 2023

This replaces the ServiceDB with an AccountManager abstraction

There are a few motivations involved in this:

  • we were down to only two services in the PDS (account & auth) so it made sense to combine them in an abstraction
  • Some PDSs may rely on an "entry way auth service". This abstraction should make it easier to work that service into the PDS without having complex switch logic in the routes
  • Concurrency concerns are very different with a single SQLite DB vs Postgres

The third point influenced the design of the AccountManager: database transactions are never exposed to routes, it is the AccountManager's prerogative to wrap transactional db queries within an abstraction. Routes should be able to call any function on the AccountManager without worrying about transactions locking.

I reworked many of the longer transactions (such as create account & refresh session) to do as much work ahead of time outside of the transaction, then do all of it's transactional writes quickly in "parallel".

I decided to take a slightly different approach with the code here. Instead of having services with a stateful db varaiable, I have files of "helper functions" that wrap a single postgres query. Then the AccountManager maintains a reference to the "AccountDB" and composes those helper functions into it's interface (sometimes just passing through directly to them)

@dholms dholms changed the title wip Account Manager Oct 25, 2023
@dholms dholms marked this pull request as ready for review October 30, 2023 22:54
Copy link
Collaborator

@devinivy devinivy left a comment

Choose a reason for hiding this comment

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

Looking good, real smooth!

packages/bsky/tests/indexing.test.ts Outdated Show resolved Hide resolved
packages/pds/src/account-manager/helpers/account.ts Outdated Show resolved Hide resolved
packages/pds/src/account-manager/helpers/account.ts Outdated Show resolved Hide resolved
packages/pds/src/sequencer/sequencer.ts Show resolved Hide resolved
packages/pds/src/context.ts Outdated Show resolved Hide resolved
packages/pds/src/api/com/atproto/server/createAccount.ts Outdated Show resolved Hide resolved
packages/pds/tests/invite-codes.test.ts Outdated Show resolved Hide resolved
]),
)
} catch (err) {
if (err instanceof auth.ConcurrentRefreshError) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you can see how i handle racing refreshes here

@dholms dholms mentioned this pull request Nov 1, 2023
Base automatically changed from pds-sqlite-refactor to pds-v2 November 1, 2023 01:32
@dholms dholms merged commit 1544e73 into pds-v2 Nov 1, 2023
10 checks passed
@dholms dholms deleted the account-manager branch November 1, 2023 01:33
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