Use GetObjectInfo instead of GetObjectNInfo before cache decision (#6553)

This commit is contained in:
Pontus Leitzler 2018-10-03 20:02:32 +02:00 committed by Dee Koder
parent 5d859b2178
commit 307765591d
1 changed files with 11 additions and 10 deletions

View File

@ -185,16 +185,16 @@ func (c cacheObjects) getMetadata(objInfo ObjectInfo) map[string]string {
func (c cacheObjects) GetObjectNInfo(ctx context.Context, bucket, object string, rs *HTTPRangeSpec, h http.Header, lockType LockType, opts ObjectOptions) (gr *GetObjectReader, err error) { func (c cacheObjects) GetObjectNInfo(ctx context.Context, bucket, object string, rs *HTTPRangeSpec, h http.Header, lockType LockType, opts ObjectOptions) (gr *GetObjectReader, err error) {
bkReader, bkErr := c.GetObjectNInfoFn(ctx, bucket, object, rs, h, writeLock, opts) objInfo, bkErr := c.GetObjectInfoFn(ctx, bucket, object, opts)
if c.isCacheExclude(bucket, object) || !bkReader.ObjInfo.IsCacheable() { if c.isCacheExclude(bucket, object) || !objInfo.IsCacheable() {
return bkReader, bkErr return c.GetObjectNInfoFn(ctx, bucket, object, rs, h, writeLock, opts)
} }
// fetch cacheFSObjects if object is currently cached or nearest available cache drive // fetch cacheFSObjects if object is currently cached or nearest available cache drive
dcache, err := c.cache.getCachedFSLoc(ctx, bucket, object) dcache, err := c.cache.getCachedFSLoc(ctx, bucket, object)
if err != nil { if err != nil {
return bkReader, bkErr return c.GetObjectNInfoFn(ctx, bucket, object, rs, h, writeLock, opts)
} }
backendDown := backendDownError(bkErr) backendDown := backendDownError(bkErr)
@ -206,8 +206,8 @@ func (c cacheObjects) GetObjectNInfo(ctx context.Context, bucket, object string,
return nil, bkErr return nil, bkErr
} }
if !backendDown && filterFromCache(bkReader.ObjInfo.UserDefined) { if !backendDown && filterFromCache(objInfo.UserDefined) {
return bkReader, bkErr return c.GetObjectNInfoFn(ctx, bucket, object, rs, h, writeLock, opts)
} }
if cacheReader, cacheErr := dcache.GetObjectNInfo(ctx, bucket, object, rs, h, lockType, opts); cacheErr == nil { if cacheReader, cacheErr := dcache.GetObjectNInfo(ctx, bucket, object, rs, h, lockType, opts); cacheErr == nil {
@ -216,7 +216,7 @@ func (c cacheObjects) GetObjectNInfo(ctx context.Context, bucket, object string,
return cacheReader, nil return cacheReader, nil
} }
if cacheReader.ObjInfo.ETag == bkReader.ObjInfo.ETag && !isStaleCache(bkReader.ObjInfo) { if cacheReader.ObjInfo.ETag == objInfo.ETag && !isStaleCache(objInfo) {
// Object is not stale, so serve from cache // Object is not stale, so serve from cache
return cacheReader, nil return cacheReader, nil
} }
@ -230,13 +230,14 @@ func (c cacheObjects) GetObjectNInfo(ctx context.Context, bucket, object string,
if rs != nil { if rs != nil {
// We don't cache partial objects. // We don't cache partial objects.
return bkReader, bkErr return c.GetObjectNInfoFn(ctx, bucket, object, rs, h, writeLock, opts)
} }
if !dcache.diskAvailable(bkReader.ObjInfo.Size * cacheSizeMultiplier) { if !dcache.diskAvailable(objInfo.Size * cacheSizeMultiplier) {
// cache only objects < 1/100th of disk capacity // cache only objects < 1/100th of disk capacity
return bkReader, bkErr return c.GetObjectNInfoFn(ctx, bucket, object, rs, h, writeLock, opts)
} }
bkReader, bkErr := c.GetObjectNInfoFn(ctx, bucket, object, rs, h, writeLock, opts)
if bkErr != nil { if bkErr != nil {
return nil, bkErr return nil, bkErr
} }