metabase

package
v1.34.2 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: AGPL-3.0 Imports: 33 Imported by: 9

Documentation

Overview

Package metabase implements storing objects and segements.

Index

Constants

View Source
const (
	Delimiter        = '/'
	LastSegmentName  = "l"
	LastSegmentIndex = uint32(math.MaxUint32)
)

Common constants for segment keys.

View Source
const (
	// Pending means that the object is being uploaded or that the client failed during upload.
	// The failed upload may be continued in the future.
	Pending = ObjectStatus(1)
	// Committed means that the object is finished and should be visible for general listing.
	Committed = ObjectStatus(3)
)
View Source
const MaxListLimit = 1000

MaxListLimit is the maximum number of items the client can request for listing.

View Source
const NextVersion = Version(0)

NextVersion means that the version should be chosen automatically.

Variables

View Source
var (
	// ErrInvalidRequest is used to indicate invalid requests.
	ErrInvalidRequest = errs.Class("metabase: invalid request")
	// ErrConflict is used to indicate conflict with the request.
	ErrConflict = errs.Class("metabase: conflict")
)
View Source
var ErrSegmentNotFound = errs.Class("segment not found")

ErrSegmentNotFound is an error class for non-existing segment.

View Source
var Error = errs.Class("metabase")

Error is the default error for metabase.

Functions

func EqualAliasPieces

func EqualAliasPieces(xs, ys AliasPieces) bool

EqualAliasPieces compares whether xs and ys are equal.

Types

type AliasPiece

type AliasPiece struct {
	Number uint16
	Alias  NodeAlias
}

AliasPiece is a piece with alias node ID.

type AliasPieces

type AliasPieces []AliasPiece

AliasPieces is a slice of AliasPiece.

func (AliasPieces) Bytes

func (aliases AliasPieces) Bytes() ([]byte, error)

Bytes compresses alias pieces to a slice of bytes.

func (*AliasPieces) Scan

func (aliases *AliasPieces) Scan(src interface{}) error

Scan implements the database/sql Scanner interface.

func (*AliasPieces) SetBytes

func (aliases *AliasPieces) SetBytes(data []byte) error

SetBytes decompresses alias pieces from a slice of bytes.

func (AliasPieces) Value

func (aliases AliasPieces) Value() (driver.Value, error)

Value implements the database/sql/driver Valuer interface.

type BeginObjectExactVersion

type BeginObjectExactVersion struct {
	ObjectStream

	ExpiresAt              *time.Time
	ZombieDeletionDeadline *time.Time

	Encryption storj.EncryptionParameters
}

BeginObjectExactVersion contains arguments necessary for starting an object upload.

type BeginObjectNextVersion

type BeginObjectNextVersion struct {
	ObjectStream

	ExpiresAt              *time.Time
	ZombieDeletionDeadline *time.Time

	Encryption storj.EncryptionParameters
}

BeginObjectNextVersion contains arguments necessary for starting an object upload.

type BeginSegment

type BeginSegment struct {
	ObjectStream

	Position    SegmentPosition
	RootPieceID storj.PieceID
	Pieces      Pieces
}

BeginSegment contains options to verify, whether a new segment upload can be started.

type BucketEmpty

type BucketEmpty struct {
	ProjectID  uuid.UUID
	BucketName string
}

BucketEmpty contains arguments necessary for checking if bucket is empty.

type BucketLocation

type BucketLocation struct {
	ProjectID  uuid.UUID
	BucketName string
}

BucketLocation defines a bucket that belongs to a project.

func ParseBucketPrefix

func ParseBucketPrefix(prefix BucketPrefix) (BucketLocation, error)

ParseBucketPrefix parses BucketPrefix.

func ParseCompactBucketPrefix

func ParseCompactBucketPrefix(compactPrefix []byte) (BucketLocation, error)

ParseCompactBucketPrefix parses BucketPrefix.

func (BucketLocation) CompactPrefix

func (loc BucketLocation) CompactPrefix() []byte

CompactPrefix converts bucket location into bucket prefix with compact project ID.

func (BucketLocation) Prefix

func (loc BucketLocation) Prefix() BucketPrefix

Prefix converts bucket location into bucket prefix.

func (BucketLocation) Verify

func (loc BucketLocation) Verify() error

Verify object location fields.

type BucketPrefix

type BucketPrefix string

BucketPrefix consists of <project id>/<bucket name>.

type CommitInlineSegment

type CommitInlineSegment struct {
	ObjectStream

	Position SegmentPosition

	ExpiresAt *time.Time

	EncryptedKeyNonce []byte
	EncryptedKey      []byte

	PlainOffset   int64 // offset in the original data stream
	PlainSize     int32 // size before encryption
	EncryptedETag []byte

	InlineData []byte
}

CommitInlineSegment contains all necessary information about the segment.

type CommitObject

type CommitObject struct {
	ObjectStream

	Encryption storj.EncryptionParameters

	EncryptedMetadata             []byte
	EncryptedMetadataNonce        []byte
	EncryptedMetadataEncryptedKey []byte
}

CommitObject contains arguments necessary for committing an object.

type CommitObjectWithSegments

