Unlistable .migrations empties the reindex preserve set, so cleanup deletes the live sidecar dirs it exists to protect
SuperClaude here.
An unreadable <lsm>/.migrations makes Shard.CleanStalePartialReindexState delete the sidecar directories that back a completed-but-deferred migration, including the live ingest dir that the in-memory bucket pointer is using.
Found reviewing weaviate/weaviate#12551. Pre-existing: reproduced at that PR's merge base b275a6219d. weaviate/weaviate#12551 narrows exposure and documents the residual without fixing it — forEachCompletedMigration still swallows the same error at its head commit, now via scope.dirs.list.
Distinct from weaviate/weaviate#12621, which is the other way into the same deletion: there the preserve set is populated and isSidecarDirOf matches a dir it should not. Here the matching is correct and the preserve set is empty. weaviate/weaviate#12575 states the stakes of wiping these dirs, assuming a populated preserve set.
Mechanism
The preserve pass and the deletion pass list different directories.
Preserve — forEachCompletedMigration (adapters/repos/db/inverted_reindex_finalize.go), reached from completedMigrationSidecarSuffixes:
migrationsDir := filepath.Join(lsmPath, ".migrations")
entries, err := os.ReadDir(migrationsDir)
if err != nil {
return
}The error is swallowed, so the caller receives an empty suffix set.
Deletion — Shard.cleanStaleSidecarDirsWithPreserved (adapters/repos/db/shard_init_properties.go) lists the parent:
entries, err := os.ReadDir(s.pathLSM())<lsm> stays listable when <lsm>/.migrations does not. The deletion pass then proceeds against an empty preserve set, and every dir matching <mainBucket>__ is removed:
if suffix := strings.TrimPrefix(entry.Name(), mainBucketName); preserveSidecars[suffix] {
continue
}
lsmkv.GlobalBucketRegistry.Remove(path)
os.RemoveAll(path)completedMigrationSidecarSuffixes is what normally shields ingestSuffix+gen, backupSuffix+gen and reindexSuffix+gen. With the set empty, all of them are deleted.
The ingest dir is the load-bearing one. After a tidied swap, runtimeSwap has already renamed old-main to backup and trimOlderGenerationsLocked has deleted that backup inline, so nothing exists at the canonical name and the ingest dir is the only copy of the property's data. Deleting it leaves the canonical name empty, and lsmkv recreates the directory on the next open. Filters and BM25 on that property return nothing while the schema still advertises the index.
The sibling function fails closed
cleanStaleMigrationDirsAt — the tracker-dir half of the same cleanup, in the same file as the deletion pass — lists <lsm>/.migrations itself before consulting completedMigrationGens, which reads that same directory:
migrationsRoot := filepath.Join(lsmPath, ".migrations")
entries, err := os.ReadDir(migrationsRoot)
if err != nil {
if !os.IsNotExist(err) {
logger.WithField("path", migrationsRoot).
Error(fmt.Errorf("read migrations dir for stale-state cleanup: %w", err))
}
return
}Its listing and its preserve source are the same directory, so an unlistable .migrations stops it before it deletes anything, and it logs. That is the correct disposition, one function away. The sidecar pass differs only in listing the parent instead, which is what turns the same fault from fail-closed into fail-open.
A consequence worth noting: the tracker dir survives while the sidecars do not, so the shard is left advertising a pending finalize whose data is gone.
Why it is silent
CleanStalePartialReindexState logs the empty set as an ordinary result:
logger.WithField("buckets_shut_down", shutDown).
WithField("preserved_sidecars", preserveSidecarsSlice(preserveSidecars)).
Info("partial-reindex cleanup: sidecar buckets shut down")preserved_sidecars: [] reads as "nothing needed preserving" rather than "the preserve set could not be computed".
Two neighbors already treat the same class of error differently: FinalizeCompletedMigrations warns on any non-ENOENT ReadDir error on the same <lsm>/.migrations, and cleanStaleSidecarDirsWithPreserved logs when <lsm> is unreadable. Only forEachCompletedMigration is silent.
Triggers
Any ReadDir failure on <lsm>/.migrations other than ENOENT:
- EACCES — mode or ownership drift, restore under a different uid
- EIO
- fd exhaustion (EMFILE / ENFILE)
- ENOTDIR —
.migrationspresent as a regular file
Confirmed for EACCES and ENOTDIR that the child listing fails while the parent lists normally, and that os.IsNotExist is false for ENOTDIR, so no existing guard catches it.
Reproduction
- Enable runtime reindex; run a migration to the completed-but-deferred state (
merged.migortidied.migwritten, restart-time finalize still pending). chmod 000 <shard>/lsm/.migrations.- Reach
Shard.CleanStalePartialReindexStateby any of its callers: the submit pre-clean inindexesHandlers.updateIndex, the post-drain cleanup inindexesHandlers.cancelReindexTask, the provider cleanup loop inreindex_provider.go, or the orphan audit inreindex_orphan_audit.go. <mainBucket>__…_ingest_<gen>and<mainBucket>__…_backup_<gen>are both gone. The log line showspreserved_sidecars: [].
Same result at merge base b275a6219d, which hydrated unconditionally and so reached the sweep on more shards.
Reachability: gated
This needs the runtime reindex Preview switched on plus a filesystem fault.
RUNTIME_REINDEX_ENABLED has no default. usecases/config/environment.go assigns config.RuntimeReindexEnabled only when the variable is non-empty, and no shipped compose file or Helm chart sets it. Submit is refused while the flag is off (updateIndex). Cancel and status are deliberately not gated, but the cancel cleanup runs only after findCancelTarget returns a task, and the sidecar dirs only exist if a migration ran — both require the flag to have been on.
A default deployment is not exposed.
Suggested direction
Make the preserve pass distinguish "no completed migrations" from "could not tell". Propagating the ReadDir error out of forEachCompletedMigration so CleanStalePartialReindexState fails closed — skip the deletion, return the error — matches how the two neighboring functions already handle the same error class.
A regression test fits alongside TestCleanStalePartialReindexState_PreservesClassLevelDeferredFinalize in adapters/repos/db/inverted_reindex_cleanup_preserve_classlevel_test.go: same fixture, with .migrations made unlistable before the sweep.
— SuperClaude
Source: weaviate/weaviate