Don't replace caches that are receiving updates (#10834)

Keep caches while they are receiving updates.
Move update code to separate function.
master
Klaus Post 4 years ago committed by GitHub
parent d1e1205036
commit bd77f29fc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      cmd/metacache-bucket.go
  2. 27
      cmd/metacache.go

@ -372,24 +372,7 @@ func (b *bucketMetacache) updateCacheEntry(update metacache) (metacache, error)
logger.Info("updateCacheEntry: bucket %s list id %v not found", b.bucket, update.id)
return update, errFileNotFound
}
existing.lastUpdate = UTCNow()
if existing.status == scanStateStarted && update.status == scanStateSuccess {
existing.ended = UTCNow()
existing.endedCycle = update.endedCycle
}
if existing.status == scanStateStarted && update.status != scanStateStarted {
existing.status = update.status
}
if existing.error == "" && update.error != "" {
existing.error = update.error
existing.status = scanStateError
existing.ended = UTCNow()
}
existing.fileNotFound = existing.fileNotFound || update.fileNotFound
existing.update(update)
b.caches[update.id] = existing
b.updated = true
return existing, nil

@ -99,8 +99,11 @@ func (m *metacache) canBeReplacedBy(other *metacache) bool {
if other.status == scanStateNone || other.status == scanStateError {
return false
}
if m.status == scanStateStarted && time.Since(m.lastUpdate) < metacacheMaxRunningAge {
return false
}
// Keep it around a bit longer.
if time.Since(m.lastHandout) < time.Hour {
if time.Since(m.lastHandout) < time.Hour || time.Since(m.lastUpdate) < metacacheMaxRunningAge {
return false
}
@ -138,6 +141,28 @@ func baseDirFromPrefix(prefix string) string {
return b
}
// update cache with new status.
// The updates are conditional so multiple callers can update with different states.
func (m *metacache) update(update metacache) {
m.lastUpdate = UTCNow()
if m.status == scanStateStarted && update.status == scanStateSuccess {
m.ended = UTCNow()
m.endedCycle = update.endedCycle
}
if m.status == scanStateStarted && update.status != scanStateStarted {
m.status = update.status
}
if m.error == "" && update.error != "" {
m.error = update.error
m.status = scanStateError
m.ended = UTCNow()
}
m.fileNotFound = m.fileNotFound || update.fileNotFound
}
// delete all cache data on disks.
func (m *metacache) delete(ctx context.Context) {
if m.bucket == "" || m.id == "" {

Loading…
Cancel
Save