This commit is contained in:
lash 2018-02-22 14:03:10 +00:00 committed by GitHub
commit d0d3548ba5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 9 deletions

View file

@ -36,7 +36,7 @@ func testApi(t *testing.T, f func(*Api)) {
} }
os.RemoveAll(datadir) os.RemoveAll(datadir)
defer os.RemoveAll(datadir) defer os.RemoveAll(datadir)
dpa, err := storage.NewLocalDPA(datadir) dpa, err := storage.NewLocalDPA(datadir, "")
if err != nil { if err != nil {
return return
} }

View file

@ -808,7 +808,7 @@ func TestFUSE(t *testing.T) {
} }
os.RemoveAll(datadir) os.RemoveAll(datadir)
dpa, err := storage.NewLocalDPA(datadir) dpa, err := storage.NewLocalDPA(datadir, "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -93,12 +93,23 @@ func NewDbStore(path string, hash SwarmHasher, capacity uint64, radius int) (s *
s.gcStartPos[0] = kpIndex s.gcStartPos[0] = kpIndex
s.gcArray = make([]*gcItem, gcArraySize) s.gcArray = make([]*gcItem, gcArraySize)
// the database closes with pointer to last entry stored
// we increment upon open so that the last entry doesn't get overwritten
data, _ := s.db.Get(keyEntryCnt) data, _ := s.db.Get(keyEntryCnt)
s.entryCnt = BytesToU64(data) s.entryCnt = BytesToU64(data)
if len(data) > 0 {
s.entryCnt++
}
data, _ = s.db.Get(keyAccessCnt) data, _ = s.db.Get(keyAccessCnt)
s.accessCnt = BytesToU64(data) s.accessCnt = BytesToU64(data)
if len(data) > 0 {
s.accessCnt++
}
data, _ = s.db.Get(keyDataIdx) data, _ = s.db.Get(keyDataIdx)
s.dataIdx = BytesToU64(data) s.dataIdx = BytesToU64(data)
if len(data) > 0 {
s.dataIdx++
}
s.gcPos, _ = s.db.Get(keyGCPos) s.gcPos, _ = s.db.Get(keyGCPos)
if s.gcPos == nil { if s.gcPos == nil {
s.gcPos = s.gcStartPos s.gcPos = s.gcStartPos

View file

@ -63,17 +63,27 @@ type DPA struct {
} }
// for testing locally // for testing locally
func NewLocalDPA(datadir string) (*DPA, error) { func NewLocalDPA(datadir string, hashalgorithm string, dbcapacity uint64, memcapacity uint) (*DPA, error) {
hash := MakeHashFunc("SHA256") if hashalgorithm == "" {
hashalgorithm = "SHA3"
}
hash := MakeHashFunc(hashalgorithm)
dbStore, err := NewDbStore(datadir, hash, singletonSwarmDbCapacity, 0) if dbcapacity == 0 {
dbcapacity = uint64(singletonSwarmDbCapacity)
}
if memcapacity == 0 {
memcapacity = uint(singletonSwarmCacheCapacity)
}
log.Debug("LocalDPA create", "dbcap", dbcapacity, "memcap", memcapacity)
dbStore, err := NewDbStore(datadir, hash, dbcapacity, 0)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return NewDPA(&LocalStore{ return NewDPA(&LocalStore{
NewMemStore(dbStore, singletonSwarmCacheCapacity), NewMemStore(dbStore, memcapacity),
dbStore, dbStore,
}, NewChunkerParams()), nil }, NewChunkerParams()), nil
} }
@ -117,6 +127,7 @@ func (self *DPA) Start() {
func (self *DPA) Stop() { func (self *DPA) Stop() {
self.lock.Lock() self.lock.Lock()
defer self.lock.Unlock() defer self.lock.Unlock()
self.Close()
if !self.running { if !self.running {
return return
} }

View file

@ -74,4 +74,6 @@ func (self *LocalStore) Get(key Key) (chunk *Chunk, err error) {
} }
// Close local store // Close local store
func (self *LocalStore) Close() {} func (self *LocalStore) Close() {
self.DbStore.Close()
}

View file

@ -29,6 +29,10 @@ import (
"github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/crypto/sha3"
) )
const (
CHUNKSIZE = 4096
)
type Hasher func() hash.Hash type Hasher func() hash.Hash
type SwarmHasher func() SwarmHash type SwarmHasher func() SwarmHash

View file

@ -318,7 +318,7 @@ func NewLocalSwarm(datadir, port string) (self *Swarm, err error) {
config.Init(prvKey) config.Init(prvKey)
config.Port = port config.Port = port
dpa, err := storage.NewLocalDPA(datadir) dpa, err := storage.NewLocalDPA(datadir, "")
if err != nil { if err != nil {
return return
} }