@@ -65,7 +65,11 @@ type BucketStores struct {
65
65
66
66
// Keeps a bucket store for each tenant.
67
67
storesMu sync.RWMutex
68
- stores map [string ]* BucketStoreWithLastError
68
+ stores map [string ]* store.BucketStore
69
+
70
+ // Keeps the last sync error for the bucket store for each tenant.
71
+ storesErrorsMu sync.RWMutex
72
+ storesErrors map [string ]error
69
73
70
74
// Metrics.
71
75
syncTimes prometheus.Histogram
@@ -100,7 +104,8 @@ func NewBucketStores(cfg tsdb.BlocksStorageConfig, shardingStrategy ShardingStra
100
104
limits : limits ,
101
105
bucket : cachingBucket ,
102
106
shardingStrategy : shardingStrategy ,
103
- stores : map [string ]* BucketStoreWithLastError {},
107
+ stores : map [string ]* store.BucketStore {},
108
+ storesErrors : map [string ]error {},
104
109
logLevel : logLevel ,
105
110
bucketStoreMetrics : NewBucketStoreMetrics (),
106
111
metaFetcherMetrics : NewMetadataFetcherMetrics (),
@@ -198,7 +203,7 @@ func (u *BucketStores) syncUsersBlocks(ctx context.Context, f func(context.Conte
198
203
199
204
type job struct {
200
205
userID string
201
- store * BucketStoreWithLastError
206
+ store * store. BucketStore
202
207
}
203
208
204
209
wg := & sync.WaitGroup {}
@@ -231,16 +236,20 @@ func (u *BucketStores) syncUsersBlocks(ctx context.Context, f func(context.Conte
231
236
defer wg .Done ()
232
237
233
238
for job := range jobs {
234
- if err := f (ctx , job .store . BucketStore ); err != nil {
239
+ if err := f (ctx , job .store ); err != nil {
235
240
if errors .Is (err , bucket .ErrCustomerManagedKeyError ) {
236
- job .store .err = err
241
+ u .storesErrorsMu .Lock ()
242
+ u .storesErrors [job .userID ] = err
243
+ u .storesErrorsMu .Unlock ()
237
244
} else {
238
245
errsMx .Lock ()
239
246
errs .Add (errors .Wrapf (err , "failed to synchronize TSDB blocks for user %s" , job .userID ))
240
247
errsMx .Unlock ()
241
248
}
242
249
} else {
243
- job .store .err = nil
250
+ u .storesErrorsMu .Lock ()
251
+ delete (u .storesErrors , job .userID )
252
+ u .storesErrorsMu .Unlock ()
244
253
}
245
254
}
246
255
}()
@@ -298,11 +307,13 @@ func (u *BucketStores) Series(req *storepb.SeriesRequest, srv storepb.Store_Seri
298
307
return nil
299
308
}
300
309
301
- if store .err != nil && errors .Is (store .err , bucket .ErrCustomerManagedKeyError ) {
302
- return httpgrpc .Errorf (int (codes .ResourceExhausted ), "store error: %s" , store .err )
310
+ err := u .getStoreError (userID )
311
+
312
+ if err != nil && errors .Is (err , bucket .ErrCustomerManagedKeyError ) {
313
+ return httpgrpc .Errorf (int (codes .ResourceExhausted ), "store error: %s" , err )
303
314
}
304
315
305
- err : = store .Series (req , spanSeriesServer {
316
+ err = store .Series (req , spanSeriesServer {
306
317
Store_SeriesServer : srv ,
307
318
ctx : spanCtx ,
308
319
})
@@ -366,12 +377,18 @@ func (u *BucketStores) scanUsers(ctx context.Context) ([]string, error) {
366
377
return users , err
367
378
}
368
379
369
- func (u * BucketStores ) getStore (userID string ) * BucketStoreWithLastError {
380
+ func (u * BucketStores ) getStore (userID string ) * store. BucketStore {
370
381
u .storesMu .RLock ()
371
382
defer u .storesMu .RUnlock ()
372
383
return u .stores [userID ]
373
384
}
374
385
386
+ func (u * BucketStores ) getStoreError (userID string ) error {
387
+ u .storesErrorsMu .RLock ()
388
+ defer u .storesErrorsMu .RUnlock ()
389
+ return u .storesErrors [userID ]
390
+ }
391
+
375
392
var (
376
393
errBucketStoreNotEmpty = errors .New ("bucket store not empty" )
377
394
errBucketStoreNotFound = errors .New ("bucket store not found" )
@@ -409,7 +426,7 @@ func (u *BucketStores) closeEmptyBucketStore(userID string) error {
409
426
return bs .Close ()
410
427
}
411
428
412
- func isEmptyBucketStore (bs * BucketStoreWithLastError ) bool {
429
+ func isEmptyBucketStore (bs * store. BucketStore ) bool {
413
430
min , max := bs .TimeRange ()
414
431
return min == math .MaxInt64 && max == math .MinInt64
415
432
}
@@ -418,7 +435,7 @@ func (u *BucketStores) syncDirForUser(userID string) string {
418
435
return filepath .Join (u .cfg .BucketStore .SyncDir , userID )
419
436
}
420
437
421
- func (u * BucketStores ) getOrCreateStore (userID string ) (* BucketStoreWithLastError , error ) {
438
+ func (u * BucketStores ) getOrCreateStore (userID string ) (* store. BucketStore , error ) {
422
439
// Check if the store already exists.
423
440
bs := u .getStore (userID )
424
441
if bs != nil {
@@ -522,7 +539,7 @@ func (u *BucketStores) getOrCreateStore(userID string) (*BucketStoreWithLastErro
522
539
bucketStoreOpts = append (bucketStoreOpts , store .WithDebugLogging ())
523
540
}
524
541
525
- s , err := store .NewBucketStore (
542
+ bs , err := store .NewBucketStore (
526
543
userBkt ,
527
544
fetcher ,
528
545
u .syncDirForUser (userID ),
@@ -542,10 +559,6 @@ func (u *BucketStores) getOrCreateStore(userID string) (*BucketStoreWithLastErro
542
559
return nil , err
543
560
}
544
561
545
- bs = & BucketStoreWithLastError {
546
- BucketStore : s ,
547
- }
548
-
549
562
u .stores [userID ] = bs
550
563
u .metaFetcherMetrics .AddUserRegistry (userID , fetcherReg )
551
564
u .bucketStoreMetrics .AddUserRegistry (userID , bucketStoreReg )
0 commit comments