diff --git a/store/lfuda.go b/store/lfuda.go index e33afa0..cfdb155 100644 --- a/store/lfuda.go +++ b/store/lfuda.go @@ -40,8 +40,6 @@ func NewLFUDAStore(component string, store BlobStore, maxSize float64) *LFUDASto const nameLFUDA = "lfuda" -var fakeTrue = []byte{'t'} - // Name is the cache type name func (l *LFUDAStore) Name() string { return nameLFUDA } @@ -66,7 +64,7 @@ func (l *LFUDAStore) Get(hash string) (stream.Blob, error) { // Put stores the blob. Following LFUDA rules it's not guaranteed that a SET will store the value!!! func (l *LFUDAStore) Put(hash string, blob stream.Blob) error { - l.lfuda.Set(hash, fakeTrue) + l.lfuda.Set(hash, true) has, _ := l.Has(hash) if has { err := l.store.Put(hash, blob) @@ -77,14 +75,16 @@ func (l *LFUDAStore) Put(hash string, blob stream.Blob) error { return nil } -// PutSD stores the sd blob +// PutSD stores the sd blob. Following LFUDA rules it's not guaranteed that a SET will store the value!!! func (l *LFUDAStore) PutSD(hash string, blob stream.Blob) error { - err := l.store.PutSD(hash, blob) - if err != nil { - return err + l.lfuda.Set(hash, true) + has, _ := l.Has(hash) + if has { + err := l.store.PutSD(hash, blob) + if err != nil { + return err + } } - - l.lfuda.Set(hash, fakeTrue) return nil } @@ -109,12 +109,13 @@ func (l *LFUDAStore) loadExisting(store lister, maxItems int) error { if err != nil { return err } + logrus.Infof("read %d files from disk", len(existing)) added := 0 for _, h := range existing { - l.lfuda.Set(h, fakeTrue) + l.lfuda.Set(h, true) added++ - if maxItems > 0 && added >= maxItems { // underlying cache is bigger than LRU cache + if maxItems > 0 && added >= maxItems { // underlying cache is bigger than the cache break } } diff --git a/store/lfuda_test.go b/store/lfuda_test.go index 9b1eb58..d5eae47 100644 --- a/store/lfuda_test.go +++ b/store/lfuda_test.go @@ -8,7 +8,6 @@ import ( "time" "github.com/lbryio/lbry.go/v2/extras/errors" - log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -68,8 +67,6 @@ func TestFUDAStore_Eviction(t *testing.T) { assert.Equal(t, cacheMaxBlobs, len(mem.Debug())) - keys := lfuda.lfuda.Keys() - log.Infof("%+v", keys) for k, v := range map[string]bool{ "one": false, "two": true, diff --git a/store/lru.go b/store/lru.go index edbe3a5..071e2b9 100644 --- a/store/lru.go +++ b/store/lru.go @@ -6,6 +6,7 @@ import ( "github.com/lbryio/reflector.go/internal/metrics" golru "github.com/hashicorp/golang-lru" + "github.com/sirupsen/logrus" ) // LRUStore adds a max cache size and LRU eviction to a BlobStore @@ -106,11 +107,12 @@ func (l *LRUStore) Delete(hash string) error { // loadExisting imports existing blobs from the underlying store into the LRU cache func (l *LRUStore) loadExisting(store lister, maxItems int) error { + logrus.Infof("loading at most %d items", maxItems) existing, err := store.list() if err != nil { return err } - + logrus.Infof("read %d files from disk", len(existing)) added := 0 for _, h := range existing { l.lru.Add(h, true) diff --git a/store/speedwalk/speedwalk.go b/store/speedwalk/speedwalk.go index 23230df..9b899e4 100644 --- a/store/speedwalk/speedwalk.go +++ b/store/speedwalk/speedwalk.go @@ -83,6 +83,5 @@ func AllFiles(startDir string, basename bool) ([]string, error) { close(pathChan) pathWG.Wait() - logrus.Infoln("loaded LRU") return paths, nil }