meilisearch / meilisearch/grenad

Be more resilient when opening too many files

Open
#48 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Rust
Stars
26
Forks
4
PR merge metrics
No merged PRs in 30d

Description

We use grenad in Meilisearch, and we often have the too many open files (os error 24) error, which stops the whole indexation. I want to propose a change in the way the grenad sorter currently works.

How does it work now?

  1. The sorter allocates a big in-memory buffer
  2. If we can insert entries into the in-memory buffer, we do and return to 2.
  3. If there are less than 25 on-disk chunks, we create a new file, dump the buffer into it, and go to 2. Otherwise, we go to 4.
  4. We create a new file and merge the 25 files into the 26th one, then delete all of them. Return to 2.

In this configuration, if an (error 24) is raised, we cannot do anything apart from returning the error above. The reason is that the in-memory buffer is full, so we cannot accept any new entry, and we cannot write the buffer's content into any chunk file as the content would be unordered.

https://github.com/meilisearch/grenad/blob/46e5e27a8ff328c22ded55278022dfd22ae32b09/src/sorter.rs#L470-L625

How can we improve that?

  1. The sorter allocates a big in-memory buffer and one backup file.
  2. If we can insert entries into the in-memory buffer, we do and return to 2.
  3. If there are less than 25 on-disk chunks, we create a new file, dump the buffer into it, and go to 2. Otherwise, we go to 4.
  4. We merge the 24 files into the backup file, then delete all of them but one that becomes the backup file. Return to 2.

In this configuration, if an (error 24) is raised, we can still merge the chunks file together into the backup file, dump the buffer's content into one of the chunks files, and keep one of the chunks files as a new backup file, dropping the others. The only moment we are not resilient to the (error 24) is at step 1., at creation time.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/sorter.rs lines 470-625 and trace how the sorter creates, dumps, and merges chunk files. Verify the proposed backup-file flow preserves ordering and can continue when opening another file returns OS error 24; done means only initial backup creation remains a failure point.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.