type CommitObjectWithSegments struct {
	ObjectStream

	EncryptedMetadata             []byte
	EncryptedMetadataNonce        []byte
	EncryptedMetadataEncryptedKey []byte

	// TODO: this probably should use segment ranges rather than individual items
	Segments []SegmentPosition
}

CommitObjectWithSegments contains arguments necessary for committing an object.

type CommitSegment

type CommitSegment struct {
	ObjectStream

	Position    SegmentPosition
	RootPieceID storj.PieceID

	ExpiresAt *time.Time

	EncryptedKeyNonce []byte
	EncryptedKey      []byte

	PlainOffset   int64 // offset in the original data stream
	PlainSize     int32 // size before encryption
	EncryptedSize int32 // segment size after encryption

	EncryptedETag []byte

	Redundancy storj.RedundancyScheme

	Pieces Pieces
}

CommitSegment contains all necessary information about the segment.

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB implements a database for storing objects and segments.

func Open

func Open(ctx context.Context, log *zap.Logger, connstr string) (*DB, error)

Open opens a connection to metabase.

func (*DB) BeginObjectExactVersion

func (db *DB) BeginObjectExactVersion(ctx context.Context, opts BeginObjectExactVersion) (committed Object, err error)

BeginObjectExactVersion adds a pending object to the database, with specific version.

func (*DB) BeginObjectNextVersion

func (db *DB) BeginObjectNextVersion(ctx context.Context, opts BeginObjectNextVersion) (committed Version, err error)

BeginObjectNextVersion adds a pending object to the database, with automatically assigned version.

func (*DB) BeginSegment

func (db *DB) BeginSegment(ctx context.Context, opts BeginSegment) (err error)

BeginSegment verifies, whether a new segment upload can be started.

func (*DB) BucketEmpty

func (db *DB) BucketEmpty(ctx context.Context, opts BucketEmpty) (empty bool, err error)

BucketEmpty returns true if bucket does not contain objects (pending or committed). This method doesn't check bucket existence.

func (*DB) CheckVersion

func (db *DB) CheckVersion(ctx context.Context) error

CheckVersion checks the database is the correct version.

func (*DB) Close

func (db *DB) Close() error

Close closes the connection to database.

func (*DB) CommitInlineSegment

func (db *DB) CommitInlineSegment(ctx context.Context, opts CommitInlineSegment) (err error)

CommitInlineSegment commits inline segment to the database.

func (*DB) CommitObject

func (db *DB) CommitObject(ctx context.Context, opts CommitObject) (object Object, err error)

CommitObject adds a pending object to the database.

func (*DB) CommitObjectWithSegments

func (db *DB) CommitObjectWithSegments(ctx context.Context, opts CommitObjectWithSegments) (object Object, deletedSegments []DeletedSegmentInfo, err error)

CommitObjectWithSegments commits pending object to the database.

func (*DB) CommitSegment

func (db *DB) CommitSegment(ctx context.Context, opts CommitSegment) (err error)

CommitSegment commits segment to the database.

func (*DB) DeleteBucketObjects

func (db *DB) DeleteBucketObjects(ctx context.Context, opts DeleteBucketObjects) (deletedObjectCount int64, err error)

DeleteBucketObjects deletes all objects in the specified bucket.

func (*DB) DeleteExpiredObjects

func (db *DB) DeleteExpiredObjects(ctx context.Context, opts DeleteExpiredObjects) (err error)

DeleteExpiredObjects deletes all objects that expired before expiredBefore.

func (*DB) DeleteObjectAnyStatusAllVersions

func (db *DB) DeleteObjectAnyStatusAllVersions(ctx context.Context, opts DeleteObjectAnyStatusAllVersions) (result DeleteObjectResult, err error)

DeleteObjectAnyStatusAllVersions deletes all object versions.

func (*DB) DeleteObjectExactVersion

func (db *DB) DeleteObjectExactVersion(ctx context.Context, opts DeleteObjectExactVersion) (result DeleteObjectResult, err error)

DeleteObjectExactVersion deletes an exact object version.

func (*DB) DeleteObjectLatestVersion

func (db *DB) DeleteObjectLatestVersion(ctx context.Context, opts DeleteObjectLatestVersion) (result DeleteObjectResult, err error)

DeleteObjectLatestVersion deletes latest object version.

func (*DB) DeleteObjectsAllVersions

func (db *DB) DeleteObjectsAllVersions(ctx context.Context, opts DeleteObjectsAllVersions) (result DeleteObjectResult, err error)

DeleteObjectsAllVersions deletes all versions of multiple objects from the same bucket.

func (*DB) DeletePart added in v1.30.1

func (db *DB) DeletePart(ctx context.Context, opts DeletePart) (err error)

DeletePart deletes all segments for given part.

func (*DB) DeletePendingObject

func (db *DB) DeletePendingObject(ctx context.Context, opts DeletePendingObject) (result DeleteObjectResult, err error)

DeletePendingObject deletes a pending object with specified version and streamID.

func (*DB) DeleteZombieObjects added in v1.30.1

func (db *DB) DeleteZombieObjects(ctx context.Context, opts DeleteZombieObjects) (err error)

