swarm/storage: HasChunk -> Has and implementation with no access count change

This commit is contained in:
Fabio Barone 2019-02-03 20:20:01 -05:00
parent fc919f562c
commit 9d4f27277e
7 changed files with 29 additions and 25 deletions

View file

@ -266,8 +266,8 @@ func (m *MapChunkStore) Get(_ context.Context, ref Address) (Chunk, error) {
return chunk, nil
}
// Need to implement HasChunk from SyncChunkStore
func (m *MapChunkStore) HasChunk(ctx context.Context, ref Address) bool {
// Need to implement Has from SyncChunkStore
func (m *MapChunkStore) Has(ctx context.Context, ref Address) bool {
m.mu.RLock()
defer m.mu.RUnlock()

View file

@ -969,14 +969,18 @@ func (s *LDBStore) Get(_ context.Context, addr Address) (chunk Chunk, err error)
return s.get(addr)
}
// HasChunk queries the underlying DB if a chunk with the given address is stored
// Has queries the underlying DB if a chunk with the given address is stored
// Returns true if the chunk is found, false if not
func (s *LDBStore) HasChunk(_ context.Context, addr Address) bool {
func (s *LDBStore) Has(_ context.Context, addr Address) bool {
s.lock.RLock()
defer s.lock.RUnlock()
proximity := s.po(addr)
_, found := s.tryAccessIdx(addr, proximity)
return found
ikey := getIndexKey(addr)
_, err := s.db.Get(ikey)
if err != nil {
return false
}
return true
}
// TODO: To conform with other private methods of this object indices should not be updated

View file

@ -132,11 +132,11 @@ func (ls *LocalStore) Put(ctx context.Context, chunk Chunk) error {
return err
}
// HasChunk queries the underlying DbStore if a chunk with the given address
// Has queries the underlying DbStore if a chunk with the given address
// is being stored there.
// Returns true if it is stored, false if not
func (ls *LocalStore) HasChunk(ctx context.Context, addr Address) bool {
return ls.DbStore.HasChunk(ctx, addr)
func (ls *LocalStore) Has(ctx context.Context, addr Address) bool {
return ls.DbStore.Has(ctx, addr)
}
// Get(chunk *Chunk) looks up a chunk in the local stores

View file

@ -210,16 +210,16 @@ func setupLocalStore(t *testing.T, ldbCap int) (ls *LocalStore, cleanup func())
return store, cleanup
}
func TestHasChunk(t *testing.T) {
func TestHas(t *testing.T) {
ldbCap := defaultGCRatio
store, cleanup := setupLocalStore(t, ldbCap)
defer cleanup()
nonStoredAddr := GenerateRandomChunk(128).Address()
has := store.HasChunk(context.Background(), nonStoredAddr)
has := store.Has(context.Background(), nonStoredAddr)
if has {
t.Fatal("Expected HasChunk() to return false, but returned true!")
t.Fatal("Expected Has() to return false, but returned true!")
}
storeChunks := GenerateRandomChunks(128, 3)
@ -229,16 +229,16 @@ func TestHasChunk(t *testing.T) {
t.Fatalf("Expected store to store chunk, but it failed: %v", err)
}
has := store.HasChunk(context.Background(), ch.Address())
has := store.Has(context.Background(), ch.Address())
if !has {
t.Fatal("Expected HasChunk() to return true, but returned false!")
t.Fatal("Expected Has() to return true, but returned false!")
}
}
//let's be paranoic and test again that the non-existent chunk returns false
has = store.HasChunk(context.Background(), nonStoredAddr)
has = store.Has(context.Background(), nonStoredAddr)
if has {
t.Fatal("Expected HasChunk() to return false, but returned true!")
t.Fatal("Expected Has() to return false, but returned true!")
}
}

View file

@ -48,8 +48,8 @@ func NewMemStore(params *StoreParams, _ *LDBStore) (m *MemStore) {
}
}
// HasChunk needed to implement SyncChunkStore
func (m *MemStore) HasChunk(_ context.Context, addr Address) bool {
// Has needed to implement SyncChunkStore
func (m *MemStore) Has(_ context.Context, addr Address) bool {
return m.cache.Contains(addr)
}

View file

@ -158,11 +158,11 @@ func (n *NetStore) get(ctx context.Context, ref Address) (Chunk, func(context.Co
return chunk, nil, nil
}
// HasChunk is the storage layer entry point to query the underlying
// Has is the storage layer entry point to query the underlying
// database to return if it has a chunk or not.
// Called from the DebugAPI
func (n *NetStore) HasChunk(ctx context.Context, ref Address) bool {
return n.store.HasChunk(ctx, ref)
func (n *NetStore) Has(ctx context.Context, ref Address) bool {
return n.store.Has(ctx, ref)
}
// getOrCreateFetcher attempts at retrieving an existing fetchers

View file

@ -292,7 +292,7 @@ func (v *ContentAddressValidator) Validate(chunk Chunk) bool {
type ChunkStore interface {
Put(ctx context.Context, ch Chunk) (err error)
Get(rctx context.Context, ref Address) (ch Chunk, err error)
HasChunk(rctx context.Context, ref Address) bool
Has(rctx context.Context, ref Address) bool
Close()
}
@ -315,8 +315,8 @@ func (f *FakeChunkStore) Put(_ context.Context, ch Chunk) error {
return nil
}
// HasChunk doesn't do anything it is just here to implement ChunkStore
func (f *FakeChunkStore) HasChunk(_ context.Context, ref Address) bool {
// Has doesn't do anything it is just here to implement ChunkStore
func (f *FakeChunkStore) Has(_ context.Context, ref Address) bool {
panic("FakeChunkStore doesn't support HasChunk")
}