Skip to content

Commit b252589

Browse files
committed
ethdb: remove Flush
1 parent d581dfe commit b252589

File tree

4 files changed

+10
-51
lines changed

4 files changed

+10
-51
lines changed

eth/backend.go

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,6 @@ type Ethereum struct {
213213
chainDb ethdb.Database // Block chain database
214214
dappDb ethdb.Database // Dapp database
215215

216-
// Closed when databases are flushed and closed
217-
databasesClosed chan bool
218-
219216
//*** SERVICES ***
220217
// State manager for processing new blocks and managing the over all states
221218
blockProcessor *core.BlockProcessor
@@ -337,7 +334,6 @@ func New(config *Config) (*Ethereum, error) {
337334

338335
eth := &Ethereum{
339336
shutdownChan: make(chan bool),
340-
databasesClosed: make(chan bool),
341337
chainDb: chainDb,
342338
dappDb: dappDb,
343339
eventMux: &event.TypeMux{},
@@ -549,8 +545,6 @@ func (s *Ethereum) Start() error {
549545
if err != nil {
550546
return err
551547
}
552-
// periodically flush databases
553-
go s.syncDatabases()
554548

555549
if s.AutoDAG {
556550
s.StartAutoDAG()
@@ -566,32 +560,6 @@ func (s *Ethereum) Start() error {
566560
return nil
567561
}
568562

569-
// sync databases every minute. If flushing fails we exit immediatly. The system
570-
// may not continue under any circumstances.
571-
func (s *Ethereum) syncDatabases() {
572-
ticker := time.NewTicker(1 * time.Minute)
573-
done:
574-
for {
575-
select {
576-
case <-ticker.C:
577-
// don't change the order of database flushes
578-
if err := s.dappDb.Flush(); err != nil {
579-
glog.Fatalf("fatal error: flush dappDb: %v (Restart your node. We are aware of this issue)\n", err)
580-
}
581-
if err := s.chainDb.Flush(); err != nil {
582-
glog.Fatalf("fatal error: flush chainDb: %v (Restart your node. We are aware of this issue)\n", err)
583-
}
584-
case <-s.shutdownChan:
585-
break done
586-
}
587-
}
588-
589-
s.chainDb.Close()
590-
s.dappDb.Close()
591-
592-
close(s.databasesClosed)
593-
}
594-
595563
func (s *Ethereum) StartForTest() {
596564
jsonlogger.LogJson(&logger.LogStarting{
597565
ClientString: s.net.Name,
@@ -622,12 +590,13 @@ func (s *Ethereum) Stop() {
622590
}
623591
s.StopAutoDAG()
624592

593+
s.chainDb.Close()
594+
s.dappDb.Close()
625595
close(s.shutdownChan)
626596
}
627597

628598
// This function will wait for a shutdown and resumes main thread execution
629599
func (s *Ethereum) WaitForShutdown() {
630-
<-s.databasesClosed
631600
<-s.shutdownChan
632601
}
633602

ethdb/database.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ type LDBDatabase struct {
6161
quitChan chan chan error // Quit channel to stop the metrics collection before closing the database
6262
}
6363

64-
// NewLDBDatabase returns a LevelDB wrapped object. LDBDatabase does not persist data by
65-
// it self but requires a background poller which syncs every X. `Flush` should be called
66-
// when data needs to be stored and written to disk.
64+
// NewLDBDatabase returns a LevelDB wrapped object.
6765
func NewLDBDatabase(file string, cache int) (*LDBDatabase, error) {
6866
// Calculate the cache allowance for this particular database
6967
cache = int(float64(cache) * cacheRatio[filepath.Base(file)])
@@ -142,11 +140,6 @@ func (self *LDBDatabase) NewIterator() iterator.Iterator {
142140
return self.db.NewIterator(nil, nil)
143141
}
144142

145-
// Flush flushes out the queue to leveldb
146-
func (self *LDBDatabase) Flush() error {
147-
return nil
148-
}
149-
150143
func (self *LDBDatabase) Close() {
151144
// Stop the metrics collection to avoid internal database races
152145
self.quitLock.Lock()
@@ -159,12 +152,14 @@ func (self *LDBDatabase) Close() {
159152
glog.V(logger.Error).Infof("metrics failure in '%s': %v\n", self.fn, err)
160153
}
161154
}
162-
// Flush and close the database
163-
if err := self.Flush(); err != nil {
164-
glog.V(logger.Error).Infof("flushing '%s' failed: %v\n", self.fn, err)
155+
err := self.db.Close()
156+
if glog.V(logger.Error) {
157+
if err == nil {
158+
glog.Infoln("closed db:", self.fn)
159+
} else {
160+
glog.Errorf("error closing db %s: %v", self.fn, err)
161+
}
165162
}
166-
self.db.Close()
167-
glog.V(logger.Error).Infoln("flushed and closed db:", self.fn)
168163
}
169164

170165
func (self *LDBDatabase) LDB() *leveldb.DB {

ethdb/interface.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ type Database interface {
2121
Get(key []byte) ([]byte, error)
2222
Delete(key []byte) error
2323
Close()
24-
Flush() error
2524
NewBatch() Batch
2625
}
2726

ethdb/memory_database.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ func (db *MemDatabase) LastKnownTD() []byte {
9191
return data
9292
}
9393

94-
func (db *MemDatabase) Flush() error {
95-
return nil
96-
}
97-
9894
func (db *MemDatabase) NewBatch() Batch {
9995
return &memBatch{db: db}
10096
}

0 commit comments

Comments
 (0)