mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 01:43:47 +00:00
swarm/storage: better naming
This commit is contained in:
parent
4b630d8221
commit
49214d72d2
6 changed files with 14 additions and 17 deletions
|
|
@ -35,8 +35,9 @@ implementation for storage or retrieval.
|
|||
*/
|
||||
|
||||
const (
|
||||
singletonSwarmDbCapacity = 50000
|
||||
singletonSwarmCacheCapacity = 500
|
||||
defaultLDBCapacity = 50000 // capacity for LevelDB
|
||||
defaultCacheCapacity = 500 // capacity for in-memory chunks' cache
|
||||
defaultChunkRequestsCacheCapacity = 50000 // capacity for container holding outgoing requests for chunks. should be set to LevelDB capacity
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -66,13 +67,13 @@ func NewLocalDPA(datadir string, basekey []byte) (*DPA, error) {
|
|||
|
||||
hash := MakeHashFunc("SHA3")
|
||||
|
||||
dbStore, err := NewLDBStore(datadir, hash, singletonSwarmDbCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) })
|
||||
dbStore, err := NewLDBStore(datadir, hash, defaultLDBCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) })
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewDPA(&LocalStore{
|
||||
memStore: NewMemStore(dbStore, singletonSwarmCacheCapacity, singletonSwarmDbCapacity),
|
||||
memStore: NewMemStore(dbStore, defaultCacheCapacity, defaultChunkRequestsCacheCapacity),
|
||||
DbStore: dbStore,
|
||||
}, NewDPAParams()), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ func testDpaRandom(toEncrypt bool, t *testing.T) {
|
|||
defer tdb.close()
|
||||
db := tdb.LDBStore
|
||||
db.setCapacity(50000)
|
||||
memStore := NewMemStore(db, defaultCacheCapacity, defaultCacheCapacity)
|
||||
memStore := NewMemStore(db, defaultCacheCapacity, defaultChunkRequestsCacheCapacity)
|
||||
localStore := &LocalStore{
|
||||
memStore: memStore,
|
||||
DbStore: db,
|
||||
|
|
@ -68,7 +68,7 @@ func testDpaRandom(toEncrypt bool, t *testing.T) {
|
|||
}
|
||||
ioutil.WriteFile("/tmp/slice.bzz.16M", slice, 0666)
|
||||
ioutil.WriteFile("/tmp/result.bzz.16M", resultSlice, 0666)
|
||||
localStore.memStore = NewMemStore(db, defaultCacheCapacity, defaultCacheCapacity)
|
||||
localStore.memStore = NewMemStore(db, defaultCacheCapacity, defaultChunkRequestsCacheCapacity)
|
||||
resultReader = dpa.Retrieve(key)
|
||||
for i := range resultSlice {
|
||||
resultSlice[i] = 0
|
||||
|
|
|
|||
|
|
@ -60,19 +60,19 @@ func NewLocalStore(hash SwarmHasher, params *StoreParams, basekey []byte, mockSt
|
|||
return nil, err
|
||||
}
|
||||
return &LocalStore{
|
||||
memStore: NewMemStore(dbStore, params.CacheCapacity, singletonSwarmDbCapacity),
|
||||
memStore: NewMemStore(dbStore, params.CacheCapacity, defaultChunkRequestsCacheCapacity),
|
||||
DbStore: dbStore,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewTestLocalStoreForAddr(path string, basekey []byte) (*LocalStore, error) {
|
||||
hasher := MakeHashFunc("SHA3")
|
||||
dbStore, err := NewLDBStore(path, hasher, singletonSwarmDbCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) })
|
||||
dbStore, err := NewLDBStore(path, hasher, defaultLDBCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) })
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
localStore := &LocalStore{
|
||||
memStore: NewMemStore(dbStore, singletonSwarmDbCapacity, singletonSwarmDbCapacity),
|
||||
memStore: NewMemStore(dbStore, defaultCacheCapacity, defaultChunkRequestsCacheCapacity),
|
||||
DbStore: dbStore,
|
||||
}
|
||||
return localStore, nil
|
||||
|
|
|
|||
|
|
@ -26,10 +26,6 @@ import (
|
|||
lru "github.com/hashicorp/golang-lru"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultCacheCapacity = 5000
|
||||
)
|
||||
|
||||
type MemStore struct {
|
||||
cache *lru.Cache
|
||||
requests *lru.Cache
|
||||
|
|
@ -124,7 +120,7 @@ func (m *MemStore) setCapacity(n int) {
|
|||
if n <= 0 {
|
||||
m.disabled = true
|
||||
} else {
|
||||
m = NewMemStore(nil, uint(n), singletonSwarmDbCapacity)
|
||||
m = NewMemStore(nil, uint(n), defaultChunkRequestsCacheCapacity)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ package storage
|
|||
import "testing"
|
||||
|
||||
func newTestMemStore() *MemStore {
|
||||
return NewMemStore(nil, defaultCacheCapacity, singletonSwarmDbCapacity)
|
||||
return NewMemStore(nil, defaultCacheCapacity, defaultChunkRequestsCacheCapacity)
|
||||
}
|
||||
|
||||
func testMemStoreRandom(n int, processors int, chunksize int, t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -897,13 +897,13 @@ func NewTestResourceHandler(datadir string, ethClient headerGetter, validator Re
|
|||
path := filepath.Join(datadir, DbDirName)
|
||||
basekey := make([]byte, 32)
|
||||
hasher := MakeHashFunc(SHA3Hash)
|
||||
dbStore, err := NewLDBStore(path, hasher, singletonSwarmDbCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) })
|
||||
dbStore, err := NewLDBStore(path, hasher, defaultLDBCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) })
|
||||
dbStore.SetTrusted()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
localStore := &LocalStore{
|
||||
memStore: NewMemStore(dbStore, singletonSwarmCacheCapacity, singletonSwarmDbCapacity),
|
||||
memStore: NewMemStore(dbStore, defaultCacheCapacity, defaultChunkRequestsCacheCapacity),
|
||||
DbStore: dbStore,
|
||||
}
|
||||
resourceChunkStore := NewResourceChunkStore(localStore, nil)
|
||||
|
|
|
|||
Loading…
Reference in a new issue