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 (
|
const (
|
||||||
singletonSwarmDbCapacity = 50000
|
defaultLDBCapacity = 50000 // capacity for LevelDB
|
||||||
singletonSwarmCacheCapacity = 500
|
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 (
|
var (
|
||||||
|
|
@ -66,13 +67,13 @@ func NewLocalDPA(datadir string, basekey []byte) (*DPA, error) {
|
||||||
|
|
||||||
hash := MakeHashFunc("SHA3")
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewDPA(&LocalStore{
|
return NewDPA(&LocalStore{
|
||||||
memStore: NewMemStore(dbStore, singletonSwarmCacheCapacity, singletonSwarmDbCapacity),
|
memStore: NewMemStore(dbStore, defaultCacheCapacity, defaultChunkRequestsCacheCapacity),
|
||||||
DbStore: dbStore,
|
DbStore: dbStore,
|
||||||
}, NewDPAParams()), nil
|
}, NewDPAParams()), nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ func testDpaRandom(toEncrypt bool, t *testing.T) {
|
||||||
defer tdb.close()
|
defer tdb.close()
|
||||||
db := tdb.LDBStore
|
db := tdb.LDBStore
|
||||||
db.setCapacity(50000)
|
db.setCapacity(50000)
|
||||||
memStore := NewMemStore(db, defaultCacheCapacity, defaultCacheCapacity)
|
memStore := NewMemStore(db, defaultCacheCapacity, defaultChunkRequestsCacheCapacity)
|
||||||
localStore := &LocalStore{
|
localStore := &LocalStore{
|
||||||
memStore: memStore,
|
memStore: memStore,
|
||||||
DbStore: db,
|
DbStore: db,
|
||||||
|
|
@ -68,7 +68,7 @@ func testDpaRandom(toEncrypt bool, t *testing.T) {
|
||||||
}
|
}
|
||||||
ioutil.WriteFile("/tmp/slice.bzz.16M", slice, 0666)
|
ioutil.WriteFile("/tmp/slice.bzz.16M", slice, 0666)
|
||||||
ioutil.WriteFile("/tmp/result.bzz.16M", resultSlice, 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)
|
resultReader = dpa.Retrieve(key)
|
||||||
for i := range resultSlice {
|
for i := range resultSlice {
|
||||||
resultSlice[i] = 0
|
resultSlice[i] = 0
|
||||||
|
|
|
||||||
|
|
@ -60,19 +60,19 @@ func NewLocalStore(hash SwarmHasher, params *StoreParams, basekey []byte, mockSt
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &LocalStore{
|
return &LocalStore{
|
||||||
memStore: NewMemStore(dbStore, params.CacheCapacity, singletonSwarmDbCapacity),
|
memStore: NewMemStore(dbStore, params.CacheCapacity, defaultChunkRequestsCacheCapacity),
|
||||||
DbStore: dbStore,
|
DbStore: dbStore,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTestLocalStoreForAddr(path string, basekey []byte) (*LocalStore, error) {
|
func NewTestLocalStoreForAddr(path string, basekey []byte) (*LocalStore, error) {
|
||||||
hasher := MakeHashFunc("SHA3")
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
localStore := &LocalStore{
|
localStore := &LocalStore{
|
||||||
memStore: NewMemStore(dbStore, singletonSwarmDbCapacity, singletonSwarmDbCapacity),
|
memStore: NewMemStore(dbStore, defaultCacheCapacity, defaultChunkRequestsCacheCapacity),
|
||||||
DbStore: dbStore,
|
DbStore: dbStore,
|
||||||
}
|
}
|
||||||
return localStore, nil
|
return localStore, nil
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,6 @@ import (
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
defaultCacheCapacity = 5000
|
|
||||||
)
|
|
||||||
|
|
||||||
type MemStore struct {
|
type MemStore struct {
|
||||||
cache *lru.Cache
|
cache *lru.Cache
|
||||||
requests *lru.Cache
|
requests *lru.Cache
|
||||||
|
|
@ -124,7 +120,7 @@ func (m *MemStore) setCapacity(n int) {
|
||||||
if n <= 0 {
|
if n <= 0 {
|
||||||
m.disabled = true
|
m.disabled = true
|
||||||
} else {
|
} else {
|
||||||
m = NewMemStore(nil, uint(n), singletonSwarmDbCapacity)
|
m = NewMemStore(nil, uint(n), defaultChunkRequestsCacheCapacity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ package storage
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func newTestMemStore() *MemStore {
|
func newTestMemStore() *MemStore {
|
||||||
return NewMemStore(nil, defaultCacheCapacity, singletonSwarmDbCapacity)
|
return NewMemStore(nil, defaultCacheCapacity, defaultChunkRequestsCacheCapacity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMemStoreRandom(n int, processors int, chunksize int, t *testing.T) {
|
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)
|
path := filepath.Join(datadir, DbDirName)
|
||||||
basekey := make([]byte, 32)
|
basekey := make([]byte, 32)
|
||||||
hasher := MakeHashFunc(SHA3Hash)
|
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()
|
dbStore.SetTrusted()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
localStore := &LocalStore{
|
localStore := &LocalStore{
|
||||||
memStore: NewMemStore(dbStore, singletonSwarmCacheCapacity, singletonSwarmDbCapacity),
|
memStore: NewMemStore(dbStore, defaultCacheCapacity, defaultChunkRequestsCacheCapacity),
|
||||||
DbStore: dbStore,
|
DbStore: dbStore,
|
||||||
}
|
}
|
||||||
resourceChunkStore := NewResourceChunkStore(localStore, nil)
|
resourceChunkStore := NewResourceChunkStore(localStore, nil)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue