Skip to content

Commit e11484c

Browse files
authored
Merge pull request #1542 from 0chain/feat/config-recover
Add allocation id to recover in config
2 parents 9c7341c + ebe7d3a commit e11484c

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

code/go/0chain.net/blobber/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/allocation"
5+
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/config"
56
"github.com/0chain/blobber/code/go/0chain.net/core/common"
67
"github.com/0chain/blobber/code/go/0chain.net/core/logging"
78
"github.com/0chain/blobber/code/go/0chain.net/core/node"
@@ -61,7 +62,7 @@ func main() {
6162

6263
if recoverTrie {
6364
logging.Logger.Info("Recovering trie")
64-
allocation.RecoverTrie()
65+
allocation.RecoverTrie(config.Configuration.RecoverAllocations)
6566
}
6667

6768
// todo: activate this when gRPC functionalities are implemented

code/go/0chain.net/blobbercore/allocation/workers.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -349,33 +349,27 @@ func deleteAllocation(ctx context.Context, a *Allocation) (err error) {
349349
return err
350350
}
351351

352-
func RecoverTrie() {
352+
func RecoverTrie(recoverAllocs []string) {
353353
var (
354-
allocs []*Allocation
355-
err error
356-
offset int64
354+
err error
357355
)
358356

359-
for {
357+
for _, allocID := range recoverAllocs {
358+
var alloc *Allocation
360359
err = datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
361-
allocs, err = Repo.GetAllocations(ctx, offset)
360+
alloc, err = Repo.GetAllocationFromDB(ctx, allocID)
362361
return err
363362
})
364363
if err != nil {
365364
logging.Logger.Error("recover_trie_fetch_alloc", zap.Error(err))
366365
return
367366
}
368-
if len(allocs) == 0 {
369-
return
370-
}
371-
offset += int64(len(allocs))
372-
// recover trie of each allocation
373-
for _, a := range allocs {
374-
logging.Logger.Info("recover_trie", zap.String("allocation_id", a.ID))
375-
err = a.recoverTrie()
376-
if err != nil {
377-
logging.Logger.Error("recover_trie", zap.Error(err))
378-
}
367+
368+
// recover trie of allocation
369+
logging.Logger.Info("recover_trie", zap.String("allocation_id", alloc.ID))
370+
err = alloc.recoverTrie()
371+
if err != nil {
372+
logging.Logger.Error("recover_trie", zap.Error(err))
379373
}
380374
}
381375
}

code/go/0chain.net/blobbercore/config/config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,10 @@ type Config struct {
157157
MinConfirmation int
158158

159159
// MountPoint is where allocation files are stored. This is basically arranged in RAID5.
160-
MountPoint string
161-
AllocDirLevel []int
162-
FileDirLevel []int
160+
MountPoint string
161+
AllocDirLevel []int
162+
FileDirLevel []int
163+
RecoverAllocations []string
163164
// AutomacitUpdate Whether to automatically update blobber updates to blockchain
164165
AutomaticUpdate bool
165166
BlobberUpdateInterval time.Duration
@@ -291,6 +292,7 @@ func ReadConfig(deploymentMode int) {
291292
if w := Configuration.DelegateWallet; len(w) != 64 {
292293
log.Fatal("invalid delegate wallet:", w)
293294
}
295+
Configuration.RecoverAllocations = viper.GetStringSlice("recover_allocations")
294296

295297
Configuration.MinSubmit = viper.GetInt("min_submit")
296298
if Configuration.MinSubmit < 1 {

config/0chain_blobber.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ finalize_allocations_interval: 24h
2727
# maximum limit on the number of combined directories and files on each allocation
2828
max_dirs_files: 50000
2929

30+
#recover allocations
31+
recover_allocations: [""]
32+
3033
# maximum limit on the number of objects in a directory
3134
max_objects_dir: 1000
3235
# limit of objects per gb(storage v2)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ require (
101101
)
102102

103103
require (
104-
github.com/0chain/common v1.18.3
104+
github.com/0chain/common v1.20.0
105105
github.com/Luzifer/go-openssl/v3 v3.1.0 // indirect
106106
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
107107
github.com/btcsuite/btcd v0.23.4 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
3636
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
3737
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
3838
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
39-
github.com/0chain/common v1.18.3 h1:42dYOv2KyMTSanuS67iDtfv+ErbSRqR8NJ3MG72MwaI=
40-
github.com/0chain/common v1.18.3/go.mod h1:Lapu2Tj7z5Sm4r+X141e7vsz4NDODTEypeElYAP3iSw=
39+
github.com/0chain/common v1.20.0 h1:Ek8YglLoTk8rfxYVB57mP2+w6XzfsztBPN3/vwH470I=
40+
github.com/0chain/common v1.20.0/go.mod h1:Lapu2Tj7z5Sm4r+X141e7vsz4NDODTEypeElYAP3iSw=
4141
github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM=
4242
github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc=
4343
github.com/0chain/gosdk v1.19.0-RC0 h1:PhHsvfEBJw9ofEFGWKqJ7UID7qMfl1LrWl2GyhIxjqE=

0 commit comments

Comments
 (0)