From f990d71b6466bac8f6b1fea9f75701316b1c0d70 Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Mon, 24 Mar 2025 14:32:18 +0530 Subject: [PATCH 1/2] add allocation id to recover in config --- code/go/0chain.net/blobber/main.go | 3 +- .../blobbercore/allocation/workers.go | 28 ++++++++----------- .../0chain.net/blobbercore/config/config.go | 8 ++++-- config/0chain_blobber.yaml | 3 ++ 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/code/go/0chain.net/blobber/main.go b/code/go/0chain.net/blobber/main.go index 3f7d34438..024ea5a28 100644 --- a/code/go/0chain.net/blobber/main.go +++ b/code/go/0chain.net/blobber/main.go @@ -2,6 +2,7 @@ package main import ( "github.com/0chain/blobber/code/go/0chain.net/blobbercore/allocation" + "github.com/0chain/blobber/code/go/0chain.net/blobbercore/config" "github.com/0chain/blobber/code/go/0chain.net/core/common" "github.com/0chain/blobber/code/go/0chain.net/core/logging" "github.com/0chain/blobber/code/go/0chain.net/core/node" @@ -61,7 +62,7 @@ func main() { if recoverTrie { logging.Logger.Info("Recovering trie") - allocation.RecoverTrie() + allocation.RecoverTrie(config.Configuration.RecoverAllocations) } // todo: activate this when gRPC functionalities are implemented diff --git a/code/go/0chain.net/blobbercore/allocation/workers.go b/code/go/0chain.net/blobbercore/allocation/workers.go index 2fcc38c9b..808396d89 100644 --- a/code/go/0chain.net/blobbercore/allocation/workers.go +++ b/code/go/0chain.net/blobbercore/allocation/workers.go @@ -349,33 +349,27 @@ func deleteAllocation(ctx context.Context, a *Allocation) (err error) { return err } -func RecoverTrie() { +func RecoverTrie(recoverAllocs []string) { var ( - allocs []*Allocation - err error - offset int64 + err error ) - for { + for _, allocID := range recoverAllocs { + var alloc *Allocation err = datastore.GetStore().WithNewTransaction(func(ctx context.Context) error { - allocs, err = Repo.GetAllocations(ctx, offset) + alloc, err = Repo.GetAllocationFromDB(ctx, allocID) return err }) if err != nil { logging.Logger.Error("recover_trie_fetch_alloc", zap.Error(err)) return } - if len(allocs) == 0 { - return - } - offset += int64(len(allocs)) - // recover trie of each allocation - for _, a := range allocs { - logging.Logger.Info("recover_trie", zap.String("allocation_id", a.ID)) - err = a.recoverTrie() - if err != nil { - logging.Logger.Error("recover_trie", zap.Error(err)) - } + + // recover trie of allocation + logging.Logger.Info("recover_trie", zap.String("allocation_id", alloc.ID)) + err = alloc.recoverTrie() + if err != nil { + logging.Logger.Error("recover_trie", zap.Error(err)) } } } diff --git a/code/go/0chain.net/blobbercore/config/config.go b/code/go/0chain.net/blobbercore/config/config.go index 3d5e457a1..9420b2276 100644 --- a/code/go/0chain.net/blobbercore/config/config.go +++ b/code/go/0chain.net/blobbercore/config/config.go @@ -157,9 +157,10 @@ type Config struct { MinConfirmation int // MountPoint is where allocation files are stored. This is basically arranged in RAID5. - MountPoint string - AllocDirLevel []int - FileDirLevel []int + MountPoint string + AllocDirLevel []int + FileDirLevel []int + RecoverAllocations []string // AutomacitUpdate Whether to automatically update blobber updates to blockchain AutomaticUpdate bool BlobberUpdateInterval time.Duration @@ -291,6 +292,7 @@ func ReadConfig(deploymentMode int) { if w := Configuration.DelegateWallet; len(w) != 64 { log.Fatal("invalid delegate wallet:", w) } + Configuration.RecoverAllocations = viper.GetStringSlice("recover_allocations") Configuration.MinSubmit = viper.GetInt("min_submit") if Configuration.MinSubmit < 1 { diff --git a/config/0chain_blobber.yaml b/config/0chain_blobber.yaml index d277d6cb2..00a02a92a 100755 --- a/config/0chain_blobber.yaml +++ b/config/0chain_blobber.yaml @@ -27,6 +27,9 @@ finalize_allocations_interval: 24h # maximum limit on the number of combined directories and files on each allocation max_dirs_files: 50000 +#recover allocations +recover_allocations: [""] + # maximum limit on the number of objects in a directory max_objects_dir: 1000 # limit of objects per gb(storage v2) From 273e376f89fb6925fb436794714c1738ff854b03 Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Mon, 24 Mar 2025 17:53:54 +0530 Subject: [PATCH 2/2] update common --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 049c5178c..5da5db8fe 100644 --- a/go.mod +++ b/go.mod @@ -101,7 +101,7 @@ require ( ) require ( - github.com/0chain/common v1.18.3 + github.com/0chain/common v1.20.0 github.com/Luzifer/go-openssl/v3 v3.1.0 // indirect github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/btcsuite/btcd v0.23.4 // indirect diff --git a/go.sum b/go.sum index d140ee9d9..d8e812fa8 100644 --- a/go.sum +++ b/go.sum @@ -36,8 +36,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -github.com/0chain/common v1.18.3 h1:42dYOv2KyMTSanuS67iDtfv+ErbSRqR8NJ3MG72MwaI= -github.com/0chain/common v1.18.3/go.mod h1:Lapu2Tj7z5Sm4r+X141e7vsz4NDODTEypeElYAP3iSw= +github.com/0chain/common v1.20.0 h1:Ek8YglLoTk8rfxYVB57mP2+w6XzfsztBPN3/vwH470I= +github.com/0chain/common v1.20.0/go.mod h1:Lapu2Tj7z5Sm4r+X141e7vsz4NDODTEypeElYAP3iSw= github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM= github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc= github.com/0chain/gosdk v1.19.0-RC0 h1:PhHsvfEBJw9ofEFGWKqJ7UID7qMfl1LrWl2GyhIxjqE=