storj/satellite/metainfo/metabase/list.go
Michal Niewrzal cfb45a785c satellite/metainfo/metabase: add TotalPlainSize to objects table
We need to know how large is object in general and we shouldn't query
segments for that.

Change-Id: Ie316e1ec38bfc39065e6046b79b55d58f3ce9d53
2020-11-25 14:35:28 +01:00

89 lines
2.3 KiB
Go

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package metabase
import (
"context"
"time"
"storj.io/common/storj"
"storj.io/common/uuid"
)
// ObjectEntry contains information about an item in a bucket.
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
// 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
}
// ObjectsIterator iterates over a sequence of ObjectEntry items.
type ObjectsIterator interface {
Next(ctx context.Context, item *ObjectEntry) bool
}
// IterateCursor is a cursor used during iteration.
type IterateCursor struct {
Key ObjectKey
Version Version
}
// IterateObjects contains arguments necessary for listing objects in a bucket.
type IterateObjects struct {
ProjectID uuid.UUID
BucketName string
Recursive bool
BatchSize int
Prefix ObjectKey
Cursor IterateCursor
Status ObjectStatus
}
// IterateObjectsAllVersions iterates through all versions of all committed objects.
func (db *DB) IterateObjectsAllVersions(ctx context.Context, opts IterateObjects, fn func(context.Context, ObjectsIterator) error) (err error) {
defer mon.Task()(&ctx)(&err)
if err = opts.Verify(); err != nil {
return err
}
return iterateAllVersions(ctx, db, opts, fn)
}
// Verify verifies get object request fields.
func (opts *IterateObjects) Verify() error {
switch {
case opts.ProjectID.IsZero():
return ErrInvalidRequest.New("ProjectID missing")
case opts.BucketName == "":
return ErrInvalidRequest.New("BucketName missing")
case opts.BatchSize < 0:
return ErrInvalidRequest.New("BatchSize is negative")
case !(opts.Status == Pending || opts.Status == Committed):
return ErrInvalidRequest.New("Status %v is not supported", opts.Status)
}
return nil
}