Fix race in findGenerations

It was possible that the findGenerations could get stuck returning
no files even when generations existed on disk.
pull/8420/head
Jason Wilder 2017-05-23 12:05:47 -06:00
parent 5619946b85
commit 4e582f297a
1 changed files with 3 additions and 4 deletions

View File

@ -492,10 +492,11 @@ func (c *DefaultPlanner) Plan(lastWrite time.Time) []CompactionGroup {
// findGenerations groups all the TSM files by generation based
// on their filename, then returns the generations in descending order (newest first).
func (c *DefaultPlanner) findGenerations() tsmGenerations {
c.mu.RLock()
c.mu.Lock()
defer c.mu.Unlock()
last := c.lastFindGenerations
lastGen := c.lastGenerations
c.mu.RUnlock()
if !last.IsZero() && c.FileStore.LastModified().Equal(last) {
return lastGen
@ -525,10 +526,8 @@ func (c *DefaultPlanner) findGenerations() tsmGenerations {
sort.Sort(orderedGenerations)
}
c.mu.Lock()
c.lastFindGenerations = genTime
c.lastGenerations = orderedGenerations
c.mu.Unlock()
return orderedGenerations
}