DeleteZombieObjects deletes all objects that zombie deletion deadline passed.

func (*DB) DestroyTables

func (db *DB) DestroyTables(ctx context.Context) error

DestroyTables deletes all tables.

TODO: remove this, only for bootstrapping.

func (*DB) EnsureNodeAliases

func (db *DB) EnsureNodeAliases(ctx context.Context, opts EnsureNodeAliases) (err error)

EnsureNodeAliases ensures that the supplied node ID-s have a alias. It's safe to concurrently try and create node ID-s for the same NodeID.

func (*DB) GetLatestObjectLastSegment

func (db *DB) GetLatestObjectLastSegment(ctx context.Context, opts GetLatestObjectLastSegment) (segment Segment, err error)

GetLatestObjectLastSegment returns an object last segment information.

func (*DB) GetObjectExactVersion

func (db *DB) GetObjectExactVersion(ctx context.Context, opts GetObjectExactVersion) (_ Object, err error)

GetObjectExactVersion returns object information for exact version.

func (*DB) GetObjectLatestVersion

func (db *DB) GetObjectLatestVersion(ctx context.Context, opts GetObjectLatestVersion) (_ Object, err error)

GetObjectLatestVersion returns object information for latest version.

func (*DB) GetSegmentByLocation

func (db *DB) GetSegmentByLocation(ctx context.Context, opts GetSegmentByLocation) (segment Segment, err error)

GetSegmentByLocation returns information about segment on the specified location.

func (*DB) GetSegmentByOffset

func (db *DB) GetSegmentByOffset(ctx context.Context, opts GetSegmentByOffset) (segment Segment, err error)

GetSegmentByOffset returns an object segment information.

func (*DB) GetSegmentByPosition

func (db *DB) GetSegmentByPosition(ctx context.Context, opts GetSegmentByPosition) (segment Segment, err error)

GetSegmentByPosition returns information about segment on the specified position.

func (*DB) GetStreamPieceCountByNodeID

func (db *DB) GetStreamPieceCountByNodeID(ctx context.Context, opts GetStreamPieceCountByNodeID) (result map[storj.NodeID]int64, err error)

GetStreamPieceCountByNodeID returns piece count by node id.

func (*DB) GetTableStats added in v1.32.2

func (db *DB) GetTableStats(ctx context.Context, opts GetTableStats) (result TableStats, err error)

GetTableStats gathers information about the metabase tables.

func (*DB) Implementation added in v1.32.2

func (db *DB) Implementation() dbutil.Implementation

Implementation rturns the database implementation.

func (*DB) IterateLoopObjects

func (db *DB) IterateLoopObjects(ctx context.Context, opts IterateLoopObjects, fn func(context.Context, LoopObjectsIterator) error) (err error)

IterateLoopObjects iterates through all objects in metabase.

func (*DB) IterateLoopSegments added in v1.31.1

func (db *DB) IterateLoopSegments(ctx context.Context, opts IterateLoopSegments, fn func(context.Context, LoopSegmentsIterator) error) (err error)

IterateLoopSegments iterates through all segments in metabase.

func (*DB) IterateLoopStreams

func (db *DB) IterateLoopStreams(ctx context.Context, opts IterateLoopStreams, handleStream func(ctx context.Context, streamID uuid.UUID, next SegmentIterator) error) (err error)

IterateLoopStreams lists multiple streams segments.

func (*DB) IterateObjectsAllVersions

func (db *DB) IterateObjectsAllVersions(ctx context.Context, opts IterateObjects, fn func(context.Context, ObjectsIterator) error) (err error)

IterateObjectsAllVersions iterates through all versions of all objects.

func (*DB) IterateObjectsAllVersionsWithStatus

func (db *DB) IterateObjectsAllVersionsWithStatus(ctx context.Context, opts IterateObjectsWithStatus, fn func(context.Context, ObjectsIterator) error) (err error)

IterateObjectsAllVersionsWithStatus iterates through all versions of all objects with specified status.

func (*DB) IteratePendingObjectsByKey

func (db *DB) IteratePendingObjectsByKey(ctx context.Context, opts IteratePendingObjectsByKey, fn func(context.Context, ObjectsIterator) error) (err error)

IteratePendingObjectsByKey iterates through all streams of pending objects with the same ObjectKey.

func (*DB) ListNodeAliases

func (db *DB) ListNodeAliases(ctx context.Context) (_ []NodeAliasEntry, err error)

ListNodeAliases lists all node alias mappings.

func (*DB) ListSegments

func (db *DB) ListSegments(ctx context.Context, opts ListSegments) (result ListSegmentsResult, err error)

ListSegments lists specified stream segments.

func (*DB) ListStreamPositions

func (db *DB) ListStreamPositions(ctx context.Context, opts ListStreamPositions) (result ListStreamPositionsResult, err error)

ListStreamPositions lists specified stream segment positions.

func (*DB) MigrateToLatest

func (db *DB) MigrateToLatest(ctx context.Context) error

MigrateToLatest migrates database to the latest version.

func (*DB) Now added in v1.30.1

func (db *DB) Now(ctx context.Context) (time.Time, error)

Now returns time on the database.

func (*DB) Ping

