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

     1  // Package xs is a collection of eXtended actions (xactions), including multi-object
     2  // operations, list-objects, (cluster) rebalance and (target) resilver, ETL, and more.
     3  /*
     4   * Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
     5   */
     6  package xs
     7  
     8  import (
     9  	"sync"
    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  	"github.com/NVIDIA/aistore/core/meta"
    17  	"github.com/NVIDIA/aistore/xact"
    18  	"github.com/NVIDIA/aistore/xact/xreg"
    19  )
    20  
    21  type (
    22  	evdFactory struct {
    23  		xreg.RenewBase
    24  		xctn *evictDelete
    25  		msg  *apc.ListRange
    26  		kind string
    27  	}
    28  	evictDelete struct {
    29  		lriterator
    30  		xact.Base
    31  		config *cmn.Config
    32  	}
    33  )
    34  
    35  //
    36  // evict/delete; utilizes mult-object lr-iterator
    37  //
    38  
    39  func (p *evdFactory) New(args xreg.Args, bck *meta.Bck) xreg.Renewable {
    40  	msg := args.Custom.(*apc.ListRange)
    41  	debug.Assert(!msg.IsList() || !msg.HasTemplate())
    42  	np := &evdFactory{RenewBase: xreg.RenewBase{Args: args, Bck: bck}, kind: p.kind, msg: msg}
    43  	return np
    44  }
    45  
    46  func (p *evdFactory) Start() (err error) {
    47  	p.xctn, err = newEvictDelete(&p.Args, p.kind, p.Bck, p.msg)
    48  	return err
    49  }
    50  
    51  func (p *evdFactory) Kind() string   { return p.kind }
    52  func (p *evdFactory) Get() core.Xact { return p.xctn }
    53  
    54  func (*evdFactory) WhenPrevIsRunning(xreg.Renewable) (xreg.WPR, error) {
    55  	return xreg.WprKeepAndStartNew, nil
    56  }
    57  
    58  func newEvictDelete(xargs *xreg.Args, kind string, bck *meta.Bck, msg *apc.ListRange) (ed *evictDelete, err error) {
    59  	ed = &evictDelete{config: cmn.GCO.Get()}
    60  	if err = ed.lriterator.init(ed, msg, bck); err != nil {
    61  		return nil, err
    62  	}
    63  	ed.InitBase(xargs.UUID, kind, bck)
    64  	return ed, nil
    65  }
    66  
    67  func (r *evictDelete) Run(wg *sync.WaitGroup) {
    68  	wg.Done()
    69  	err := r.lriterator.run(r, core.T.Sowner().Get())
    70  	if err != nil {
    71  		r.AddErr(err, 5, cos.SmoduleXs) // duplicated?
    72  	}
    73  	r.lriterator.wait()
    74  	r.Finish()
    75  }
    76  
    77  func (r *evictDelete) do(lom *core.LOM, lrit *lriterator) {
    78  	ecode, err := core.T.DeleteObject(lom, r.Kind() == apc.ActEvictObjects)
    79  	if err == nil { // done
    80  		r.ObjsAdd(1, lom.SizeBytes(true))
    81  		return
    82  	}
    83  	if cos.IsNotExist(err, ecode) || cmn.IsErrObjNought(err) {
    84  		if lrit.lrp == lrpList {
    85  			goto eret // unlike range and prefix
    86  		}
    87  		return
    88  	}
    89  eret:
    90  	r.AddErr(err, 5, cos.SmoduleXs)
    91  }
    92  
    93  func (r *evictDelete) Snap() (snap *core.Snap) {
    94  	snap = &core.Snap{}
    95  	r.ToSnap(snap)
    96  
    97  	snap.IdleX = r.IsIdle()
    98  	return
    99  }