model

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2023 License: Apache-2.0, MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCIDEntry = errors.New("invalid CID entry in the database")
View Source
var ErrInvalidJobState = errors.New("invalid job state")
View Source
var ErrInvalidStringMapEntry = errors.New("invalid string map entry in the database")
View Source
var ErrInvalidStringSliceEntry = errors.New("invalid string slice entry in the database")
View Source
var JobTypeStrings = []string{
	string(Scan),
	string(Pack),
	string(DagGen),
}
View Source
var JobTypes = []JobType{
	Scan,
	Pack,
	DagGen,
}
View Source
var Tables = []any{
	&Worker{},
	&Global{},
	&Preparation{},
	&Storage{},
	&OutputAttachment{},
	&SourceAttachment{},
	&Job{},
	&File{},
	&FileRange{},
	&Directory{},
	&Car{},
	&CarBlock{},
	&Deal{},
	&Schedule{},
	&Wallet{},
}

Functions

func AutoMigrate

func AutoMigrate(db *gorm.DB) error

func DropAll

func DropAll(db *gorm.DB) error

func StoragePricePerEpochToPricePerDeal

func StoragePricePerEpochToPricePerDeal(price string, dealSize int64, durationEpoch int32) float64

Types

type CID

type CID cid.Cid

func (CID) MarshalBinary added in v0.2.14

func (c CID) MarshalBinary() ([]byte, error)

func (CID) MarshalJSON

func (c CID) MarshalJSON() ([]byte, error)

func (*CID) Scan

func (c *CID) Scan(src any) error

func (CID) String

func (c CID) String() string

func (*CID) UnmarshalBinary added in v0.2.14

func (c *CID) UnmarshalBinary(b []byte) error

func (*CID) UnmarshalJSON

func (c *CID) UnmarshalJSON(b []byte) error

func (CID) Value

func (c CID) Value() (driver.Value, error)

type Car

type Car struct {
	ID          uint32    `gorm:"primaryKey"                                        json:"id"                                  table:"verbose"`
	CreatedAt   time.Time `json:"createdAt"                                         table:"verbose;format:2006-01-02 15:04:05"`
	PieceCID    CID       `gorm:"column:piece_cid;index;type:bytes;size:255"        json:"pieceCid"                            swaggertype:"string"`
	PieceSize   int64     `json:"pieceSize"`
	RootCID     CID       `gorm:"column:root_cid;type:bytes"                        json:"rootCid"                             swaggertype:"string"`
	FileSize    int64     `json:"fileSize"`
	StorageID   *uint32   `json:"storageId"                                         table:"verbose"`
	Storage     *Storage  ``                   /* 135-byte string literal not displayed */
	StoragePath string    `json:"storagePath"` // StoragePath is the path to the CAR file inside the storage. If the StorageID is nil but StoragePath is not empty, it means the CAR file is stored at the local absolute path.

	// Association
	PreparationID uint32            `json:"preparationId"                                        table:"-"`
	Preparation   *Preparation      `gorm:"foreignKey:PreparationID;constraint:OnDelete:CASCADE" json:"preparation,omitempty" swaggerignore:"true" table:"-"`
	AttachmentID  *uint32           `json:"attachmentId"                                         table:"-"`
	Attachment    *SourceAttachment `gorm:"foreignKey:AttachmentID;constraint:OnDelete:CASCADE"  json:"attachment,omitempty"  swaggerignore:"true" table:"-"`
	JobID         *uint64           `json:"jobId,omitempty"                                      table:"-"`
	Job           *Job              `gorm:"foreignKey:JobID;constraint:OnDelete:SET NULL"        json:"job,omitempty"         swaggerignore:"true" table:"-"`
	// contains filtered or unexported fields
}

Car makes a reference to a CAR file that has been potentially exported to the disk. In the case of inline preparation, the path may be empty so the Car should be constructed on the fly using CarBlock. The index on PieceCID is to find all CARs that can matches the PieceCID

type CarBlock

