github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/ais/backend/common.go (about)

     1  // Package backend contains implementation of various backend providers.
     2  /*
     3   * Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
     4   */
     5  package backend
     6  
     7  import (
     8  	"net/http"
     9  	"time"
    10  
    11  	"github.com/NVIDIA/aistore/api/apc"
    12  	"github.com/NVIDIA/aistore/cmn"
    13  	"github.com/NVIDIA/aistore/cmn/debug"
    14  	"github.com/NVIDIA/aistore/core"
    15  	"github.com/NVIDIA/aistore/core/meta"
    16  	"github.com/NVIDIA/aistore/fs"
    17  )
    18  
    19  type base struct {
    20  	provider string
    21  }
    22  
    23  func (b *base) Provider() string { return b.provider }
    24  
    25  func (b *base) CreateBucket(_ *meta.Bck) (int, error) {
    26  	return http.StatusNotImplemented, cmn.NewErrUnsupp("create", b.provider+" bucket")
    27  }
    28  
    29  func newErrInventory(provider string) error {
    30  	return cmn.NewErrUnsupp("list "+provider+" backend objects via", "bucket inventory")
    31  }
    32  
    33  func (b *base) GetBucketInv(*meta.Bck, *core.LsoInvCtx) (int, error) {
    34  	return 0, newErrInventory(b.provider)
    35  }
    36  
    37  func (b *base) ListObjectsInv(*meta.Bck, *apc.LsoMsg, *cmn.LsoRes, *core.LsoInvCtx) error {
    38  	return newErrInventory(b.provider)
    39  }
    40  
    41  //
    42  // common helpers and misc
    43  //
    44  
    45  func fmtTime(t time.Time) string { return t.Format(time.RFC3339) }
    46  
    47  func calcPageSize(pageSize, maxPageSize int64) int64 {
    48  	debug.Assert(pageSize >= 0, pageSize)
    49  	if pageSize == 0 {
    50  		return maxPageSize
    51  	}
    52  	return min(pageSize, maxPageSize)
    53  }
    54  
    55  //nolint:deadcode,unused // used by dummy backends
    56  func newErrInitBackend(provider string) error { return &cmn.ErrInitBackend{Provider: provider} }
    57  
    58  func allocPutParams(res core.GetReaderResult, owt cmn.OWT) *core.PutParams {
    59  	params := core.AllocPutParams()
    60  	{
    61  		params.WorkTag = fs.WorkfileColdget
    62  		params.Reader = res.R
    63  		params.OWT = owt
    64  		params.Cksum = res.ExpCksum
    65  		params.Size = res.Size
    66  		params.Atime = time.Now()
    67  		params.ColdGET = true
    68  	}
    69  	return params
    70  }