From 10a367f978c6c1eac7ee23267280755e26a4df46 Mon Sep 17 00:00:00 2001 From: siddontang Date: Thu, 13 Nov 2014 13:41:07 +0800 Subject: [PATCH] rpl file store check read table keepalived --- rpl/file_store.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/rpl/file_store.go b/rpl/file_store.go index 63d287c..a8f4940 100644 --- a/rpl/file_store.go +++ b/rpl/file_store.go @@ -58,11 +58,15 @@ type FileStore struct { rs tableReaders w *tableWriter + + quit chan struct{} } func NewFileStore(base string, maxSize int64, syncType int) (*FileStore, error) { s := new(FileStore) + s.quit = make(chan struct{}) + var err error if err = os.MkdirAll(base, 0755); err != nil { @@ -88,6 +92,8 @@ func NewFileStore(base string, maxSize int64, syncType int) (*FileStore, error) s.w = newTableWriter(s.base, index, s.maxFileSize) s.w.SetSyncType(syncType) + go s.checkTableReaders() + return s, nil } @@ -244,6 +250,8 @@ func (s *FileStore) Clear() error { } func (s *FileStore) Close() error { + close(s.quit) + s.wm.Lock() s.rm.Lock() @@ -267,6 +275,27 @@ func (s *FileStore) Close() error { return nil } +func (s *FileStore) checkTableReaders() { + t := time.NewTicker(60 * time.Second) + defer t.Stop() + for { + select { + case <-t.C: + s.rm.Lock() + + for _, r := range s.rs { + if !r.Keepalived() { + r.Close() + } + } + + s.rm.Unlock() + case <-s.quit: + return + } + } +} + func (s *FileStore) load() error { fs, err := ioutil.ReadDir(s.base) if err != nil {