satellite/metainfo: document migrated objects
Document the fields that migrated objects have missing, it's easy to forget that they might not exist. Avoid downloading the segment, if we're not sure whether it's the correct one. We'll later improve the code with an heuristic to get a best guess, which segment to download. Change-Id: I12395c17bbf0edf25e0d00c8d072fce6085e303b
This commit is contained in:
parent
51d667a65e
commit
ec7af97a17
@ -126,13 +126,13 @@ func (db *DB) PostgresMigration() *migrate.Migration {
|
||||
encrypted_metadata BYTEA default NULL,
|
||||
encrypted_metadata_encrypted_key BYTEA default NULL,
|
||||
|
||||
total_plain_size INT4 NOT NULL default 0,
|
||||
total_plain_size INT4 NOT NULL default 0, -- migrated objects have this = 0
|
||||
total_encrypted_size INT4 NOT NULL default 0,
|
||||
fixed_segment_size INT4 NOT NULL default 0,
|
||||
fixed_segment_size INT4 NOT NULL default 0, -- migrated objects have this = 0
|
||||
|
||||
encryption INT8 NOT NULL default 0,
|
||||
|
||||
zombie_deletion_deadline TIMESTAMPTZ default now() + '1 day', -- should this be in a separate table?
|
||||
zombie_deletion_deadline TIMESTAMPTZ default now() + '1 day',
|
||||
|
||||
PRIMARY KEY (project_id, bucket_name, object_key, version)
|
||||
)`,
|
||||
@ -144,16 +144,16 @@ func (db *DB) PostgresMigration() *migrate.Migration {
|
||||
encrypted_key_nonce BYTEA NOT NULL,
|
||||
encrypted_key BYTEA NOT NULL,
|
||||
|
||||
encrypted_size INT4 NOT NULL, -- maybe this can be skipped?
|
||||
plain_offset INT8 NOT NULL, -- this is needed to find segment based on plain byte offset
|
||||
plain_size INT4 NOT NULL,
|
||||
encrypted_size INT4 NOT NULL,
|
||||
plain_offset INT8 NOT NULL, -- migrated objects have this = 0
|
||||
plain_size INT4 NOT NULL, -- migrated objects have this = 0
|
||||
|
||||
redundancy INT8 NOT NULL default 0,
|
||||
|
||||
inline_data BYTEA DEFAULT NULL,
|
||||
remote_pieces BYTEA[],
|
||||
|
||||
PRIMARY KEY (stream_id, position) -- TODO: should this use plain_offset for the primary index?
|
||||
PRIMARY KEY (stream_id, position)
|
||||
)`,
|
||||
},
|
||||
},
|
||||
|
@ -21,10 +21,13 @@ var ErrSegmentNotFound = errs.Class("segment not found")
|
||||
// TODO define separated struct.
|
||||
type Object RawObject
|
||||
|
||||
// SegmentsHavePlainOffsets returns whether the object segments contain the necessary plain offset and
|
||||
// plain size.
|
||||
func (obj *Object) SegmentsHavePlainOffsets() bool {
|
||||
return obj.TotalPlainSize > 0
|
||||
// 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
|
||||
func (obj *Object) IsMigrated() bool {
|
||||
return obj.TotalPlainSize <= 0
|
||||
}
|
||||
|
||||
// Segment segment metadata.
|
||||
|
@ -122,8 +122,10 @@ type ListStreamPositionsResult struct {
|
||||
|
||||
// SegmentPositionInfo contains information for segment position.
|
||||
type SegmentPositionInfo struct {
|
||||
Position SegmentPosition
|
||||
PlainSize int32
|
||||
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
|
||||
|
@ -27,9 +27,11 @@ type RawObject struct {
|
||||
EncryptedMetadata []byte
|
||||
EncryptedMetadataEncryptedKey []byte
|
||||
|
||||
// TotalPlainSize is 0 for a migrated object.
|
||||
TotalPlainSize int64
|
||||
TotalEncryptedSize int64
|
||||
FixedSegmentSize int32
|
||||
// FixedSegmentSize is 0 for a migrated object.
|
||||
FixedSegmentSize int32
|
||||
|
||||
Encryption storj.EncryptionParameters
|
||||
|
||||
@ -52,7 +54,9 @@ type RawSegment struct {
|
||||
EncryptedKey []byte
|
||||
|
||||
EncryptedSize int32 // size of the whole segment (not a piece)
|
||||
PlainSize int32
|
||||
// PlainSize is 0 for a migrated object.
|
||||
PlainSize int32
|
||||
// PlainOffset is 0 for a migrated object.
|
||||
PlainOffset int64
|
||||
EncryptedETag []byte
|
||||
|
||||
|
@ -979,6 +979,9 @@ func (endpoint *Endpoint) DownloadObject(ctx context.Context, req *pb.ObjectDown
|
||||
if len(segments.Segments) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
if object.IsMigrated() && streamRange != nil && streamRange.PlainStart > 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
segment, err := endpoint.metainfo.metabaseDB.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
||||
StreamID: object.StreamID,
|
||||
@ -1124,9 +1127,10 @@ func calculateStreamRange(object metabase.Object, req *pb.Range) (*metabase.Stre
|
||||
if req == nil || req.Range == nil {
|
||||
return nil, nil
|
||||
}
|
||||
// we cannot calculate stream ranges for old objects.
|
||||
if !object.SegmentsHavePlainOffsets() {
|
||||
// TODO: handle object.FixedSegmentSize
|
||||
|
||||
if object.IsMigrated() {
|
||||
// The object is in old format, which does not have plain_offset specified.
|
||||
// We need to fallback to returning all segments.
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user