github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/storage/types.go (about)

     1  package storage
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/filecoin-project/bacalhau/pkg/model"
     7  )
     8  
     9  // StorageProvider returns a storage that can be used by the job to store data.
    10  type StorageProvider interface {
    11  	model.Provider[model.StorageSourceType, Storage]
    12  }
    13  
    14  type Storage interface {
    15  	model.Providable
    16  
    17  	HasStorageLocally(context.Context, model.StorageSpec) (bool, error)
    18  
    19  	// how big is the given volume in terms of resource consumption?
    20  	GetVolumeSize(context.Context, model.StorageSpec) (uint64, error)
    21  
    22  	PrepareStorage(context.Context, model.StorageSpec) (StorageVolume, error)
    23  
    24  	CleanupStorage(context.Context, model.StorageSpec, StorageVolume) error
    25  
    26  	// given a local file path - "store" it and return a StorageSpec
    27  	Upload(context.Context, string) (model.StorageSpec, error)
    28  
    29  	// given a StorageSpec - explode it into a list of storage specs it contains
    30  	// each file path will be appended to the "path" of the storage spec
    31  	Explode(context.Context, model.StorageSpec) ([]model.StorageSpec, error)
    32  }
    33  
    34  // a storage entity that is consumed are produced by a job
    35  // input storage specs are turned into storage volumes by drivers
    36  // for example - the input storage spec might be ipfs cid XXX
    37  // and a driver will turn that into a host path that can be consumed by a job
    38  // another example - a wasm storage driver references the upstream ipfs
    39  // cid (source) that can be streamed via a library call using the target name
    40  // put simply - the nature of a storage volume depends on it's use by the
    41  // executor engine
    42  type StorageVolume struct {
    43  	Type   StorageVolumeConnectorType `json:"type"`
    44  	Source string                     `json:"source"`
    45  	Target string                     `json:"target"`
    46  }