forked from TrueCloudLab/frostfs-node
[#1972] node: Do not save objects if node not in a container
Do not use node's local storage if it is clear that an object will be removed anyway as a redundant. It requires moving the changing local storage logic from the validation step to the local target implementation. It allows performing any relations checks (e.g. object locking) only if a node is considered as a valid container member and is expected to store (stored previously) all the helper objects (e.g. `LOCK`, `TOMBSTONE`, etc). Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
a77392e9ce
commit
aab398f4f5
7 changed files with 158 additions and 117 deletions
|
@ -114,7 +114,8 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
obj.SetType(object.TypeTombstone)
|
||||
obj.SetContainerID(cidtest.ID())
|
||||
|
||||
require.Error(t, v.ValidateContent(obj)) // no tombstone content
|
||||
_, err := v.ValidateContent(obj)
|
||||
require.Error(t, err) // no tombstone content
|
||||
|
||||
content := object.NewTombstone()
|
||||
content.SetMembers([]oid.ID{oidtest.ID()})
|
||||
|
@ -124,7 +125,8 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
|
||||
obj.SetPayload(data)
|
||||
|
||||
require.Error(t, v.ValidateContent(obj)) // no members in tombstone
|
||||
_, err = v.ValidateContent(obj)
|
||||
require.Error(t, err) // no members in tombstone
|
||||
|
||||
content.SetMembers([]oid.ID{oidtest.ID()})
|
||||
|
||||
|
@ -133,7 +135,8 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
|
||||
obj.SetPayload(data)
|
||||
|
||||
require.Error(t, v.ValidateContent(obj)) // no expiration epoch in tombstone
|
||||
_, err = v.ValidateContent(obj)
|
||||
require.Error(t, err) // no expiration epoch in tombstone
|
||||
|
||||
var expirationAttribute object.Attribute
|
||||
expirationAttribute.SetKey(objectV2.SysAttributeExpEpoch)
|
||||
|
@ -141,15 +144,23 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
|
||||
obj.SetAttributes(expirationAttribute)
|
||||
|
||||
require.Error(t, v.ValidateContent(obj)) // different expiration values
|
||||
_, err = v.ValidateContent(obj)
|
||||
require.Error(t, err) // different expiration values
|
||||
|
||||
id := oidtest.ID()
|
||||
|
||||
content.SetExpirationEpoch(10)
|
||||
content.SetMembers([]oid.ID{id})
|
||||
data, err = content.Marshal()
|
||||
require.NoError(t, err)
|
||||
|
||||
obj.SetPayload(data)
|
||||
|
||||
require.NoError(t, v.ValidateContent(obj)) // all good
|
||||
contentGot, err := v.ValidateContent(obj)
|
||||
require.NoError(t, err) // all good
|
||||
|
||||
require.EqualValues(t, []oid.ID{id}, contentGot.Objects())
|
||||
require.Equal(t, object.TypeTombstone, contentGot.Type())
|
||||
})
|
||||
|
||||
t.Run("storage group content", func(t *testing.T) {
|
||||
|
@ -157,7 +168,8 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
obj.SetType(object.TypeStorageGroup)
|
||||
|
||||
t.Run("empty payload", func(t *testing.T) {
|
||||
require.Error(t, v.ValidateContent(obj))
|
||||
_, err := v.ValidateContent(obj)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
var content storagegroup.StorageGroup
|
||||
|
@ -168,7 +180,9 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
obj.SetPayload(data)
|
||||
require.ErrorIs(t, v.ValidateContent(obj), errEmptySGMembers)
|
||||
|
||||
_, err = v.ValidateContent(obj)
|
||||
require.ErrorIs(t, err, errEmptySGMembers)
|
||||
})
|
||||
|
||||
t.Run("non-unique members", func(t *testing.T) {
|
||||
|
@ -180,17 +194,25 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
obj.SetPayload(data)
|
||||
require.Error(t, v.ValidateContent(obj))
|
||||
|
||||
_, err = v.ValidateContent(obj)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("correct SG", func(t *testing.T) {
|
||||
content.SetMembers([]oid.ID{oidtest.ID(), oidtest.ID()})
|
||||
ids := []oid.ID{oidtest.ID(), oidtest.ID()}
|
||||
content.SetMembers(ids)
|
||||
|
||||
data, err := content.Marshal()
|
||||
require.NoError(t, err)
|
||||
|
||||
obj.SetPayload(data)
|
||||
require.NoError(t, v.ValidateContent(obj))
|
||||
|
||||
content, err := v.ValidateContent(obj)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.EqualValues(t, ids, content.Objects())
|
||||
require.Equal(t, object.TypeStorageGroup, content.Type())
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue