diff --git a/internal/frostfs/authmate.go b/internal/frostfs/authmate.go index 37d9d31..008a999 100644 --- a/internal/frostfs/authmate.go +++ b/internal/frostfs/authmate.go @@ -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() { diff --git a/internal/frostfs/crdt/gset.go b/internal/frostfs/crdt/gset.go index 977c7d7..888e11f 100644 --- a/internal/frostfs/crdt/gset.go +++ b/internal/frostfs/crdt/gset.go @@ -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 } diff --git a/internal/frostfs/crdt/gset_test.go b/internal/frostfs/crdt/gset_test.go index a26589d..b080de7 100644 --- a/internal/frostfs/crdt/gset_test.go +++ b/internal/frostfs/crdt/gset_test.go @@ -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()) + }) +}