You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 0e1afae
Browse filesBrowse the repository at this point in the historyBrowse files
Compactor: let an in-flight compaction finish on shutdown (#7973)
* Compactor: let an in-flight compaction finish on shutdown
Add -compactor.compaction-drain-timeout. When set, shutdown no longer
cancels a compaction that is already running. Compactions run under a
context detached from the service context, cancelled once the drain
timeout has passed after shutdown is requested. The compactor stops
picking up further tenants as soon as shutdown is requested.
Thanos's BucketCompactor keeps taking groups off its queue and repeats
whole compaction passes until no work is left, and only sees
cancellation through the calls it makes. A detached context alone would
therefore keep compacting the tenant's backlog until the timeout cut it
mid-merge. Two gates stop that. The planner returns an empty plan for
every group not yet planned when shutdown is requested, which thanos
treats as a group with nothing to do. The grouper returns no groups on
later passes. Under the partitioning strategy, building a group writes
a visit marker claiming its partition, so without the grouper gate a
draining compactor would claim partitions it never compacts and other
compactors would skip them until the marker timed out.
Defaults to 0, which keeps the current behaviour of cancelling the
running compaction immediately.
Signed-off-by: Alex Le <leqiyue@amazon.com>
* Compactor: reference the PR number in the CHANGELOG entry
Signed-off-by: Alex Le <leqiyue@amazon.com>
* Compactor: use go.uber.org/atomic in the shutdown drain tests
Signed-off-by: Alex Le <leqiyue@amazon.com>
* Compactor: build the TSDB compactor and bucket client with the drain context
The TSDB compactor keeps the context it is built with and checks it
while merging, so building it in starting() with the service context
aborted the merge at shutdown even with a drain timeout set. Only the
block download and upload, which use the context thanos passes down,
were protected.
Create the drain context in starting() and pass it to both the blocks
compactor factory and the bucket client factory. The GCS bucket client
builds its token source with that context, and for credential types
other than service account keys a token refresh sends its request with
it, so a refresh during the drain would otherwise fail.
The test mock now records the context its factory was given, so a test
can assert the merge context survives shutdown.
Signed-off-by: Alex Le <leqiyue@amazon.com>
* Compactor: stay in the ring and stop retrying while draining
The ring subservices were started with the service context, so the
lifecycler left the ring as soon as shutdown started, while the
compaction was still draining. With the default sharding strategy,
which has no visit markers, another compactor then took over the
tenant and compacted the same blocks. Start them with the compaction
context instead. stopping() already stops them explicitly, so the
instance now leaves the ring once the drain ends.
A compaction that failed with a retriable error during the drain was
retried on the compaction context. The retry built no groups because of
the shutdown gate and returned nil, so the failure was reported as a
success. Stop retrying once shutdown has been requested and handle the
last error as when retries run out.
Signed-off-by: Alex Le <leqiyue@amazon.com>
---------
Signed-off-by: Alex Le <leqiyue@amazon.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,7 @@
8
8
*[FEATURE] Distributor: Add experimental OTLP metrics ingestion over gRPC (`opentelemetry.proto.collector.metrics.v1.MetricsService/Export`) on the gRPC server port. Enable it with `-distributor.otlp.grpc-enabled`. The tenant is read from the `X-Scope-OrgID` gRPC metadata, and the request size is limited by `-server.grpc-max-recv-msg-size-bytes`. #7873
9
9
*[FEATURE] Storage: Add support for Alibaba Cloud OSS as a backend for blocks, ruler, and alertmanager storage. Configured via `-<prefix>.oss.*` flags with `backend: oss`. #7907
10
10
*[ENHANCEMENT] Compactor: Add `-compactor.block-ranges-compaction-delay` to configure the compaction group graceful period per `-compactor.block-ranges` entry, matched by position. A larger block range can now be held back until its sub-ranges have settled, instead of every range sharing one period derived from `-compactor.cleanup-interval`. Leaving it empty, and any range without an entry, keeps the current behaviour of twice `-compactor.cleanup-interval`. The delay is a lower bound: groups only become eligible on a compaction run, so the effective wait can be up to `-compactor.compaction-interval` longer. Only used by the partitioning compaction strategy. #7916
11
+
*[ENHANCEMENT] Compactor: Add `-compactor.compaction-drain-timeout`. When set, a compaction that is already running when shutdown is requested is allowed to finish, for up to this duration, instead of being cancelled. The compactor stops planning new compaction groups and stops picking up further tenants as soon as shutdown is requested. Defaults to 0, which cancels the running compaction immediately and discards the work it has done so far. #7973
11
12
*[ENHANCEMENT] Ring: Add the `cortex_ring_member_zonal_ownership_percent{name, member, zone}` metric, reporting the fraction of its own zone's token space owned by each ring member. With zone-aware replication a write is routed within a single zone, so the existing `cortex_ring_member_ownership_percent`, which is computed over the merged token list of all zones, does not reflect the hash range a member actually serves. Reported when ring detailed metrics and zone awareness are both enabled. #7910
12
13
*[ENHANCEMENT] Ingester: Add experimental `-ingester.use-ring-ownership-for-limits` (requires zone-aware replication). It converts global series and metadata limits to per-ingester limits using the ingester's actual share of each tenant's hash space within its zone, instead of an equal share, which throttles tenants early on an unbalanced ring. Shares ignore `-distributor.extend-writes`, so a tenant can be throttled early while an instance is JOINING, LEAVING or PENDING. Exposes `cortex_ingester_ring_ownership_share{user}` and `cortex_ingester_ring_ownership_computations_total`. #7954#7961
13
14
*[ENHANCEMENT] Distributor: Support partial write for Prometheus Remote Write 2.0 requests. Invalid series are now skipped and reported together in the `400` response instead of rejecting the whole batch, the valid ones are written, and the `X-Prometheus-Remote-Write-*-Written` response headers are set even when a `400` is returned. #7761
f.DurationVar(&cfg.CompactionInterval, "compactor.compaction-interval", time.Hour, "The frequency at which the compaction runs")
334
336
f.IntVar(&cfg.CompactionRetries, "compactor.compaction-retries", 3, "How many times to retry a failed compaction within a single compaction run.")
335
337
f.IntVar(&cfg.CompactionConcurrency, "compactor.compaction-concurrency", 1, "Max number of concurrent compactions running.")
338
+
f.DurationVar(&cfg.CompactionDrainTimeout, "compactor.compaction-drain-timeout", 0, "How long to let a compaction that is already running finish once shutdown has been requested, before cancelling it. As soon as shutdown is requested the compactor stops planning new compaction groups and stops picking up further tenants, regardless of this setting. 0 cancels the running compaction immediately, discarding the work it has done so far. A compaction is only allowed to finish if the process is given at least this long to terminate, so this value should be below the deployment's termination grace period.")
336
339
f.DurationVar(&cfg.CleanupInterval, "compactor.cleanup-interval", 15*time.Minute, "How frequently compactor should run blocks cleanup and maintenance, as well as update the bucket index.")
337
340
f.IntVar(&cfg.CleanupConcurrency, "compactor.cleanup-concurrency", 20, "Max number of tenants for which blocks cleanup and maintenance should run concurrently.")
338
341
f.BoolVar(&cfg.ShardingEnabled, "compactor.sharding-enabled", false, "Shard tenants across multiple compactor instances. Sharding is required if you run multiple compactor instances, in order to coordinate compactions and avoid race conditions leading to the same tenant blocks simultaneously compacted by different instances.")
0 commit comments