[#335] Improve determining AccessBox latest version
All checks were successful
/ DCO (pull_request) Successful in 1m26s
/ Vulncheck (pull_request) Successful in 1m56s
/ Lint (pull_request) Successful in 4m53s
/ Tests (1.20) (pull_request) Successful in 2m56s
/ Tests (1.21) (pull_request) Successful in 2m49s
/ Builds (1.20) (pull_request) Successful in 3m11s
/ Builds (1.21) (pull_request) Successful in 1m12s
All checks were successful
/ DCO (pull_request) Successful in 1m26s
/ Vulncheck (pull_request) Successful in 1m56s
/ Lint (pull_request) Successful in 4m53s
/ Tests (1.20) (pull_request) Successful in 2m56s
/ Tests (1.21) (pull_request) Successful in 2m49s
/ Builds (1.20) (pull_request) Successful in 3m11s
/ Builds (1.21) (pull_request) Successful in 1m12s
Signed-off-by: Anoke <rustamgta1011@gmail.com>
This commit is contained in:
parent
9152b084ec
commit
eb13da1565
3 changed files with 31 additions and 10 deletions
|
@ -76,7 +76,7 @@ func (x *AuthmateFrostFS) GetCredsObject(ctx context.Context, addr oid.Address)
|
|||
|
||||
credObjID := addr.Object()
|
||||
if last := versions.GetLast(); last != nil {
|
||||
credObjID = last.OjbID
|
||||
credObjID = last.ObjID
|
||||
}
|
||||
|
||||
res, err := x.frostFS.ReadObject(ctx, layer.PrmObjectRead{
|
||||
|
@ -107,7 +107,7 @@ func (x *AuthmateFrostFS) CreateObject(ctx context.Context, prm tokens.PrmObject
|
|||
}
|
||||
|
||||
if versions.GetLast() == nil {
|
||||
versions.AppendVersion(&crdt.ObjectVersion{OjbID: addr.Object()})
|
||||
versions.AppendVersion(&crdt.ObjectVersion{ObjID: addr.Object()})
|
||||
}
|
||||
|
||||
for key, val := range versions.GetCRDTHeaders() {
|
||||
|
|
|
@ -20,13 +20,13 @@ type ObjectVersions struct {
|
|||
}
|
||||
|
||||
type ObjectVersion struct {
|
||||
OjbID oid.ID
|
||||
ObjID oid.ID
|
||||
Headers map[string]string
|
||||
CreationEpoch uint64
|
||||
}
|
||||
|
||||
func (o *ObjectVersion) VersionID() string {
|
||||
return o.OjbID.EncodeToString()
|
||||
return o.ObjID.EncodeToString()
|
||||
}
|
||||
|
||||
func NewObjectVersions(name string) *ObjectVersions {
|
||||
|
@ -42,7 +42,7 @@ func NewObjectVersion(obj *object.Object) *ObjectVersion {
|
|||
}
|
||||
|
||||
return &ObjectVersion{
|
||||
OjbID: objID,
|
||||
ObjID: objID,
|
||||
Headers: headers,
|
||||
CreationEpoch: obj.CreationEpoch(),
|
||||
}
|
||||
|
@ -108,8 +108,15 @@ func (v *ObjectVersions) getAddHeader() string {
|
|||
}
|
||||
|
||||
func less(ov1, ov2 *ObjectVersion) bool {
|
||||
versionID1, versionID2 := ov1.VersionID(), ov2.VersionID()
|
||||
if strings.Contains(ov1.Headers[versionsAddAttr], versionID2) {
|
||||
return false
|
||||
}
|
||||
if strings.Contains(ov2.Headers[versionsAddAttr], versionID1) {
|
||||
return true
|
||||
}
|
||||
if ov1.CreationEpoch == ov2.CreationEpoch {
|
||||
return ov1.VersionID() < ov2.VersionID()
|
||||
return versionID1 < versionID2
|
||||
}
|
||||
return ov1.CreationEpoch < ov2.CreationEpoch
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@ func TestObjectVersionsSort(t *testing.T) {
|
|||
|
||||
t.Run("sort by oids", func(t *testing.T) {
|
||||
versions := NewObjectVersions("test")
|
||||
versions.AppendVersion(&ObjectVersion{CreationEpoch: 3, OjbID: getTestOID(2)})
|
||||
versions.AppendVersion(&ObjectVersion{CreationEpoch: 3, OjbID: getTestOID(1)})
|
||||
versions.AppendVersion(&ObjectVersion{CreationEpoch: 1, OjbID: getTestOID(3)})
|
||||
versions.AppendVersion(&ObjectVersion{CreationEpoch: 2, OjbID: getTestOID(4)})
|
||||
versions.AppendVersion(&ObjectVersion{CreationEpoch: 3, ObjID: getTestOID(2)})
|
||||
versions.AppendVersion(&ObjectVersion{CreationEpoch: 3, ObjID: getTestOID(1)})
|
||||
versions.AppendVersion(&ObjectVersion{CreationEpoch: 1, ObjID: getTestOID(3)})
|
||||
versions.AppendVersion(&ObjectVersion{CreationEpoch: 2, ObjID: getTestOID(4)})
|
||||
|
||||
last := versions.GetLast()
|
||||
require.Equal(t, uint64(3), last.CreationEpoch)
|
||||
|
@ -36,3 +36,17 @@ func getTestOID(val byte) oid.ID {
|
|||
res.SetSHA256([32]byte{val})
|
||||
return res
|
||||
}
|
||||
|
||||
func TestObjectVersionsSort1(t *testing.T) {
|
||||
t.Run("sort by headers", func(t *testing.T) {
|
||||
versions := NewObjectVersions("test")
|
||||
versions.AppendVersion(&ObjectVersion{Headers: versions.GetCRDTHeaders(), ObjID: getTestOID(2)})
|
||||
versions.AppendVersion(&ObjectVersion{Headers: versions.GetCRDTHeaders(), ObjID: getTestOID(3)})
|
||||
versions.AppendVersion(&ObjectVersion{Headers: versions.GetCRDTHeaders(), ObjID: getTestOID(4)})
|
||||
versions.AppendVersion(&ObjectVersion{Headers: versions.GetCRDTHeaders(), ObjID: getTestOID(1)})
|
||||
|
||||
last := versions.GetLast()
|
||||
require.Equal(t, uint64(0), last.CreationEpoch)
|
||||
require.Equal(t, getTestOID(1).String(), last.VersionID())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue