github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/cmn/owt.go (about)

     1  // Package cmn provides common constants, types, and utilities for AIS clients
     2  // and AIStore.
     3  /*
     4   * Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
     5   */
     6  package cmn
     7  
     8  import (
     9  	"strconv"
    10  
    11  	"github.com/NVIDIA/aistore/cmn/debug"
    12  )
    13  
    14  // Object Write Transaction (OWT) controls certain aspects of creating new objects in the cluster.
    15  // In particular, OwtGet* group below simultaneously specifies cold-GET variations
    16  // (that all involve reading from a remote backend) and the associated locking
    17  // (that will always reflect a tradeoff between consistency and parallelism)
    18  // NOTE: enum entries' order is important
    19  type OWT int
    20  
    21  const (
    22  	// PUT and PUT-like transactions
    23  	OwtPut       OWT = iota // PUT
    24  	OwtPromote              // promote target-accessible files and directories
    25  	OwtArchive              // multi-obj arch
    26  	OwtTransform            // ETL
    27  	OwtCopy                 // copy and move objects within cluster
    28  	OwtRebalance            // NOTE: must be the last in PUT* group
    29  	//
    30  	// GET and friends
    31  	//
    32  	OwtGetTryLock      // if !try-lock(exclusive) { return error }; read from remote; ...
    33  	OwtGetLock         // lock(exclusive); read from remote; ...
    34  	OwtGet             // GET (with upgrading read-lock in the local-write path)
    35  	OwtGetPrefetchLock // (used for maximum parallelism when prefetching)
    36  	//
    37  	// None of the above
    38  	//
    39  	OwtNone
    40  )
    41  
    42  func (owt *OWT) FromS(s string) {
    43  	n, err := strconv.Atoi(s)
    44  	debug.AssertNoErr(err)
    45  	*owt = OWT(n)
    46  }
    47  
    48  func (owt OWT) ToS() (s string) { return strconv.Itoa(int(owt)) }
    49  
    50  func (owt OWT) String() (s string) {
    51  	switch owt {
    52  	case OwtPut:
    53  		s = "owt-put"
    54  	case OwtPromote:
    55  		s = "owt-promote"
    56  	case OwtArchive:
    57  		s = "owt-archive"
    58  	case OwtTransform:
    59  		s = "owt-transform"
    60  	case OwtCopy:
    61  		s = "owt-copy"
    62  	case OwtRebalance:
    63  		s = "owt-rebalance"
    64  	case OwtGetTryLock:
    65  		s = "owt-get-try-lock"
    66  	case OwtGetLock:
    67  		s = "owt-get-lock"
    68  	case OwtGet:
    69  		s = "owt-get"
    70  	case OwtGetPrefetchLock:
    71  		s = "owt-prefetch-lock"
    72  	case OwtNone:
    73  		s = "owt-none"
    74  	default:
    75  		debug.Assert(false)
    76  	}
    77  	return
    78  }