@ -85,16 +85,15 @@ type cacheObjects struct {
}
}
func ( c * cacheObjects ) incHitsToMeta ( ctx context . Context , dcache * diskCache , bucket , object string , size int64 , eTag string , rs * HTTPRangeSpec ) error {
func ( c * cacheObjects ) incHitsToMeta ( ctx context . Context , dcache * diskCache , bucket , object string , size int64 , eTag string , rs * HTTPRangeSpec ) error {
metadata := make ( map [ string ] string )
metadata := map [ string ] string { "etag" : eTag }
metadata [ "etag" ] = eTag
return dcache . SaveMetadata ( ctx , bucket , object , metadata , size , rs , "" , true )
return dcache . SaveMetadata ( ctx , bucket , object , metadata , size , rs , "" , true )
}
}
// Backend metadata could have changed through server side copy - reset cache metadata if that is the case
// Backend metadata could have changed through server side copy - reset cache metadata if that is the case
func ( c * cacheObjects ) updateMetadataIfChanged ( ctx context . Context , dcache * diskCache , bucket , object string , bkObjectInfo , cacheObjInfo ObjectInfo , rs * HTTPRangeSpec ) error {
func ( c * cacheObjects ) updateMetadataIfChanged ( ctx context . Context , dcache * diskCache , bucket , object string , bkObjectInfo , cacheObjInfo ObjectInfo , rs * HTTPRangeSpec ) error {
bkMeta := make ( map [ string ] string )
bkMeta := make ( map [ string ] string , len ( bkObjectInfo . UserDefined ) )
cacheMeta := make ( map [ string ] string )
cacheMeta := make ( map [ string ] string , len ( cacheObjInfo . UserDefined ) )
for k , v := range bkObjectInfo . UserDefined {
for k , v := range bkObjectInfo . UserDefined {
if strings . HasPrefix ( strings . ToLower ( k ) , ReservedMetadataPrefixLower ) {
if strings . HasPrefix ( strings . ToLower ( k ) , ReservedMetadataPrefixLower ) {
// Do not need to send any internal metadata
// Do not need to send any internal metadata
@ -166,7 +165,7 @@ func (c *cacheObjects) DeleteObjects(ctx context.Context, bucket string, objects
// construct a metadata k-v map
// construct a metadata k-v map
func getMetadata ( objInfo ObjectInfo ) map [ string ] string {
func getMetadata ( objInfo ObjectInfo ) map [ string ] string {
metadata := make ( map [ string ] string )
metadata := make ( map [ string ] string , len ( objInfo . UserDefined ) + 4 )
metadata [ "etag" ] = objInfo . ETag
metadata [ "etag" ] = objInfo . ETag
metadata [ "content-type" ] = objInfo . ContentType
metadata [ "content-type" ] = objInfo . ContentType
if objInfo . ContentEncoding != "" {
if objInfo . ContentEncoding != "" {
@ -334,11 +333,12 @@ func (c *cacheObjects) GetObjectNInfo(ctx context.Context, bucket, object string
// Initialize pipe.
// Initialize pipe.
pipeReader , pipeWriter := io . Pipe ( )
pipeReader , pipeWriter := io . Pipe ( )
teeReader := io . TeeReader ( bkReader , pipeWriter )
teeReader := io . TeeReader ( bkReader , pipeWriter )
userDefined := getMetadata ( bkReader . ObjInfo )
go func ( ) {
go func ( ) {
putErr := dcache . Put ( ctx , bucket , object ,
putErr := dcache . Put ( ctx , bucket , object ,
io . LimitReader ( pipeReader , bkReader . ObjInfo . Size ) ,
io . LimitReader ( pipeReader , bkReader . ObjInfo . Size ) ,
bkReader . ObjInfo . Size , nil , ObjectOptions {
bkReader . ObjInfo . Size , nil , ObjectOptions {
UserDefined : getMetadata ( bkReader . ObjInfo ) ,
UserDefined : userDefined ,
} , false )
} , false )
// close the write end of the pipe, so the error gets
// close the write end of the pipe, so the error gets
// propagated to getObjReader
// propagated to getObjReader