From 67df75484fa2938bf998c7187ce349b6a1b345e1 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 14 Apr 2023 00:06:25 -0700 Subject: [PATCH] lib/{mergeset,storage}: remove isInMerge flag from parts only when they werent removed yet from the list of active parts This prevents from possible panic during access to pw.p when it is set to nil at partWrapper.decRef() called inside swapSrcWithDstParts() --- lib/mergeset/table.go | 2 +- lib/storage/partition.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mergeset/table.go b/lib/mergeset/table.go index e6cb48a3e..a184066e2 100644 --- a/lib/mergeset/table.go +++ b/lib/mergeset/table.go @@ -1072,7 +1072,6 @@ func (tb *Table) mergeParts(pws []*partWrapper, stopCh <-chan struct{}, isFinal // Nothing to merge. return errNothingToMerge } - defer tb.releasePartsToMerge(pws) startTime := time.Now() @@ -1132,6 +1131,7 @@ func (tb *Table) mergeParts(pws []*partWrapper, stopCh <-chan struct{}, isFinal putBlockStreamWriter(bsw) closeBlockStreamReaders() if err != nil { + tb.releasePartsToMerge(pws) return err } if mpNew != nil { diff --git a/lib/storage/partition.go b/lib/storage/partition.go index f45715b8a..13cbe4690 100644 --- a/lib/storage/partition.go +++ b/lib/storage/partition.go @@ -1250,7 +1250,6 @@ func (pt *partition) mergeParts(pws []*partWrapper, stopCh <-chan struct{}, isFi // Nothing to merge. return errNothingToMerge } - defer pt.releasePartsToMerge(pws) startTime := time.Now() @@ -1311,6 +1310,7 @@ func (pt *partition) mergeParts(pws []*partWrapper, stopCh <-chan struct{}, isFi putBlockStreamWriter(bsw) closeBlockStreamReaders() if err != nil { + pt.releasePartsToMerge(pws) return err } if mpNew != nil {