mirror of
https://github.com/minio/minio.git
synced 2025-03-31 17:53:43 -04:00
Don't replace caches that are receiving updates (#10834)
Keep caches while they are receiving updates. Move update code to separate function.
This commit is contained in:
parent
d1e1205036
commit
bd77f29fc4
@ -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)
|
logger.Info("updateCacheEntry: bucket %s list id %v not found", b.bucket, update.id)
|
||||||
return update, errFileNotFound
|
return update, errFileNotFound
|
||||||
}
|
}
|
||||||
|
existing.update(update)
|
||||||
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
|
|
||||||
b.caches[update.id] = existing
|
b.caches[update.id] = existing
|
||||||
b.updated = true
|
b.updated = true
|
||||||
return existing, nil
|
return existing, nil
|
||||||
|
@ -99,8 +99,11 @@ func (m *metacache) canBeReplacedBy(other *metacache) bool {
|
|||||||
if other.status == scanStateNone || other.status == scanStateError {
|
if other.status == scanStateNone || other.status == scanStateError {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if m.status == scanStateStarted && time.Since(m.lastUpdate) < metacacheMaxRunningAge {
|
||||||
|
return false
|
||||||
|
}
|
||||||
// Keep it around a bit longer.
|
// 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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,6 +141,28 @@ func baseDirFromPrefix(prefix string) string {
|
|||||||
return b
|
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.
|
// delete all cache data on disks.
|
||||||
func (m *metacache) delete(ctx context.Context) {
|
func (m *metacache) delete(ctx context.Context) {
|
||||||
if m.bucket == "" || m.id == "" {
|
if m.bucket == "" || m.id == "" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user