func (db *DB) Ping(ctx context.Context) error

Ping checks whether connection has been established.

func (*DB) PostgresMigration

func (db *DB) PostgresMigration() *migrate.Migration

PostgresMigration returns steps needed for migrating postgres database.

func (*DB) TestingAllCommittedObjects

func (db *DB) TestingAllCommittedObjects(ctx context.Context, projectID uuid.UUID, bucketName string) (objects []ObjectEntry, err error)

TestingAllCommittedObjects gets all objects from bucket. Use only for testing purposes.

func (*DB) TestingAllObjectSegments

func (db *DB) TestingAllObjectSegments(ctx context.Context, objectLocation ObjectLocation) (segments []Segment, err error)

TestingAllObjectSegments gets all segments for given object. Use only for testing purposes.

func (*DB) TestingAllObjects

func (db *DB) TestingAllObjects(ctx context.Context) (objects []Object, err error)

TestingAllObjects gets all objects. Use only for testing purposes.

func (*DB) TestingAllPendingObjects

func (db *DB) TestingAllPendingObjects(ctx context.Context, projectID uuid.UUID, bucketName string) (objects []ObjectEntry, err error)

TestingAllPendingObjects gets all objects from bucket. Use only for testing purposes.

func (*DB) TestingAllSegments

func (db *DB) TestingAllSegments(ctx context.Context) (segments []Segment, err error)

TestingAllSegments gets all segments. Use only for testing purposes.

func (*DB) TestingDeleteAll

func (db *DB) TestingDeleteAll(ctx context.Context) (err error)

TestingDeleteAll deletes all objects and segments from the database.

func (*DB) TestingGetState

func (db *DB) TestingGetState(ctx context.Context) (_ *RawState, err error)

TestingGetState returns the state of the database.

func (*DB) TestingSetCleanup added in v1.31.1

func (db *DB) TestingSetCleanup(cleanup func() error)

TestingSetCleanup is used to set the callback for cleaning up test database.

func (*DB) UnderlyingTagSQL

func (db *DB) UnderlyingTagSQL() tagsql.DB

UnderlyingTagSQL returns *tagsql.DB. TODO: remove.

func (*DB) UpdateObjectMetadata

func (db *DB) UpdateObjectMetadata(ctx context.Context, opts UpdateObjectMetadata) (err error)

UpdateObjectMetadata updates an object metadata.

func (*DB) UpdateSegmentPieces

func (db *DB) UpdateSegmentPieces(ctx context.Context, opts UpdateSegmentPieces) (err error)

UpdateSegmentPieces updates pieces for specified segment. If provided old pieces won't match current database state update will fail.

type DeleteBucketObjects

type DeleteBucketObjects struct {
	Bucket    BucketLocation
	BatchSize int

	// DeletePiecesBatchSize maximum number of DeletedSegmentInfo entries
	// passed to DeletePieces function at once.
	DeletePiecesBatchSize int
	// DeletePieces is called for every batch of objects.
	// Slice `segments` will be reused between calls.
	DeletePieces func(ctx context.Context, segments []DeletedSegmentInfo) error
}

DeleteBucketObjects contains arguments for deleting a whole bucket.

type DeleteExpiredObjects

type DeleteExpiredObjects struct {
	ExpiredBefore  time.Time
	AsOfSystemTime time.Time
	BatchSize      int
}

DeleteExpiredObjects contains all the information necessary to delete expired objects and segments.

type DeleteObjectAnyStatusAllVersions

type DeleteObjectAnyStatusAllVersions struct {
	ObjectLocation
}

DeleteObjectAnyStatusAllVersions contains arguments necessary for deleting all object versions.

type DeleteObjectExactVersion

type DeleteObjectExactVersion struct {
	Version Version
	ObjectLocation
}

DeleteObjectExactVersion contains arguments necessary for deleting an exact version of object.

func (*DeleteObjectExactVersion) Verify

func (obj *DeleteObjectExactVersion) Verify() error

Verify delete object fields.

type DeleteObjectLatestVersion

type DeleteObjectLatestVersion struct {
	ObjectLocation
}

DeleteObjectLatestVersion contains arguments necessary for deleting latest object version.

type DeleteObjectResult

type DeleteObjectResult struct {
	Objects  []Object
	Segments []DeletedSegmentInfo
}

DeleteObjectResult result of deleting object.

type DeleteObjectsAllVersions

type DeleteObjectsAllVersions struct {
	Locations []ObjectLocation
}

DeleteObjectsAllVersions contains arguments necessary for deleting all versions of multiple objects from the same bucket.

func (*DeleteObjectsAllVersions) Verify

func (delete *DeleteObjectsAllVersions) Verify() error

Verify delete objects fields.

type DeletePart added in v1.30.1

type DeletePart struct {
	StreamID   uuid.UUID
	PartNumber uint32

	DeletePieces func(ctx context.Context, segment DeletedSegmentInfo) error
}

DeletePart contains arguments necessary for deleting single part.

type DeletePendingObject

type DeletePendingObject struct {
	ObjectStream
}

DeletePendingObject contains arguments necessary for deleting a pending object.

func (*DeletePendingObject) Verify

