@@ -15,6 +15,7 @@ import (
15
15
badger4 "github.com/ipfs/go-ds-badger4"
16
16
)
17
17
18
+ // OnDelete implements [header.Store] interface.
18
19
func (s * Store [H ]) OnDelete (fn func (context.Context , uint64 ) error ) {
19
20
s .onDeleteMu .Lock ()
20
21
defer s .onDeleteMu .Unlock ()
@@ -81,15 +82,20 @@ func (s *Store[H]) DeleteTo(ctx context.Context, to uint64) error {
81
82
return nil
82
83
}
83
84
84
- // deleteRange deletes range of headers defined by from and to
85
+ // deleteRangeParallelThreshold defines the threshold for parallel deletion.
86
+ // If range is smaller than this threshold, deletion will be performed sequentially.
87
+ var deleteRangeParallelThreshold uint64 = 10000
88
+
89
+ // deleteRange deletes [from:to) header range from the store.
85
90
func (s * Store [H ]) deleteRange (ctx context.Context , from , to uint64 ) error {
86
- if to - from < 1000 {
91
+ if to - from < deleteRangeParallelThreshold {
87
92
return s .deleteSequential (ctx , from , to )
88
93
}
89
94
90
95
return s .deleteParallel (ctx , from , to )
91
96
}
92
97
98
+ // deleteSequential deletes [from:to) header range from the store sequentially.
93
99
func (s * Store [H ]) deleteSequential (ctx context.Context , from , to uint64 ) error {
94
100
log .Debugw ("starting delete range sequential" , "from_height" , from , "to_height" , to )
95
101
@@ -153,7 +159,7 @@ func (s *Store[H]) delete(ctx context.Context, height uint64, batch datastore.Ba
153
159
154
160
// workerNum defines how many parallel delete workers to run
155
161
// Scales of number of CPUs configred for the process.
156
- var workerNum = runtime .GOMAXPROCS (- 1 ) * 4
162
+ var workerNum = runtime .GOMAXPROCS (- 1 ) * 2
157
163
158
164
// deleteParallel deletes [from:to) header range from the store in parallel.
159
165
// It gracefully handles context and errors attempting to save interrupted progress.
0 commit comments