summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandomChars <random@chars.jp>2021-10-16 15:48:18 +0900
committerRandomChars <random@chars.jp>2021-10-16 15:48:18 +0900
commit2b855c42c33e91820f14720f699c92017826afe2 (patch)
tree03868ca2573006d0185815f30bea1bfdd469a9ab
parentd4954821575ddf3f8dfc05ddbd54e2a98e6d393f (diff)
safe concurrent access and (transparent) creation of page DBsv1.4.3
-rw-r--r--store/page.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/store/page.go b/store/page.go
index 937b195..8a1a623 100644
--- a/store/page.go
+++ b/store/page.go
@@ -12,10 +12,18 @@ const PageSize = 64
// pageDB returns leveldb of page variant and creates it as required.
func (s *Store) pageDB(variant string) *leveldb.DB {
+ l := s.getLock("pageDB_get")
+ l.RLock()
+ defer l.RUnlock()
+
if s.pageldb[variant] != nil {
return s.pageldb[variant]
} else {
+ l.RUnlock()
+ l.Lock()
if db, err := leveldb.OpenFile(s.PageVariantPath(variant), nil); err != nil {
+ l.Unlock()
+ l.RLock()
s.fatalClose(fmt.Sprintf("Error opening leveldb for page variant %s, %s", variant, err))
} else {
s.pageldb[variant] = db
@@ -23,6 +31,8 @@ func (s *Store) pageDB(variant string) *leveldb.DB {
log.Infof("Page variant %s created.", variant)
s.pageSetTotalCountNoDestroy(variant, 0)
}
+ l.Unlock()
+ l.RLock()
return db
}
}