From 1758fa8fbb95acb3553dc2207f66d0674961d7af Mon Sep 17 00:00:00 2001 From: Georges Chaudy Date: Wed, 3 Sep 2025 11:06:08 +0200 Subject: [PATCH] unistore: use scorch indexing instead of upside_down (#110463) * use scorchwith in memory * comments * refactor --- pkg/storage/unified/search/bleve.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/storage/unified/search/bleve.go b/pkg/storage/unified/search/bleve.go index 7df4cbe9170..d465d2ccdfc 100644 --- a/pkg/storage/unified/search/bleve.go +++ b/pkg/storage/unified/search/bleve.go @@ -199,6 +199,18 @@ func (b *bleveBackend) updateIndexSizeMetric(indexPath string) { } } +// newBleveIndex creates a new bleve index with consistent configuration. +// If path is empty, creates an in-memory index. +// If path is not empty, creates a file-based index at the specified path. +func newBleveIndex(path string, mapper mapping.IndexMapping) (bleve.Index, error) { + kvstore := bleve.Config.DefaultKVStore + if path == "" { + // use in-memory kvstore + kvstore = bleve.Config.DefaultMemKVStore + } + return bleve.NewUsing(path, mapper, bleve.Config.DefaultIndexType, kvstore, nil) +} + // BuildIndex builds an index from scratch or retrieves it from the filesystem. // If built successfully, the new index replaces the old index in the cache (if there was any). // An index in the file system is considered to be valid if the requested resourceVersion is smaller than or equal to @@ -299,7 +311,7 @@ func (b *bleveBackend) BuildIndex( return nil, fmt.Errorf("invalid path %s", indexDir) } - index, err = bleve.New(indexDir, mapper) + index, err = newBleveIndex(indexDir, mapper) if errors.Is(err, bleve.ErrorIndexPathExists) { now = now.Add(time.Second) // Bump time for next try index = nil // Bleve actually returns non-nil value with ErrorIndexPathExists @@ -314,7 +326,7 @@ func (b *bleveBackend) BuildIndex( defer closeIndexOnExit(index, indexDir) // Close index, and delete new index directory. } } else { - index, err = bleve.NewMemOnly(mapper) + index, err = newBleveIndex("", mapper) if err != nil { return nil, fmt.Errorf("error creating new in-memory bleve index: %w", err) }