Documentation
¶
Index ¶
- Variables
- type Store
- func (s *Store) AbortMultipartUpload(accessKeyID, bucket, name string, uploadID s3.UploadID) (size int64, _ error)
- func (s *Store) AbortMultipartUploads(bucket string, prefix string, before time.Time, limit int) (aborted []sia.AbortedUpload, err error)
- func (s *Store) AddMultipartPart(accessKeyID, bucket, name string, uploadID s3.UploadID, filename string, ...) (prev string, size int64, _ error)
- func (s *Store) AllBucketLifecycleConfigurations() (configs []sia.BucketLifecycleConfiguration, err error)
- func (s *Store) AllFilenames() (filenames []string, err error)
- func (s *Store) AppKey() (types.PrivateKey, string, error)
- func (s *Store) Backup(ctx context.Context, destPath string) (err error)
- func (s *Store) Close() error
- func (s *Store) CompleteMultipartUpload(accessKeyID, bucket, name string, uploadID s3.UploadID, contentMD5 [16]byte, ...) (versionID string, orphan objects.OrphanedFile, _ error)
- func (s *Store) CopyObject(accessKeyID, srcBucket, srcName string, srcVersion s3.VersionRequest, ...) (_ *s3.CopyObjectResult, orphan objects.OrphanedFile, err error)
- func (s *Store) CreateAccessKey(userName, accessKeyID, secretKey string) error
- func (s *Store) CreateBucket(accessKeyID, bucket string) error
- func (s *Store) CreateMultipartUpload(accessKeyID, bucket, name string, uploadID s3.UploadID, meta map[string]string) error
- func (s *Store) CreateUser(name string) error
- func (s *Store) DeleteAccessKey(accessKeyID string) error
- func (s *Store) DeleteBucket(accessKeyID, bucket string) error
- func (s *Store) DeleteBucketLifecycleConfiguration(accessKeyID, bucket string) error
- func (s *Store) DeleteObject(accessKeyID, bucket string, objectID s3.ObjectID) (versionID string, isDeleteMarker bool, orphan objects.OrphanedFile, _ error)
- func (s *Store) DeleteUser(name string) error
- func (s *Store) DiskUsage() (usage uint64, err error)
- func (s *Store) ExpireObjects(bucket string, prefix string, before time.Time, limit int) (deleted int, orphans []objects.OrphanedFile, err error)
- func (s *Store) GetBucketLifecycleConfiguration(accessKeyID, bucket string) (config string, err error)
- func (s *Store) GetBucketVersioning(accessKeyID, bucket string) (status string, err error)
- func (s *Store) GetObject(accessKeyID, bucket, name string, version s3.VersionRequest, partNumber *int32) (*objects.Object, error)
- func (s *Store) HasMultipartUpload(accessKeyID, bucket, name string, uploadID s3.UploadID) (hasParts bool, err error)
- func (s *Store) HeadBucket(accessKeyID, bucket string) error
- func (s *Store) ListAccessKeys(userName *string) ([]sia.AccessKeyInfo, error)
- func (s *Store) ListBuckets(accessKeyID string) ([]s3.BucketInfo, error)
- func (s *Store) ListMultipartUploads(accessKeyID, bucket string, prefix s3.Prefix, page s3.ListMultipartUploadsPage) (_ *s3.ListMultipartUploadsResult, err error)
- func (s *Store) ListObjectVersions(accessKeyID, bucket string, prefix s3.Prefix, page s3.ListObjectVersionsPage) (*s3.ObjectVersionsListResult, error)
- func (s *Store) ListObjects(accessKeyID, bucket string, prefix s3.Prefix, page s3.ListObjectsPage) (result *s3.ObjectsListResult, err error)
- func (s *Store) ListParts(accessKeyID, bucket, name string, uploadID s3.UploadID, partNumberMarker int, ...) (*s3.ListPartsResult, error)
- func (s *Store) ListUsers() ([]string, error)
- func (s *Store) LoadSecret(accessKeyID string) (string, error)
- func (s *Store) MarkObjectPinned(siaObjectID types.Hash256) (orphans []objects.OrphanedFile, _ error)
- func (s *Store) MarkObjectUploaded(bucket, name, versionID string, contentMD5 [16]byte, sealed sdk.SealedObject, ...) error
- func (s *Store) MultipartParts(accessKeyID, bucket, name string, uploadID s3.UploadID) ([]objects.Part, error)
- func (s *Store) NextPinningAttempt() (next time.Time, ok bool, err error)
- func (s *Store) ObjectPartsByName(bucket, name, versionID string) ([]objects.Part, error)
- func (s *Store) ObjectsCursor() (cursor slabs.Cursor, err error)
- func (s *Store) ObjectsForPinning(now time.Time, limit int) ([]objects.UnpinnedObject, error)
- func (s *Store) ObjectsForUpload() ([]objects.ObjectForUpload, error)
- func (s *Store) OrphanedObjects(limit int) (ids []types.Hash256, err error)
- func (s *Store) PutBucketLifecycleConfiguration(accessKeyID, bucket, config string) error
- func (s *Store) PutBucketVersioning(accessKeyID, bucket, status string) error
- func (s *Store) PutObject(accessKeyID, bucket, name string, contentMD5 [16]byte, meta map[string]string, ...) (versionID string, orphan objects.OrphanedFile, _ error)
- func (s *Store) RemoveOrphanedObject(objectID types.Hash256) error
- func (s *Store) RescheduleUnpinnedObject(siaObjectID types.Hash256, nextAttemptAt time.Time) error
- func (s *Store) ScheduleObjectForReupload(siaObjectID types.Hash256) error
- func (s *Store) SetAppKey(key types.PrivateKey, indexerURL string) error
- func (s *Store) SetObjectsCursor(cursor slabs.Cursor) error
- func (s *Store) UpdateSiaObjects(siaObjects []objects.SiaObject) (updated int64, err error)
- func (s *Store) UploadStats() (stats s3.UploadStats, err error)
- func (s *Store) UserNameForAccessKey(accessKeyID string) (name string, err error)
Constants ¶
This section is empty.
Variables ¶
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 ¶
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) AbortMultipartUploads ¶ added in v0.1.2
func (s *Store) AbortMultipartUploads(bucket string, prefix string, before time.Time, limit int) (aborted []sia.AbortedUpload, err error)
AbortMultipartUploads deletes up to limit incomplete multipart uploads in the named bucket that match prefix and were initiated at or before the cutoff. It returns the removed uploads and the on-disk size of their parts so the caller can clean up the upload directories. It performs no ownership checks.
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) AllBucketLifecycleConfigurations ¶ added in v0.1.2
func (s *Store) AllBucketLifecycleConfigurations() (configs []sia.BucketLifecycleConfiguration, err error)
AllBucketLifecycleConfigurations returns the lifecycle configuration for every bucket that has one. It is intended for the background lifecycle loop and performs no ownership checks.
func (*Store) AllFilenames ¶
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) Backup ¶ added in v0.1.2
Backup creates a backup of the open database at destPath using the SQLite backup API. The backup runs over the store's own connection, so writes to the database are blocked for the duration of the backup but the snapshot is always consistent.
func (*Store) CompleteMultipartUpload ¶
func (s *Store) CompleteMultipartUpload(accessKeyID, bucket, name string, uploadID s3.UploadID, contentMD5 [16]byte, contentLength int64) (versionID string, orphan objects.OrphanedFile, _ 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 string, srcVersion s3.VersionRequest, dstBucket, dstName string, meta map[string]string, replace bool) (_ *s3.CopyObjectResult, orphan objects.OrphanedFile, err error)
CopyObject atomically reads the source object and writes it to the destination within a single transaction, applying metadata per the replace flag. The result carries the wire-encoded version IDs of the new copy and the source copied; an orphaned pending file is returned for the caller to remove.
func (*Store) CreateAccessKey ¶
CreateAccessKey creates a new access key for the given user.
func (*Store) CreateBucket ¶
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 ¶
CreateUser creates a new user with the given name.
func (*Store) DeleteAccessKey ¶
DeleteAccessKey deletes the access key with the given ID.
func (*Store) DeleteBucket ¶
DeleteBucket deletes a bucket if it is empty and owned by the requesting user.
func (*Store) DeleteBucketLifecycleConfiguration ¶ added in v0.1.2
DeleteBucketLifecycleConfiguration removes the lifecycle configuration for a bucket. It is not an error if no configuration exists.
func (*Store) DeleteObject ¶
func (s *Store) DeleteObject(accessKeyID, bucket string, objectID s3.ObjectID) (versionID string, isDeleteMarker bool, orphan objects.OrphanedFile, _ error)
DeleteObject deletes an object according to the bucket's versioning status, returning the wire-encoded version ID affected and whether a delete marker was involved. A non-nil objectID.VersionID permanently deletes that version ("" is the null version); otherwise an enabled bucket inserts a delete marker, a suspended bucket replaces the null version with a null delete marker, and an unversioned bucket deletes outright. A removed object's filename is returned for cleanup if no longer referenced.
func (*Store) DeleteUser ¶
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 ¶
DiskUsage returns the total bytes currently held on disk in the uploads directory, across objects with a staged filename (pending upload or uploaded but not yet pinned) and in-progress multipart parts. Objects sharing a filename (e.g. via CopyObject) are counted once.
func (*Store) ExpireObjects ¶ added in v0.1.2
func (s *Store) ExpireObjects(bucket string, prefix string, before time.Time, limit int) (deleted int, orphans []objects.OrphanedFile, err error)
ExpireObjects expires up to limit objects whose current version matches prefix and was last modified at or before the cutoff, applying a versioning-aware delete (see [deleteCurrentObject]) to each. NoncurrentVersionExpiration is not supported. Returns the number of objects expired; performs no ownership checks.
func (*Store) GetBucketLifecycleConfiguration ¶ added in v0.1.2
func (s *Store) GetBucketLifecycleConfiguration(accessKeyID, bucket string) (config string, err error)
GetBucketLifecycleConfiguration returns the serialized lifecycle configuration for a bucket, or ErrNoSuchLifecycleConfiguration if none is set.
func (*Store) GetBucketVersioning ¶ added in v0.1.2
GetBucketVersioning returns the versioning status of the bucket. The status is one of "" (never configured), "Enabled" or "Suspended".
func (*Store) GetObject ¶
func (s *Store) GetObject(accessKeyID, bucket, name string, version s3.VersionRequest, partNumber *int32) (*objects.Object, error)
GetObject retrieves an object. An unspecified version returns the current version (ErrNoSuchKey if the key has no versions); a specified version returns that version (ErrNoSuchVersion if absent). The result may be a delete marker.
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 ¶
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) ListObjectVersions ¶ added in v0.1.2
func (s *Store) ListObjectVersions(accessKeyID, bucket string, prefix s3.Prefix, page s3.ListObjectVersionsPage) (*s3.ObjectVersionsListResult, error)
ListObjectVersions lists every version (including delete markers) of the objects in the bucket, ordered by key ascending then by version creation order descending (newest first), applying prefix, delimiter and the (key-marker, version-id-marker) cursor.
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) LoadSecret ¶
LoadSecret returns the secret key for the given access key ID.
func (*Store) MarkObjectPinned ¶ added in v0.1.2
func (s *Store) MarkObjectPinned(siaObjectID types.Hash256) (orphans []objects.OrphanedFile, _ error)
MarkObjectPinned completes the upload lifecycle for a Sia object that has been successfully pinned in the indexer: the unpinned_objects row is removed and filename is cleared on every objects row referencing the sia_object_id (e.g. copies share one pin row). Filenames that are no longer referenced by any objects row are returned for cleanup by the caller. If no unpinned_objects row exists the object was deleted while the pin was in flight, so the sia_object_id is recorded in orphaned_objects for the orphan loop to unpin; the pin must not be silently dropped since inserting into orphaned_objects is the only mechanism that unpins objects.
func (*Store) MarkObjectUploaded ¶
func (s *Store) MarkObjectUploaded(bucket, name, versionID string, contentMD5 [16]byte, sealed sdk.SealedObject, pinBefore time.Time) error
MarkObjectUploaded transitions a pending upload to an uploaded-but-not-yet- pinned object by setting sia_object_id and sia_object on the objects row and upserting a corresponding unpinned_objects row keyed by sia_object_id. The filename is intentionally kept set so the file on disk remains available as a backup until the pin completes. When several objects share the same sia_object_id (e.g. dedup or a CopyObject of a not-yet-pinned source) they share a single unpinned_objects row whose pin_before is the latest deadline seen. Returns ErrObjectNotFound if no pending object exists for the bucket and name 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) NextPinningAttempt ¶ added in v0.1.2
NextPinningAttempt returns the earliest next_attempt_at across all unpinned_objects rows. The boolean is false when the table is empty.
func (*Store) ObjectPartsByName ¶
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 ¶
ObjectsCursor returns the cursor for resuming object event syncing.
func (*Store) ObjectsForPinning ¶ added in v0.1.2
ObjectsForPinning returns up to limit unpinned objects whose next_attempt_at is at or before now, in ascending next_attempt_at order. Rows whose sia_object_id is no longer referenced by any objects row are skipped — the pin loop is not responsible for cleaning those up.
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 ¶
OrphanedObjects returns up to limit object IDs from the orphaned_objects table.
func (*Store) PutBucketLifecycleConfiguration ¶ added in v0.1.2
PutBucketLifecycleConfiguration stores the serialized lifecycle configuration for a bucket, replacing any existing configuration.
func (*Store) PutBucketVersioning ¶ added in v0.1.2
PutBucketVersioning sets the versioning status of the bucket to status, which must be "Enabled" or "Suspended".
func (*Store) PutObject ¶
func (s *Store) PutObject(accessKeyID, bucket, name string, contentMD5 [16]byte, meta map[string]string, length int64, fileName *string) (versionID string, orphan objects.OrphanedFile, _ error)
PutObject stores the object and returns the wire-encoded version ID to report ("" on a suspended or unversioned bucket, since neither reports a version). An enabled bucket creates a new version; otherwise the null version is overwritten, orphaning any prior object ID or pending file that is no longer referenced (the latter returned so the caller can remove it from disk).
func (*Store) RemoveOrphanedObject ¶
RemoveOrphanedObject removes an object ID from the orphaned_objects table.
func (*Store) RescheduleUnpinnedObject ¶ added in v0.1.2
RescheduleUnpinnedObject updates next_attempt_at for the unpinned object identified by sia_object_id. Returns ErrObjectNotFound if no row exists.
func (*Store) ScheduleObjectForReupload ¶ added in v0.1.2
ScheduleObjectForReupload reverts every objects row referencing the given sia_object_id back to the pending-upload state and removes the unpinned_objects row. The old sia_object_id is recorded in orphaned_objects: an earlier pin attempt may have succeeded in the indexer without MarkObjectPinned having committed, and the re-upload always produces a new id, so the old one is never referenced again. Returns ErrObjectNotFound if no unpinned_objects row exists for the sia_object_id.
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 ¶
SetObjectsCursor updates the cursor for resuming object event syncing.
func (*Store) UpdateSiaObjects ¶
UpdateSiaObjects batch updates sealed object metadata in the database within a single transaction. It returns the number of sealed objects that were updated; objects that are no longer tracked are skipped.
func (*Store) UploadStats ¶
func (s *Store) UploadStats() (stats s3.UploadStats, err error)
UploadStats returns statistics about the background upload pipeline, read from the incrementally maintained stats table.