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

     1  // Package dsort provides distributed massively parallel resharding for very large datasets.
     2  /*
     3   * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
     4   */
     5  package dsort
     6  
     7  import (
     8  	"sync"
     9  
    10  	"github.com/NVIDIA/aistore/api/apc"
    11  	"github.com/NVIDIA/aistore/cmn/debug"
    12  	"github.com/NVIDIA/aistore/core"
    13  	"github.com/NVIDIA/aistore/core/meta"
    14  	"github.com/NVIDIA/aistore/xact"
    15  	"github.com/NVIDIA/aistore/xact/xreg"
    16  )
    17  
    18  /////////////
    19  // factory //
    20  /////////////
    21  
    22  type (
    23  	factory struct {
    24  		xreg.RenewBase
    25  		xctn *xaction
    26  	}
    27  	xaction struct {
    28  		xact.Base
    29  		args *xreg.DsortArgs
    30  	}
    31  )
    32  
    33  func (*factory) New(args xreg.Args, _ *meta.Bck) xreg.Renewable {
    34  	return &factory{RenewBase: xreg.RenewBase{Args: args}}
    35  }
    36  
    37  func (p *factory) Start() error {
    38  	custom := p.Args.Custom
    39  	args, ok := custom.(*xreg.DsortArgs)
    40  	debug.Assert(ok)
    41  	p.xctn = &xaction{args: args}
    42  	p.xctn.InitBase(p.UUID(), apc.ActDsort, args.BckTo /*compare w/ tcb and tco*/)
    43  	return nil
    44  }
    45  
    46  func (*factory) Kind() string     { return apc.ActDsort }
    47  func (p *factory) Get() core.Xact { return p.xctn }
    48  
    49  func (*factory) WhenPrevIsRunning(xreg.Renewable) (xreg.WPR, error) {
    50  	return xreg.WprKeepAndStartNew, nil
    51  }
    52  
    53  /////////////
    54  // xaction //
    55  /////////////
    56  
    57  func (*xaction) Run(*sync.WaitGroup) { debug.Assert(false) }
    58  
    59  // NOTE: two ways to abort:
    60  // - Manager.abort(errs ...error) legacy, and
    61  // - xaction.Abort, to implement the corresponding interface and uniformly support `api.AbortXaction`
    62  func (r *xaction) Abort(err error) (ok bool) {
    63  	m, exists := Managers.Get(r.ID(), false /*incl. archived*/)
    64  	if !exists {
    65  		return
    66  	}
    67  	if aborted := m.aborted(); !aborted {
    68  		m.abort(err)
    69  		ok = m.aborted()
    70  	}
    71  	return
    72  }
    73  
    74  func (r *xaction) Snap() (snap *core.Snap) {
    75  	snap = &core.Snap{}
    76  	r.ToSnap(snap)
    77  
    78  	m, exists := Managers.Get(r.ID(), true /*incl. archived*/)
    79  	if !exists {
    80  		return
    81  	}
    82  	m.Metrics.lock()
    83  	m.Metrics.update()
    84  	m.Metrics.unlock()
    85  
    86  	snap.Ext = m.Metrics
    87  
    88  	j := m.Metrics.ToJobInfo(r.ID(), m.Pars)
    89  	snap.StartTime = j.StartedTime
    90  	snap.StartTime = j.StartedTime
    91  	snap.EndTime = j.FinishTime
    92  	snap.SrcBck = j.SrcBck
    93  	snap.DstBck = j.DstBck
    94  	snap.AbortedX = j.Aborted
    95  
    96  	return
    97  }