func (opts *DeletePendingObject) Verify() error

Verify verifies delete pending object fields validity.

type DeleteZombieObjects added in v1.30.1

type DeleteZombieObjects struct {
	DeadlineBefore time.Time
	AsOfSystemTime time.Time
	BatchSize      int
}

DeleteZombieObjects contains all the information necessary to delete zombie objects and segments.

type DeletedSegmentInfo

type DeletedSegmentInfo struct {
	RootPieceID storj.PieceID
	Pieces      Pieces
}

DeletedSegmentInfo info about deleted segment.

type EnsureNodeAliases

type EnsureNodeAliases struct {
	Nodes []storj.NodeID
}

EnsureNodeAliases contains arguments necessary for creating NodeAlias-es.

type GetLatestObjectLastSegment

type GetLatestObjectLastSegment struct {
	ObjectLocation
}

GetLatestObjectLastSegment contains arguments necessary for fetching a last segment information.

type GetObjectExactVersion

type GetObjectExactVersion struct {
	Version Version
	ObjectLocation
}

GetObjectExactVersion contains arguments necessary for fetching an information about exact object version.

func (*GetObjectExactVersion) Verify

func (obj *GetObjectExactVersion) Verify() error

Verify verifies get object reqest fields.

type GetObjectLatestVersion

type GetObjectLatestVersion struct {
	ObjectLocation
}

GetObjectLatestVersion contains arguments necessary for fetching an object information for latest version.

type GetSegmentByLocation

type GetSegmentByLocation struct {
	SegmentLocation
}

GetSegmentByLocation contains arguments necessary for fetching a segment on specific segment location.

type GetSegmentByOffset

type GetSegmentByOffset struct {
	ObjectLocation
	PlainOffset int64
}

GetSegmentByOffset contains arguments necessary for fetching a segment information.

type GetSegmentByPosition

type GetSegmentByPosition struct {
	StreamID uuid.UUID
	Position SegmentPosition
}

GetSegmentByPosition contains arguments necessary for fetching a segment on specific position.

func (*GetSegmentByPosition) Verify

func (seg *GetSegmentByPosition) Verify() error

Verify verifies get segment request fields.

type GetStreamPieceCountByNodeID

type GetStreamPieceCountByNodeID struct {
	StreamID uuid.UUID
}

GetStreamPieceCountByNodeID contains arguments for GetStreamPieceCountByNodeID.

type GetTableStats added in v1.32.2

type GetTableStats struct {
	AsOfSystemInterval time.Duration
}

GetTableStats contains arguments necessary for getting table statistics.

type IterateCursor

type IterateCursor struct {
	Key     ObjectKey
	Version Version
}

IterateCursor is a cursor used during iteration through objects.

The cursor is exclusive.

type IterateLoopObjects

type IterateLoopObjects struct {
	BatchSize int

	AsOfSystemTime     time.Time
	AsOfSystemInterval time.Duration
}

IterateLoopObjects contains arguments necessary for listing objects in metabase.

func (*IterateLoopObjects) Verify

func (opts *IterateLoopObjects) Verify() error

Verify verifies get object request fields.

type IterateLoopSegments added in v1.31.1

type IterateLoopSegments struct {
	BatchSize          int
	AsOfSystemTime     time.Time
	AsOfSystemInterval time.Duration
}

IterateLoopSegments contains arguments necessary for listing segments in metabase.

func (*IterateLoopSegments) Verify added in v1.31.1

func (opts *IterateLoopSegments) Verify() error

Verify verifies segments request fields.

type IterateLoopStreams

type IterateLoopStreams struct {
	StreamIDs []uuid.UUID

	AsOfSystemTime     time.Time
	AsOfSystemInterval time.Duration
}

IterateLoopStreams contains arguments necessary for listing multiple streams segments.

type IterateObjects

type IterateObjects struct {
	ProjectID  uuid.UUID
	BucketName string
	BatchSize  int
	Prefix     ObjectKey
	Cursor     IterateCursor
}

IterateObjects contains arguments necessary for listing objects in a bucket.

func (*IterateObjects) Verify

func (opts *IterateObjects) Verify() error

Verify verifies get object request fields.

type IterateObjectsWithStatus

type IterateObjectsWithStatus struct {
	ProjectID  uuid.UUID
	BucketName string
	Recursive  bool
	BatchSize  int
	Prefix     ObjectKey
	Cursor     IterateCursor
	Status     ObjectStatus
}

IterateObjectsWithStatus contains arguments necessary for listing objects in a bucket.

func (*IterateObjectsWithStatus) Verify

func (opts *IterateObjectsWithStatus) Verify() error

Verify verifies get object request fields.

type IteratePendingObjectsByKey

type IteratePendingObjectsByKey struct {
	ObjectLocation
	BatchSize int
	Cursor    StreamIDCursor
}

IteratePendingObjectsByKey contains arguments necessary for listing pending objects by ObjectKey.

func (*IteratePendingObjectsByKey) Verify

func (opts *IteratePendingObjectsByKey) Verify() error

Verify verifies get object request fields.

type ListSegments

type ListSegments struct {
	StreamID uuid.UUID
	Cursor   SegmentPosition
	Limit    int
}

