Updated ref counting to remove accessed shards from the list of ones to close. Updated the close to close as many as it takes to get below the leve

pull/301/head
Paul Dix 2014-03-06 18:18:09 -05:00 committed by John Shahid
parent e39508f834
commit afd2d8c9be
1 changed files with 5 additions and 2 deletions

View File

@ -133,8 +133,11 @@ func (self *LevelDbShardDatastore) GetOrCreateShard(id uint32) (cluster.LocalSha
func (self *LevelDbShardDatastore) incrementShardRefCountAndCloseOldestIfNeeded(id uint32) {
self.shardRefCounts[id] += 1
delete(self.shardsToClose, id)
if self.maxOpenShards > 0 && len(self.shards) > self.maxOpenShards {
self.closeOldestShard()
for i := len(self.shards) - self.maxOpenShards; i > 0; i-- {
self.closeOldestShard()
}
}
}
@ -188,7 +191,7 @@ func (self *LevelDbShardDatastore) closeOldestShard() {
var oldestId uint32
oldestAccess := int64(math.MaxInt64)
for id, lastAccess := range self.lastAccess {
if lastAccess < oldestAccess {
if lastAccess < oldestAccess && self.shardsToClose[id] == false {
oldestId = id
oldestAccess = lastAccess
}