core

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidContinuationToken    = errors.New("invalid continuation token")
	ErrRecordNotFound              = errors.New("record not found")
	ErrStagedRecordNotFound        = errors.New("staged metadata not found - was StageBlobMetadata() called beforehand?")
	ErrBlobNotFound                = errors.New("the blob was not found in the store")
	ErrExistingDatabaseSchemaNewer = errors.New("the existing database schema is newer that what the server supports")
)

Functions

func CollectGarbage

func CollectGarbage(ctx context.Context, db MetadataDatabase, store BlobStore, olderThan time.Time) error

When we write a blob, we first stage it in the metadata database, then write it to the blob store, then promote the staged metadata to completed. If the write fails to the blob store, we delete the staged metadata. But if the process crashes after the blob write but before we can complete the metadata, there will be orphaned blobs in the blob store. This function deletes these orphaned blobs from the blob store and their corresponding staged records in the medatada database.

func UnixTimeMsToTime

func UnixTimeMsToTime(timeValueMs int64) time.Time

Types

type BlobInfo

type BlobInfo struct {
	Key       BlobKey
	Tags      BlobTags
	CreatedAt time.Time
	ExpiresAt *time.Time
}

type BlobKey

type BlobKey struct {
	Subject string
	Id      uuid.UUID
}

type BlobStore

type BlobStore interface {
	SaveBlob(ctx context.Context, contents io.Reader, key BlobKey) error
	ReadBlob(ctx context.Context, writer io.Writer, key BlobKey) error
	DeleteBlob(ctx context.Context, key BlobKey) error
	HealthCheck(ctx context.Context) error
}

type BlobTags

type BlobTags struct {
	Name        *string
	Device      *string
	Session     *string
	ContentType *string
	TimeToLive  *string
	CustomTags  map[string][]string
}

type ContinutationToken

type ContinutationToken string

type MetadataDatabase

type MetadataDatabase interface {
	StageBlobMetadata(ctx context.Context, key BlobKey, tags *BlobTags) (*BlobInfo, error)
	CompleteStagedBlobMetadata(ctx context.Context, key BlobKey) error
	DeleteBlobMetadata(ctx context.Context, key BlobKey) error
	GetPageOfExpiredBlobMetadata(ctx context.Context, olderThan time.Time) ([]BlobKey, error)
	GetBlobMetadata(ctx context.Context, key BlobKey, expiresAfter time.Time) (*BlobInfo, error)
	SearchBlobMetadata(ctx context.Context, tags map[string][]string, at *time.Time, ct *ContinutationToken, pageSize int, expiresAfter time.Time) ([]BlobInfo, *ContinutationToken, error)
	HealthCheck(ctx context.Context) error
}

Jump to

Keyboard shortcuts

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