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

fix: adjust storage options for MapeoManager and MapeoProject #235

Merged
merged 7 commits into from
Aug 30, 2023

Conversation

achou11
Copy link
Member

@achou11 achou11 commented Aug 29, 2023

Closes #226

Tried my best to follow the checklist but there were some uncertainties, mostly around handling the storage opt in MapeoProject

@achou11 achou11 requested a review from gmaclennan August 29, 2023 21:15
@achou11 achou11 force-pushed the 226/storage-opts-update branch from 42758ad to 68adf44 Compare August 29, 2023 21:19
Comment on lines 65 to 82
const coreManagerStorage =
storagePath !== undefined
typeof storage === 'string'
? (name) =>
new RandomAccessFile(
path.join(storagePath, CORE_STORAGE_FOLDER_NAME, name),
path.join(dbPath, storage, CORE_STORAGE_FOLDER_NAME, name),
{ pool: filePool }
)
: () => new RAM()
: (name) => storage(path.join(CORE_STORAGE_FOLDER_NAME, name))

/** @type {ConstructorParameters<typeof DataStore>[0]['storage']} */
const indexerStorage =
storagePath !== undefined
typeof storage === 'string'
? (name) =>
new RandomAccessFile(
path.join(storagePath, INDEXER_STORAGE_FOLDER_NAME, name),
path.join(dbPath, storage, INDEXER_STORAGE_FOLDER_NAME, name),
{ pool: filePool }
)
: () => new RAM()
: (name) => storage(path.join(INDEXER_STORAGE_FOLDER_NAME, name))
Copy link
Member Author

Choose a reason for hiding this comment

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

If a path is passed, use a default random-access-file storage function

Inside MapeoProject, the storage function will still need to be wrapped to separate index storage from core storage.

Made the guess that these points applied here, but could be mistaken

* @param {import('@mapeo/crypto').KeyManager} opts.keyManager mapeo/crypto KeyManager instance
* @param {Buffer} opts.projectKey 32-byte public key of the project creator core
* @param {Buffer} [opts.projectSecretKey] 32-byte secret key of the project creator core
* @param {Partial<Record<import('./core-manager/index.js').Namespace, Buffer>>} [opts.encryptionKeys] Encryption keys for each namespace
* @param {import('drizzle-orm/better-sqlite3').BetterSQLite3Database} opts.sharedDb
* @param {IndexWriter} opts.sharedIndexWriter
* @param {import('./types.js').StorageParam} opts.storage Folder to store all hypercore data
* @param {import('./core-manager/random-access-file-pool.js').RandomAccessFilePool} [opts.filePool] FilePool instance to use if opts.storage is a path
Copy link
Member Author

Choose a reason for hiding this comment

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

Create a single instance of RandomAccessFilePool in MapeoManager and use that for all storages

is this aligned with what you described here? wasn't explicitly noted to create an opt for MapeoProject but seemed to make sense given the changes required by other points

Comment on lines 65 to 68
? () => ({
dbPath: ':memory:',
storage: () => new RAM(),
})
Copy link
Member Author

Choose a reason for hiding this comment

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

have a feeling that this shouldn't be a function that creates a new RAM instance each time a project is created. is the idea to share the ram instance across all projects too?

@gmaclennan
Copy link
Member

Not quite what I meant, sorry the issue wasn't clear. I pushed 28d4f89 to show what I meant. I think this is done now, can you review?

Corestore already creates a `core` folder, which resulted in weird paths
`cores/cores/...`, so renamed the folder to be `corestore/cores`
There are a few things that Hypercore does in its default storage for
managing lock files and sparse files

https://github.com/holepunchto/hypercore/blob/7c9f8b07b33e60753470728b4a9a11bcb549e158/index.js#L177
@gmaclennan
Copy link
Member

Should merge and release digidem/multi-core-indexer#17 before merging, so that we can update the snapshot and fix the storage locations

Copy link
Member

@gmaclennan gmaclennan left a comment

Choose a reason for hiding this comment

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

I made some changes and added a test to catch breaking changes to storage locations. There is a bug fix here for something unrelated (encoding project keys). There should be a failing test for that, in a separate PR.

@achou11
Copy link
Member Author

achou11 commented Aug 30, 2023

your changes lgtm! thanks for making the fixes - was hoping to do this to take something off your plate but ended up with you doing most of the work anyways 😄

@achou11 achou11 merged commit 1bd2613 into main Aug 30, 2023
@achou11 achou11 deleted the 226/storage-opts-update branch August 30, 2023 14:02
@achou11 achou11 changed the title chore: adjust storage options for MapeoManager and MapeoProject fix: adjust storage options for MapeoManager and MapeoProject Aug 30, 2023
gmaclennan added a commit that referenced this pull request Sep 6, 2023
* main: (25 commits)
  add initial implementation of MemberApi (#232)
  feat: $blobs.getUrl and $blobs.create methods (#184)
  chore: update manager e2e tests (#237)
  feat: add capabilities (#231)
  feat: coreOwnership integration [3/3] (#230)
  feat: CoreOwnership class w getOwner & getCoreKey [2/3] (#229)
  feat: handle `coreOwnership` records in `IndexWriter` [1/3] (#214)
  fix: adjust storage options for MapeoManager and MapeoProject (#235)
  implement addProject method for MapeoManager class (#215)
  implement listProjects method for MapeoManager class (#208)
  feat: expose blobStore.writerDriveId (#219)
  implement wrapper client containing createProject and getProject methods (#199)
  add project settings functionality to MapeoProject (#187)
  feat: Add encode/decode for project keys [3/3] (#203)
  feat: update protobuf for RPC [2/3] (#202)
  chore: move protobuf messages into src/generated [1/3] (#201)
  feat: Add internal `dataType.createWithDocId()` (#192)
  chore: explicitly set "mode" opt for encryptionKeys column creation (#186)
  chore: fix linting and type checking (#183)
  chore: consolidate encryption key columns in projectKeys table (#181)
  ...
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.

Fix storage options for MapeoManager and MapeoProject
2 participants