type CarBlock struct {
	ID             uint64 `gorm:"primaryKey"                           json:"id"`
	CID            CID    `gorm:"index;column:cid;type:bytes;size:255" json:"cid" swaggertype:"string"` // CID is the CID of the block.
	CarOffset      int64  `json:"carOffset"`                                                            // Offset of the block in the Car
	CarBlockLength int32  `json:"carBlockLength"`                                                       // Length of the block in the Car, including varint, CID and raw block
	Varint         []byte `json:"varint"`                                                               // Varint is the varint that represents the length of the block and the CID.
	RawBlock       []byte `json:"rawBlock"`                                                             // Raw block
	FileOffset     int64  `json:"fileOffset"`                                                           // Offset of the block in the File

	// Associations
	CarID  uint32  `gorm:"index"                                         json:"carId"`
	Car    *Car    `gorm:"foreignKey:CarID;constraint:OnDelete:CASCADE"  json:"car,omitempty"  swaggerignore:"true"`
	FileID *uint64 `json:"fileId"`
	File   *File   `gorm:"foreignKey:FileID;constraint:OnDelete:CASCADE" json:"file,omitempty" swaggerignore:"true"`
	// contains filtered or unexported fields
}

CarBlock tells us the CIDs of all blocks inside a Car and the offset of those blocks. From this table we can determine how to get the block by CID from a Car. Or we can determine how to assemble a CAR file from blocks from File. It is also possible to get all Car that are associated with File. The index on CarID is used to find all blocks in a Car. The index on CID is used to find a specific block with CID.

func (CarBlock) BlockLength

func (c CarBlock) BlockLength() int32

BlockLength computes and returns the length of the block data in bytes. If the block length has already been calculated and stored, it returns the stored value. Otherwise, it calculates the block length based on the raw block data if it is available, or by subtracting the CID byte length and varint length from the total CarBlock length.

Returns: - An int32 representing the length of the block data in bytes.

type ConfigMap added in v0.4.0

type ConfigMap map[string]string

func (*ConfigMap) Scan added in v0.4.0

func (m *ConfigMap) Scan(src any) error

func (ConfigMap) String added in v0.4.0

func (m ConfigMap) String() string

func (ConfigMap) Value added in v0.4.0

func (m ConfigMap) Value() (driver.Value, error)

type Deal

type Deal struct {
	ID               uint64    `gorm:"primaryKey"                      json:"id"                                  table:"verbose"`
	CreatedAt        time.Time `json:"createdAt"                       table:"verbose;format:2006-01-02 15:04:05"`
	UpdatedAt        time.Time `json:"updatedAt"                       table:"verbose;format:2006-01-02 15:04:05"`
	DealID           *uint64   `gorm:"unique"                          json:"dealId"`
	State            DealState `gorm:"index:idx_pending"               json:"state"`
	Provider         string    `json:"provider"`
	ProposalID       string    `json:"proposalId"                      table:"verbose"`
	Label            string    `json:"label"                           table:"verbose"`
	PieceCID         CID       `gorm:"column:piece_cid;index;size:255" json:"pieceCid"                            swaggertype:"string"`
	PieceSize        int64     `json:"pieceSize"`
	StartEpoch       int32     `json:"startEpoch"`
	EndEpoch         int32     `json:"endEpoch"                        table:"verbose"`
	SectorStartEpoch int32     `json:"sectorStartEpoch"                table:"verbose"`
	Price            string    `json:"price"`
	Verified         bool      `json:"verified"`
	ErrorMessage     string    `json:"errorMessage"                    table:"verbose"`

	// Associations
	ScheduleID *uint32   `json:"scheduleId"                                         table:"verbose"`
	Schedule   *Schedule `gorm:"foreignKey:ScheduleID;constraint:OnDelete:SET NULL" json:"schedule,omitempty" swaggerignore:"true" table:"expand"`
	ClientID   string    `gorm:"index:idx_pending"                                  json:"clientId"`
	Wallet     *Wallet   `gorm:"foreignKey:ClientID;constraint:OnDelete:SET NULL"   json:"wallet,omitempty"   swaggerignore:"true" table:"expand"`
}

Deal is the deal model for all deals made by deal pusher or tracked by the tracker. The index on PieceCID is used to track replication of the same piece CID. The index on State and ClientID is used to calculate number and size of pending deals.

func (Deal) Key

func (d Deal) Key() string

Key returns a mostly unique key to match deal from locally proposed deals and deals from the chain.

type DealState

type DealState string
const (
	DealProposed        DealState = "proposed"
	DealPublished       DealState = "published"
	DealActive          DealState = "active"
	DealExpired         DealState = "expired"
	DealProposalExpired DealState = "proposal_expired"
	DealRejected        DealState = "rejected"
	DealSlashed         DealState = "slashed"
	DealErrored         DealState = "error"
)

type Directory

