mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
Merge pull request #279 from ethersphere/rename-dbstore-to-LDBStore
rename DbStore to LDBStore
This commit is contained in:
commit
a2ff1aa879
9 changed files with 47 additions and 47 deletions
|
|
@ -35,7 +35,7 @@ func dbExport(ctx *cli.Context) {
|
||||||
utils.Fatalf("invalid arguments, please specify both <chunkdb> (path to a local chunk database), <file> (path to write the tar archive to, - for stdout) and the base key")
|
utils.Fatalf("invalid arguments, please specify both <chunkdb> (path to a local chunk database), <file> (path to write the tar archive to, - for stdout) and the base key")
|
||||||
}
|
}
|
||||||
|
|
||||||
store, err := openDbStore(args[0], common.Hex2Bytes(args[2]))
|
store, err := openLDBStore(args[0], common.Hex2Bytes(args[2]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Fatalf("error opening local chunk database: %s", err)
|
utils.Fatalf("error opening local chunk database: %s", err)
|
||||||
}
|
}
|
||||||
|
|
@ -67,7 +67,7 @@ func dbImport(ctx *cli.Context) {
|
||||||
utils.Fatalf("invalid arguments, please specify both <chunkdb> (path to a local chunk database), <file> (path to read the tar archive from, - for stdin) and the base key")
|
utils.Fatalf("invalid arguments, please specify both <chunkdb> (path to a local chunk database), <file> (path to read the tar archive from, - for stdin) and the base key")
|
||||||
}
|
}
|
||||||
|
|
||||||
store, err := openDbStore(args[0], common.Hex2Bytes(args[2]))
|
store, err := openLDBStore(args[0], common.Hex2Bytes(args[2]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Fatalf("error opening local chunk database: %s", err)
|
utils.Fatalf("error opening local chunk database: %s", err)
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +99,7 @@ func dbClean(ctx *cli.Context) {
|
||||||
utils.Fatalf("invalid arguments, please specify <chunkdb> (path to a local chunk database) and the base key")
|
utils.Fatalf("invalid arguments, please specify <chunkdb> (path to a local chunk database) and the base key")
|
||||||
}
|
}
|
||||||
|
|
||||||
store, err := openDbStore(args[0], common.Hex2Bytes(args[1]))
|
store, err := openLDBStore(args[0], common.Hex2Bytes(args[1]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Fatalf("error opening local chunk database: %s", err)
|
utils.Fatalf("error opening local chunk database: %s", err)
|
||||||
}
|
}
|
||||||
|
|
@ -108,10 +108,10 @@ func dbClean(ctx *cli.Context) {
|
||||||
store.Cleanup()
|
store.Cleanup()
|
||||||
}
|
}
|
||||||
|
|
||||||
func openDbStore(path string, basekey []byte) (*storage.DbStore, error) {
|
func openLDBStore(path string, basekey []byte) (*storage.LDBStore, error) {
|
||||||
if _, err := os.Stat(filepath.Join(path, "CURRENT")); err != nil {
|
if _, err := os.Stat(filepath.Join(path, "CURRENT")); err != nil {
|
||||||
return nil, fmt.Errorf("invalid chunkdb path: %s", err)
|
return nil, fmt.Errorf("invalid chunkdb path: %s", err)
|
||||||
}
|
}
|
||||||
hash := storage.MakeHashFunc("SHA3")
|
hash := storage.MakeHashFunc("SHA3")
|
||||||
return storage.NewDbStore(path, hash, 10000000, func(k storage.Key) (ret uint8) { return uint8(storage.Proximity(basekey[:], k[:])) })
|
return storage.NewLDBStore(path, hash, 10000000, func(k storage.Key) (ret uint8) { return uint8(storage.Proximity(basekey[:], k[:])) })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,12 @@ package storage
|
||||||
|
|
||||||
// wrapper of db-s to provide mockable custom local chunk store access to syncer
|
// wrapper of db-s to provide mockable custom local chunk store access to syncer
|
||||||
type DBAPI struct {
|
type DBAPI struct {
|
||||||
db *DbStore
|
db *LDBStore
|
||||||
loc *LocalStore
|
loc *LocalStore
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDBAPI(loc *LocalStore) *DBAPI {
|
func NewDBAPI(loc *LocalStore) *DBAPI {
|
||||||
return &DBAPI{loc.DbStore.(*DbStore), loc}
|
return &DBAPI{loc.DbStore.(*LDBStore), loc}
|
||||||
}
|
}
|
||||||
|
|
||||||
// to obtain the chunks from key or request db entry only
|
// to obtain the chunks from key or request db entry only
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ func NewLocalDPA(datadir string, basekey []byte) (*DPA, error) {
|
||||||
|
|
||||||
hash := MakeHashFunc("SHA3")
|
hash := MakeHashFunc("SHA3")
|
||||||
|
|
||||||
dbStore, err := NewDbStore(datadir, hash, singletonSwarmDbCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) })
|
dbStore, err := NewLDBStore(datadir, hash, singletonSwarmDbCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) })
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ func TestDPArandom(t *testing.T) {
|
||||||
t.Fatalf("init dbStore failed: %v", err)
|
t.Fatalf("init dbStore failed: %v", err)
|
||||||
}
|
}
|
||||||
defer tdb.close()
|
defer tdb.close()
|
||||||
db := tdb.DbStore
|
db := tdb.LDBStore
|
||||||
db.setCapacity(50000)
|
db.setCapacity(50000)
|
||||||
memStore := NewMemStore(db, defaultCacheCapacity)
|
memStore := NewMemStore(db, defaultCacheCapacity)
|
||||||
localStore := &LocalStore{
|
localStore := &LocalStore{
|
||||||
|
|
@ -91,7 +91,7 @@ func TestDPA_capacity(t *testing.T) {
|
||||||
t.Fatalf("init dbStore failed: %v", err)
|
t.Fatalf("init dbStore failed: %v", err)
|
||||||
}
|
}
|
||||||
defer tdb.close()
|
defer tdb.close()
|
||||||
db := tdb.DbStore
|
db := tdb.LDBStore
|
||||||
memStore := NewMemStore(db, 0)
|
memStore := NewMemStore(db, 0)
|
||||||
localStore := &LocalStore{
|
localStore := &LocalStore{
|
||||||
memStore,
|
memStore,
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ type gcItem struct {
|
||||||
idxKey []byte
|
idxKey []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
type DbStore struct {
|
type LDBStore struct {
|
||||||
db *LDBDatabase
|
db *LDBDatabase
|
||||||
|
|
||||||
// this should be stored in db, accessed transactionally
|
// this should be stored in db, accessed transactionally
|
||||||
|
|
@ -106,8 +106,8 @@ type DbStore struct {
|
||||||
// TODO: Instead of passing the distance function, just pass the address from which distances are calculated
|
// TODO: Instead of passing the distance function, just pass the address from which distances are calculated
|
||||||
// to avoid the appearance of a pluggable distance metric and opportunities of bugs associated with providing
|
// to avoid the appearance of a pluggable distance metric and opportunities of bugs associated with providing
|
||||||
// a function different from the one that is actually used.
|
// a function different from the one that is actually used.
|
||||||
func NewDbStore(path string, hash SwarmHasher, capacity uint64, po func(Key) uint8) (s *DbStore, err error) {
|
func NewLDBStore(path string, hash SwarmHasher, capacity uint64, po func(Key) uint8) (s *LDBStore, err error) {
|
||||||
s = new(DbStore)
|
s = new(LDBStore)
|
||||||
s.hashfunc = hash
|
s.hashfunc = hash
|
||||||
|
|
||||||
s.batchC = make(chan bool)
|
s.batchC = make(chan bool)
|
||||||
|
|
@ -158,8 +158,8 @@ func NewDbStore(path string, hash SwarmHasher, capacity uint64, po func(Key) uin
|
||||||
// NewMockDbStore creates a new instance of DbStore with
|
// NewMockDbStore creates a new instance of DbStore with
|
||||||
// mockStore set to a provided value. If mockStore argument is nil,
|
// mockStore set to a provided value. If mockStore argument is nil,
|
||||||
// this function behaves exactly as NewDbStore.
|
// this function behaves exactly as NewDbStore.
|
||||||
func NewMockDbStore(path string, hash SwarmHasher, capacity uint64, po func(Key) uint8, mockStore *mock.NodeStore) (s *DbStore, err error) {
|
func NewMockDbStore(path string, hash SwarmHasher, capacity uint64, po func(Key) uint8, mockStore *mock.NodeStore) (s *LDBStore, err error) {
|
||||||
s, err = NewDbStore(path, hash, capacity, po)
|
s, err = NewLDBStore(path, hash, capacity, po)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -195,7 +195,7 @@ func getIndexGCValue(index *dpaDBIndex) uint64 {
|
||||||
return index.Access
|
return index.Access
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DbStore) updateIndexAccess(index *dpaDBIndex) {
|
func (s *LDBStore) updateIndexAccess(index *dpaDBIndex) {
|
||||||
index.Access = s.accessCnt
|
index.Access = s.accessCnt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -286,7 +286,7 @@ func gcListSelect(list []*gcItem, left int, right int, n int) int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DbStore) collectGarbage(ratio float32) {
|
func (s *LDBStore) collectGarbage(ratio float32) {
|
||||||
it := s.db.NewIterator()
|
it := s.db.NewIterator()
|
||||||
it.Seek(s.gcPos)
|
it.Seek(s.gcPos)
|
||||||
if it.Valid() {
|
if it.Valid() {
|
||||||
|
|
@ -345,7 +345,7 @@ func (s *DbStore) collectGarbage(ratio float32) {
|
||||||
|
|
||||||
// Export writes all chunks from the store to a tar archive, returning the
|
// Export writes all chunks from the store to a tar archive, returning the
|
||||||
// number of chunks written.
|
// number of chunks written.
|
||||||
func (s *DbStore) Export(out io.Writer) (int64, error) {
|
func (s *LDBStore) Export(out io.Writer) (int64, error) {
|
||||||
tw := tar.NewWriter(out)
|
tw := tar.NewWriter(out)
|
||||||
defer tw.Close()
|
defer tw.Close()
|
||||||
|
|
||||||
|
|
@ -387,7 +387,7 @@ func (s *DbStore) Export(out io.Writer) (int64, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// of chunks read.
|
// of chunks read.
|
||||||
func (s *DbStore) Import(in io.Reader) (int64, error) {
|
func (s *LDBStore) Import(in io.Reader) (int64, error) {
|
||||||
tr := tar.NewReader(in)
|
tr := tar.NewReader(in)
|
||||||
|
|
||||||
var count int64
|
var count int64
|
||||||
|
|
@ -429,7 +429,7 @@ func (s *DbStore) Import(in io.Reader) (int64, error) {
|
||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DbStore) Cleanup() {
|
func (s *LDBStore) Cleanup() {
|
||||||
//Iterates over the database and checks that there are no faulty chunks
|
//Iterates over the database and checks that there are no faulty chunks
|
||||||
it := s.db.NewIterator()
|
it := s.db.NewIterator()
|
||||||
startPosition := []byte{kpIndex}
|
startPosition := []byte{kpIndex}
|
||||||
|
|
@ -468,7 +468,7 @@ func (s *DbStore) Cleanup() {
|
||||||
log.Warn(fmt.Sprintf("Found %v errors out of %v entries", errorsFound, total))
|
log.Warn(fmt.Sprintf("Found %v errors out of %v entries", errorsFound, total))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DbStore) ReIndex() {
|
func (s *LDBStore) ReIndex() {
|
||||||
//Iterates over the database and checks that there are no faulty chunks
|
//Iterates over the database and checks that there are no faulty chunks
|
||||||
it := s.db.NewIterator()
|
it := s.db.NewIterator()
|
||||||
startPosition := []byte{keyOldData}
|
startPosition := []byte{keyOldData}
|
||||||
|
|
@ -511,7 +511,7 @@ func (s *DbStore) ReIndex() {
|
||||||
log.Warn(fmt.Sprintf("Found %v errors out of %v entries", errorsFound, total))
|
log.Warn(fmt.Sprintf("Found %v errors out of %v entries", errorsFound, total))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DbStore) delete(idx uint64, idxKey []byte, po uint8) {
|
func (s *LDBStore) delete(idx uint64, idxKey []byte, po uint8) {
|
||||||
batch := new(leveldb.Batch)
|
batch := new(leveldb.Batch)
|
||||||
batch.Delete(idxKey)
|
batch.Delete(idxKey)
|
||||||
batch.Delete(getDataKey(idx, po))
|
batch.Delete(getDataKey(idx, po))
|
||||||
|
|
@ -526,26 +526,26 @@ func (s *DbStore) delete(idx uint64, idxKey []byte, po uint8) {
|
||||||
s.db.Write(batch)
|
s.db.Write(batch)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DbStore) CurrentBucketStorageIndex(po uint8) uint64 {
|
func (s *LDBStore) CurrentBucketStorageIndex(po uint8) uint64 {
|
||||||
s.lock.RLock()
|
s.lock.RLock()
|
||||||
defer s.lock.RUnlock()
|
defer s.lock.RUnlock()
|
||||||
|
|
||||||
return s.bucketCnt[po]
|
return s.bucketCnt[po]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DbStore) Size() uint64 {
|
func (s *LDBStore) Size() uint64 {
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
defer s.lock.Unlock()
|
defer s.lock.Unlock()
|
||||||
return s.entryCnt
|
return s.entryCnt
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DbStore) CurrentStorageIndex() uint64 {
|
func (s *LDBStore) CurrentStorageIndex() uint64 {
|
||||||
s.lock.RLock()
|
s.lock.RLock()
|
||||||
defer s.lock.RUnlock()
|
defer s.lock.RUnlock()
|
||||||
return s.dataIdx
|
return s.dataIdx
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DbStore) Put(chunk *Chunk) {
|
func (s *LDBStore) Put(chunk *Chunk) {
|
||||||
ikey := getIndexKey(chunk.Key)
|
ikey := getIndexKey(chunk.Key)
|
||||||
var index dpaDBIndex
|
var index dpaDBIndex
|
||||||
|
|
||||||
|
|
@ -577,7 +577,7 @@ func (s *DbStore) Put(chunk *Chunk) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// force putting into db, does not check access index
|
// force putting into db, does not check access index
|
||||||
func (s *DbStore) doPut(chunk *Chunk, ikey []byte, index *dpaDBIndex, po uint8) {
|
func (s *LDBStore) doPut(chunk *Chunk, ikey []byte, index *dpaDBIndex, po uint8) {
|
||||||
data := s.encodeDataFunc(chunk)
|
data := s.encodeDataFunc(chunk)
|
||||||
s.batch.Put(getDataKey(s.dataIdx, po), data)
|
s.batch.Put(getDataKey(s.dataIdx, po), data)
|
||||||
index.Idx = s.dataIdx
|
index.Idx = s.dataIdx
|
||||||
|
|
@ -592,7 +592,7 @@ func (s *DbStore) doPut(chunk *Chunk, ikey []byte, index *dpaDBIndex, po uint8)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DbStore) writeBatches() {
|
func (s *LDBStore) writeBatches() {
|
||||||
for range s.batchesC {
|
for range s.batchesC {
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
b := s.batch
|
b := s.batch
|
||||||
|
|
@ -618,7 +618,7 @@ func (s *DbStore) writeBatches() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// must be called non concurrently
|
// must be called non concurrently
|
||||||
func (s *DbStore) writeBatch(b *leveldb.Batch, entryCnt, dataIdx, accessCnt uint64) error {
|
func (s *LDBStore) writeBatch(b *leveldb.Batch, entryCnt, dataIdx, accessCnt uint64) error {
|
||||||
b.Put(keyEntryCnt, U64ToBytes(entryCnt))
|
b.Put(keyEntryCnt, U64ToBytes(entryCnt))
|
||||||
b.Put(keyDataIdx, U64ToBytes(dataIdx))
|
b.Put(keyDataIdx, U64ToBytes(dataIdx))
|
||||||
b.Put(keyAccessCnt, U64ToBytes(accessCnt))
|
b.Put(keyAccessCnt, U64ToBytes(accessCnt))
|
||||||
|
|
@ -644,7 +644,7 @@ func newMockEncodeDataFunc(mockStore *mock.NodeStore) func(chunk *Chunk) []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to find index; if found, update access cnt and return true
|
// try to find index; if found, update access cnt and return true
|
||||||
func (s *DbStore) tryAccessIdx(ikey []byte, index *dpaDBIndex) bool {
|
func (s *LDBStore) tryAccessIdx(ikey []byte, index *dpaDBIndex) bool {
|
||||||
idata, err := s.db.Get(ikey)
|
idata, err := s.db.Get(ikey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
|
|
@ -658,13 +658,13 @@ func (s *DbStore) tryAccessIdx(ikey []byte, index *dpaDBIndex) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DbStore) Get(key Key) (chunk *Chunk, err error) {
|
func (s *LDBStore) Get(key Key) (chunk *Chunk, err error) {
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
defer s.lock.Unlock()
|
defer s.lock.Unlock()
|
||||||
return s.get(key)
|
return s.get(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DbStore) get(key Key) (chunk *Chunk, err error) {
|
func (s *LDBStore) get(key Key) (chunk *Chunk, err error) {
|
||||||
var indx dpaDBIndex
|
var indx dpaDBIndex
|
||||||
|
|
||||||
if s.tryAccessIdx(getIndexKey(key), &indx) {
|
if s.tryAccessIdx(getIndexKey(key), &indx) {
|
||||||
|
|
@ -724,7 +724,7 @@ func newMockGetDataFunc(mockStore *mock.NodeStore) func(key Key) (data []byte, e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DbStore) updateAccessCnt(key Key) {
|
func (s *LDBStore) updateAccessCnt(key Key) {
|
||||||
|
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
defer s.lock.Unlock()
|
defer s.lock.Unlock()
|
||||||
|
|
@ -734,7 +734,7 @@ func (s *DbStore) updateAccessCnt(key Key) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DbStore) setCapacity(c uint64) {
|
func (s *LDBStore) setCapacity(c uint64) {
|
||||||
|
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
defer s.lock.Unlock()
|
defer s.lock.Unlock()
|
||||||
|
|
@ -755,12 +755,12 @@ func (s *DbStore) setCapacity(c uint64) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DbStore) Close() {
|
func (s *LDBStore) Close() {
|
||||||
s.db.Close()
|
s.db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SyncIterator(start, stop, po, f) calls f on each hash of a bin po from start to stop
|
// SyncIterator(start, stop, po, f) calls f on each hash of a bin po from start to stop
|
||||||
func (s *DbStore) SyncIterator(since uint64, until uint64, po uint8, f func(Key, uint64) bool) error {
|
func (s *LDBStore) SyncIterator(since uint64, until uint64, po uint8, f func(Key, uint64) bool) error {
|
||||||
sincekey := getDataKey(since, po)
|
sincekey := getDataKey(since, po)
|
||||||
untilkey := getDataKey(until, po)
|
untilkey := getDataKey(until, po)
|
||||||
it := s.db.NewIterator()
|
it := s.db.NewIterator()
|
||||||
|
|
@ -30,7 +30,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type testDbStore struct {
|
type testDbStore struct {
|
||||||
*DbStore
|
*LDBStore
|
||||||
dir string
|
dir string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,7 +40,7 @@ func newTestDbStore(mock bool) (*testDbStore, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var db *DbStore
|
var db *LDBStore
|
||||||
if mock {
|
if mock {
|
||||||
globalStore := mem.NewGlobalStore()
|
globalStore := mem.NewGlobalStore()
|
||||||
addr := common.HexToAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed")
|
addr := common.HexToAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed")
|
||||||
|
|
@ -48,7 +48,7 @@ func newTestDbStore(mock bool) (*testDbStore, error) {
|
||||||
|
|
||||||
db, err = NewMockDbStore(dir, MakeHashFunc(SHA3Hash), defaultDbCapacity, testPoFunc, mockStore)
|
db, err = NewMockDbStore(dir, MakeHashFunc(SHA3Hash), defaultDbCapacity, testPoFunc, mockStore)
|
||||||
} else {
|
} else {
|
||||||
db, err = NewDbStore(dir, MakeHashFunc(SHA3Hash), defaultDbCapacity, testPoFunc)
|
db, err = NewLDBStore(dir, MakeHashFunc(SHA3Hash), defaultDbCapacity, testPoFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &testDbStore{db, dir}, err
|
return &testDbStore{db, dir}, err
|
||||||
|
|
@ -66,7 +66,7 @@ func NewLocalStore(hash SwarmHasher, params *StoreParams, basekey []byte, mockSt
|
||||||
func NewTestLocalStore(path string) (*LocalStore, error) {
|
func NewTestLocalStore(path string) (*LocalStore, error) {
|
||||||
basekey := make([]byte, 32)
|
basekey := make([]byte, 32)
|
||||||
hasher := MakeHashFunc("SHA3")
|
hasher := MakeHashFunc("SHA3")
|
||||||
dbStore, err := NewDbStore(path, hasher, singletonSwarmDbCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) })
|
dbStore, err := NewLDBStore(path, hasher, singletonSwarmDbCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) })
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -79,7 +79,7 @@ func NewTestLocalStore(path string) (*LocalStore, error) {
|
||||||
|
|
||||||
func NewTestLocalStoreForAddr(path string, basekey []byte) (*LocalStore, error) {
|
func NewTestLocalStoreForAddr(path string, basekey []byte) (*LocalStore, error) {
|
||||||
hasher := MakeHashFunc("SHA3")
|
hasher := MakeHashFunc("SHA3")
|
||||||
dbStore, err := NewDbStore(path, hasher, singletonSwarmDbCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) })
|
dbStore, err := NewLDBStore(path, hasher, singletonSwarmDbCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) })
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ type MemStore struct {
|
||||||
entryCnt, capacity uint // stored entries
|
entryCnt, capacity uint // stored entries
|
||||||
accessCnt uint64 // access counter; oldest is thrown away when full
|
accessCnt uint64 // access counter; oldest is thrown away when full
|
||||||
dbAccessCnt uint64
|
dbAccessCnt uint64
|
||||||
dbStore *DbStore
|
ldbStore *LDBStore
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,10 +61,10 @@ a hash prefix subtree containing subtrees or one storage entry (but never both)
|
||||||
(access[] is a binary tree inside the multi-bit leveled hash tree)
|
(access[] is a binary tree inside the multi-bit leveled hash tree)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func NewMemStore(d *DbStore, capacity uint) (m *MemStore) {
|
func NewMemStore(d *LDBStore, capacity uint) (m *MemStore) {
|
||||||
m = &MemStore{}
|
m = &MemStore{}
|
||||||
m.memtree = newMemTree(memTreeFLW, nil, 0)
|
m.memtree = newMemTree(memTreeFLW, nil, 0)
|
||||||
m.dbStore = d
|
m.ldbStore = d
|
||||||
m.setCapacity(capacity)
|
m.setCapacity(capacity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -240,8 +240,8 @@ func (s *MemStore) Get(hash Key) (chunk *Chunk, err error) {
|
||||||
if s.dbAccessCnt-node.lastDBaccess > dbForceUpdateAccessCnt {
|
if s.dbAccessCnt-node.lastDBaccess > dbForceUpdateAccessCnt {
|
||||||
s.dbAccessCnt++
|
s.dbAccessCnt++
|
||||||
node.lastDBaccess = s.dbAccessCnt
|
node.lastDBaccess = s.dbAccessCnt
|
||||||
if s.dbStore != nil {
|
if s.ldbStore != nil {
|
||||||
s.dbStore.updateAccessCnt(hash)
|
s.ldbStore.updateAccessCnt(hash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -870,7 +870,7 @@ 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 := NewDbStore(path, hasher, singletonSwarmDbCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) })
|
dbStore, err := NewLDBStore(path, hasher, singletonSwarmDbCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) })
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue