Skip to content

Commit 7bbbf23

Browse files
authored
Extend BloomStore with Client(model.Time) function (#11881)
**What this PR does / why we need it**: For certain operations, we want direct access to the `BloomClient`. Since every schema period has its own client, the `Client()` function accepts a `model.Timestamp` for which the client should be returned. The function may return an error, if no client for the given time could be found. --------- Signed-off-by: Christian Haudum <[email protected]>
1 parent 69d152b commit 7bbbf23

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

pkg/bloomgateway/processor_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ func (s *dummyStore) FetchBlocks(_ context.Context, _ []bloomshipper.BlockRef) (
4242
panic("don't call me")
4343
}
4444

45-
func (s *dummyStore) Fetcher(_ model.Time) *bloomshipper.Fetcher {
46-
return nil
45+
func (s *dummyStore) Fetcher(_ model.Time) (*bloomshipper.Fetcher, error) {
46+
return nil, nil
47+
}
48+
49+
func (s *dummyStore) Client(_ model.Time) (bloomshipper.Client, error) {
50+
return nil, nil
4751
}
4852

4953
func (s *dummyStore) Stop() {

pkg/storage/stores/shipper/bloomshipper/store.go

+25-6
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@ import (
1818
"github.com/grafana/loki/pkg/storage/config"
1919
)
2020

21+
var (
22+
errNoStore = errors.New("no store found for time")
23+
)
24+
2125
type Store interface {
2226
ResolveMetas(ctx context.Context, params MetaSearchParams) ([][]MetaRef, []*Fetcher, error)
2327
FetchMetas(ctx context.Context, params MetaSearchParams) ([]Meta, error)
2428
FetchBlocks(ctx context.Context, refs []BlockRef) ([]BlockDirectory, error)
25-
Fetcher(ts model.Time) *Fetcher
29+
Fetcher(ts model.Time) (*Fetcher, error)
30+
Client(ts model.Time) (Client, error)
2631
Stop()
2732
}
2833

@@ -112,8 +117,13 @@ func (b *bloomStoreEntry) FetchBlocks(ctx context.Context, refs []BlockRef) ([]B
112117
}
113118

114119
// Fetcher implements Store.
115-
func (b *bloomStoreEntry) Fetcher(_ model.Time) *Fetcher {
116-
return b.fetcher
120+
func (b *bloomStoreEntry) Fetcher(_ model.Time) (*Fetcher, error) {
121+
return b.fetcher, nil
122+
}
123+
124+
// Client implements Store.
125+
func (b *bloomStoreEntry) Client(_ model.Time) (Client, error) {
126+
return b.bloomClient, nil
117127
}
118128

119129
// Stop implements Store.
@@ -219,11 +229,19 @@ func (b *BloomStore) Block(ref BlockRef) (loc Location) {
219229
}
220230

221231
// Fetcher implements Store.
222-
func (b *BloomStore) Fetcher(ts model.Time) *Fetcher {
232+
func (b *BloomStore) Fetcher(ts model.Time) (*Fetcher, error) {
223233
if store := b.getStore(ts); store != nil {
224234
return store.Fetcher(ts)
225235
}
226-
return nil
236+
return nil, errNoStore
237+
}
238+
239+
// Client implements Store.
240+
func (b *BloomStore) Client(ts model.Time) (Client, error) {
241+
if store := b.getStore(ts); store != nil {
242+
return store.Client(ts)
243+
}
244+
return nil, errNoStore
227245
}
228246

229247
// ResolveMetas implements Store.
@@ -294,7 +312,7 @@ func (b *BloomStore) FetchBlocks(ctx context.Context, blocks []BlockRef) ([]Bloc
294312

295313
if len(res) > 0 {
296314
refs = append(refs, res)
297-
fetchers = append(fetchers, s.Fetcher(s.start))
315+
fetchers = append(fetchers, s.fetcher)
298316
}
299317
}
300318

@@ -341,6 +359,7 @@ func (b *BloomStore) getStore(ts model.Time) *bloomStoreEntry {
341359
return b.stores[j]
342360
}
343361

362+
// should in theory never happen
344363
return nil
345364
}
346365

0 commit comments

Comments
 (0)