mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-11 15:21:02 +00:00
rebuild rank caches on restore
This commit is contained in:
parent
b25ad81e67
commit
7520e0ef28
2 changed files with 30 additions and 1 deletions
6
api.go
6
api.go
|
|
@ -2283,7 +2283,11 @@ func (api *API) RestoreShard(ctx context.Context, indexName string, shard uint64
|
|||
return err
|
||||
}
|
||||
}
|
||||
_, err = view.CreateFragmentIfNotExists(shard)
|
||||
frag, err := view.CreateFragmentIfNotExists(shard)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = frag.RebuildRankCache(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
25
fragment.go
25
fragment.go
|
|
@ -2890,6 +2890,31 @@ func (f *fragment) FlushCache() error {
|
|||
defer f.mu.Unlock()
|
||||
return f.flushCache()
|
||||
}
|
||||
func (f *fragment) RebuildRankCache(ctx context.Context) error {
|
||||
if f.CacheType != CacheTypeRanked {
|
||||
return nil //only rebuild ranked caches
|
||||
}
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
tx, err := f.holder.BeginTx(false, f.idx, f.shard)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
rows, err := f.unprotectedRows(ctx, tx, uint64(0))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range rows {
|
||||
n, err := tx.CountRange(f.index(), f.field(), f.view(), f.shard, id*ShardWidth, (id+1)*ShardWidth)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "CountRange")
|
||||
}
|
||||
f.cache.BulkAdd(id, n)
|
||||
}
|
||||
f.cache.Invalidate()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fragment) flushCache() error {
|
||||
if f.cache == nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue