fix - change private api from ui (#829)

This commit is contained in:
Alex Sharov 2020-07-30 17:17:09 +07:00 committed by GitHub
parent 8c8433302e
commit 6c4ec563e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -115,15 +115,11 @@ func (opts lmdbOpts) Open() (KV, error) {
} }
if !opts.inMem { if !opts.inMem {
ctx, ctxCancel := context.WithCancel(context.Background()) if staleReaders, err := db.env.ReaderCheck(); err != nil {
db.stopStaleReadsCheck = ctxCancel db.log.Error("failed ReaderCheck", "err", err)
db.wg.Add(1) } else if staleReaders > 0 {
go func() { db.log.Debug("cleared reader slots from dead processes", "amount", staleReaders)
defer db.wg.Done() }
ticker := time.NewTicker(time.Minute)
defer ticker.Stop()
db.staleReadsCheckLoop(ctx, ticker)
}()
} }
return db, nil return db, nil
@ -160,35 +156,9 @@ func NewLMDB() lmdbOpts {
return lmdbOpts{} return lmdbOpts{}
} }
// staleReadsCheckLoop - In any real application it is important to check for readers that were
// never closed by their owning process, and for which the owning process
// has exited. See the documentation on transactions for more information.
func (db *LmdbKV) staleReadsCheckLoop(ctx context.Context, ticker *time.Ticker) {
for db.env != nil {
// check once on app start
staleReaders, err2 := db.env.ReaderCheck()
if err2 != nil {
db.log.Error("failed ReaderCheck", "err", err2)
}
if staleReaders > 0 {
db.log.Info("cleared reader slots from dead processes", "amount", staleReaders)
}
select {
case <-ctx.Done():
return
case <-ticker.C:
}
}
}
// Close closes db // Close closes db
// All transactions must be closed before closing the database. // All transactions must be closed before closing the database.
func (db *LmdbKV) Close() { func (db *LmdbKV) Close() {
if db.stopStaleReadsCheck != nil {
db.stopStaleReadsCheck()
}
if db.env != nil { if db.env != nil {
db.wg.Wait() db.wg.Wait()
} }