ListSegments contains arguments necessary for listing stream segments.

type ListSegmentsResult

type ListSegmentsResult struct {
	Segments []Segment
	More     bool
}

ListSegmentsResult result of listing segments.

type ListStreamPositions

type ListStreamPositions struct {
	StreamID uuid.UUID
	Cursor   SegmentPosition
	Limit    int

	Range *StreamRange
}

ListStreamPositions contains arguments necessary for listing stream segments.

type ListStreamPositionsResult

type ListStreamPositionsResult struct {
	Segments []SegmentPositionInfo
	More     bool
}

ListStreamPositionsResult result of listing segments.

type LoopObjectEntry

type LoopObjectEntry struct {
	ObjectStream                       // metrics, repair, tally
	Status                ObjectStatus // verify
	CreatedAt             time.Time    // temp used by metabase-createdat-migration
	ExpiresAt             *time.Time   // tally
	SegmentCount          int32        // metrics
	TotalEncryptedSize    int64        // tally
	EncryptedMetadataSize int          // tally
}

LoopObjectEntry contains information about object needed by metainfo loop.

func (LoopObjectEntry) Expired added in v1.34.1

func (o LoopObjectEntry) Expired(now time.Time) bool

Expired checks if object is expired relative to now.

type LoopObjectsIterator

type LoopObjectsIterator interface {
	Next(ctx context.Context, item *LoopObjectEntry) bool
}

LoopObjectsIterator iterates over a sequence of LoopObjectEntry items.

type LoopSegmentEntry

type LoopSegmentEntry struct {
	StreamID      uuid.UUID
	Position      SegmentPosition
	CreatedAt     *time.Time // repair
	ExpiresAt     *time.Time
	RepairedAt    *time.Time // repair
	RootPieceID   storj.PieceID
	EncryptedSize int32 // size of the whole segment (not a piece)
	PlainOffset   int64 // verify
	PlainSize     int32 // verify
	Redundancy    storj.RedundancyScheme
	Pieces        Pieces
}

LoopSegmentEntry contains information about segment metadata needed by metainfo loop.

func (LoopSegmentEntry) Inline

func (s LoopSegmentEntry) Inline() bool

Inline returns true if segment is inline.

type LoopSegmentsIterator added in v1.31.1

type LoopSegmentsIterator interface {
	Next(ctx context.Context, item *LoopSegmentEntry) bool
}

LoopSegmentsIterator iterates over a sequence of LoopSegmentEntry items.

type NodeAlias

type NodeAlias int32

NodeAlias is a metabase local alias for NodeID-s to reduce segment table size.

type NodeAliasCache

type NodeAliasCache struct {
	// contains filtered or unexported fields
}

NodeAliasCache is a write-through cache for looking up node ID and alias mapping.

func NewNodeAliasCache

func NewNodeAliasCache(db NodeAliasDB) *NodeAliasCache

NewNodeAliasCache creates a new cache using the specified database.

func (*NodeAliasCache) Aliases

func (cache *NodeAliasCache) Aliases(ctx context.Context, nodes []storj.NodeID) ([]NodeAlias, error)

Aliases returns node aliases corresponding to the node ID-s, adding missing node ID-s to the database when needed.

func (*NodeAliasCache) ConvertAliasesToPieces

func (cache *NodeAliasCache) ConvertAliasesToPieces(ctx context.Context, aliasPieces AliasPieces) (_ Pieces, err error)

ConvertAliasesToPieces converts alias pieces to pieces.

func (*NodeAliasCache) ConvertPiecesToAliases

func (cache *NodeAliasCache) ConvertPiecesToAliases(ctx context.Context, pieces Pieces) (_ AliasPieces, err error)

ConvertPiecesToAliases converts pieces to alias pieces.

func (*NodeAliasCache) Nodes

func (cache *NodeAliasCache) Nodes(ctx context.Context, aliases []NodeAlias) ([]storj.NodeID, error)

Nodes returns node ID-s corresponding to the aliases, refreshing the cache once when an alias is missing. This results in an error when the alias is not in the database.

type NodeAliasDB

type NodeAliasDB interface {
	EnsureNodeAliases(ctx context.Context, opts EnsureNodeAliases) error
	ListNodeAliases(ctx context.Context) (_ []NodeAliasEntry, err error)
}

NodeAliasDB is an interface for looking up node alises.

type NodeAliasEntry

type NodeAliasEntry struct {
	ID    storj.NodeID
	Alias NodeAlias
}

NodeAliasEntry is a mapping between NodeID and NodeAlias.

type NodeAliasMap

type NodeAliasMap struct {
	// contains filtered or unexported fields
}

NodeAliasMap contains bidirectional mapping between node ID and a NodeAlias.

func NewNodeAliasMap

func NewNodeAliasMap(entries []NodeAliasEntry) *NodeAliasMap

NewNodeAliasMap creates a new alias map from the given entries.

func (*NodeAliasMap) Aliases

func (m *NodeAliasMap) Aliases(nodes []storj.NodeID) (xs []NodeAlias, missing []storj.NodeID)

Aliases returns alises-s for the given node ID-s and node ID-s that are not in this map.

