Skip to content

Multi-process mode: two processes opening a new model both backfill the same index #192

Open

Description

@CaffeinatedCoder

With AllowMultiProcessAccess, two processes can open the same database with a model that declares a new index at about the same time. Each sees no such index in its metadata snapshot, builds its own copy with its own root page (ApplyIndexBuilder → CreateUnregistered → RebuildIndexAsync), and calls Register → SaveMetadata.

SaveMetadata writes the process's whole in-memory CollectionMetadata; only SequenceValue is re-read from the file first. So the second save wins:

  • the first process's index pages are leaked;
  • the first process keeps maintaining an index whose root is no longer in the metadata, so its later writes are missing from the persisted index.

The same last-writer-wins applies to any other metadata change CollectionIndexManager makes in two processes. This was also the case before #175; index creation on open just didn't fill the index.

Possible fixes: take the cross-process writer lock around "check the stored metadata → build → register", and re-read the metadata under that lock before building, so the second process picks up the first one's index instead of building its own. Or make SaveMetadata merge index entries instead of overwriting them.

Noted in the review of #175.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status
      Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions