2022-05-20 15:02:00 +00:00
|
|
|
package data
|
|
|
|
|
|
|
|
import (
|
2022-06-02 15:26:26 +00:00
|
|
|
"strconv"
|
2022-05-20 15:02:00 +00:00
|
|
|
"time"
|
|
|
|
|
2023-03-07 14:38:08 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
2022-05-20 15:02:00 +00:00
|
|
|
)
|
|
|
|
|
2022-08-08 22:35:26 +00:00
|
|
|
const (
|
|
|
|
UnversionedObjectVersionID = "null"
|
|
|
|
)
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
// NodeVersion represent node from tree service.
|
|
|
|
type NodeVersion struct {
|
|
|
|
BaseNodeVersion
|
|
|
|
IsUnversioned bool
|
2023-06-27 12:49:20 +00:00
|
|
|
IsCombined bool
|
2022-05-20 15:02:00 +00:00
|
|
|
}
|
|
|
|
|
2024-01-17 14:26:02 +00:00
|
|
|
// ExtendedNodeVersion contains additional node info to be able to sort versions by timestamp.
|
|
|
|
type ExtendedNodeVersion struct {
|
|
|
|
NodeVersion *NodeVersion
|
|
|
|
IsLatest bool
|
2024-01-22 07:01:24 +00:00
|
|
|
DirName string
|
2022-08-09 12:10:04 +00:00
|
|
|
}
|
|
|
|
|
2024-01-17 14:26:02 +00:00
|
|
|
func (e ExtendedNodeVersion) Version() string {
|
|
|
|
if e.NodeVersion.IsUnversioned {
|
|
|
|
return UnversionedObjectVersionID
|
|
|
|
}
|
|
|
|
|
|
|
|
return e.NodeVersion.OID.EncodeToString()
|
2022-05-20 15:02:00 +00:00
|
|
|
}
|
|
|
|
|
2024-01-22 07:01:24 +00:00
|
|
|
func (e ExtendedNodeVersion) Name() string {
|
|
|
|
if e.DirName != "" {
|
|
|
|
return e.DirName
|
|
|
|
}
|
|
|
|
|
|
|
|
return e.NodeVersion.FilePath
|
|
|
|
}
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
// ExtendedObjectInfo contains additional node info to be able to sort versions by timestamp.
|
|
|
|
type ExtendedObjectInfo struct {
|
|
|
|
ObjectInfo *ObjectInfo
|
|
|
|
NodeVersion *NodeVersion
|
2022-05-31 15:03:58 +00:00
|
|
|
IsLatest bool
|
2022-05-20 15:02:00 +00:00
|
|
|
}
|
|
|
|
|
2022-08-08 22:35:26 +00:00
|
|
|
func (e ExtendedObjectInfo) Version() string {
|
|
|
|
if e.NodeVersion.IsUnversioned {
|
|
|
|
return UnversionedObjectVersionID
|
|
|
|
}
|
|
|
|
|
|
|
|
return e.ObjectInfo.ID.EncodeToString()
|
|
|
|
}
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
// BaseNodeVersion is minimal node info from tree service.
|
|
|
|
// Basically used for "system" object.
|
|
|
|
type BaseNodeVersion struct {
|
2024-01-17 14:26:02 +00:00
|
|
|
ID uint64
|
|
|
|
ParenID uint64
|
|
|
|
OID oid.ID
|
|
|
|
Timestamp uint64
|
2024-01-22 11:11:12 +00:00
|
|
|
Size uint64
|
2024-01-17 14:26:02 +00:00
|
|
|
ETag string
|
|
|
|
MD5 string
|
|
|
|
FilePath string
|
|
|
|
Created *time.Time
|
|
|
|
Owner *user.ID
|
|
|
|
IsDeleteMarker bool
|
2024-07-22 09:00:17 +00:00
|
|
|
CreationEpoch uint64
|
2024-01-17 14:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *BaseNodeVersion) GetETag(md5Enabled bool) string {
|
|
|
|
if md5Enabled && len(v.MD5) > 0 {
|
|
|
|
return v.MD5
|
|
|
|
}
|
|
|
|
return v.ETag
|
|
|
|
}
|
|
|
|
|
2024-01-22 08:09:11 +00:00
|
|
|
// IsFilledExtra returns true is node was created by version of gate v0.29.x and later.
|
2024-01-17 14:26:02 +00:00
|
|
|
func (v BaseNodeVersion) IsFilledExtra() bool {
|
|
|
|
return v.Created != nil && v.Owner != nil
|
|
|
|
}
|
|
|
|
|
2024-01-22 11:11:12 +00:00
|
|
|
func (v *BaseNodeVersion) FillExtra(owner *user.ID, created *time.Time, realSize uint64) {
|
|
|
|
v.Owner = owner
|
|
|
|
v.Created = created
|
|
|
|
v.Size = realSize
|
2022-05-20 15:02:00 +00:00
|
|
|
}
|
2022-05-24 06:58:33 +00:00
|
|
|
|
|
|
|
type ObjectTaggingInfo struct {
|
2022-06-27 09:08:26 +00:00
|
|
|
CnrID cid.ID
|
2022-05-24 06:58:33 +00:00
|
|
|
ObjName string
|
|
|
|
VersionID string
|
|
|
|
}
|
2022-05-23 14:34:13 +00:00
|
|
|
|
|
|
|
// MultipartInfo is multipart upload information.
|
|
|
|
type MultipartInfo struct {
|
2022-05-24 11:30:37 +00:00
|
|
|
// ID is node id in tree service.
|
|
|
|
// It's ignored when creating a new multipart upload.
|
2023-04-24 23:49:12 +00:00
|
|
|
ID uint64
|
|
|
|
Key string
|
|
|
|
UploadID string
|
|
|
|
Owner user.ID
|
|
|
|
Created time.Time
|
|
|
|
Meta map[string]string
|
|
|
|
CopiesNumbers []uint32
|
2023-12-04 06:42:25 +00:00
|
|
|
Finished bool
|
2024-07-22 09:00:17 +00:00
|
|
|
CreationEpoch uint64
|
2022-05-23 14:34:13 +00:00
|
|
|
}
|
2022-05-24 11:30:37 +00:00
|
|
|
|
|
|
|
// PartInfo is upload information about part.
|
|
|
|
type PartInfo struct {
|
2023-06-27 12:49:20 +00:00
|
|
|
Key string `json:"key"`
|
|
|
|
UploadID string `json:"uploadId"`
|
|
|
|
Number int `json:"number"`
|
|
|
|
OID oid.ID `json:"oid"`
|
|
|
|
Size uint64 `json:"size"`
|
|
|
|
ETag string `json:"etag"`
|
2023-10-02 08:52:07 +00:00
|
|
|
MD5 string `json:"md5"`
|
2023-06-27 12:49:20 +00:00
|
|
|
Created time.Time `json:"created"`
|
2022-05-24 11:30:37 +00:00
|
|
|
}
|
2022-05-26 13:11:14 +00:00
|
|
|
|
2024-07-18 13:40:55 +00:00
|
|
|
type PartInfoExtended struct {
|
|
|
|
PartInfo
|
|
|
|
|
|
|
|
// Timestamp is used to find the latest version of part info in case of tree split
|
|
|
|
// when there are multiple nodes for the same part.
|
|
|
|
Timestamp uint64
|
|
|
|
}
|
|
|
|
|
2022-06-02 15:26:26 +00:00
|
|
|
// ToHeaderString form short part representation to use in S3-Completed-Parts header.
|
|
|
|
func (p *PartInfo) ToHeaderString() string {
|
2023-10-27 15:15:33 +00:00
|
|
|
// ETag value contains SHA256 checksum which is used while getting object parts attributes.
|
2023-06-01 13:45:28 +00:00
|
|
|
return strconv.Itoa(p.Number) + "-" + strconv.FormatUint(p.Size, 10) + "-" + p.ETag
|
2022-06-02 15:26:26 +00:00
|
|
|
}
|
|
|
|
|
2023-10-27 15:15:33 +00:00
|
|
|
func (p *PartInfo) GetETag(md5Enabled bool) string {
|
|
|
|
if md5Enabled && len(p.MD5) > 0 {
|
|
|
|
return p.MD5
|
|
|
|
}
|
|
|
|
return p.ETag
|
|
|
|
}
|
|
|
|
|
2022-05-26 13:11:14 +00:00
|
|
|
// LockInfo is lock information to create appropriate tree node.
|
|
|
|
type LockInfo struct {
|
2022-06-27 09:33:36 +00:00
|
|
|
id uint64
|
|
|
|
|
|
|
|
legalHoldOID oid.ID
|
|
|
|
setLegalHold bool
|
|
|
|
|
|
|
|
retentionOID oid.ID
|
|
|
|
setRetention bool
|
|
|
|
untilDate string
|
|
|
|
isCompliance bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewLockInfo(id uint64) *LockInfo {
|
|
|
|
return &LockInfo{id: id}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l LockInfo) ID() uint64 {
|
|
|
|
return l.id
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *LockInfo) SetLegalHold(objID oid.ID) {
|
|
|
|
l.legalHoldOID = objID
|
|
|
|
l.setLegalHold = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *LockInfo) ResetLegalHold() {
|
|
|
|
l.setLegalHold = false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l LockInfo) LegalHold() oid.ID {
|
|
|
|
return l.legalHoldOID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l LockInfo) IsLegalHoldSet() bool {
|
|
|
|
return l.setLegalHold
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *LockInfo) SetRetention(objID oid.ID, until string, isCompliance bool) {
|
|
|
|
l.retentionOID = objID
|
|
|
|
l.setRetention = true
|
|
|
|
l.untilDate = until
|
|
|
|
l.isCompliance = isCompliance
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l LockInfo) IsRetentionSet() bool {
|
|
|
|
return l.setRetention
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l LockInfo) Retention() oid.ID {
|
|
|
|
return l.retentionOID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l LockInfo) UntilDate() string {
|
|
|
|
return l.untilDate
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l LockInfo) IsCompliance() bool {
|
|
|
|
return l.isCompliance
|
2022-05-26 13:11:14 +00:00
|
|
|
}
|