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

Migrate to sqlite db backend #644

Open
wants to merge 498 commits into
base: main
Choose a base branch
from
Open

Migrate to sqlite db backend #644

wants to merge 498 commits into from

Conversation

tmpfs
Copy link
Collaborator

@tmpfs tmpfs commented Dec 29, 2024

Database Importer

All the main data is being imported but we also need to support:

  • File blobs
  • Preferences
  • Server remote origins
  • Audit logs
  • System messages

Database backup/archive

  • Store db file checksum in the manifest and verify on restore to temp file

Housekeeping

  • Remove obsolete dependencies on sos-sdk
  • Do not re-export reducers
  • Move AccountRef and FolderRef to sos-core
  • Test specs for authentication required functions in account and client storage
  • The sos_protocol dependency should not depend on sos_account as it bloats the dependencies for sos_server

Server

Local Accounts

Once client storage for db is ready check all the folders are being created correctly:

  • Default folder
  • Archive
  • Authenticator
  • Contacts

Account Upgrade

  • Create backup archives first
  • Verify the root hash for each account matches before deleting files and moving db into place

File Blobs

These are currently being imported into the database however large blobs will slow the db read and writes down so we need to consider whether to:

  1. Keep all blobs as external files (affects archiving and db portability)
  2. Only put small blobs (< 1MB) in the database (adds complexity by having blobs in multiple locations)

Decided to go with option 1) and keep all file blobs external. -- this means we will still need a backup archive that supports compressing the database and files for all accounts.

Columns

  • Use blob for checksum types

Backend

Update the backend writers to support both file system and database backends:

  • VaultWriter
  • Event Logs
  • Folder
  • Preferences
  • Server origins
  • System messages
  • Audit trail
  • Server storage
  • Identity login folder
  • Read/Create device vault (identity folder)
  • Client storage
  • Account builder
  • Database backup archives (w/ external file blobs)
  • CLI upgrade tool tools db upgrade

Note we would like to use the STRICT table keyword to prevent type coercion but it doesn't work with the DATETIME column type.


Date time handling

If we rely on sqlite to insert and generate date and times then they are in a non-ISO 8601 format (space-delimited instead of T) however in some instances we must insert the date/time (eg: event rows) which we use RFC3339. If we don't rely on SQLite to generate or update date and time and instead rely only on the Rust code then we can always use RFC3339 date/times for consistency.

We would then also be able to remove UtcDateTime::parse_utc_iso8601.

Initial work on this completed in 9cec5be

Pragma Hardening

https://www.sqlite.org/pragma.html#pragma_synchronous

MacOS only - https://www.sqlite.org/pragma.html#pragma_fullfsync

@tmpfs tmpfs self-assigned this Dec 29, 2024
@tmpfs tmpfs force-pushed the sqlite-db branch 2 times, most recently from 4cf84ef to 79d7c4a Compare January 6, 2025 08:06
tmpfs added 27 commits January 10, 2025 18:49
Update doc comments to reflect new language.
Make truncate() a private implementation detail.
So it's clearer if we are just streaming records or also the decoded
events.
We can get the CommitHash from the EventRecord.
Lookup account and folder row ids from the database based on the
AccountId and VaultId identifiers.
tmpfs added 30 commits February 5, 2025 09:16
In order to do strict verification of account root hashes we need to
depend upon the sos-client-storage library which creates a circular
dependency with sos-database.
Pass the authenticated user identity into the client storage.
Ensures that the imported account events exactly match the
original account events.
Prevent duplicate calls as the storage constructor now automatically
loads the folder event logs.
So we can check if the server is running with db storage or not.
So that compiling the server does not depend upon sos_account or
sos_client_storage.
A hard conflict is being encountered which is triggering a sign out
which causes the test to fail with a no search index error.
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.

1 participant