From 3da83006eb2b64c47c17a1ce0195108ef8c0a418 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 3 Sep 2024 22:41:25 +0300 Subject: [PATCH 1/8] go.mod, workflow, README: make 1.22 minimal required version This follows https://github.com/nspcc-dev/.github/pull/31. Signed-off-by: Pavel Karpy --- .github/workflows/go.yml | 4 +--- CHANGELOG.md | 2 +- README.md | 2 +- go.mod | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index e5452c2063..e2494e1863 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -46,11 +46,9 @@ jobs: strategy: matrix: os: [ubuntu-22.04, macos-14] - go: [ '1.21', '1.22', '1.23' ] + go: [ '1.22', '1.23' ] exclude: # Only the latest Go version MacOS. - - os: macos-14 - go: '1.21' - os: macos-14 go: '1.22' # Exclude the latest Go version for Ubuntu as Coverage uses it. diff --git a/CHANGELOG.md b/CHANGELOG.md index 607a22a741..16f95c8924 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ Changelog for NeoFS Node ### Removed ### Updated -- Go to 1.21 version (#2517) +- Go to 1.22 version (#2517, #2738) ### Updating from v0.43.0 diff --git a/README.md b/README.md index 85eb826383..5ae9cb2167 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ The latest version of neofs-node works with neofs-contract # Building -To make all binaries you need Go 1.20+ and `make`: +To make all binaries you need Go 1.22+ and `make`: ``` make all ``` diff --git a/go.mod b/go.mod index fd57696e0e..cf90a80197 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/nspcc-dev/neofs-node -go 1.21 +go 1.22 require ( github.com/cheggaaa/pb v1.0.29 From 8956e74f5688feb806aae2dfd7b0d25d306c77b1 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 4 Sep 2024 18:11:26 +0300 Subject: [PATCH 2/8] .docker: bump golang image version to the newest 1.23 Signed-off-by: Pavel Karpy --- .docker/Dockerfile.adm | 2 +- .docker/Dockerfile.cli | 2 +- .docker/Dockerfile.ir | 2 +- .docker/Dockerfile.storage | 2 +- .docker/Dockerfile.storage-testnet | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.docker/Dockerfile.adm b/.docker/Dockerfile.adm index 1abb67219f..ccab599fd1 100644 --- a/.docker/Dockerfile.adm +++ b/.docker/Dockerfile.adm @@ -1,4 +1,4 @@ -FROM golang:1.22 as builder +FROM golang:1.23 as builder ARG BUILD=now ARG VERSION=dev ARG REPO=repository diff --git a/.docker/Dockerfile.cli b/.docker/Dockerfile.cli index 316c207684..518e0c266a 100644 --- a/.docker/Dockerfile.cli +++ b/.docker/Dockerfile.cli @@ -1,4 +1,4 @@ -FROM golang:1.22 as builder +FROM golang:1.23 as builder ARG BUILD=now ARG VERSION=dev ARG REPO=repository diff --git a/.docker/Dockerfile.ir b/.docker/Dockerfile.ir index 41c7779092..fbeb9f62c8 100644 --- a/.docker/Dockerfile.ir +++ b/.docker/Dockerfile.ir @@ -1,4 +1,4 @@ -FROM golang:1.22 as builder +FROM golang:1.23 as builder ARG BUILD=now ARG VERSION=dev ARG REPO=repository diff --git a/.docker/Dockerfile.storage b/.docker/Dockerfile.storage index 4a8718c13c..e3d8acc4d8 100644 --- a/.docker/Dockerfile.storage +++ b/.docker/Dockerfile.storage @@ -1,4 +1,4 @@ -FROM golang:1.22 as builder +FROM golang:1.23 as builder ARG BUILD=now ARG VERSION=dev ARG REPO=repository diff --git a/.docker/Dockerfile.storage-testnet b/.docker/Dockerfile.storage-testnet index 44a93ed034..9b9280856c 100644 --- a/.docker/Dockerfile.storage-testnet +++ b/.docker/Dockerfile.storage-testnet @@ -1,4 +1,4 @@ -FROM golang:1.22 as builder +FROM golang:1.23 as builder ARG BUILD=now ARG VERSION=dev ARG REPO=repository From 4d16669c33a09dac0fd2cb871f8b55bfb49be7b1 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 3 Sep 2024 22:48:06 +0300 Subject: [PATCH 3/8] *: do not copy iteration vars Go devs decided that it is a unique copy every iteration since go 1.22. Signed-off-by: Pavel Karpy --- pkg/services/object/tombstone/verify.go | 1 - pkg/services/tree/sync.go | 1 - 2 files changed, 2 deletions(-) diff --git a/pkg/services/object/tombstone/verify.go b/pkg/services/object/tombstone/verify.go index cdd02be349..fc12b1ede3 100644 --- a/pkg/services/object/tombstone/verify.go +++ b/pkg/services/object/tombstone/verify.go @@ -56,7 +56,6 @@ func (v *Verifier) VerifyTomb(ctx context.Context, cnr cid.ID, t object.Tombston wg.SetLimit(maxConcurrentChecks) for _, member := range t.Members() { - member := member wg.Go(func() error { err := v.verifyMember(ctx, cnr, member) if err != nil { diff --git a/pkg/services/tree/sync.go b/pkg/services/tree/sync.go index e7c9c08036..9249c2bb00 100644 --- a/pkg/services/tree/sync.go +++ b/pkg/services/tree/sync.go @@ -305,7 +305,6 @@ func (s *Service) syncLoop(ctx context.Context) { var wg sync.WaitGroup for _, cnr := range cnrsToSync { wg.Add(1) - cnr := cnr err := s.syncPool.Submit(func() { defer wg.Done() s.log.Debug("syncing container trees...", zap.Stringer("cid", cnr)) From cd542da26c5d02ae4a3ca1e3227cf347240b0b1f Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 3 Sep 2024 22:50:49 +0300 Subject: [PATCH 4/8] *: use range over numbers if possible Signed-off-by: Pavel Karpy --- cmd/neofs-adm/internal/modules/config/config.go | 2 +- cmd/neofs-adm/internal/modules/morph/dump_hashes.go | 2 +- cmd/neofs-adm/internal/modules/morph/generate.go | 2 +- cmd/neofs-adm/internal/modules/morph/initialize.go | 4 ++-- .../internal/modules/morph/initialize_test.go | 4 ++-- cmd/neofs-cli/modules/util/acl.go | 2 +- cmd/neofs-node/config/node/config.go | 2 +- cmd/neofs-node/reputation/ticker/fixed_test.go | 2 +- pkg/core/object/fmt.go | 2 +- pkg/innerring/contracts.go | 2 +- pkg/innerring/processors/audit/scheduler_test.go | 8 ++++---- pkg/innerring/processors/governance/list_test.go | 4 ++-- pkg/local_object_storage/blobstor/bench_test.go | 12 ++++++------ pkg/local_object_storage/blobstor/blobstor_test.go | 2 +- .../blobstor/common/storage_test.go | 2 +- .../blobstor/compression/bench_test.go | 2 +- .../blobstor/fstree/fstree_write_generic.go | 2 +- pkg/local_object_storage/blobstor/iterate_test.go | 2 +- pkg/local_object_storage/engine/container_test.go | 2 +- pkg/local_object_storage/engine/control_test.go | 2 +- pkg/local_object_storage/engine/engine_test.go | 10 +++++----- pkg/local_object_storage/engine/gc_test.go | 2 +- pkg/local_object_storage/engine/list_test.go | 2 +- pkg/local_object_storage/engine/tree_test.go | 6 +++--- pkg/local_object_storage/metabase/containers_test.go | 8 ++++---- pkg/local_object_storage/metabase/counter_test.go | 8 ++++---- pkg/local_object_storage/metabase/get_test.go | 4 ++-- pkg/local_object_storage/metabase/graveyard_test.go | 4 ++-- pkg/local_object_storage/metabase/inhume_test.go | 2 +- pkg/local_object_storage/metabase/list_test.go | 10 +++++----- pkg/local_object_storage/metabase/lock_test.go | 4 ++-- pkg/local_object_storage/metabase/put_test.go | 2 +- pkg/local_object_storage/metabase/select_test.go | 4 ++-- pkg/local_object_storage/pilorama/boltdb.go | 2 +- pkg/local_object_storage/pilorama/forest_test.go | 12 ++++++------ pkg/local_object_storage/shard/dump_test.go | 6 +++--- pkg/local_object_storage/shard/gc_test.go | 2 +- pkg/local_object_storage/shard/list_test.go | 4 ++-- pkg/local_object_storage/shard/metrics_test.go | 8 ++++---- pkg/local_object_storage/writecache/flush.go | 2 +- pkg/local_object_storage/writecache/flush_test.go | 4 ++-- pkg/local_object_storage/writecache/storage.go | 2 +- pkg/morph/client/constructor.go | 2 +- pkg/morph/client/multi.go | 2 +- pkg/morph/event/notary_preparator_test.go | 2 +- .../transport/object/grpc/replication_test.go | 2 +- pkg/services/audit/auditor/pdp.go | 4 ++-- .../announcement/load/controller/calls_test.go | 2 +- pkg/services/control/server/evacuate.go | 2 +- pkg/services/control/types_test.go | 6 +++--- pkg/services/object/acl/v2/util_test.go | 2 +- pkg/services/object/get/get_test.go | 2 +- pkg/services/object/search/search_test.go | 2 +- pkg/services/object_manager/placement/traverser.go | 4 ++-- .../session/storage/persistent/executor_test.go | 2 +- pkg/services/tree/getsubtree_test.go | 2 +- pkg/services/tree/replicator.go | 2 +- 57 files changed, 104 insertions(+), 104 deletions(-) diff --git a/cmd/neofs-adm/internal/modules/config/config.go b/cmd/neofs-adm/internal/modules/config/config.go index 779e03f7ea..2ab38b48fd 100644 --- a/cmd/neofs-adm/internal/modules/config/config.go +++ b/cmd/neofs-adm/internal/modules/config/config.go @@ -126,7 +126,7 @@ func generateConfigExample(appDir string, credSize int) (string, error) { } tmpl.AlphabetDir = filepath.Join(appDir, "alphabet-wallets") - for i := 0; i < credSize; i++ { + for i := range credSize { tmpl.Glagolitics = append(tmpl.Glagolitics, glagolitsa.LetterByIndex(i)) } diff --git a/cmd/neofs-adm/internal/modules/morph/dump_hashes.go b/cmd/neofs-adm/internal/modules/morph/dump_hashes.go index 669678f19d..ebc5e31267 100644 --- a/cmd/neofs-adm/internal/modules/morph/dump_hashes.go +++ b/cmd/neofs-adm/internal/modules/morph/dump_hashes.go @@ -64,7 +64,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error { } var contracts = make([]string, 0, irSize+len(contractList)) - for i := 0; i < irSize; i++ { + for i := range irSize { contracts = append(contracts, getAlphabetNNSDomain(i)) } contracts = append(contracts, contractList...) diff --git a/cmd/neofs-adm/internal/modules/morph/generate.go b/cmd/neofs-adm/internal/modules/morph/generate.go index 493ac500c8..1c421b6fe9 100644 --- a/cmd/neofs-adm/internal/modules/morph/generate.go +++ b/cmd/neofs-adm/internal/modules/morph/generate.go @@ -211,7 +211,7 @@ func createWallets(fileNameTemplate, label, password string, number uint32) ([]u base := strings.TrimSuffix(fileNameTemplate, ext) walletNumberFormat := fmt.Sprintf("%%0%dd", digitsNum(number)) - for i := 0; i < int(number); i++ { + for i := range int(number) { filename := fileNameTemplate if number != 1 { filename = base + "_" + fmt.Sprintf(walletNumberFormat, i) + ext diff --git a/cmd/neofs-adm/internal/modules/morph/initialize.go b/cmd/neofs-adm/internal/modules/morph/initialize.go index f1bd496582..ccc4704eda 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize.go @@ -198,7 +198,7 @@ func openAlphabetWallets(v *viper.Viper, walletDir string) ([]*wallet.Wallet, er var size int loop: - for i := 0; i < len(walletFiles); i++ { + for i := range walletFiles { name := glagolitsa.LetterByIndex(i) + ".json" for j := range walletFiles { if walletFiles[j].Name() == name { @@ -213,7 +213,7 @@ loop: } wallets := make([]*wallet.Wallet, size) - for i := 0; i < size; i++ { + for i := range size { letter := glagolitsa.LetterByIndex(i) p := filepath.Join(walletDir, letter+".json") w, err := wallet.NewWalletFromFile(p) diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_test.go b/cmd/neofs-adm/internal/modules/morph/initialize_test.go index 9eeb5cb3d0..1235ca3066 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_test.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_test.go @@ -82,7 +82,7 @@ func generateTestData(t *testing.T, dir string, size int) { require.NoError(t, generateAlphabetCreds(generateAlphabetCmd, nil)) var pubs []string - for i := 0; i < size; i++ { + for i := range size { p := filepath.Join(dir, glagolitsa.LetterByIndex(i)+".json") w, err := wallet.NewWalletFromFile(p) require.NoError(t, err, "wallet doesn't exist") @@ -110,7 +110,7 @@ func generateTestData(t *testing.T, dir string, size int) { } func setTestCredentials(v *viper.Viper, size int) { - for i := 0; i < size; i++ { + for i := range size { v.Set("credentials."+glagolitsa.LetterByIndex(i), strconv.FormatUint(uint64(i), 10)) } } diff --git a/cmd/neofs-cli/modules/util/acl.go b/cmd/neofs-cli/modules/util/acl.go index ec12e51663..d46d70bc80 100644 --- a/cmd/neofs-cli/modules/util/acl.go +++ b/cmd/neofs-cli/modules/util/acl.go @@ -35,7 +35,7 @@ func PrettyPrintTableBACL(cmd *cobra.Command, bacl *acl.Basic) { fmt.Fprintln(w, strings.Join(bits, "\t")) // Footer footer := []string{"X F"} - for i := 0; i < 7; i++ { + for range 7 { footer = append(footer, "U S O B") } fmt.Fprintln(w, strings.Join(footer, "\t")) diff --git a/cmd/neofs-node/config/node/config.go b/cmd/neofs-node/config/node/config.go index 0d62635385..e01ac44b22 100644 --- a/cmd/neofs-node/config/node/config.go +++ b/cmd/neofs-node/config/node/config.go @@ -117,7 +117,7 @@ func BootstrapAddresses(c *config.Config) (addr network.AddressGroup) { func Attributes(c *config.Config) (attrs []string) { const maxAttributes = 100 - for i := 0; i < maxAttributes; i++ { + for i := range maxAttributes { attr := config.StringSafe(c.Sub(subsection), attributePrefix+"_"+strconv.Itoa(i)) if attr == "" { return diff --git a/cmd/neofs-node/reputation/ticker/fixed_test.go b/cmd/neofs-node/reputation/ticker/fixed_test.go index 25e9bd08f7..0df7055b85 100644 --- a/cmd/neofs-node/reputation/ticker/fixed_test.go +++ b/cmd/neofs-node/reputation/ticker/fixed_test.go @@ -50,7 +50,7 @@ func TestFixedTimer_Tick(t *testing.T) { require.NoError(t, err) - for i := 0; i < int(test.duration); i++ { + for range test.duration { if !timer.Tick() { break } diff --git a/pkg/core/object/fmt.go b/pkg/core/object/fmt.go index 756579f085..b05c565469 100644 --- a/pkg/core/object/fmt.go +++ b/pkg/core/object/fmt.go @@ -327,7 +327,7 @@ func (v *FormatValidator) ValidateContent(o *object.Object) (ContentMeta, error) uniqueFilter := make(map[oid.ID]struct{}, lenMM) - for i := 0; i < lenMM; i++ { + for i := range lenMM { if _, alreadySeen := uniqueFilter[mm[i]]; alreadySeen { return ContentMeta{}, fmt.Errorf("storage group contains non-unique member: %s", mm[i]) } diff --git a/pkg/innerring/contracts.go b/pkg/innerring/contracts.go index f8af6a3f99..2c4df88026 100644 --- a/pkg/innerring/contracts.go +++ b/pkg/innerring/contracts.go @@ -121,7 +121,7 @@ func parseAlphabetContracts(ctx *nnsContext, _logger *zap.Logger, cfg *viper.Vip num = glagolitsa.Size } - for ind := 0; ind < num; ind++ { + for ind := range num { letter := glagolitsa.LetterByIndex(ind) contractHash, err := parseContract(ctx, _logger, cfg, morph, "contracts.alphabet."+letter, diff --git a/pkg/innerring/processors/audit/scheduler_test.go b/pkg/innerring/processors/audit/scheduler_test.go index 2318044a54..426fb1c30a 100644 --- a/pkg/innerring/processors/audit/scheduler_test.go +++ b/pkg/innerring/processors/audit/scheduler_test.go @@ -21,7 +21,7 @@ func TestSelect(t *testing.T) { m := hitMap(cids) - for i := 0; i < irSize; i++ { + for i := range irSize { s := audit.Select(cids, 0, uint64(i), irSize) require.Equal(t, len(cids)/irSize, len(s)) @@ -41,7 +41,7 @@ func TestSelect(t *testing.T) { m := hitMap(cids) - for i := 0; i < irSize; i++ { + for i := range irSize { s := audit.Select(cids, 0, uint64(i), irSize) for _, id := range s { @@ -60,7 +60,7 @@ func TestSelect(t *testing.T) { m := hitMap(cids) - for i := 0; i < irSize; i++ { + for i := range irSize { s := audit.Select(cids, uint64(i), 0, irSize) for _, id := range s { @@ -78,7 +78,7 @@ func TestSelect(t *testing.T) { func generateContainers(n int) []cid.ID { result := make([]cid.ID, n) - for i := 0; i < n; i++ { + for i := range n { result[i] = cidtest.ID() } diff --git a/pkg/innerring/processors/governance/list_test.go b/pkg/innerring/processors/governance/list_test.go index fec1b617df..7867d3b274 100644 --- a/pkg/innerring/processors/governance/list_test.go +++ b/pkg/innerring/processors/governance/list_test.go @@ -50,7 +50,7 @@ func TestNewAlphabetList(t *testing.T) { } ln := len(rounds) - for i := 0; i < ln; i++ { + for i := range ln { list, err = newAlphabetList(list, exp) require.NoError(t, err) require.True(t, equalPublicKeyLists(list, rounds[i])) @@ -132,7 +132,7 @@ func TestUpdateInnerRing(t *testing.T) { func generateKeys(n int) (keys.PublicKeys, error) { pubKeys := make(keys.PublicKeys, 0, n) - for i := 0; i < n; i++ { + for range n { privKey, err := keys.NewPrivateKey() if err != nil { return nil, err diff --git a/pkg/local_object_storage/blobstor/bench_test.go b/pkg/local_object_storage/blobstor/bench_test.go index 2c76c0d844..32b5ba78ae 100644 --- a/pkg/local_object_storage/blobstor/bench_test.go +++ b/pkg/local_object_storage/blobstor/bench_test.go @@ -45,10 +45,10 @@ func benchmark(b *testing.B, p common.Storage, objSize uint64, nThreads int) { b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { var wg sync.WaitGroup - for i := 0; i < nThreads; i++ { + for range nThreads { wg.Add(1) go func() { defer wg.Done() @@ -140,7 +140,7 @@ func BenchmarkGet(b *testing.B) { } var ach = make(chan oid.Address) - for i := 0; i < 100; i++ { + for range 100 { go func() { for j := 0; j < nObjects/100; j++ { prm := prm @@ -153,16 +153,16 @@ func BenchmarkGet(b *testing.B) { } }() } - for i := 0; i < nObjects; i++ { + for range nObjects { a := <-ach objs = append(objs, a) } b.ResetTimer() - for n := 0; n < b.N; n++ { + for n := range b.N { var wg sync.WaitGroup - for i := 0; i < tc.nThreads; i++ { + for i := range tc.nThreads { wg.Add(1) go func(ind int) { defer wg.Done() diff --git a/pkg/local_object_storage/blobstor/blobstor_test.go b/pkg/local_object_storage/blobstor/blobstor_test.go index 8bb6a333af..db9443af2a 100644 --- a/pkg/local_object_storage/blobstor/blobstor_test.go +++ b/pkg/local_object_storage/blobstor/blobstor_test.go @@ -49,7 +49,7 @@ func TestCompression(t *testing.T) { bigObj := make([]*objectSDK.Object, objCount) smallObj := make([]*objectSDK.Object, objCount) - for i := 0; i < objCount; i++ { + for i := range objCount { bigObj[i] = testObject(smallSizeLimit * 2) smallObj[i] = testObject(smallSizeLimit / 2) } diff --git a/pkg/local_object_storage/blobstor/common/storage_test.go b/pkg/local_object_storage/blobstor/common/storage_test.go index b14315f3a4..13b7b7b924 100644 --- a/pkg/local_object_storage/blobstor/common/storage_test.go +++ b/pkg/local_object_storage/blobstor/common/storage_test.go @@ -25,7 +25,7 @@ func TestCopy(t *testing.T) { mObjs := make(map[oid.Address][]byte, nObjects) - for i := 0; i < nObjects; i++ { + for range nObjects { addr := oidtest.Address() data := make([]byte, 32) rand.Read(data) diff --git a/pkg/local_object_storage/blobstor/compression/bench_test.go b/pkg/local_object_storage/blobstor/compression/bench_test.go index 6e05366cfb..8178edaacd 100644 --- a/pkg/local_object_storage/blobstor/compression/bench_test.go +++ b/pkg/local_object_storage/blobstor/compression/bench_test.go @@ -34,7 +34,7 @@ func BenchmarkCompression(b *testing.B) { func benchWith(b *testing.B, c Config, data []byte) { b.ResetTimer() b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { _ = c.Compress(data) } } diff --git a/pkg/local_object_storage/blobstor/fstree/fstree_write_generic.go b/pkg/local_object_storage/blobstor/fstree/fstree_write_generic.go index 8c85b1c671..d51ec8f8c4 100644 --- a/pkg/local_object_storage/blobstor/fstree/fstree_write_generic.go +++ b/pkg/local_object_storage/blobstor/fstree/fstree_write_generic.go @@ -57,7 +57,7 @@ func (w *genericWriter) writeData(_ oid.ID, p string, data []byte) error { // In a very rare situation we can have multiple partially written copies on disk, // this will be fixed in another issue (we should remove garbage on start). const retryCount = 5 - for i := 0; i < retryCount; i++ { + for i := range retryCount { tmpPath := p + "#" + strconv.FormatUint(uint64(i), 10) err := w.writeAndRename(tmpPath, p, data) if err != syscall.EEXIST || i == retryCount-1 { diff --git a/pkg/local_object_storage/blobstor/iterate_test.go b/pkg/local_object_storage/blobstor/iterate_test.go index 78191e924a..bb8a612efe 100644 --- a/pkg/local_object_storage/blobstor/iterate_test.go +++ b/pkg/local_object_storage/blobstor/iterate_test.go @@ -144,7 +144,7 @@ func TestIterate_IgnoreErrors(t *testing.T) { //require.NoError(t, b.Init()) // //var p string - //for i := 0; i < 2; i++ { + //for i := range 2 { // bp := filepath.Join(bs.rootPath, "1", strconv.FormatUint(uint64(i), 10)) // if _, ok := bs.blobovniczas.opened.Get(bp); !ok { // p = bp diff --git a/pkg/local_object_storage/engine/container_test.go b/pkg/local_object_storage/engine/container_test.go index 8ca2d87f20..2c3ae9dded 100644 --- a/pkg/local_object_storage/engine/container_test.go +++ b/pkg/local_object_storage/engine/container_test.go @@ -33,7 +33,7 @@ func TestStorageEngine_ContainerCleanUp(t *testing.T) { _ = e.Close() }) - for i := 0; i < 5; i++ { + for i := range 5 { _, err := e.AddShard( shard.WithBlobStorOptions( blobstor.WithStorages(newStorages(filepath.Join(path, strconv.Itoa(i)), errSmallSize))), diff --git a/pkg/local_object_storage/engine/control_test.go b/pkg/local_object_storage/engine/control_test.go index 6cf9a19f3e..108ed21a04 100644 --- a/pkg/local_object_storage/engine/control_test.go +++ b/pkg/local_object_storage/engine/control_test.go @@ -271,7 +271,7 @@ func engineWithShards(t *testing.T, path string, num int) (*StorageEngine, []str currShards := make([]string, 0, num) e := New() - for i := 0; i < num; i++ { + for i := range num { id, err := e.AddShard( shard.WithBlobStorOptions( blobstor.WithStorages(newStorages(filepath.Join(addPath, strconv.Itoa(i)), errSmallSize))), diff --git a/pkg/local_object_storage/engine/engine_test.go b/pkg/local_object_storage/engine/engine_test.go index d86e4c3af0..26a8519f5e 100644 --- a/pkg/local_object_storage/engine/engine_test.go +++ b/pkg/local_object_storage/engine/engine_test.go @@ -51,7 +51,7 @@ func BenchmarkExists(b *testing.B) { func benchmarkExists(b *testing.B, shardNum int) { shards := make([]*shard.Shard, shardNum) - for i := 0; i < shardNum; i++ { + for i := range shardNum { shards[i] = testNewShard(b, i) } @@ -62,7 +62,7 @@ func benchmarkExists(b *testing.B, shardNum int) { }) addr := oidtest.Address() - for i := 0; i < 100; i++ { + for range 100 { obj := generateObjectWithCID(b, cidtest.ID()) err := Put(e, obj) if err != nil { @@ -72,7 +72,7 @@ func benchmarkExists(b *testing.B, shardNum int) { b.ReportAllocs() b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { ok, err := e.exists(addr) if err != nil || ok { b.Fatalf("%t %v", ok, err) @@ -149,7 +149,7 @@ func testNewShard(t testing.TB, id int) *shard.Shard { func testEngineFromShardOpts(t *testing.T, num int, extraOpts []shard.Option) *StorageEngine { engine := New() - for i := 0; i < num; i++ { + for i := range num { _, err := engine.AddShard(append([]shard.Option{ shard.WithBlobStorOptions( blobstor.WithStorages( @@ -210,7 +210,7 @@ func addAttribute(obj *object.Object, key, val string) { func testNewEngineWithShardNum(t *testing.T, num int) *StorageEngine { shards := make([]*shard.Shard, 0, num) - for i := 0; i < num; i++ { + for i := range num { shards = append(shards, testNewShard(t, i)) } diff --git a/pkg/local_object_storage/engine/gc_test.go b/pkg/local_object_storage/engine/gc_test.go index c3448f26d9..01515b902a 100644 --- a/pkg/local_object_storage/engine/gc_test.go +++ b/pkg/local_object_storage/engine/gc_test.go @@ -29,7 +29,7 @@ func TestChildrenExpiration(t *testing.T) { owner := usertest.ID() e := New() - for i := 0; i < numOfShards; i++ { + for i := range numOfShards { _, err := e.AddShard( shard.WithBlobStorOptions( blobstor.WithStorages( diff --git a/pkg/local_object_storage/engine/list_test.go b/pkg/local_object_storage/engine/list_test.go index 2762aa37a6..4c8ee3c411 100644 --- a/pkg/local_object_storage/engine/list_test.go +++ b/pkg/local_object_storage/engine/list_test.go @@ -27,7 +27,7 @@ func TestListWithCursor(t *testing.T) { expected := make([]object.AddressWithType, 0, total) got := make([]object.AddressWithType, 0, total) - for i := 0; i < total; i++ { + for range total { containerID := cidtest.ID() obj := generateObjectWithCID(t, containerID) diff --git a/pkg/local_object_storage/engine/tree_test.go b/pkg/local_object_storage/engine/tree_test.go index 1c5b569ea6..8d991ba17c 100644 --- a/pkg/local_object_storage/engine/tree_test.go +++ b/pkg/local_object_storage/engine/tree_test.go @@ -27,7 +27,7 @@ func benchmarkTreeVsSearch(b *testing.B, objCount int) { d := pilorama.CIDDescriptor{CID: cid, Position: 0, Size: 1} treeID := "someTree" - for i := 0; i < objCount; i++ { + for i := range objCount { obj := generateObjectWithCID(b, cid) addAttribute(obj, pilorama.AttributeFilename, strconv.Itoa(i)) err := Put(e, obj) @@ -49,7 +49,7 @@ func benchmarkTreeVsSearch(b *testing.B, objCount int) { fs.AddFilter(pilorama.AttributeFilename, strconv.Itoa(objCount/2), object.MatchStringEqual) prm.WithFilters(fs) - for i := 0; i < b.N; i++ { + for range b.N { res, err := e.Select(prm) if err != nil { b.Fatal(err) @@ -60,7 +60,7 @@ func benchmarkTreeVsSearch(b *testing.B, objCount int) { } }) b.Run("TreeGetByPath", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { nodes, err := e.TreeGetByPath(cid, treeID, pilorama.AttributeFilename, []string{strconv.Itoa(objCount / 2)}, true) if err != nil { b.Fatal(err) diff --git a/pkg/local_object_storage/metabase/containers_test.go b/pkg/local_object_storage/metabase/containers_test.go index 9c4db58d12..65cfc77e5e 100644 --- a/pkg/local_object_storage/metabase/containers_test.go +++ b/pkg/local_object_storage/metabase/containers_test.go @@ -23,7 +23,7 @@ func TestDB_Containers(t *testing.T) { cids := make(map[string]int, N) - for i := 0; i < N; i++ { + for range N { obj := generateObject(t) cnr, _ := obj.ContainerID() @@ -109,7 +109,7 @@ func TestDB_ContainersCount(t *testing.T) { expected := make([]cid.ID, 0, R+T+SG+L) for _, upload := range uploadObjects { - for i := 0; i < upload.amount; i++ { + for range upload.amount { obj := generateObject(t) obj.SetType(upload.typ) @@ -146,11 +146,11 @@ func TestDB_ContainerSize(t *testing.T) { cids := make(map[cid.ID]int, C) objs := make(map[cid.ID][]*objectSDK.Object, C*N) - for i := 0; i < C; i++ { + for range C { cnr := cidtest.ID() cids[cnr] = 0 - for j := 0; j < N; j++ { + for range N { size := rand.Intn(1024) parent := generateObjectWithCID(t, cnr) diff --git a/pkg/local_object_storage/metabase/counter_test.go b/pkg/local_object_storage/metabase/counter_test.go index 0604d7e0c5..75c7ad0f34 100644 --- a/pkg/local_object_storage/metabase/counter_test.go +++ b/pkg/local_object_storage/metabase/counter_test.go @@ -28,13 +28,13 @@ func TestCounters(t *testing.T) { t.Run("put", func(t *testing.T) { oo := make([]*object.Object, 0, objCount) - for i := 0; i < objCount; i++ { + for range objCount { oo = append(oo, generateObject(t)) } var prm meta.PutPrm - for i := 0; i < objCount; i++ { + for i := range objCount { prm.SetObject(oo[i]) _, err = db.Put(prm) @@ -106,7 +106,7 @@ func TestCounters(t *testing.T) { // put objects and check that parent info // does not affect the counter - for i := 0; i < objCount; i++ { + for i := range objCount { o := generateObject(t) if i < objCount/2 { // half of the objs will have the parent o.SetParent(parObj) @@ -274,7 +274,7 @@ func putObjs(t *testing.T, db *meta.DB, count int, withParent bool) []*object.Ob parent := generateObject(t) oo := make([]*object.Object, 0, count) - for i := 0; i < count; i++ { + for i := range count { o := generateObject(t) if withParent { o.SetParent(parent) diff --git a/pkg/local_object_storage/metabase/get_test.go b/pkg/local_object_storage/metabase/get_test.go index c747e1cc4d..ffba530f27 100644 --- a/pkg/local_object_storage/metabase/get_test.go +++ b/pkg/local_object_storage/metabase/get_test.go @@ -185,7 +185,7 @@ func benchmarkGet(b *testing.B, numOfObj int) { ) addrs := make([]oid.Address, 0, numOfObj) - for i := 0; i < numOfObj; i++ { + for range numOfObj { raw := generateObject(b) addrs = append(addrs, object.AddressOf(raw)) @@ -223,7 +223,7 @@ func benchmarkGet(b *testing.B, numOfObj int) { b.Run("serial", func(b *testing.B) { b.ReportAllocs() - for i := 0; i < b.N; i++ { + for i := range b.N { var getPrm meta.GetPrm getPrm.SetAddress(addrs[i%len(addrs)]) diff --git a/pkg/local_object_storage/metabase/graveyard_test.go b/pkg/local_object_storage/metabase/graveyard_test.go index 605e216ad6..747e512ac2 100644 --- a/pkg/local_object_storage/metabase/graveyard_test.go +++ b/pkg/local_object_storage/metabase/graveyard_test.go @@ -445,7 +445,7 @@ func TestDB_GetGarbage(t *testing.T) { var oo []*objectsdk.Object var size uint64 - for i := 0; i < numOfObjs; i++ { + for i := range numOfObjs { raw := generateObjectWithCID(t, cID) addAttribute(raw, "foo"+strconv.Itoa(i), "bar"+strconv.Itoa(i)) @@ -465,7 +465,7 @@ func TestDB_GetGarbage(t *testing.T) { _, err = db.InhumeContainer(cID) require.NoError(t, err) - for i := 0; i < numOfObjs; i++ { + for i := range numOfObjs { garbageObjs, garbageContainers, err := db.GetGarbage(i + 1) require.NoError(t, err) require.Len(t, garbageObjs, i+1) diff --git a/pkg/local_object_storage/metabase/inhume_test.go b/pkg/local_object_storage/metabase/inhume_test.go index 017e2c1f11..3a38a21991 100644 --- a/pkg/local_object_storage/metabase/inhume_test.go +++ b/pkg/local_object_storage/metabase/inhume_test.go @@ -122,7 +122,7 @@ func TestInhumeContainer(t *testing.T) { var oo []*objectsdk.Object var size uint64 - for i := 0; i < numOfObjs; i++ { + for i := range numOfObjs { raw := generateObjectWithCID(t, cID) addAttribute(raw, "foo"+strconv.Itoa(i), "bar"+strconv.Itoa(i)) diff --git a/pkg/local_object_storage/metabase/list_test.go b/pkg/local_object_storage/metabase/list_test.go index 3a325afa28..de193f21a0 100644 --- a/pkg/local_object_storage/metabase/list_test.go +++ b/pkg/local_object_storage/metabase/list_test.go @@ -49,7 +49,7 @@ func benchmarkListWithCursor(b *testing.B, db *meta.DB, batchSize int) { b.ResetTimer() b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { res, err := db.ListWithCursor(prm) if err != nil { if err != meta.ErrEndOfListing { @@ -75,7 +75,7 @@ func TestLisObjectsWithCursor(t *testing.T) { expected := make([]object.AddressWithType, 0, total) // fill metabase with objects - for i := 0; i < containers; i++ { + for range containers { containerID := cidtest.ID() // add one regular object @@ -144,7 +144,7 @@ func TestLisObjectsWithCursor(t *testing.T) { expectedIterations-- } - for i := 0; i < expectedIterations; i++ { + for range expectedIterations { res, cursor, err = metaListWithCursor(db, uint32(countPerReq), cursor) require.NoError(t, err, "count:%d", countPerReq) got = append(got, res...) @@ -172,7 +172,7 @@ func TestAddObjectDuringListingWithCursor(t *testing.T) { expected := make(map[string]int, total) // fill metabase with objects - for i := 0; i < total; i++ { + for range total { obj := generateObject(t) err := putBig(db, obj) require.NoError(t, err) @@ -189,7 +189,7 @@ func TestAddObjectDuringListingWithCursor(t *testing.T) { } // add new objects - for i := 0; i < total; i++ { + for range total { obj := generateObject(t) err = putBig(db, obj) require.NoError(t, err) diff --git a/pkg/local_object_storage/metabase/lock_test.go b/pkg/local_object_storage/metabase/lock_test.go index bda96ad36d..2b09453afc 100644 --- a/pkg/local_object_storage/metabase/lock_test.go +++ b/pkg/local_object_storage/metabase/lock_test.go @@ -149,7 +149,7 @@ func TestDB_Lock(t *testing.T) { inhumePrm.SetGCMark() - for i := 0; i < objsNum; i++ { + for i := range objsNum { inhumePrm.SetAddresses(objectcore.AddressOf(objs[i])) res, err = db.Inhume(inhumePrm) @@ -243,7 +243,7 @@ func putAndLockObj(t *testing.T, db *meta.DB, numOfLockedObjs int) ([]*object.Ob lockedObjs := make([]*object.Object, 0, numOfLockedObjs) lockedObjIDs := make([]oid.ID, 0, numOfLockedObjs) - for i := 0; i < numOfLockedObjs; i++ { + for range numOfLockedObjs { obj := generateObjectWithCID(t, cnr) err := putBig(db, obj) require.NoError(t, err) diff --git a/pkg/local_object_storage/metabase/put_test.go b/pkg/local_object_storage/metabase/put_test.go index bc1724f746..8fa9f52e37 100644 --- a/pkg/local_object_storage/metabase/put_test.go +++ b/pkg/local_object_storage/metabase/put_test.go @@ -70,7 +70,7 @@ func BenchmarkPut(b *testing.B) { objs := prepareObjects(b, b.N) b.ResetTimer() b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { if err := metaPut(db, objs[index.Add(1)], nil); err != nil { b.Fatal(err) } diff --git a/pkg/local_object_storage/metabase/select_test.go b/pkg/local_object_storage/metabase/select_test.go index a607d4c99e..5d92d3ac0d 100644 --- a/pkg/local_object_storage/metabase/select_test.go +++ b/pkg/local_object_storage/metabase/select_test.go @@ -773,7 +773,7 @@ func BenchmarkSelect(b *testing.B) { db := newDB(b) cid := cidtest.ID() - for i := 0; i < objCount; i++ { + for i := range objCount { var attr objectSDK.Attribute attr.SetKey("myHeader") attr.SetValue(strconv.Itoa(i)) @@ -878,7 +878,7 @@ func benchmarkSelect(b *testing.B, db *meta.DB, cid cidSDK.ID, fs objectSDK.Sear prm.SetContainerID(cid) prm.SetFilters(fs) - for i := 0; i < b.N; i++ { + for range b.N { res, err := db.Select(prm) if err != nil { b.Fatal(err) diff --git a/pkg/local_object_storage/pilorama/boltdb.go b/pkg/local_object_storage/pilorama/boltdb.go index 26b83f4aec..70390b70fe 100644 --- a/pkg/local_object_storage/pilorama/boltdb.go +++ b/pkg/local_object_storage/pilorama/boltdb.go @@ -433,7 +433,7 @@ func (t *boltForest) applyOperation(logBucket, treeBucket *bbolt.Bucket, ms []*M key, value = c.Prev() } - for i := 0; i < len(ms); i++ { + for i := range len(ms) { // Loop invariant: key represents the next stored timestamp after ms[i].Time. // 2. Insert the operation. diff --git a/pkg/local_object_storage/pilorama/forest_test.go b/pkg/local_object_storage/pilorama/forest_test.go index fe0e6bdc3b..333398f957 100644 --- a/pkg/local_object_storage/pilorama/forest_test.go +++ b/pkg/local_object_storage/pilorama/forest_test.go @@ -671,7 +671,7 @@ func TestForest_ParallelApply(t *testing.T) { // The operations are guaranteed to be applied and returned sorted by `Time`. func prepareRandomTree(nodeCount, opCount int) []Move { ops := make([]Move, nodeCount+opCount) - for i := 0; i < nodeCount; i++ { + for i := range nodeCount { ops[i] = Move{ Parent: 0, Meta: Meta{ @@ -757,14 +757,14 @@ func testForestTreeParallelApply(t *testing.T, constructor func(t testing.TB, _ require.NoError(t, expected.TreeApply(d, treeID, &ops[i], false)) } - for i := 0; i < iterCount; i++ { + for range iterCount { // Shuffle random operations, leave initialization in place. rand.Shuffle(len(ops), func(i, j int) { ops[i], ops[j] = ops[j], ops[i] }) actual := constructor(t, WithMaxBatchSize(batchSize)) wg := new(sync.WaitGroup) ch := make(chan *Move, 0) - for i := 0; i < batchSize; i++ { + for range batchSize { wg.Add(1) go func() { defer wg.Done() @@ -805,7 +805,7 @@ func testForestTreeApplyRandom(t *testing.T, constructor func(t testing.TB, _ .. } const iterCount = 200 - for i := 0; i < iterCount; i++ { + for range iterCount { // Shuffle random operations, leave initialization in place. rand.Shuffle(len(ops), func(i, j int) { ops[i], ops[j] = ops[j], ops[i] }) @@ -897,7 +897,7 @@ func benchmarkApply(b *testing.B, s Forest, genFunc func(int) []Move) { d := CIDDescriptor{cid, 0, 1} treeID := "version" ch := make(chan int, b.N) - for i := 0; i < b.N; i++ { + for i := range b.N { ch <- i } @@ -943,7 +943,7 @@ func testTreeGetByPath(t *testing.T, s Forest) { if mf, ok := s.(*memoryForest); ok { single := mf.treeMap[cid.String()+"/"+treeID] t.Run("test meta", func(t *testing.T) { - for i := 0; i < 6; i++ { + for i := range 6 { require.Equal(t, uint64(i), single.infoMap[Node(i+1)].Meta.Time) } }) diff --git a/pkg/local_object_storage/shard/dump_test.go b/pkg/local_object_storage/shard/dump_test.go index af704fc4d1..0e0dea8f15 100644 --- a/pkg/local_object_storage/shard/dump_test.go +++ b/pkg/local_object_storage/shard/dump_test.go @@ -81,7 +81,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) { const headerSize = 400 objects := make([]*objectSDK.Object, objCount) - for i := 0; i < objCount; i++ { + for i := range objCount { cnr := cidtest.ID() var size int switch i % 6 { @@ -225,7 +225,7 @@ func TestStream(t *testing.T) { const objCount = 5 objects := make([]*objectSDK.Object, objCount) - for i := 0; i < objCount; i++ { + for i := range objCount { cnr := cidtest.ID() obj := generateObjectWithCID(t, cnr) objects[i] = obj @@ -320,7 +320,7 @@ func TestDumpIgnoreErrors(t *testing.T) { sh := newCustomShard(t, dir, true, wcOpts, bsOpts(2)) objects := make([]*objectSDK.Object, objCount) - for i := 0; i < objCount; i++ { + for i := range objCount { size := (wcSmallObjectSize << (i % 4)) - headerSize obj := generateObjectWithPayload(t, cidtest.ID(), make([]byte, size)) objects[i] = obj diff --git a/pkg/local_object_storage/shard/gc_test.go b/pkg/local_object_storage/shard/gc_test.go index bc7de3e8da..1892272404 100644 --- a/pkg/local_object_storage/shard/gc_test.go +++ b/pkg/local_object_storage/shard/gc_test.go @@ -132,7 +132,7 @@ func TestGC_ContainerCleanup(t *testing.T) { cID := cidtest.ID() oo := make([]oid.Address, 0, numOfObjs) - for i := 0; i < numOfObjs; i++ { + for i := range numOfObjs { var putPrm shard.PutPrm obj := generateObjectWithCID(t, cID) diff --git a/pkg/local_object_storage/shard/list_test.go b/pkg/local_object_storage/shard/list_test.go index 07290106bb..9c7332766c 100644 --- a/pkg/local_object_storage/shard/list_test.go +++ b/pkg/local_object_storage/shard/list_test.go @@ -34,10 +34,10 @@ func testShardList(t *testing.T, sh *shard.Shard) { objs := make(map[string]int) var putPrm shard.PutPrm - for i := 0; i < C; i++ { + for range C { cnr := cidtest.ID() - for j := 0; j < N; j++ { + for range N { obj := generateObjectWithCID(t, cnr) addPayload(obj, 1<<2) diff --git a/pkg/local_object_storage/shard/metrics_test.go b/pkg/local_object_storage/shard/metrics_test.go index cb7def33e9..7c4574b9a9 100644 --- a/pkg/local_object_storage/shard/metrics_test.go +++ b/pkg/local_object_storage/shard/metrics_test.go @@ -81,7 +81,7 @@ func TestCounters(t *testing.T) { const objNumber = 10 oo := make([]*object.Object, objNumber) - for i := 0; i < objNumber; i++ { + for i := range objNumber { oo[i] = generateObject(t) } @@ -105,7 +105,7 @@ func TestCounters(t *testing.T) { t.Run("put", func(t *testing.T) { var prm shard.PutPrm - for i := 0; i < objNumber; i++ { + for i := range objNumber { prm.SetObject(oo[i]) _, err := sh.Put(prm) @@ -122,7 +122,7 @@ func TestCounters(t *testing.T) { var prm shard.InhumePrm inhumedNumber := objNumber / 4 - for i := 0; i < inhumedNumber; i++ { + for i := range inhumedNumber { prm.MarkAsGarbage(objectcore.AddressOf(oo[i])) _, err := sh.Inhume(prm) @@ -226,7 +226,7 @@ func shardWithMetrics(t *testing.T, path string) (*shard.Shard, *metricsStore) { func addrFromObjs(oo []*object.Object) []oid.Address { aa := make([]oid.Address, len(oo)) - for i := 0; i < len(oo); i++ { + for i := range len(oo) { aa[i] = objectcore.AddressOf(oo[i]) } diff --git a/pkg/local_object_storage/writecache/flush.go b/pkg/local_object_storage/writecache/flush.go index 4b894be957..5b06e47a36 100644 --- a/pkg/local_object_storage/writecache/flush.go +++ b/pkg/local_object_storage/writecache/flush.go @@ -30,7 +30,7 @@ const ( // runFlushLoop starts background workers which periodically flush objects to the blobstor. func (c *cache) runFlushLoop() { - for i := 0; i < c.workersCount; i++ { + for i := range c.workersCount { c.wg.Add(1) go c.flushWorker(i) } diff --git a/pkg/local_object_storage/writecache/flush_test.go b/pkg/local_object_storage/writecache/flush_test.go index d9df539d83..79c53a4786 100644 --- a/pkg/local_object_storage/writecache/flush_test.go +++ b/pkg/local_object_storage/writecache/flush_test.go @@ -84,7 +84,7 @@ func TestFlush(t *testing.T) { require.NoError(t, wc.Flush(false)) - for i := 0; i < 2; i++ { + for i := range 2 { var mPrm meta.GetPrm mPrm.SetAddress(objects[i].addr) _, err := mb.Get(mPrm) @@ -115,7 +115,7 @@ func TestFlush(t *testing.T) { require.NoError(t, wc.SetMode(mode.Degraded)) - for i := 0; i < 2; i++ { + for i := range 2 { var mPrm meta.GetPrm mPrm.SetAddress(objects[i].addr) _, err := mb.Get(mPrm) diff --git a/pkg/local_object_storage/writecache/storage.go b/pkg/local_object_storage/writecache/storage.go index 895df0a186..2feacbf8da 100644 --- a/pkg/local_object_storage/writecache/storage.go +++ b/pkg/local_object_storage/writecache/storage.go @@ -111,7 +111,7 @@ func (c *cache) deleteFromDB(keys []string) []string { } return nil }) - for i := 0; i < errorIndex; i++ { + for i := range errorIndex { c.objCounters.DecDB() storagelog.Write(c.log, storagelog.AddressField(keys[i]), diff --git a/pkg/morph/client/constructor.go b/pkg/morph/client/constructor.go index 2a03f591e1..7e7714d60c 100644 --- a/pkg/morph/client/constructor.go +++ b/pkg/morph/client/constructor.go @@ -174,7 +174,7 @@ func New(key *keys.PrivateKey, opts ...Option) (*Client, error) { } cli.setActor(act) - for attempt := 0; attempt < cfg.reconnectionRetries; attempt++ { + for range cfg.reconnectionRetries { err = cli.reachedHeight(cfg.minRequiredHeight) if !errors.Is(err, ErrStaleNodes) { break diff --git a/pkg/morph/client/multi.go b/pkg/morph/client/multi.go index dd46276a08..f8e63a82c8 100644 --- a/pkg/morph/client/multi.go +++ b/pkg/morph/client/multi.go @@ -16,7 +16,7 @@ type Endpoint struct { func (c *Client) SwitchRPC() bool { c.switchLock.Lock() - for attempt := 0; attempt < c.cfg.reconnectionRetries; attempt++ { + for range c.cfg.reconnectionRetries { if c.switchRPC() { c.switchLock.Unlock() diff --git a/pkg/morph/event/notary_preparator_test.go b/pkg/morph/event/notary_preparator_test.go index 87ad300a78..5cffcdf125 100644 --- a/pkg/morph/event/notary_preparator_test.go +++ b/pkg/morph/event/notary_preparator_test.go @@ -441,7 +441,7 @@ func TestPrepare_CorrectNR(t *testing.T) { preparator := notaryPreparator(alphaKeys[0].GetScriptHash(), alphaKeysSource(), blockCounter{100, nil}) for _, test := range tests { - for i := 0; i < 1; i++ { // run tests against 3 and 4 witness NR + for i := range 1 { // run tests against 3 and 4 witness NR for j, dummyMultisig := range []bool{true, false} { // run tests against empty and dummy multisig/Notary witness method := test.method + strconv.FormatInt(int64(j), 10) preparator.allowNotaryEvent(notaryScriptWithHash{ diff --git a/pkg/network/transport/object/grpc/replication_test.go b/pkg/network/transport/object/grpc/replication_test.go index 13529bd98d..e48e34b72f 100644 --- a/pkg/network/transport/object/grpc/replication_test.go +++ b/pkg/network/transport/object/grpc/replication_test.go @@ -426,7 +426,7 @@ func BenchmarkServer_Replicate(b *testing.B) { b.ReportAllocs() b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { resp, err := srv.Replicate(ctx, req) require.NoError(b, err) require.Zero(b, resp.GetStatus().GetCode()) diff --git a/pkg/services/audit/auditor/pdp.go b/pkg/services/audit/auditor/pdp.go index e6b918b303..656809ae16 100644 --- a/pkg/services/audit/auditor/pdp.go +++ b/pkg/services/audit/auditor/pdp.go @@ -47,7 +47,7 @@ func (c *Context) distributeRanges(p *gamePair) { p.rn1 = make([]*object.Range, hashRangeNumber-1) p.rn2 = make([]*object.Range, hashRangeNumber-1) - for i := 0; i < hashRangeNumber-1; i++ { + for i := range hashRangeNumber - 1 { p.rn1[i] = object.NewRange() p.rn2[i] = object.NewRange() } @@ -88,7 +88,7 @@ func (c *Context) splitPayload(id oid.ID) []uint64 { notches = make([]uint64, 0, hashRangeNumber) ) - for i := uint64(0); i < hashRangeNumber; i++ { + for i := range uint64(hashRangeNumber) { if i < hashRangeNumber-1 { maxL := size - prev - (hashRangeNumber - i) if maxL == 0 { diff --git a/pkg/services/container/announcement/load/controller/calls_test.go b/pkg/services/container/announcement/load/controller/calls_test.go index e61c9fe783..4693864cc0 100644 --- a/pkg/services/container/announcement/load/controller/calls_test.go +++ b/pkg/services/container/announcement/load/controller/calls_test.go @@ -117,7 +117,7 @@ func TestSimpleScenario(t *testing.T) { // create 2 random values for processing epoch and 1 for some different announces := make([]container.SizeEstimation, 0, goodNum) - for i := 0; i < goodNum; i++ { + for range goodNum { a := randAnnouncement() a.SetEpoch(processEpoch) diff --git a/pkg/services/control/server/evacuate.go b/pkg/services/control/server/evacuate.go index e0a8e9d5e2..f8996cfff7 100644 --- a/pkg/services/control/server/evacuate.go +++ b/pkg/services/control/server/evacuate.go @@ -78,7 +78,7 @@ func (s *Server) replicate(addr oid.Address, obj *objectSDK.Object) error { nodes := placement.FlattenNodes(ns) bs := (*keys.PublicKey)(&s.key.PublicKey).Bytes() - for i := 0; i < len(nodes); i++ { + for i := range nodes { if bytes.Equal(nodes[i].PublicKey(), bs) { copy(nodes[i:], nodes[i+1:]) nodes = nodes[:len(nodes)-1] diff --git a/pkg/services/control/types_test.go b/pkg/services/control/types_test.go index 955fe3342f..432affe7fc 100644 --- a/pkg/services/control/types_test.go +++ b/pkg/services/control/types_test.go @@ -27,7 +27,7 @@ func generateNetmap() *control.Netmap { nodes := make([]*control.NodeInfo, 0, nodeCount) - for i := 0; i < nodeCount; i++ { + for range nodeCount { n := new(control.NodeInfo) n.SetPublicKey(testData(33)) n.SetAddresses([]string{testString(), testString()}) @@ -37,7 +37,7 @@ func generateNetmap() *control.Netmap { attrs := make([]*control.NodeInfo_Attribute, 0, attrCount) - for j := 0; j < attrCount; j++ { + for range attrCount { a := new(control.NodeInfo_Attribute) a.SetKey(testString()) a.SetValue(testString()) @@ -46,7 +46,7 @@ func generateNetmap() *control.Netmap { parents := make([]string, 0, parentsCount) - for k := 0; k < parentsCount; k++ { + for range parentsCount { parents = append(parents, testString()) } diff --git a/pkg/services/object/acl/v2/util_test.go b/pkg/services/object/acl/v2/util_test.go index 8576aba1dd..5c41276d71 100644 --- a/pkg/services/object/acl/v2/util_test.go +++ b/pkg/services/object/acl/v2/util_test.go @@ -36,7 +36,7 @@ func TestOriginalTokens(t *testing.T) { var sTokenV2 session.Token sToken.WriteToV2(&sTokenV2) - for i := 0; i < 10; i++ { + for i := range 10 { metaHeaders := testGenerateMetaHeader(uint32(i), &bTokenV2, &sTokenV2) res, err := originalSessionToken(metaHeaders) require.NoError(t, err) diff --git a/pkg/services/object/get/get_test.go b/pkg/services/object/get/get_test.go index 22a826cb7c..ff996b0db7 100644 --- a/pkg/services/object/get/get_test.go +++ b/pkg/services/object/get/get_test.go @@ -463,7 +463,7 @@ func generateChain(ln int, cnr cid.ID) ([]*objectSDK.Object, []oid.ID, []byte) { ids := make([]oid.ID, 0, ln) payload := make([]byte, 0, ln*10) - for i := 0; i < ln; i++ { + for i := range ln { ids = append(ids, curID) addr.SetObject(curID) diff --git a/pkg/services/object/search/search_test.go b/pkg/services/object/search/search_test.go index 37bc2c7425..33dd74100c 100644 --- a/pkg/services/object/search/search_test.go +++ b/pkg/services/object/search/search_test.go @@ -139,7 +139,7 @@ func testSHA256() (cs [sha256.Size]byte) { func generateIDs(num int) []oid.ID { res := make([]oid.ID, num) - for i := 0; i < num; i++ { + for i := range num { res[i].SetSHA256(testSHA256()) } diff --git a/pkg/services/object_manager/placement/traverser.go b/pkg/services/object_manager/placement/traverser.go index d16b0331b8..07ce073598 100644 --- a/pkg/services/object_manager/placement/traverser.go +++ b/pkg/services/object_manager/placement/traverser.go @@ -95,7 +95,7 @@ func NewTraverser(opts ...Option) (*Traverser, error) { replNum := cfg.policy.NumberOfReplicas() rem = make([]int, 0, replNum) - for i := 0; i < replNum; i++ { + for i := range replNum { if cfg.trackCopies { rem = append(rem, int(cfg.policy.ReplicaNumberByIndex(i))) } else { @@ -185,7 +185,7 @@ func (t *Traverser) Next() []Node { nodes := make([]Node, count) - for i := 0; i < count; i++ { + for i := range count { err := nodes[i].addresses.FromIterator(network.NodeEndpointsIterator(t.vectors[0][i])) if err != nil { return nil diff --git a/pkg/services/session/storage/persistent/executor_test.go b/pkg/services/session/storage/persistent/executor_test.go index ea7933c574..0abd39db4c 100644 --- a/pkg/services/session/storage/persistent/executor_test.go +++ b/pkg/services/session/storage/persistent/executor_test.go @@ -39,7 +39,7 @@ func TestTokenStore(t *testing.T) { tokens := make([]tok, 0, tokenNumber) - for i := 0; i < tokenNumber; i++ { + for i := range tokenNumber { req.SetExpiration(uint64(i)) res, err := ts.Create(context.Background(), req) diff --git a/pkg/services/tree/getsubtree_test.go b/pkg/services/tree/getsubtree_test.go index b58cdb8cb5..39656b030e 100644 --- a/pkg/services/tree/getsubtree_test.go +++ b/pkg/services/tree/getsubtree_test.go @@ -57,7 +57,7 @@ func TestGetSubTree(t *testing.T) { loop: for i := 1; i < len(acc.seen); i++ { parent := acc.seen[i].Body.ParentId - for j := 0; j < i; j++ { + for j := range i { if acc.seen[j].Body.NodeId == parent { continue loop } diff --git a/pkg/services/tree/replicator.go b/pkg/services/tree/replicator.go index 9d095bff41..3a70413f09 100644 --- a/pkg/services/tree/replicator.go +++ b/pkg/services/tree/replicator.go @@ -93,7 +93,7 @@ func (s *Service) replicationWorker() { } func (s *Service) replicateLoop(ctx context.Context) { - for i := 0; i < s.replicatorWorkerCount; i++ { + for range s.replicatorWorkerCount { go s.replicationWorker() go s.localReplicationWorker() } From 43cf1b88b80a82f636c48027765d8ee0ffa8caea Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 3 Sep 2024 22:59:27 +0300 Subject: [PATCH 5/8] .golangci.yml: add `intrange` linter Signed-off-by: Pavel Karpy --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index 52a0ec615d..2dd8db66b3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -58,6 +58,7 @@ linters: - gofmt - goimports - gomodguard + - intrange - misspell - predeclared - reassign From 913fc84883e52855993f83b7cb349f7e1b9ab06c Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 3 Sep 2024 23:41:54 +0300 Subject: [PATCH 6/8] *: use `slice.Concat` where possible Closes #2738. Signed-off-by: Pavel Karpy --- pkg/services/object/put/distributed.go | 9 +-------- pkg/services/object_manager/placement/netmap.go | 15 ++------------- .../object_manager/placement/traverser.go | 13 ++----------- pkg/services/tree/sync.go | 6 ++---- 4 files changed, 7 insertions(+), 36 deletions(-) diff --git a/pkg/services/object/put/distributed.go b/pkg/services/object/put/distributed.go index 9b2f7726f0..cb0b59554f 100644 --- a/pkg/services/object/put/distributed.go +++ b/pkg/services/object/put/distributed.go @@ -189,14 +189,7 @@ func (x placementIterator) iterateNodesForObject(obj oid.ID, f func(nodeDesc) er return fmt.Errorf("sort container nodes for the object: %w", err) } if x.linearReplNum > 0 { - var n int - for i := range nodeLists { - n += len(nodeLists[i]) - } - ns := make([]netmap.NodeInfo, 0, n) - for i := range nodeLists { - ns = append(ns, nodeLists[i]...) - } + ns := slices.Concat(nodeLists...) nodeLists = [][]netmap.NodeInfo{ns} replCounts = []uint{x.linearReplNum} } else { diff --git a/pkg/services/object_manager/placement/netmap.go b/pkg/services/object_manager/placement/netmap.go index c5013ddd0b..6e275ed985 100644 --- a/pkg/services/object_manager/placement/netmap.go +++ b/pkg/services/object_manager/placement/netmap.go @@ -3,6 +3,7 @@ package placement import ( "crypto/sha256" "fmt" + "slices" "sync" "github.com/hashicorp/golang-lru/v2/simplelru" @@ -99,17 +100,5 @@ func BuildObjectPlacement(nm *netmapSDK.NetMap, cnrNodes [][]netmapSDK.NodeInfo, // FlattenNodes appends each row to the flat list. func FlattenNodes(ns [][]netmapSDK.NodeInfo) []netmapSDK.NodeInfo { - var sz int - - for i := range ns { - sz += len(ns[i]) - } - - result := make([]netmapSDK.NodeInfo, 0, sz) - - for i := range ns { - result = append(result, ns[i]...) - } - - return result + return slices.Concat(ns...) } diff --git a/pkg/services/object_manager/placement/traverser.go b/pkg/services/object_manager/placement/traverser.go index 07ce073598..6fca550931 100644 --- a/pkg/services/object_manager/placement/traverser.go +++ b/pkg/services/object_manager/placement/traverser.go @@ -3,6 +3,7 @@ package placement import ( "errors" "fmt" + "slices" "sync" "github.com/nspcc-dev/neofs-node/pkg/network" @@ -119,17 +120,7 @@ func NewTraverser(opts ...Option) (*Traverser, error) { } func flatNodes(ns [][]netmap.NodeInfo) [][]netmap.NodeInfo { - sz := 0 - for i := range ns { - sz += len(ns[i]) - } - - flat := make([]netmap.NodeInfo, 0, sz) - for i := range ns { - flat = append(flat, ns[i]...) - } - - return [][]netmap.NodeInfo{flat} + return [][]netmap.NodeInfo{slices.Concat(ns...)} } // Node is a descriptor of storage node with information required for intra-container communication. diff --git a/pkg/services/tree/sync.go b/pkg/services/tree/sync.go index 9249c2bb00..ef7cb5a8d0 100644 --- a/pkg/services/tree/sync.go +++ b/pkg/services/tree/sync.go @@ -8,6 +8,7 @@ import ( "io" "math" "math/rand" + "slices" "sync" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama" @@ -365,10 +366,7 @@ func randomizeNodeOrder(cnrNodes []netmap.NodeInfo, pos int) []netmap.NodeInfo { return nil } - nodes := make([]netmap.NodeInfo, len(cnrNodes)-1) - n := copy(nodes, cnrNodes[:pos]) - copy(nodes[n:], cnrNodes[pos+1:]) - + nodes := slices.Concat(cnrNodes[:pos], cnrNodes[pos+1:]) rand.Shuffle(len(nodes), func(i, j int) { nodes[i], nodes[j] = nodes[j], nodes[i] }) From 3a9e0d0db8b0200a037461f7375b9bf48e077b52 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 4 Sep 2024 18:18:27 +0300 Subject: [PATCH 7/8] node/control/evacuate: use slices.DeleteFunc for clean up It uses fewer code lines. Signed-off-by: Pavel Karpy --- pkg/services/control/server/evacuate.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/services/control/server/evacuate.go b/pkg/services/control/server/evacuate.go index f8996cfff7..4071994f88 100644 --- a/pkg/services/control/server/evacuate.go +++ b/pkg/services/control/server/evacuate.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "slices" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" @@ -78,12 +79,9 @@ func (s *Server) replicate(addr oid.Address, obj *objectSDK.Object) error { nodes := placement.FlattenNodes(ns) bs := (*keys.PublicKey)(&s.key.PublicKey).Bytes() - for i := range nodes { - if bytes.Equal(nodes[i].PublicKey(), bs) { - copy(nodes[i:], nodes[i+1:]) - nodes = nodes[:len(nodes)-1] - } - } + nodes = slices.DeleteFunc(nodes, func(info netmap.NodeInfo) bool { + return bytes.Equal(info.PublicKey(), bs) + }) var res replicatorResult var task replicator.Task From b44048e795b28755cc76786e841030a2bcb91db7 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 4 Sep 2024 18:30:44 +0300 Subject: [PATCH 8/8] notary_preparator_test: fix testing NR without Alphabet's sign Signed-off-by: Pavel Karpy --- pkg/morph/event/notary_preparator_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/morph/event/notary_preparator_test.go b/pkg/morph/event/notary_preparator_test.go index 5cffcdf125..87f0d3678e 100644 --- a/pkg/morph/event/notary_preparator_test.go +++ b/pkg/morph/event/notary_preparator_test.go @@ -441,7 +441,7 @@ func TestPrepare_CorrectNR(t *testing.T) { preparator := notaryPreparator(alphaKeys[0].GetScriptHash(), alphaKeysSource(), blockCounter{100, nil}) for _, test := range tests { - for i := range 1 { // run tests against 3 and 4 witness NR + for i := range 2 { // run tests against 3 and 4 witness NR for j, dummyMultisig := range []bool{true, false} { // run tests against empty and dummy multisig/Notary witness method := test.method + strconv.FormatInt(int64(j), 10) preparator.allowNotaryEvent(notaryScriptWithHash{