type Directory struct {
	ID       uint64 `gorm:"primaryKey"            json:"id"`
	CID      CID    `gorm:"column:cid;type:bytes" json:"cid" swaggertype:"string"` // CID is the CID of the directory.
	Data     []byte `gorm:"column:data"           json:"-"   swaggerignore:"true"` // Data is the serialized directory data.
	Name     string `json:"name"`                                                  // Name is the name of the directory.
	Exported bool   `json:"exported"`                                              // Exported is a flag that indicates whether the directory has been exported to the DAG.

	// Associations
	AttachmentID uint32            `gorm:"index:directory_source_parent"                       json:"attachmentId"`
	Attachment   *SourceAttachment `gorm:"foreignKey:AttachmentID;constraint:OnDelete:CASCADE" json:"attachment,omitempty" swaggerignore:"true"`
	ParentID     *uint64           `gorm:"index:directory_source_parent"                       json:"parentId"`
	Parent       *Directory        `gorm:"foreignKey:ParentID;constraint:OnDelete:CASCADE"     json:"parent,omitempty"     swaggerignore:"true"`
}

Directory is a link between parent and child directories. The index on AttachmentID and ParentID is used to find all root directories, as well as all directories in a directory.

type File added in v0.3.0

type File struct {
	ID               uint64 `gorm:"primaryKey"                     json:"id"`
	CID              CID    `gorm:"column:cid;type:bytes;size:255" json:"cid"  swaggertype:"string"` // CID is the CID of the file.
	Path             string `gorm:"index"                          json:"path"`                      // Path is the relative path to the file inside the storage.
	Hash             string `json:"hash"`                                                            // Hash is the hash of the file.
	Size             int64  `json:"size"`                                                            // Size is the size of the file in bytes.
	LastModifiedNano int64  `json:"lastModifiedNano"`

	// Associations
	AttachmentID uint32            `json:"attachmentId"`
	Attachment   *SourceAttachment `gorm:"foreignKey:AttachmentID;constraint:OnDelete:CASCADE" json:"attachment,omitempty" swaggerignore:"true"`
	DirectoryID  *uint64           `gorm:"index"                                               json:"directoryId"`
	Directory    *Directory        `gorm:"foreignKey:DirectoryID;constraint:OnDelete:CASCADE"  json:"directory,omitempty"  swaggerignore:"true"`
	FileRanges   []FileRange       `gorm:"constraint:OnDelete:CASCADE"                         json:"fileRanges,omitempty"`
	// contains filtered or unexported fields
}

File makes a reference to the source storage file, e.g., a local file. The index on Path is used as part of scanning to find existing file and add new versions. The index on DirectoryID is used to find all files in a directory.

func (File) FileName added in v0.4.0

func (i File) FileName() string

type FileRange added in v0.3.0

type FileRange struct {
	ID     uint64 `gorm:"primaryKey"            json:"id"`
	Offset int64  `json:"offset"`                                                // Offset is the offset of the range inside the file.
	Length int64  `json:"length"`                                                // Length is the length of the range in bytes.
	CID    CID    `gorm:"column:cid;type:bytes" json:"cid" swaggertype:"string"` // CID is the CID of the range.

	// Associations
	JobID  *uint64 `gorm:"index"                                         json:"jobId"`
	Job    *Job    `gorm:"foreignKey:JobID;constraint:OnDelete:SET NULL" json:"job,omitempty"  swaggerignore:"true"`
	FileID uint64  `gorm:"index"                                         json:"fileId"`
	File   *File   `gorm:"foreignKey:FileID;constraint:OnDelete:CASCADE" json:"file,omitempty" swaggerignore:"true"`
}

FileRange is a range of bytes inside File. The index on FileID is used to find all FileRange in a file. The index on JobID is used to find all FileRange in a job.

type Global

type Global struct {
	Key   string `gorm:"primaryKey" json:"key"`
	Value string `json:"value"`
}

type Job added in v0.4.0

type Job struct {
	ID              uint64   `gorm:"primaryKey"           json:"id"`
	Type            JobType  `gorm:"index:job_type_state" json:"type"`
	State           JobState `gorm:"index:job_type_state" json:"state"`
	ErrorMessage    string   `json:"errorMessage"`
	ErrorStackTrace string   `json:"errorStackTrace"      table:"verbose"`

	// Associations
	WorkerID     *string           `gorm:"size:63"                                                        json:"workerId,omitempty"`
	Worker       *Worker           `` /* 141-byte string literal not displayed */
	AttachmentID uint32            `json:"attachmentId"                                                   table:"verbose"`
	Attachment   *SourceAttachment `` /* 133-byte string literal not displayed */
	FileRanges   []FileRange       `` /* 128-byte string literal not displayed */
}

Job is a job that is executed by a worker. The composite index on Type and State is used to find jobs that are ready to be executed.