func (*NodeAliasMap) ContainsAll

func (m *NodeAliasMap) ContainsAll(nodeIDs []storj.NodeID, nodeAliases []NodeAlias) bool

ContainsAll returns true when the table contains all entries.

func (*NodeAliasMap) Merge

func (m *NodeAliasMap) Merge(other *NodeAliasMap)

Merge merges the other map into m.

func (*NodeAliasMap) Node

func (m *NodeAliasMap) Node(alias NodeAlias) (x storj.NodeID, ok bool)

Node returns NodeID for the given alias.

func (*NodeAliasMap) Nodes

func (m *NodeAliasMap) Nodes(aliases []NodeAlias) (xs []storj.NodeID, missing []NodeAlias)

Nodes returns NodeID-s for the given aliases and aliases that are not in this map.

func (*NodeAliasMap) Size

func (m *NodeAliasMap) Size() int

Size returns the number of entries in this map.

type Object

type Object RawObject

Object object metadata. TODO define separated struct.

func (*Object) IsMigrated

func (obj *Object) IsMigrated() bool

IsMigrated returns whether the object comes from PointerDB. Pointer objects are special that they are missing some information.

  • TotalPlainSize = 0 and FixedSegmentSize = 0.
  • Segment.PlainOffset = 0, Segment.PlainSize = 0

type ObjectEntry

type ObjectEntry struct {
	IsPrefix bool

	ObjectKey ObjectKey
	Version   Version
	StreamID  uuid.UUID

	CreatedAt time.Time
	ExpiresAt *time.Time

	Status       ObjectStatus
	SegmentCount int32

	EncryptedMetadataNonce        []byte
	EncryptedMetadata             []byte
	EncryptedMetadataEncryptedKey []byte

	TotalPlainSize     int64
	TotalEncryptedSize int64
	FixedSegmentSize   int32

	Encryption storj.EncryptionParameters
}

ObjectEntry contains information about an item in a bucket.

type ObjectKey

type ObjectKey string

ObjectKey is an encrypted object key encoded using Path Component Encoding. It is not ascii safe.

type ObjectLocation

type ObjectLocation struct {
	ProjectID  uuid.UUID
	BucketName string
	ObjectKey  ObjectKey
}

ObjectLocation is decoded object key information.

func (ObjectLocation) Bucket

func (obj ObjectLocation) Bucket() BucketLocation

Bucket returns bucket location this object belongs to.

func (ObjectLocation) Verify

func (obj ObjectLocation) Verify() error

Verify object location fields.

type ObjectStatus

type ObjectStatus byte

ObjectStatus defines the statuses that the object might be in.

type ObjectStream

type ObjectStream struct {
	ProjectID  uuid.UUID
	BucketName string
	ObjectKey  ObjectKey
	Version    Version
	StreamID   uuid.UUID
}

ObjectStream uniquely defines an object and stream.

func (*ObjectStream) Location

func (obj *ObjectStream) Location() ObjectLocation

Location returns object location.

func (*ObjectStream) Verify

func (obj *ObjectStream) Verify() error

Verify object stream fields.

type ObjectsIterator

type ObjectsIterator interface {
	Next(ctx context.Context, item *ObjectEntry) bool
}

ObjectsIterator iterates over a sequence of ObjectEntry items.

type Piece

type Piece struct {
	Number      uint16
	StorageNode storj.NodeID
}

Piece defines information for a segment piece.

type Pieces

type Pieces []Piece

Pieces defines information for pieces.

func (Pieces) Equal

func (p Pieces) Equal(pieces Pieces) bool

Equal checks if Pieces structures are equal.

func (Pieces) Len

func (p Pieces) Len() int

Len is the number of pieces.

func (Pieces) Less

func (p Pieces) Less(i, j int) bool

Less reports whether the piece with index i should sort before the piece with index j.

func (*Pieces) Scan

func (pieces *Pieces) Scan(value interface{}) error

Scan implements sql.Scanner interface.

func (Pieces) Swap

func (p Pieces) Swap(i, j int)

Swap swaps the pieces with indexes i and j.

func (Pieces) Value

func (pieces Pieces) Value() (driver.Value, error)

Value implements sql/driver.Valuer interface.

func (Pieces) Verify

func (p Pieces) Verify() error

Verify verifies pieces.

type RawObject

type RawObject struct {
	ObjectStream

	CreatedAt time.Time
	ExpiresAt *time.Time

	Status       ObjectStatus
	SegmentCount int32

	EncryptedMetadataNonce        []byte
	EncryptedMetadata             []byte
	EncryptedMetadataEncryptedKey []byte

	// TotalPlainSize is 0 for a migrated object.
	TotalPlainSize     int64
	TotalEncryptedSize int64
	// FixedSegmentSize is 0 for a migrated object.
	FixedSegmentSize int32

	Encryption storj.EncryptionParameters

	// ZombieDeletionDeadline defines when the pending raw object should be deleted from the database.
	// This is as a safeguard against objects that failed to upload and the client has not indicated
	// whether they want to continue uploading or delete the already uploaded data.
	ZombieDeletionDeadline *time.Time
}

