Skip to content

Commit

Permalink
Same versionid for different versions (#993)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov authored Sep 2, 2024
2 parents 493cdba + 550251b commit a69f23a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
13 changes: 12 additions & 1 deletion api/layer/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,18 @@ func (n *layer) objectDelete(ctx context.Context, bktInfo *data.BucketInfo, idOb

n.cache.DeleteObject(newAddress(bktInfo.CID, idObj))

return n.neoFS.DeleteObject(ctx, prm)
err := n.neoFS.DeleteObject(ctx, prm)

reqInfo := api.GetReqInfo(ctx)
n.log.Debug("delete object",
zap.String("reqId", reqInfo.RequestID),
zap.String("bucket", bktInfo.Name),
zap.Stringer("cid", bktInfo.CID),
zap.Stringer("oid", idObj),
zap.Error(err),
)

return err
}

// objectPutAndHash prepare auth parameters and invoke neofs.CreateObject.
Expand Down
14 changes: 14 additions & 0 deletions internal/neofs/neofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package neofs
import (
"bytes"
"context"
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"errors"
"fmt"
Expand Down Expand Up @@ -55,6 +57,11 @@ type NeoFS struct {
buffers *sync.Pool
}

const (
objectNonceSize = 8
objectNonceAttribute = "__NEOFS__NONCE"
)

// NewNeoFS creates new NeoFS using provided pool.Pool.
func NewNeoFS(p *pool.Pool, signer user.Signer, anonSigner user.Signer, cfg Config, epochGetter EpochGetter) *NeoFS {
buffers := sync.Pool{}
Expand Down Expand Up @@ -268,6 +275,13 @@ func (x *NeoFS) CreateObject(ctx context.Context, prm layer.PrmObjectCreate) (oi
attrs = append(attrs, *a)
}

nonce := make([]byte, objectNonceSize)
if _, err := rand.Read(nonce); err != nil {
return oid.ID{}, fmt.Errorf("object nonce: %w", err)
}
objectNonceAttr := object.NewAttribute(objectNonceAttribute, base64.StdEncoding.EncodeToString(nonce))
attrs = append(attrs, *objectNonceAttr)

var obj object.Object
obj.SetContainerID(prm.Container)
obj.SetOwnerID(&prm.Creator)
Expand Down
46 changes: 46 additions & 0 deletions internal/neofs/neofs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/rand"
"encoding/base64"
"fmt"
"io"
"runtime"
Expand All @@ -19,7 +20,10 @@ import (
"github.com/nspcc-dev/neofs-sdk-go/container"
"github.com/nspcc-dev/neofs-sdk-go/container/acl"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
neofscryptotest "github.com/nspcc-dev/neofs-sdk-go/crypto/test"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
"github.com/nspcc-dev/neofs-sdk-go/object"
"github.com/nspcc-dev/neofs-sdk-go/pool"
"github.com/nspcc-dev/neofs-sdk-go/user"
"github.com/nspcc-dev/neofs-sdk-go/waiter"
Expand Down Expand Up @@ -234,3 +238,45 @@ func uploadDownload(ctx context.Context, t *testing.T, neo *NeoFS, p *pool.Pool,
require.True(t, bytes.Equal(payload, pl))
}
}

func TestObjectNonce(t *testing.T) {
var (
signer = user.NewAutoIDSignerRFC6979(neofscryptotest.Signer().ECDSAPrivateKey)
cnrID = cidtest.ID()
payload = []byte{1, 2, 3, 4, 5}
uid = signer.UserID()
m = make(map[string]int)
ts = time.Now().Unix()
attrTS = object.NewAttribute(object.AttributeTimestamp, strconv.FormatInt(ts, 10))
)

for i := 0; i < 10; i++ {
var (
obj object.Object
nonce = make([]byte, objectNonceSize)
)

_, err := rand.Read(nonce)
require.NoError(t, err)

obj.SetContainerID(cnrID)
obj.SetOwnerID(&uid)
obj.SetPayloadSize(uint64(len(payload)))
obj.SetPayload(payload)

var (
attr = object.NewAttribute(objectNonceAttribute, base64.StdEncoding.EncodeToString(nonce))
attrs = []object.Attribute{*attrTS, *attr}
)

obj.SetAttributes(attrs...)
require.NoError(t, obj.CalculateAndSetID())

m[obj.GetID().String()]++
}

// each ID is uniq
for _, v := range m {
require.Equal(t, 1, v)
}
}

0 comments on commit a69f23a

Please sign in to comment.