sqlite

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAppKey = errors.New("no app key set")

ErrNoAppKey is returned when no application key is set.

Functions

This section is empty.

Types

type Store

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

A Store is a persistent store that uses a SQL database as its backend.

func OpenDatabase

func OpenDatabase(fp string, log *zap.Logger) (*Store, error)

OpenDatabase creates a new SQLite store and initializes the database. If the database does not exist, it is created.

func (*Store) AbortMultipartUpload

func (s *Store) AbortMultipartUpload(accessKeyID, bucket, name string, uploadID s3.UploadID) (size int64, _ error)

AbortMultipartUpload removes a multipart upload from the store and returns the total size of all parts that were removed.

func (*Store) AddMultipartPart

func (s *Store) AddMultipartPart(accessKeyID, bucket, name string, uploadID s3.UploadID, filename string, partNumber int, contentMD5 [16]byte, contentLength int64) (prev string, size int64, _ error)

AddMultipartPart adds metadata for a multipart part to the store. It returns the previous part's filename and content length if a part with the same number already existed.

func (*Store) AllFilenames

func (s *Store) AllFilenames() (filenames []string, err error)

AllFilenames returns all filenames from the objects table and in-progress multipart uploads.

func (*Store) AppKey

func (s *Store) AppKey() (types.PrivateKey, string, error)

AppKey retrieves the application private key and the indexer URL it was registered with.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database.

func (*Store) CompleteMultipartUpload

func (s *Store) CompleteMultipartUpload(accessKeyID, bucket, name string, uploadID s3.UploadID, contentMD5 [16]byte, contentLength int64) (orphanFile string, orphanSize int64, _ error)

CompleteMultipartUpload finalizes a multipart upload by creating the object and transferring parts from the upload to the object. If the overwritten object's ID has no remaining references, it is inserted into the orphaned_objects table. If the overwrite leaves a previously pending file unreferenced, its filename is returned so the caller can remove it from disk.

func (*Store) CopyObject

func (s *Store) CopyObject(accessKeyID, srcBucket, srcName, dstBucket, dstName string, meta map[string]string, replace bool) (result *objects.Object, orphanFile string, orphanSize int64, err error)

CopyObject atomically reads the source object and writes it to the destination within a single transaction, applying metadata according to the replace flag. Returns the copied object metadata, and if the copy overwrote a previously pending object whose file is no longer referenced, its filename so the caller can remove it from disk.

func (*Store) CreateAccessKey

func (s *Store) CreateAccessKey(userName, accessKeyID, secretKey string) error

CreateAccessKey creates a new access key for the given user.

func (*Store) CreateBucket

func (s *Store) CreateBucket(accessKeyID, bucket string) error

CreateBucket creates a new bucket owned by the user associated with the given access key.

func (*Store) CreateMultipartUpload

func (s *Store) CreateMultipartUpload(accessKeyID, bucket, name string, uploadID s3.UploadID, meta map[string]string) error

CreateMultipartUpload persists metadata for a new multipart upload.

func (*Store) CreateUser

func (s *Store) CreateUser(name string) error

CreateUser creates a new user with the given name.

func (*Store) DeleteAccessKey

func (s *Store) DeleteAccessKey(accessKeyID string) error

DeleteAccessKey deletes the access key with the given ID.

func (*Store) DeleteBucket

func (s *Store) DeleteBucket(accessKeyID, bucket string) error

DeleteBucket deletes a bucket if it is empty and owned by the requesting user.

func (*Store) DeleteObject

func (s *Store) DeleteObject(accessKeyID, bucket string, objectID s3.ObjectID) (orphanFile string, orphanSize int64, _ error)

DeleteObject deletes the object with the given bucket and name if it exists and all provided preconditions match. If the deleted object's ID has no remaining references, it is inserted into the orphaned_objects table. If the object hasn't been uploaded yet, its filename is returned for cleanup.

func (*Store) DeleteUser

func (s *Store) DeleteUser(name string) error

DeleteUser deletes the user with the given name. Access keys belonging to the user are deleted via cascade. Returns an error if the user owns any buckets.

func (*Store) DiskUsage

func (s *Store) DiskUsage() (usage uint64, err error)

DiskUsage returns the total bytes pending upload to Sia, across pending objects and in-progress multipart parts. Pending objects sharing a filename (e.g. via CopyObject) are counted once.

func (*Store) GetObject

func (s *Store) GetObject(accessKeyID, bucket, name string, partNumber *int32) (*objects.Object, error)

GetObject retrieves the object with the given bucket and name.

func (*Store) HasMultipartUpload

func (s *Store) HasMultipartUpload(accessKeyID, bucket, name string, uploadID s3.UploadID) (hasParts bool, err error)

HasMultipartUpload checks if a multipart upload exists and reports whether any parts have been uploaded for it.

func (*Store) HeadBucket

func (s *Store) HeadBucket(accessKeyID, bucket string) error

