Drop neo-go's slices package usage #815

Merged
dstepanov-yadro merged 1 commit from dstepanov-yadro/frostfs-node:fix/drop_slice_copy into master 2023-11-17 10:56:28 +00:00
9 changed files with 25 additions and 20 deletions

View file

@ -1,21 +1,24 @@
package frostfs
import (
"bytes"
"encoding/hex"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
frostfsEvent "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event/frostfs"
"github.com/nspcc-dev/neo-go/pkg/util/slice"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)
func (np *Processor) handleDeposit(ev event.Event) {
deposit := ev.(frostfsEvent.Deposit)
depositIDBin := bytes.Clone(deposit.ID())
slices.Reverse(depositIDBin)
np.log.Info(logs.Notification,
zap.String("type", "deposit"),
zap.String("id", hex.EncodeToString(slice.CopyReverse(deposit.ID()))))
zap.String("id", hex.EncodeToString(depositIDBin)))
// send event to the worker pool
@ -31,9 +34,11 @@ func (np *Processor) handleDeposit(ev event.Event) {
func (np *Processor) handleWithdraw(ev event.Event) {
withdraw := ev.(frostfsEvent.Withdraw)
withdrawBin := bytes.Clone(withdraw.ID())
slices.Reverse(withdrawBin)
np.log.Info(logs.Notification,
zap.String("type", "withdraw"),
zap.String("id", hex.EncodeToString(slice.CopyReverse(withdraw.ID()))))
zap.String("id", hex.EncodeToString(withdrawBin)))
// send event to the worker pool

View file

@ -1,13 +1,13 @@
package blobovnicza
import (
"bytes"
"context"
"errors"
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
"github.com/nspcc-dev/neo-go/pkg/util/slice"
"go.etcd.io/bbolt"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
@ -63,7 +63,7 @@ func (b *Blobovnicza) Get(ctx context.Context, prm GetPrm) (GetRes, error) {
return nil
}
data = slice.Copy(data)
data = bytes.Clone(data)
return errInterruptForEach
})

View file

@ -1,13 +1,13 @@
package blobovnicza
import (
"bytes"
"context"
"errors"
"path/filepath"
"testing"
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
"github.com/nspcc-dev/neo-go/pkg/util/slice"
"github.com/stretchr/testify/require"
"go.etcd.io/bbolt"
)
@ -30,7 +30,7 @@ func TestBlobovniczaIterate(t *testing.T) {
seen := make([][]byte, 0, 2)
inc := func(e IterationElement) error {
seen = append(seen, slice.Copy(e.data))
seen = append(seen, bytes.Clone(e.data))
return nil
}

View file

@ -1,6 +1,7 @@
package blobovniczatree
import (
"bytes"
"context"
"os"
"path/filepath"
@ -10,7 +11,6 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/internal/blobstortest"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test"
"github.com/nspcc-dev/neo-go/pkg/util/slice"
"github.com/stretchr/testify/require"
)
@ -37,7 +37,7 @@ func TestExistsInvalidStorageID(t *testing.T) {
t.Run("valid but wrong storage id", func(t *testing.T) {
// "0/X/Y" <-> "1/X/Y"
storageID := slice.Copy(putRes.StorageID)
storageID := bytes.Clone(putRes.StorageID)
if storageID[0] == '0' {
storageID[0]++
} else {

View file

@ -1,8 +1,9 @@
package meta
import (
"bytes"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/metaerr"
"github.com/nspcc-dev/neo-go/pkg/util/slice"
"go.etcd.io/bbolt"
)
@ -25,7 +26,7 @@ func (db *DB) ReadShardID() ([]byte, error) {
err := db.boltDB.View(func(tx *bbolt.Tx) error {
b := tx.Bucket(shardInfoBucket)
if b != nil {
id = slice.Copy(b.Get(shardIDKey))
id = bytes.Clone(b.Get(shardIDKey))
}
return nil
})

View file

@ -1,6 +1,7 @@
package meta
import (
"bytes"
"context"
"errors"
"time"
@ -9,7 +10,6 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
"github.com/nspcc-dev/neo-go/pkg/util/slice"
"go.etcd.io/bbolt"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
@ -72,7 +72,7 @@ func (db *DB) storageID(tx *bbolt.Tx, addr oid.Address) ([]byte, error) {
return nil, nil
}
return slice.Copy(storageID), nil
return bytes.Clone(storageID), nil
}
// UpdateStorageIDPrm groups the parameters of UpdateStorageID operation.

View file

@ -1,6 +1,7 @@
package shard
import (
"bytes"
"context"
"math"
"path/filepath"
@ -16,7 +17,6 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test"
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
"github.com/nspcc-dev/neo-go/pkg/util/slice"
"github.com/stretchr/testify/require"
)
@ -105,7 +105,7 @@ func testShardGetRange(t *testing.T, hasWriteCache bool) {
testutil.AddPayload(obj, tc.payloadSize)
addr := object.AddressOf(obj)
payload := slice.Copy(obj.Payload())
payload := bytes.Clone(obj.Payload())
var putPrm PutPrm
putPrm.SetObject(obj)

View file

@ -17,7 +17,6 @@ import (
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
"github.com/mr-tron/base58"
"github.com/nspcc-dev/neo-go/pkg/util/slice"
"go.etcd.io/bbolt"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
@ -106,12 +105,12 @@ func (c *cache) flushSmallObjects(ctx context.Context) {
if len(lastKey) == len(k) {
copy(lastKey, k)
} else {
lastKey = slice.Copy(k)
lastKey = bytes.Clone(k)
}
m = append(m, objectInfo{
addr: string(k),
data: slice.Copy(v),
data: bytes.Clone(v),
})
}
return nil

View file

@ -1,6 +1,7 @@
package writecachebbolt
import (
"bytes"
"context"
"time"
@ -12,7 +13,6 @@ import (
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
"github.com/nspcc-dev/neo-go/pkg/util/slice"
"go.etcd.io/bbolt"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
@ -95,7 +95,7 @@ func Get(db *bbolt.DB, key []byte) ([]byte, error) {
if value == nil {
return logicerr.Wrap(new(apistatus.ObjectNotFound))
}
value = slice.Copy(value)
value = bytes.Clone(value)
return nil
})
return value, metaerr.Wrap(err)