Skip to content

Commit c32c520

Browse files
committed
delet
1 parent 27e9805 commit c32c520

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

store/store_delete.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,12 @@ func (s *Store[H]) delete(ctx context.Context, height uint64, batch datastore.Ba
151151
return nil
152152
}
153153

154-
var deleteTimeoutError = errors.New("delete timeout")
154+
// workerNum defines how many parallel delete workers to run
155+
// Scales of number of CPUs configred for the process.
156+
var workerNum = runtime.GOMAXPROCS(-1) * 4
155157

156-
// it gracefully handles context and errors
157-
// attempting to save interrupted progress.
158+
// deleteParallel deletes [from:to) header range from the store in parallel.
159+
// It gracefully handles context and errors attempting to save interrupted progress.
158160
func (s *Store[H]) deleteParallel(ctx context.Context, from, to uint64) (err error) {
159161
log.Debugw("starting delete range parallel", "from_height", from, "to_height", to)
160162

@@ -181,14 +183,14 @@ func (s *Store[H]) deleteParallel(ctx context.Context, from, to uint64) (err err
181183
"from_height", from,
182184
"expected_to_height", to,
183185
"actual_to_height", newTailHeight,
184-
"took", time.Since(startTime),
186+
"took(s)", time.Since(startTime),
185187
)
186188
} else {
187189
log.Errorw("partial delete with error",
188190
"from_height", from,
189191
"expected_to_height", to,
190192
"actual_to_height", newTailHeight,
191-
"took", time.Since(startTime),
193+
"took(s)", time.Since(startTime),
192194
"err", err,
193195
)
194196
}
@@ -205,7 +207,6 @@ func (s *Store[H]) deleteParallel(ctx context.Context, from, to uint64) (err err
205207
onDelete := slices.Clone(s.onDelete)
206208
s.onDeleteMu.Unlock()
207209

208-
workerNum := runtime.NumCPU() * 4
209210
jobCh := make(chan uint64, workerNum)
210211
errCh := make(chan error, 1)
211212

@@ -277,3 +278,5 @@ func (s *Store[H]) deleteParallel(ctx context.Context, from, to uint64) (err err
277278
close(jobCh)
278279
return err
279280
}
281+
282+
var deleteTimeoutError = errors.New("delete timeout")

0 commit comments

Comments
 (0)