Skip to content

Commit 38f4c3c

Browse files
authored
store: lock around iterating over s.blocks (#8088)
Hold a lock around s.blocks when iterating over it. I have experienced a case where a block had been added to a blockSet twice somehow and it being somehow removed from s.blocks is the only way it could happen. This is the only "bad" thing I've been able to spot. Signed-off-by: Giedrius Statkevičius <[email protected]>
1 parent a13fc75 commit 38f4c3c

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

docs/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ See up to date [jsonnet mixins](https://github.com/thanos-io/thanos/tree/main/mi
162162
* [HelloFresh blog posts part 1](https://engineering.hellofresh.com/monitoring-at-hellofresh-part-1-architecture-677b4bd6b728)
163163
* [HelloFresh blog posts part 2](https://engineering.hellofresh.com/monitoring-at-hellofresh-part-2-operating-the-monitoring-system-8175cd939c1d)
164164
* [Thanos deployment](https://www.metricfire.com/blog/ha-kubernetes-monitoring-using-prometheus-and-thanos)
165-
* [Taboola user story](https://blog.taboola.com/monitoring-and-metering-scale/)
165+
* [Taboola user story](https://www.taboola.com/engineering/monitoring-and-metering-scale/)
166166
* [Thanos via Prometheus Operator](https://kkc.github.io/2019/02/10/prometheus-operator-with-thanos/)
167167

168168
* 2018:

pkg/extprom/http/instrument_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type ClientMetrics struct {
2323

2424
// NewClientMetrics creates a new instance of ClientMetrics.
2525
// It will also register the metrics with the included register.
26-
// This ClientMetrics should be re-used for diff clients with the same purpose.
26+
// This ClientMetrics should be reused for diff clients with the same purpose.
2727
// e.g. 1 ClientMetrics should be used for all the clients that talk to Alertmanager.
2828
func NewClientMetrics(reg prometheus.Registerer) *ClientMetrics {
2929
var m ClientMetrics

pkg/query/endpointset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func (e *EndpointSet) Update(ctx context.Context) {
366366
if er.HasStoreAPI() && (er.ComponentType() == component.Sidecar || er.ComponentType() == component.Rule) &&
367367
stats[component.Sidecar.String()][extLset]+stats[component.Rule.String()][extLset] > 0 {
368368

369-
level.Warn(e.logger).Log("msg", "found duplicate storeEndpoints producer (sidecar or ruler). This is not advices as it will malform data in in the same bucket",
369+
level.Warn(e.logger).Log("msg", "found duplicate storeEndpoints producer (sidecar or ruler). This is not advised as it will malform data in in the same bucket",
370370
"address", addr, "extLset", extLset, "duplicates", fmt.Sprintf("%v", stats[component.Sidecar.String()][extLset]+stats[component.Rule.String()][extLset]+1))
371371
}
372372
stats[er.ComponentType().String()][extLset]++

pkg/runutil/runutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
// The rununtil.Exhaust* family of functions provide the same functionality but
4646
// they take an io.ReadCloser and they exhaust the whole reader before closing
4747
// them. They are useful when trying to use http keep-alive connections because
48-
// for the same connection to be re-used the whole response body needs to be
48+
// for the same connection to be reused the whole response body needs to be
4949
// exhausted.
5050
package runutil
5151

pkg/store/bucket.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,15 @@ func (s *BucketStore) SyncBlocks(ctx context.Context) error {
766766
return metaFetchErr
767767
}
768768

769+
s.mtx.RLock()
770+
keys := make([]ulid.ULID, 0, len(s.blocks))
771+
for k := range s.blocks {
772+
keys = append(keys, k)
773+
}
774+
s.mtx.RUnlock()
775+
769776
// Drop all blocks that are no longer present in the bucket.
770-
for id := range s.blocks {
777+
for _, id := range keys {
771778
if _, ok := metas[id]; ok {
772779
continue
773780
}

0 commit comments

Comments
 (0)