HeadBucket verifies that the bucket exists and is owned by the user associated with the given access key.

func (*Store) ListAccessKeys

func (s *Store) ListAccessKeys(userName *string) ([]sia.AccessKeyInfo, error)

ListAccessKeys returns all access keys for the given user. If userName is nil, all access keys are returned.

func (*Store) ListBuckets

func (s *Store) ListBuckets(accessKeyID string) ([]s3.BucketInfo, error)

ListBuckets lists all buckets owned by the user associated with the given access key.

func (*Store) ListMultipartUploads

func (s *Store) ListMultipartUploads(accessKeyID, bucket string, prefix s3.Prefix, page s3.ListMultipartUploadsPage) (_ *s3.ListMultipartUploadsResult, err error)

ListMultipartUploads lists all multipart uploads for the given bucket and filters.

func (*Store) ListObjects

func (s *Store) ListObjects(accessKeyID, bucket string, prefix s3.Prefix, page s3.ListObjectsPage) (result *s3.ObjectsListResult, err error)

ListObjects lists objects in the specified bucket, filtered by prefix and pagination settings.

func (*Store) ListParts

func (s *Store) ListParts(accessKeyID, bucket, name string, uploadID s3.UploadID, partNumberMarker int, maxParts int64) (*s3.ListPartsResult, error)

ListParts lists uploaded parts for a multipart upload.

func (*Store) ListUsers

func (s *Store) ListUsers() ([]string, error)

ListUsers returns the names of all users.

func (*Store) LoadSecret

func (s *Store) LoadSecret(accessKeyID string) (string, error)

LoadSecret returns the secret key for the given access key ID.

func (*Store) MarkObjectUploaded

func (s *Store) MarkObjectUploaded(bucket, name string, contentMD5 [16]byte, sealed sdk.SealedObject) error

MarkObjectUploaded transitions a pending upload to a Sia-backed object by setting the object_id, sia_object and cached_at fields while clearing filename. The update targets any pending object matching the bucket and name, returning ErrObjectNotFound if no pending object exists or ErrObjectModified if the stored content MD5 does not match the provided contentMD5.

func (*Store) MultipartParts

func (s *Store) MultipartParts(accessKeyID, bucket, name string, uploadID s3.UploadID) ([]objects.Part, error)

MultipartParts returns the parts belonging to the specified multipart upload.

func (*Store) ObjectPartsByName

func (s *Store) ObjectPartsByName(bucket, name string) ([]objects.Part, error)

ObjectPartsByName returns the parts for a completed multipart object. It is intended for internal callers (the upload loop and downstream of an ownership-scoped GetObject) and does not perform an access check.

func (*Store) ObjectsCursor

func (s *Store) ObjectsCursor() (cursor slabs.Cursor, err error)

ObjectsCursor returns the cursor for resuming object event syncing.

func (*Store) ObjectsForUpload

func (s *Store) ObjectsForUpload() ([]objects.ObjectForUpload, error)

ObjectsForUpload returns all objects stored on disk, ordered by size descending for greedy best-fit slab filling.

func (*Store) OrphanedObjects

func (s *Store) OrphanedObjects(limit int) (ids []types.Hash256, err error)

OrphanedObjects returns up to limit object IDs from the orphaned_objects table.

func (*Store) PutObject

func (s *Store) PutObject(accessKeyID, bucket, name string, contentMD5 [16]byte, meta map[string]string, length int64, fileName *string) (orphanFile string, orphanSize int64, _ error)

PutObject stores the given object in the given bucket with the given name or overwrites it if it already exists. If the overwritten object's ID has no remaining references, it is inserted into the orphaned_objects table. If the overwrite leaves a previously pending file unreferenced, its filename is returned so the caller can remove it from disk and release its disk usage.

func (*Store) RemoveOrphanedObject

func (s *Store) RemoveOrphanedObject(objectID types.Hash256) error

RemoveOrphanedObject removes an object ID from the orphaned_objects table.

func (*Store) SetAppKey

func (s *Store) SetAppKey(key types.PrivateKey, indexerURL string) error

SetAppKey sets the application private key and the indexer URL it was registered with.

func (*Store) SetObjectsCursor

func (s *Store) SetObjectsCursor(cursor slabs.Cursor) error

SetObjectsCursor updates the cursor for resuming object event syncing.

func (*Store) UpdateSiaObjects

func (s *Store) UpdateSiaObjects(siaObjects []objects.SiaObject) (updated int64, err error)

UpdateSiaObjects batch updates object metadata in the database within a single transaction. It returns the number of rows that were updated.

func (*Store) UploadStats

func (s *Store) UploadStats() (stats s3.UploadStats, err error)

UploadStats returns statistics about the background upload pipeline.

func (*Store) UserNameForAccessKey

func (s *Store) UserNameForAccessKey(accessKeyID string) (name string, err error)

UserNameForAccessKey returns the user name associated with the given access key ID.

Jump to

Keyboard shortcuts

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