Skip to content

Commit f990d71

Browse files
committed
add allocation id to recover in config
1 parent 3275101 commit f990d71

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
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)

0 commit comments

Comments
 (0)