[#96] node: Drop neo-go's slices package

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-11-17 10:58:04 +03:00
parent 47286ebf32
commit 76ff26039c
9 changed files with 25 additions and 20 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,7 @@
package meta package meta
import ( import (
"bytes"
"context" "context"
"errors" "errors"
"time" "time"
@ -9,7 +10,6 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
"github.com/nspcc-dev/neo-go/pkg/util/slice"
"go.etcd.io/bbolt" "go.etcd.io/bbolt"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace" "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 nil, nil
} }
return slice.Copy(storageID), nil return bytes.Clone(storageID), nil
} }
// UpdateStorageIDPrm groups the parameters of UpdateStorageID operation. // UpdateStorageIDPrm groups the parameters of UpdateStorageID operation.

View file

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

View file

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

View file

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