mirror of
https://github.com/minio/minio.git
synced 2024-12-25 06:35:56 -05:00
fix: potential crash in diskCache when fileScorer is empty (#13850)
``` goroutine 115 [running]: github.com/minio/minio/cmd.(*diskCache).purge.func3({0xc007a10a40, 0x40}, 0x40) github.com/minio/minio/cmd/disk-cache-backend.go:430 +0x90d ```
This commit is contained in:
parent
12b63061c2
commit
7d70afc937
@ -325,7 +325,11 @@ func (c *diskCache) purge(ctx context.Context) {
|
|||||||
expiry := UTCNow().Add(-cacheExpiryDays)
|
expiry := UTCNow().Add(-cacheExpiryDays)
|
||||||
// defaulting max hits count to 100
|
// defaulting max hits count to 100
|
||||||
// ignore error we know what value we are passing.
|
// ignore error we know what value we are passing.
|
||||||
scorer, _ := newFileScorer(toFree, time.Now().Unix(), 100)
|
scorer, err := newFileScorer(toFree, time.Now().Unix(), 100)
|
||||||
|
if err != nil {
|
||||||
|
logger.LogIf(ctx, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// this function returns FileInfo for cached range files.
|
// this function returns FileInfo for cached range files.
|
||||||
fiStatRangesFn := func(ranges map[string]string, pathPrefix string) map[string]os.FileInfo {
|
fiStatRangesFn := func(ranges map[string]string, pathPrefix string) map[string]os.FileInfo {
|
||||||
@ -388,9 +392,7 @@ func (c *diskCache) purge(ctx context.Context) {
|
|||||||
switch {
|
switch {
|
||||||
case cc != nil:
|
case cc != nil:
|
||||||
if cc.isStale(objInfo.ModTime) {
|
if cc.isStale(objInfo.ModTime) {
|
||||||
if err = removeAll(cacheDir); err != nil {
|
removeAll(cacheDir)
|
||||||
logger.LogIf(ctx, err)
|
|
||||||
}
|
|
||||||
scorer.adjustSaveBytes(-objInfo.Size)
|
scorer.adjustSaveBytes(-objInfo.Size)
|
||||||
// break early if sufficient disk space reclaimed.
|
// break early if sufficient disk space reclaimed.
|
||||||
if c.diskUsageLow() {
|
if c.diskUsageLow() {
|
||||||
@ -408,9 +410,7 @@ func (c *diskCache) purge(ctx context.Context) {
|
|||||||
for fname, fi := range cachedRngFiles {
|
for fname, fi := range cachedRngFiles {
|
||||||
if cc != nil {
|
if cc != nil {
|
||||||
if cc.isStale(objInfo.ModTime) {
|
if cc.isStale(objInfo.ModTime) {
|
||||||
if err = removeAll(fname); err != nil {
|
removeAll(fname)
|
||||||
logger.LogIf(ctx, err)
|
|
||||||
}
|
|
||||||
scorer.adjustSaveBytes(-fi.Size())
|
scorer.adjustSaveBytes(-fi.Size())
|
||||||
|
|
||||||
// break early if sufficient disk space reclaimed.
|
// break early if sufficient disk space reclaimed.
|
||||||
|
@ -419,6 +419,9 @@ func (f *fileScorer) addFileWithObjInfo(objInfo ObjectInfo, hits int) {
|
|||||||
// Returns true if there still is a need to delete files (n+saveBytes >0),
|
// Returns true if there still is a need to delete files (n+saveBytes >0),
|
||||||
// false if no more bytes needs to be saved.
|
// false if no more bytes needs to be saved.
|
||||||
func (f *fileScorer) adjustSaveBytes(n int64) bool {
|
func (f *fileScorer) adjustSaveBytes(n int64) bool {
|
||||||
|
if f == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if int64(f.saveBytes)+n <= 0 {
|
if int64(f.saveBytes)+n <= 0 {
|
||||||
f.saveBytes = 0
|
f.saveBytes = 0
|
||||||
f.trimQueue()
|
f.trimQueue()
|
||||||
|
Loading…
Reference in New Issue
Block a user