Skip to content

Commit

Permalink
lsm: hold read lock on iterate (#557)
Browse files Browse the repository at this point in the history
* lsm: hold read lock on Iterate

Otherwise, snapshots will not hold a read lock over the index when iterating.

* *: handle 0-size object storage blocks

There are sometimes errors when serializing a block. This would cause us to
create a file but not delete it. This commit deletes an object storage file on
serialization failure.

Additionally, this commit ignores empty object storage files on scans.
  • Loading branch information
asubiotto authored Oct 10, 2023
1 parent 35a6479 commit 5eb3a50
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions index/lsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ func (l *LSM) Prefixes(ctx context.Context, prefix string) ([]string, error) {
}

func (l *LSM) Iterate(iter func(node *Node) bool) {
l.RLock()
defer l.RUnlock()
l.levels.Iterate(iter)
}

Expand Down
13 changes: 12 additions & 1 deletion store.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ func (t *TableBlock) Persist() error {
}

if err != nil {
return fmt.Errorf("failed to serialize block: %v", err)
if deleteErr := sink.Delete(context.Background(), fileName); deleteErr != nil {
err = fmt.Errorf("%v failed to delete file on error: %w", err, deleteErr)
}
return fmt.Errorf("failed to serialize block: %w", err)
}
}

Expand Down Expand Up @@ -212,6 +215,14 @@ func (b *DefaultObjstoreBucket) ProcessFile(ctx context.Context, blockDir string

span.SetAttributes(attribute.Int64("size", attribs.Size))

if attribs.Size == 0 {
level.Debug(b.logger).Log(
"msg", "ignoring empty block",
"blockTime", blockUlid.Time(),
)
return nil
}

file, err := b.openBlockFile(ctx, blockName, attribs.Size)
if err != nil {
return err
Expand Down

0 comments on commit 5eb3a50

Please sign in to comment.