From 5eb3a5073486ee73199a7c2ab4768b7fd3e7e2a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfonso=20Subiotto=20Marqu=C3=A9s?= Date: Tue, 10 Oct 2023 17:48:29 +0200 Subject: [PATCH] lsm: hold read lock on iterate (#557) * 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. --- index/lsm.go | 2 ++ store.go | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/index/lsm.go b/index/lsm.go index e9eaba139..002c6ec26 100644 --- a/index/lsm.go +++ b/index/lsm.go @@ -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) } diff --git a/store.go b/store.go index b09daa5af..11ea334b9 100644 --- a/store.go +++ b/store.go @@ -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) } } @@ -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