diff --git a/swarm/storage/dbstore.go b/swarm/storage/dbstore.go index 4ddebb0217..f5d124d297 100644 --- a/swarm/storage/dbstore.go +++ b/swarm/storage/dbstore.go @@ -408,7 +408,7 @@ func (s *DbStore) getEntryCnt() uint64 { return s.entryCnt } -func (s *DbStore) close() { +func (s *DbStore) Close() { s.db.Close() } diff --git a/swarm/storage/dbstore_test.go b/swarm/storage/dbstore_test.go index 3d2b5bc36f..ddce7ccfea 100644 --- a/swarm/storage/dbstore_test.go +++ b/swarm/storage/dbstore_test.go @@ -38,7 +38,7 @@ func initDbStore(t *testing.T) *DbStore { func testDbStore(l int64, branches int64, t *testing.T) { m := initDbStore(t) - defer m.close() + defer m.Close() testStore(m, l, branches, t) } @@ -64,7 +64,7 @@ func TestDbStore2_100_(t *testing.T) { func TestDbStoreNotFound(t *testing.T) { m := initDbStore(t) - defer m.close() + defer m.Close() _, err := m.Get(ZeroKey) if err != notFound { t.Errorf("Expected notFound, got %v", err) @@ -73,7 +73,7 @@ func TestDbStoreNotFound(t *testing.T) { func TestDbStoreSyncIterator(t *testing.T) { m := initDbStore(t) - defer m.close() + defer m.Close() keys := []Key{ Key(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000")), Key(common.Hex2Bytes("4000000000000000000000000000000000000000000000000000000000000000")), diff --git a/swarm/storage/dpa.go b/swarm/storage/dpa.go index 31b6c54ac2..7b3e23cac2 100644 --- a/swarm/storage/dpa.go +++ b/swarm/storage/dpa.go @@ -237,3 +237,8 @@ func (self *dpaChunkStore) Put(entry *Chunk) { self.n++ self.netStore.Put(chunk) } + +// Close chunk store +func (self *dpaChunkStore) Close() { + return +} diff --git a/swarm/storage/localstore.go b/swarm/storage/localstore.go index 541462f0c4..14827e3618 100644 --- a/swarm/storage/localstore.go +++ b/swarm/storage/localstore.go @@ -72,3 +72,8 @@ func (self *LocalStore) Get(key Key) (chunk *Chunk, err error) { self.memStore.Put(chunk) return } + +// Close local store +func (self *LocalStore) Close() { + return +} diff --git a/swarm/storage/memstore.go b/swarm/storage/memstore.go index f133bd7d31..e55abb45fc 100644 --- a/swarm/storage/memstore.go +++ b/swarm/storage/memstore.go @@ -314,3 +314,8 @@ func (s *MemStore) removeOldest() { } } } + +// Close memstore +func (s *MemStore) Close() { + return +} diff --git a/swarm/storage/netstore.go b/swarm/storage/netstore.go index f97862bbbd..46479b58a5 100644 --- a/swarm/storage/netstore.go +++ b/swarm/storage/netstore.go @@ -132,3 +132,8 @@ func (self *NetStore) Get(key Key) (*Chunk, error) { go self.cloud.Retrieve(chunk) return chunk, nil } + +// Close netstore +func (self *NetStore) Close() { + return +} diff --git a/swarm/storage/types.go b/swarm/storage/types.go index f3ab99c6c8..cc5ded931d 100644 --- a/swarm/storage/types.go +++ b/swarm/storage/types.go @@ -167,6 +167,7 @@ The ChunkStore interface is implemented by : type ChunkStore interface { Put(*Chunk) // effectively there is no error even if there is an error Get(Key) (*Chunk, error) + Close() } /* diff --git a/swarm/swarm.go b/swarm/swarm.go index 4b3621affc..eab01f036c 100644 --- a/swarm/swarm.go +++ b/swarm/swarm.go @@ -54,6 +54,7 @@ type Swarm struct { privateKey *ecdsa.PrivateKey corsString string swapEnabled bool + lstore *storage.LocalStore // local store, needs to store for releasing resources after node stopped } type SwarmAPI struct { @@ -90,7 +91,7 @@ func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api. glog.V(logger.Debug).Infof("Setting up Swarm service components") hash := storage.MakeHashFunc(config.ChunkerParams.Hash) - lstore, err := storage.NewLocalStore(hash, config.StoreParams) + self.lstore, err = storage.NewLocalStore(hash, config.StoreParams) if err != nil { return } @@ -98,7 +99,7 @@ func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api. // setup local store glog.V(logger.Debug).Infof("Set up local storage") - self.dbAccess = network.NewDbAccess(lstore) + self.dbAccess = network.NewDbAccess(self.lstore) glog.V(logger.Debug).Infof("Set up local db access (iterator/counter)") // set up the kademlia hive @@ -115,15 +116,15 @@ func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api. glog.V(logger.Debug).Infof("-> set swarm forwarder as cloud storage backend") // setup cloud storage internal access layer - self.storage = storage.NewNetStore(hash, lstore, cloud, config.StoreParams) + self.storage = storage.NewNetStore(hash, self.lstore, cloud, config.StoreParams) glog.V(logger.Debug).Infof("-> swarm net store shared access layer to Swarm Chunk Store") // set up Depo (storage handler = cloud storage access layer for incoming remote requests) - self.depo = network.NewDepo(hash, lstore, self.storage) + self.depo = network.NewDepo(hash, self.lstore, self.storage) glog.V(logger.Debug).Infof("-> REmote Access to CHunks") // set up DPA, the cloud storage local access layer - dpaChunkStore := storage.NewDpaChunkStore(lstore, self.storage) + dpaChunkStore := storage.NewDpaChunkStore(self.lstore, self.storage) glog.V(logger.Debug).Infof("-> Local Access to Swarm") // Swarm Hash Merklised Chunking for Arbitrary-length Document/File storage self.dpa = storage.NewDPA(dpaChunkStore, self.config.ChunkerParams) @@ -212,6 +213,11 @@ func (self *Swarm) Stop() error { ch.Stop() ch.Save() } + + if self.lstore != nil { + self.lstore.DbStore.Close() + } + return self.config.Save() }