RawObject defines the full object that is stored in the database. It should be rarely used directly.

type RawSegment

type RawSegment struct {
	StreamID uuid.UUID
	Position SegmentPosition

	CreatedAt  *time.Time // TODO: make it non-nilable after we migrate all existing segments to have creation time
	RepairedAt *time.Time
	ExpiresAt  *time.Time

	RootPieceID       storj.PieceID
	EncryptedKeyNonce []byte
	EncryptedKey      []byte

	EncryptedSize int32 // size of the whole segment (not a piece)
	// PlainSize is 0 for a migrated object.
	PlainSize int32
	// PlainOffset is 0 for a migrated object.
	PlainOffset   int64
	EncryptedETag []byte

	Redundancy storj.RedundancyScheme

	InlineData []byte
	Pieces     Pieces
}

RawSegment defines the full segment that is stored in the database. It should be rarely used directly.

type RawState

type RawState struct {
	Objects  []RawObject
	Segments []RawSegment
}

RawState contains full state of a table.

type Segment

type Segment RawSegment

Segment segment metadata. TODO define separated struct.

func (Segment) Expired added in v1.34.1

func (s Segment) Expired(now time.Time) bool

Expired checks if segment is expired relative to now.

func (Segment) Inline

func (s Segment) Inline() bool

Inline returns true if segment is inline.

type SegmentIterator

type SegmentIterator func(ctx context.Context, segment *LoopSegmentEntry) bool

SegmentIterator returns the next segment.

type SegmentKey

type SegmentKey []byte

SegmentKey is an encoded metainfo key. This is used as the key in pointerdb key-value store.

type SegmentLocation

type SegmentLocation struct {
	ProjectID  uuid.UUID
	BucketName string
	ObjectKey  ObjectKey
	Position   SegmentPosition
}

SegmentLocation is decoded segment key information.

func ParseSegmentKey

func ParseSegmentKey(encoded SegmentKey) (SegmentLocation, error)

ParseSegmentKey parses an segment key into segment location.

func (SegmentLocation) Bucket

func (seg SegmentLocation) Bucket() BucketLocation

Bucket returns bucket location this segment belongs to.

func (SegmentLocation) Encode

func (seg SegmentLocation) Encode() SegmentKey

Encode converts segment location into a segment key.

func (SegmentLocation) Object

func (seg SegmentLocation) Object() ObjectLocation

Object returns the object location associated with this segment location.

func (SegmentLocation) Verify

func (seg SegmentLocation) Verify() error

Verify segment location fields.

type SegmentPosition

type SegmentPosition struct {
	Part  uint32
	Index uint32
}

SegmentPosition is segment part and index combined.

func SegmentPositionFromEncoded

func SegmentPositionFromEncoded(v uint64) SegmentPosition

SegmentPositionFromEncoded decodes an uint64 into a SegmentPosition.

func (SegmentPosition) Encode

func (pos SegmentPosition) Encode() uint64

Encode encodes a segment position into an uint64, that can be stored in a database.

func (SegmentPosition) Less

func (pos SegmentPosition) Less(b SegmentPosition) bool

Less returns whether pos should before b.

func (*SegmentPosition) Scan

func (params *SegmentPosition) Scan(value interface{}) error

Scan implements sql.Scanner interface.

func (SegmentPosition) Value

func (params SegmentPosition) Value() (driver.Value, error)

Value implements sql/driver.Valuer interface.

type SegmentPositionInfo

type SegmentPositionInfo struct {
	Position SegmentPosition
	// PlainSize is 0 for a migrated object.
	PlainSize int32
	// PlainOffset is 0 for a migrated object.
	PlainOffset       int64
	CreatedAt         *time.Time // TODO: make it non-nilable after we migrate all existing segments to have creation time
	EncryptedETag     []byte
	EncryptedKeyNonce []byte
	EncryptedKey      []byte
}

SegmentPositionInfo contains information for segment position.

type StreamIDCursor

type StreamIDCursor struct {
	StreamID uuid.UUID
}

StreamIDCursor is a cursor used during iteration through streamIDs of a pending object.

type StreamRange

type StreamRange struct {
	PlainStart int64
	PlainLimit int64 // limit is exclusive
}

StreamRange allows to limit stream positions based on the plain offsets.

type TableStats added in v1.32.2

type TableStats struct {
	ObjectCount  int64
	SegmentCount int64
}

TableStats contains information about the metabase status.

type UpdateObjectMetadata

type UpdateObjectMetadata struct {
	ObjectStream

	EncryptedMetadata             []byte
	EncryptedMetadataNonce        []byte
	EncryptedMetadataEncryptedKey []byte
}

UpdateObjectMetadata contains arguments necessary for replacing an object metadata.

type UpdateSegmentPieces

type UpdateSegmentPieces struct {
	StreamID uuid.UUID
	Position SegmentPosition

	OldPieces Pieces

	NewRedundancy storj.RedundancyScheme
	NewPieces     Pieces

	NewRepairedAt time.Time // sets new time of last segment repair (optional).
}

UpdateSegmentPieces contains arguments necessary for updating segment pieces.

type Version

type Version int64

Version is used to uniquely identify objects with the same key.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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