Compare commits
1 Commits
main
...
urlcache_e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc1bb58598 |
@ -3,6 +3,7 @@ package drive
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
@ -18,6 +19,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
urlCacheDriveItemThreshold = 300 * 1000
|
urlCacheDriveItemThreshold = 300 * 1000
|
||||||
urlCacheRefreshInterval = 1 * time.Hour
|
urlCacheRefreshInterval = 1 * time.Hour
|
||||||
|
maxRefreshFailuresAllowed = 3
|
||||||
)
|
)
|
||||||
|
|
||||||
type getItemPropertyer interface {
|
type getItemPropertyer interface {
|
||||||
@ -36,20 +38,19 @@ var _ getItemPropertyer = &urlCache{}
|
|||||||
|
|
||||||
// urlCache caches download URLs for drive items
|
// urlCache caches download URLs for drive items
|
||||||
type urlCache struct {
|
type urlCache struct {
|
||||||
driveID string
|
driveID string
|
||||||
prevDelta string
|
prevDelta string
|
||||||
idToProps map[string]itemProps
|
idToProps map[string]itemProps
|
||||||
lastRefreshTime time.Time
|
lastRefreshTime time.Time
|
||||||
refreshInterval time.Duration
|
refreshInterval time.Duration
|
||||||
|
refreshFailureCount int64
|
||||||
// cacheMu protects idToProps and lastRefreshTime
|
// cacheMu protects idToProps and lastRefreshTime
|
||||||
cacheMu sync.RWMutex
|
cacheMu sync.RWMutex
|
||||||
// refreshMu serializes cache refresh attempts by potential writers
|
// refreshMu serializes cache refresh attempts by potential writers
|
||||||
refreshMu sync.Mutex
|
refreshMu sync.Mutex
|
||||||
deltaQueryCount int
|
deltaQueryCount int
|
||||||
|
itemPager api.DriveItemDeltaEnumerator
|
||||||
itemPager api.DriveItemDeltaEnumerator
|
errs *fault.Bus
|
||||||
|
|
||||||
errs *fault.Bus
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// newURLache creates a new URL cache for the specified drive ID
|
// newURLache creates a new URL cache for the specified drive ID
|
||||||
@ -109,11 +110,17 @@ func (uc *urlCache) getItemProperties(
|
|||||||
return itemProps{}, clues.New("item id is empty")
|
return itemProps{}, clues.New("item id is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if atomic.LoadInt64(&uc.refreshFailureCount) > maxRefreshFailuresAllowed {
|
||||||
|
return itemProps{}, clues.New("url cache in failed state")
|
||||||
|
}
|
||||||
|
|
||||||
ctx = clues.Add(ctx, "drive_id", uc.driveID)
|
ctx = clues.Add(ctx, "drive_id", uc.driveID)
|
||||||
|
|
||||||
if uc.needsRefresh() {
|
if uc.needsRefresh() {
|
||||||
err := uc.refreshCache(ctx)
|
err := uc.refreshCache(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
atomic.AddInt64(&uc.refreshFailureCount, 1)
|
||||||
|
|
||||||
return itemProps{}, err
|
return itemProps{}, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user