type JobState added in v0.4.0

type JobState string
const (
	// Created means the job has been created is not ready for processing.
	Created JobState = "created"
	// Ready means the job is ready for processing.
	Ready JobState = "ready"
	// Paused means the job is ready but has been paused and should not be picked up for processing.
	Paused JobState = "paused"
	// Processing means the job is currently being processed.
	Processing JobState = "processing"
	// Complete means the job is complete.
	Complete JobState = "complete"
	// Error means the job has some error.
	Error JobState = "error"
)

func (*JobState) Set added in v0.4.0

func (js *JobState) Set(value string) error

func (*JobState) String added in v0.4.0

func (js *JobState) String() string

type JobType added in v0.4.0

type JobType string
const (
	Scan   JobType = "scan"
	Pack   JobType = "pack"
	DagGen JobType = "daggen"
)

type OutputAttachment added in v0.4.0

type OutputAttachment struct {
	ID uint32 `gorm:"primaryKey" json:"id"`

	// Associations
	PreparationID uint32       `gorm:"uniqueIndex:prep_output"                              json:"preparationId"`
	Preparation   *Preparation `gorm:"foreignKey:PreparationID;constraint:OnDelete:CASCADE" json:"preparation,omitempty" swaggerignore:"true"`
	StorageID     uint32       `gorm:"uniqueIndex:prep_output"                              json:"storageId"`
	Storage       *Storage     `gorm:"foreignKey:StorageID;constraint:OnDelete:CASCADE"     json:"storage,omitempty"     swaggerignore:"true"`
}

OutputAttachment is a link between a Preparation and a Storage that is used as an output.

type Preparation added in v0.4.0

type Preparation struct {
	ID                uint32    `gorm:"primaryKey"        json:"id"`
	Name              string    `gorm:"unique"            json:"name"`
	CreatedAt         time.Time `json:"createdAt"         table:"verbose;format:2006-01-02 15:04:05"`
	UpdatedAt         time.Time `json:"updatedAt"         table:"verbose;format:2006-01-02 15:04:05"`
	DeleteAfterExport bool      `json:"deleteAfterExport"` // DeleteAfterExport is a flag that indicates whether the source files should be deleted after export.
	MaxSize           int64     `json:"maxSize"`
	PieceSize         int64     `json:"pieceSize"`

	// Associations
	Wallets        []Wallet  `` /* 131-byte string literal not displayed */
	SourceStorages []Storage `` /* 155-byte string literal not displayed */
	OutputStorages []Storage `` /* 155-byte string literal not displayed */
}

Preparation is a data preparation definition that can attach multiple source storages and up to one output storage.

func (*Preparation) FindByIDOrName added in v0.4.0

func (s *Preparation) FindByIDOrName(db *gorm.DB, name string, preloads ...string) error

type Schedule

type Schedule struct {
	ID                    uint32        `gorm:"primaryKey"            json:"id"`
	CreatedAt             time.Time     `json:"createdAt"             table:"verbose;format:2006-01-02 15:04:05"`
	UpdatedAt             time.Time     `json:"updatedAt"             table:"verbose;format:2006-01-02 15:04:05"`
	URLTemplate           string        `json:"urlTemplate"           table:"verbose"`
	HTTPHeaders           StringSlice   `gorm:"type:JSON"             json:"httpHeaders"                         table:"verbose"`
	Provider              string        `json:"provider"`
	PricePerGBEpoch       float64       `json:"pricePerGbEpoch"       table:"verbose"`
	PricePerGB            float64       `json:"pricePerGb"            table:"verbose"`
	PricePerDeal          float64       `json:"pricePerDeal"          table:"verbose"`
	TotalDealNumber       int           `json:"totalDealNumber"       table:"verbose"`
	TotalDealSize         int64         `json:"totalDealSize"`
	Verified              bool          `json:"verified"`
	KeepUnsealed          bool          `json:"keepUnsealed"          table:"verbose"`
	AnnounceToIPNI        bool          `json:"announceToIpni"        table:"verbose"`
	StartDelay            time.Duration `json:"startDelay"            swaggertype:"primitive,integer"`
	Duration              time.Duration `json:"duration"              swaggertype:"primitive,integer"`
	State                 ScheduleState `json:"state"`
	ScheduleCron          string        `json:"scheduleCron"`
	ScheduleCronPerpetual bool          `json:"scheduleCronPerpetual"`
	ScheduleDealNumber    int           `json:"scheduleDealNumber"`
	ScheduleDealSize      int64         `json:"scheduleDealSize"`
	MaxPendingDealNumber  int           `json:"maxPendingDealNumber"`
	MaxPendingDealSize    int64         `json:"maxPendingDealSize"`
	Notes                 string        `json:"notes"`
	ErrorMessage          string        `json:"errorMessage"          table:"verbose"`
	AllowedPieceCIDs      StringSlice   `gorm:"type:JSON"             json:"allowedPieceCids"                    table:"verbose"`

	// Associations
	PreparationID uint32       `json:"preparationId"`
	Preparation   *Preparation `gorm:"foreignKey:PreparationID;constraint:OnDelete:CASCADE" json:"preparation,omitempty" swaggerignore:"true" table:"expand"`
}

