Indexing attempts for e-mails in index queue keep failing

Issue Description

Several e-mail items in index queue just keep failing after each attempt with errors like Record not found in database (store.not-found): details = Blob not found, accountId = 0, documentId = 0. accountId always differs and documentId is always between 0 and 2, usually 0).
Already tried the two store maintenance tasks for reindexing without success.
No obvious wrong behaviour like missing e-mails is recognisable.

Stalwart Version

v1.x

Installation Method

Binary (Linux)

Database Backend

RocksDB

Blob Storage

Filesystem

Search Engine

Internal

Directory Backend

Internal

Additional Context

Version 1.0.1 (also with 1.0.0 before)

Successfully migrated (without option to rerun it now) from 0.16.27 to 1.0.0 with the migrate tool version 1.0.1

I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.

on

I have searched this support forum (open and closed topics) and confirm this is not a duplicate.

on

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

I couldn’t find a documented fix for this exact case, but the source explains what the error means.

The message comes from the email index builder. For each queued email, it reads the message’s stored metadata and then fetches the raw message from the blob store using the hash in that metadata. If the blob store has no blob for that hash, it fails with Blob not found. The accountId and documentId in the error identify the message whose metadata row exists but whose blob is missing.

That points at the data, not at the index. A reindex task can’t fix it, because it only queues the same items again, and the missing blob makes them fail again. Since you migrated from 0.16.27, the likely causes are blobs that didn’t come across in the migration, or messages whose blobs were already gone before it. I haven’t confirmed which. Missing blobs would also explain why nothing looks wrong day to day. Search indexing is the only thing that reads these messages in the background, so it’s the first place the problem shows up. Opening or fetching the affected messages in a client would probably fail too.

Some things to check:

  1. Look up the failing partitions with stalwart-cli query IndexQueueStatus. Note the partition (account) and reason for each one.
  2. Check whether the blobs for those accounts exist in your filesystem blob store. Also confirm the blob store location in your 1.0 config is the same directory 0.16 used. If it points somewhere else, every blob would be missing. In that case you’d see many more failures than a few.
  3. Try fetching the affected messages over IMAP or JMAP. If the fetch fails with a similar error, the messages are really missing their content.

Failed partitions are retried automatically with backoff, up to every 30 minutes. If you restore the blobs, you can retry immediately by setting the partition status back to Running:

stalwart-cli update IndexQueueStatus <id> --field status='{"@type":"Running"}'

I couldn’t find a documented way to drop queue entries for messages whose blob is permanently gone. A staff member will need to say how to clear them safely.

Docs: Search indexing | Stalwart

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

The store was reused. So data was left in place during the migration. Therefore I don’t think any blobs were actually lost during the process.

The endless retries are a bug on our side. When the indexer finds a message whose blob is gone, it fails the whole queue partition and retries it later from the same message, so it never gets past it and the messages queued behind it in that partition don’t get indexed either. A missing blob should be logged and skipped. I’ve filed that.

The missing blobs themselves are a separate question, and I’d like to understand them before anyone assumes the migration lost data. The ids being so low in every account points at early messages, so the history of the 0.16 setup matters here: did that server ever keep blobs anywhere other than the current file system store, for example in RocksDB before the blob store was switched?

Hi Yannik,

The indexer was treating a missing message blob as a temporary error. It stopped at that message and retried the whole partition forever, and anything queued after it for the same account never got indexed. That’s also why the reindex tasks didn’t help: they queued the same message again. In the next weekly Stalwart release the indexer logs the missing blob once, skips that message and carries on with the rest.

That still leaves the question of why those blobs are gone. A reused store shouldn’t lose anything, and documents 0 to 2 are among the first ids each account handed out, so I suspect blobs from an older storage setup in 0.16 rather than the migration itself. Did you ever change the blob store in 0.16 (for example from the default data store to the filesystem)? If you still have the output of stalwart-migrate verify, the blob section would help too. You can also open one of those messages in a mail client; if the blob is missing, the server logs Blob not found. for it.

I found the reason for the blobs not being found. No error in Stalwart, but just my own stupidity. I will explain later, but I need to now quickly fix my mistake first.

So what happened was the following:

After the actual migration but before running the final install script I switched the names of the old /var/lib/stalwart with /var/lib/stalwart-v1 (and of course adjusted the config file accordingly), because I wanted the folder names to stay the same. But with that of course the old blobs weren’t at the right location anymore. So they couldn’t be found, but because the old e-mail were all locally cached in the clients and the new e-mails showed up normally nobody did notice.

So completely my fault.

I was able to fix the situation manually and the index queue is empty now. Like you said still probably best for one failure not to hold up the whole queue forever, but the original reason for the error was my own lack of concentration.