Skip to content

Commit

Permalink
Add storage index tests (#1060)
Browse files Browse the repository at this point in the history
  • Loading branch information
sesposito authored Jul 18, 2023
1 parent ca07adf commit 1b24c98
Show file tree
Hide file tree
Showing 2 changed files with 492 additions and 3 deletions.
19 changes: 16 additions & 3 deletions server/storage_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (si *LocalStorageIndex) Write(ctx context.Context, objects StorageOpWrites)
count, _ := reader.Count() // cannot return err

// Apply eviction strategy if size of index is +10% than max size
if count > uint64(float32(idx.MaxEntries)*(1+0.1)) {
if count > uint64(float32(idx.MaxEntries)*(1.1)) {
deleteCount := int(count - uint64(idx.MaxEntries))
req := bluge.NewTopNSearch(deleteCount, bluge.NewMatchAllQuery())
req.SortBy([]string{"update_time"})
Expand Down Expand Up @@ -211,6 +211,9 @@ func (si *LocalStorageIndex) List(ctx context.Context, indexName, query string,
si.logger.Warn("Attempted to list more index entries than configured maximum index size", zap.String("index_name", idx.Name), zap.Int("limit", limit), zap.Int("max_entries", idx.MaxEntries))
}

if query == "" {
query = "*"
}
parsedQuery, err := ParseQueryString(query)
if err != nil {
return nil, err
Expand Down Expand Up @@ -445,7 +448,7 @@ func (si *LocalStorageIndex) queryMatchesToStorageIndexResults(dmi search.Docume
idxResult.Value = string(value)
case "version":
idxResult.Version = string(value)
case "updateTime":
case "update_time":
updateTime, vErr := bluge.DecodeDateTime(value)
if err != nil {
err = vErr
Expand Down Expand Up @@ -525,7 +528,17 @@ func (si *LocalStorageIndex) CreateIndex(ctx context.Context, name, collection,
si.indicesByCollection[collection] = []*storageIndex{storageIdx}
}

si.logger.Info("Initialized storage engine index", zap.Any("config", idx))
cfgKey := key
if key == "" {
cfgKey = "*"
}
si.logger.Info("Initialized storage engine index", zap.Any("configuration", map[string]any{
"name": name,
"collection": collection,
"key": cfgKey,
"fields": fields,
"max_entries": maxEntries,
}))

return nil
}
Expand Down
Loading

0 comments on commit 1b24c98

Please sign in to comment.