type ScheduleState

type ScheduleState string
const (
	ScheduleActive    ScheduleState = "active"
	SchedulePaused    ScheduleState = "paused"
	ScheduleError     ScheduleState = "error"
	ScheduleCompleted ScheduleState = "completed"
)

type SourceAttachment added in v0.4.0

type SourceAttachment struct {
	ID uint32 `gorm:"primaryKey" json:"id"`

	// Associations
	PreparationID   uint32       `gorm:"uniqueIndex:prep_source"                              json:"preparationId"`
	Preparation     *Preparation `gorm:"foreignKey:PreparationID;constraint:OnDelete:CASCADE" json:"preparation,omitempty" swaggerignore:"true"`
	StorageID       uint32       `gorm:"uniqueIndex:prep_source"                              json:"storageId"`
	Storage         *Storage     `gorm:"foreignKey:StorageID;constraint:OnDelete:CASCADE"     json:"storage,omitempty"     swaggerignore:"true"`
	LastScannedPath string       `json:"lastScannedPath"`
}

SourceAttachment is a link between a Preparation and a Storage that is used as a source.

func (*SourceAttachment) FindByPreparationAndSource added in v0.4.0

func (s *SourceAttachment) FindByPreparationAndSource(db *gorm.DB, preparation string, source string) error

func (*SourceAttachment) RootDirectoryCID added in v0.4.0

func (s *SourceAttachment) RootDirectoryCID(ctx context.Context, db *gorm.DB) (cid.Cid, error)

func (*SourceAttachment) RootDirectoryID added in v0.4.0

func (s *SourceAttachment) RootDirectoryID(ctx context.Context, db *gorm.DB) (uint64, error)

type Storage added in v0.4.0

type Storage struct {
	ID        uint32    `gorm:"primaryKey" json:"id"`
	Name      string    `gorm:"unique"     json:"name"`
	CreatedAt time.Time `json:"createdAt"  table:"verbose;format:2006-01-02 15:04:05"`
	UpdatedAt time.Time `json:"updatedAt"  table:"verbose;format:2006-01-02 15:04:05"`
	Type      string    `json:"type"`
	Path      string    `json:"path"`                       // Path is the path to the storage root.
	Config    ConfigMap `gorm:"type:JSON"  table:"verbose"` // Config is a map of key-value pairs that can be used to store RClone options.

	// Associations
	PreparationsAsSource []Preparation `` /* 156-byte string literal not displayed */
	PreparationsAsOutput []Preparation `` /* 156-byte string literal not displayed */
	// contains filtered or unexported fields
}

Storage is a storage system definition that can be used as either source or output of a Preparation.

func (*Storage) FindByIDOrName added in v0.4.0

func (s *Storage) FindByIDOrName(db *gorm.DB, name string, preloads ...string) error

type StringSlice

type StringSlice []string

func (*StringSlice) Scan

func (ss *StringSlice) Scan(src any) error

func (StringSlice) Value

func (ss StringSlice) Value() (driver.Value, error)

type Wallet

type Wallet struct {
	ID         string `gorm:"primaryKey;size:15"   json:"id"`      // ID is the short ID of the wallet
	Address    string `gorm:"index"                json:"address"` // Address is the Filecoin full address of the wallet
	PrivateKey string `json:"privateKey,omitempty" table:"-"`      // PrivateKey is the private key of the wallet
}

type Worker

type Worker struct {
	ID            string     `gorm:"primaryKey"    json:"id"`
	LastHeartbeat time.Time  `json:"lastHeartbeat"`
	Hostname      string     `json:"hostname"`
	Type          WorkerType `json:"type"`
}

type WorkerType added in v0.4.0

type WorkerType string
const (
	DealTracker   WorkerType = "deal_tracker"
	DealPusher    WorkerType = "deal_pusher"
	DatasetWorker WorkerType = "dataset_worker"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL