Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
Fix/minimize rebuild (#15)
Browse files Browse the repository at this point in the history
* Sync pinner on every pin operation by default
* Optimize reindexing by writing only corrupt pins
* Sync periodically while reindexing
* Log pinning and reindexing operations

Co-authored-by: Petar Maymounkov <petarm@gmail.com>
  • Loading branch information
gammazero and petar authored Jul 29, 2021
1 parent 3565d71 commit f708928
Show file tree
Hide file tree
Showing 6 changed files with 736 additions and 210 deletions.
32 changes: 11 additions & 21 deletions dsindex/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,40 +112,30 @@ func (x *indexer) ForEach(ctx context.Context, key string, fn func(key, value st
if err != nil {
return err
}
defer results.Close()

for {
r, ok := results.NextSync()
if !ok {
break
for r := range results.Next() {
if ctx.Err() != nil {
return ctx.Err()
}
if r.Error != nil {
err = r.Error
break
}
if ctx.Err() != nil {
err = ctx.Err()
break
return fmt.Errorf("cannot read index: %v", r.Error)
}
ent := r.Entry
var decIdx string
decIdx, err = decode(path.Base(path.Dir(ent.Key)))
decIdx, err := decode(path.Base(path.Dir(ent.Key)))
if err != nil {
err = fmt.Errorf("cannot decode index: %v", err)
break
return fmt.Errorf("cannot decode index: %v", err)
}
var decKey string
decKey, err = decode(path.Base(ent.Key))
decKey, err := decode(path.Base(ent.Key))
if err != nil {
err = fmt.Errorf("cannot decode key: %v", err)
break
return fmt.Errorf("cannot decode key: %v", err)
}
if !fn(decIdx, decKey) {
break
return nil
}
}
results.Close()

return err
return nil
}

func (x *indexer) HasValue(ctx context.Context, key, value string) (bool, error) {
Expand Down
Loading

0 comments on commit f708928

Please sign in to comment.