github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/xact/xs/wanted_lso.go (about)

     1  // Package xs contains most of the supported eXtended actions (xactions) with some
     2  // exceptions that include certain storage services (mirror, EC) and extensions (downloader, lru).
     3  /*
     4   * Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved.
     5   */
     6  package xs
     7  
     8  import (
     9  	"fmt"
    10  
    11  	"github.com/NVIDIA/aistore/api/apc"
    12  	"github.com/NVIDIA/aistore/cmn"
    13  	"github.com/NVIDIA/aistore/cmn/cos"
    14  	"github.com/NVIDIA/aistore/cmn/debug"
    15  	"github.com/NVIDIA/aistore/core"
    16  )
    17  
    18  // `apc.LsoMsg` flags
    19  
    20  var (
    21  	allmap map[string]cos.BitFlags
    22  )
    23  
    24  func init() {
    25  	allmap = make(map[string]cos.BitFlags, len(apc.GetPropsAll))
    26  	for i, n := range apc.GetPropsAll {
    27  		allmap[n] = cos.BitFlags(1) << i
    28  	}
    29  }
    30  
    31  func wanted(msg *apc.LsoMsg) (flags cos.BitFlags) {
    32  	for prop, fl := range allmap {
    33  		if msg.WantProp(prop) {
    34  			flags = flags.Set(fl)
    35  		}
    36  	}
    37  	return
    38  }
    39  
    40  func (wi *walkInfo) setWanted(e *cmn.LsoEnt, lom *core.LOM) {
    41  	var (
    42  		custom  = e.Custom
    43  		version = e.Version
    44  	)
    45  	for name, fl := range allmap {
    46  		if !wi.wanted.IsSet(fl) {
    47  			continue
    48  		}
    49  		switch name {
    50  		case apc.GetPropsName:
    51  		case apc.GetPropsStatus:
    52  		case apc.GetPropsCached: // via obj.SetPresent()
    53  
    54  		case apc.GetPropsSize:
    55  			if e.Size > 0 && lom.SizeBytes() != e.Size {
    56  				e.SetVerChanged()
    57  			}
    58  			e.Size = lom.SizeBytes()
    59  		case apc.GetPropsVersion:
    60  			e.Version = lom.Version()
    61  		case apc.GetPropsChecksum:
    62  			e.Checksum = lom.Checksum().Value()
    63  		case apc.GetPropsAtime:
    64  			e.Atime = cos.FormatNanoTime(lom.AtimeUnix(), wi.msg.TimeFormat)
    65  		case apc.GetPropsLocation:
    66  			e.Location = lom.Location()
    67  		case apc.GetPropsCopies:
    68  			e.Copies = int16(lom.NumCopies())
    69  
    70  		case apc.GetPropsEC:
    71  			// TODO?: risk of significant slow-down loading EC metafiles
    72  		case apc.GetPropsCustom:
    73  			if md := lom.GetCustomMD(); len(md) > 0 {
    74  				e.Custom = fmt.Sprintf("%+v", md)
    75  			}
    76  		default:
    77  			debug.Assert(false, name)
    78  		}
    79  	}
    80  	if wi.msg.IsFlagSet(apc.LsVerChanged) && !e.IsVerChanged() {
    81  		// slow path: extensive version-changed check
    82  		md := cmn.S2CustomMD(custom, version)
    83  		if len(md) > 0 {
    84  			var oa cmn.ObjAttrs
    85  			oa.CustomMD = md
    86  			oa.Size = e.Size
    87  			if !lom.Equal(&oa) {
    88  				e.SetVerChanged()
    89  			}
    90  		}
    91  	}
    92  }