Skip to content

Commit 6dd27e7

Browse files
mchusovlianovfjl
authored andcommitted
swarm/storage: release chunk storage after stop swarm (ethereum#3651)
closes ethereum#3650
1 parent fa99986 commit 6dd27e7

File tree

8 files changed

+36
-9
lines changed

8 files changed

+36
-9
lines changed

swarm/storage/dbstore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ func (s *DbStore) getEntryCnt() uint64 {
408408
return s.entryCnt
409409
}
410410

411-
func (s *DbStore) close() {
411+
func (s *DbStore) Close() {
412412
s.db.Close()
413413
}
414414

swarm/storage/dbstore_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func initDbStore(t *testing.T) *DbStore {
3838

3939
func testDbStore(l int64, branches int64, t *testing.T) {
4040
m := initDbStore(t)
41-
defer m.close()
41+
defer m.Close()
4242
testStore(m, l, branches, t)
4343
}
4444

@@ -64,7 +64,7 @@ func TestDbStore2_100_(t *testing.T) {
6464

6565
func TestDbStoreNotFound(t *testing.T) {
6666
m := initDbStore(t)
67-
defer m.close()
67+
defer m.Close()
6868
_, err := m.Get(ZeroKey)
6969
if err != notFound {
7070
t.Errorf("Expected notFound, got %v", err)
@@ -73,7 +73,7 @@ func TestDbStoreNotFound(t *testing.T) {
7373

7474
func TestDbStoreSyncIterator(t *testing.T) {
7575
m := initDbStore(t)
76-
defer m.close()
76+
defer m.Close()
7777
keys := []Key{
7878
Key(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000")),
7979
Key(common.Hex2Bytes("4000000000000000000000000000000000000000000000000000000000000000")),

swarm/storage/dpa.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,8 @@ func (self *dpaChunkStore) Put(entry *Chunk) {
237237
self.n++
238238
self.netStore.Put(chunk)
239239
}
240+
241+
// Close chunk store
242+
func (self *dpaChunkStore) Close() {
243+
return
244+
}

swarm/storage/localstore.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,8 @@ func (self *LocalStore) Get(key Key) (chunk *Chunk, err error) {
7272
self.memStore.Put(chunk)
7373
return
7474
}
75+
76+
// Close local store
77+
func (self *LocalStore) Close() {
78+
return
79+
}

swarm/storage/memstore.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,8 @@ func (s *MemStore) removeOldest() {
314314
}
315315
}
316316
}
317+
318+
// Close memstore
319+
func (s *MemStore) Close() {
320+
return
321+
}

swarm/storage/netstore.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,8 @@ func (self *NetStore) Get(key Key) (*Chunk, error) {
132132
go self.cloud.Retrieve(chunk)
133133
return chunk, nil
134134
}
135+
136+
// Close netstore
137+
func (self *NetStore) Close() {
138+
return
139+
}

swarm/storage/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ The ChunkStore interface is implemented by :
167167
type ChunkStore interface {
168168
Put(*Chunk) // effectively there is no error even if there is an error
169169
Get(Key) (*Chunk, error)
170+
Close()
170171
}
171172

172173
/*

swarm/swarm.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type Swarm struct {
5454
privateKey *ecdsa.PrivateKey
5555
corsString string
5656
swapEnabled bool
57+
lstore *storage.LocalStore // local store, needs to store for releasing resources after node stopped
5758
}
5859

5960
type SwarmAPI struct {
@@ -90,15 +91,15 @@ func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api.
9091
glog.V(logger.Debug).Infof("Setting up Swarm service components")
9192

9293
hash := storage.MakeHashFunc(config.ChunkerParams.Hash)
93-
lstore, err := storage.NewLocalStore(hash, config.StoreParams)
94+
self.lstore, err = storage.NewLocalStore(hash, config.StoreParams)
9495
if err != nil {
9596
return
9697
}
9798

9899
// setup local store
99100
glog.V(logger.Debug).Infof("Set up local storage")
100101

101-
self.dbAccess = network.NewDbAccess(lstore)
102+
self.dbAccess = network.NewDbAccess(self.lstore)
102103
glog.V(logger.Debug).Infof("Set up local db access (iterator/counter)")
103104

104105
// set up the kademlia hive
@@ -115,15 +116,15 @@ func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api.
115116
glog.V(logger.Debug).Infof("-> set swarm forwarder as cloud storage backend")
116117
// setup cloud storage internal access layer
117118

118-
self.storage = storage.NewNetStore(hash, lstore, cloud, config.StoreParams)
119+
self.storage = storage.NewNetStore(hash, self.lstore, cloud, config.StoreParams)
119120
glog.V(logger.Debug).Infof("-> swarm net store shared access layer to Swarm Chunk Store")
120121

121122
// set up Depo (storage handler = cloud storage access layer for incoming remote requests)
122-
self.depo = network.NewDepo(hash, lstore, self.storage)
123+
self.depo = network.NewDepo(hash, self.lstore, self.storage)
123124
glog.V(logger.Debug).Infof("-> REmote Access to CHunks")
124125

125126
// set up DPA, the cloud storage local access layer
126-
dpaChunkStore := storage.NewDpaChunkStore(lstore, self.storage)
127+
dpaChunkStore := storage.NewDpaChunkStore(self.lstore, self.storage)
127128
glog.V(logger.Debug).Infof("-> Local Access to Swarm")
128129
// Swarm Hash Merklised Chunking for Arbitrary-length Document/File storage
129130
self.dpa = storage.NewDPA(dpaChunkStore, self.config.ChunkerParams)
@@ -212,6 +213,11 @@ func (self *Swarm) Stop() error {
212213
ch.Stop()
213214
ch.Save()
214215
}
216+
217+
if self.lstore != nil {
218+
self.lstore.DbStore.Close()
219+
}
220+
215221
return self.config.Save()
216222
}
217223

0 commit comments

Comments
 (0)