Skip to content

Commit 96098c5

Browse files
committed
[VIndex] Support context cancel during indexing
Context cancellation wasn't checked when inserting keys into the index. This was a bug, and becomes particularly problematic when building large in-memory indexes. The process gets slower and slower until it OOMs, and it's hard to kill.
1 parent b40558a commit 96098c5

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

vindex/map.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,11 @@ func (b *VerifiableIndex) buildMap(ctx context.Context, updateIndex bool) error
558558
b.indexMu.Lock()
559559
defer b.indexMu.Unlock()
560560
for h := range updatedKeys {
561+
select {
562+
case <-ctx.Done():
563+
return ctx.Err()
564+
default:
565+
}
561566
idxes := b.data[h]
562567

563568
// Here we hash by simply appending all indices in the list and hashing that

0 commit comments

Comments
 (0)