You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "tju-yxq (via GitHub)" <gi...@apache.org> on 2026/08/27 19:43:02 UTC
[PR] fix: keep native alert collection leases alive [rocketmq-dashboard]
tju-yxq opened a new pull request, #2642:
URL: https://github.com/apache/rocketmq-dashboard/pull/2642
## Summary
- keep the native alert collection lease alive for the full collection pass, including passes that return no samples;
- renew the lease conditionally for the current holder and stop active work when renewal is lost;
- expose lease duration and renewal interval through alerting configuration.
## Why
A long empty collection pass previously touched the lease only at pass start (and again only when non-empty samples were persisted). With the default lease duration, another Studio replica could acquire the lease while the original pass was still contacting brokers.
## Implementation
- add holder- and expiry-checked lease renewal;
- run a bounded daemon heartbeat per active collection pass;
- cancel outstanding collectors and skip persistence after renewal failure;
- shut down the renewal executor with the scheduler;
- document the configuration and behavior.
Closes #2641
## Verification
- `mvn -q '-Dtest=CollectorSchedulerTest,MybatisPlusAlertCollectionLeaseTest' test` — 9 tests passed;
- `mvn -DskipTests=false test` — 1792 tests passed, 0 failures, 0 errors, 0 skipped;
- `git diff --check` passed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: keep native alert collection leases alive [rocketmq-dashboard]
Posted by "tju-yxq (via GitHub)" <gi...@apache.org>.
tju-yxq commented on PR #2642:
URL: https://github.com/apache/rocketmq-dashboard/pull/2642#issuecomment-5528696969
Rebased and reconciled the scheduler changes requested in review in `3f42d66c` (production/test commit `2e461155`).
The branch now keeps both designs:
- the current mainline whole-pass deadline, per-instance timeout, sliding-window scheduling from #2807/#2957, and `processSuccessfulCollection(...)` flow;
- periodic lease renewal for the entire active pass, including empty passes, with cancellation and persistence blocking after lease loss.
I also retained the persist-time ownership check as defense in depth and the scheduler now closes the renewal executor during shutdown.
Verification after the rebase:
- focused scheduler/lease tests: 14 passed;
- full server suite: 1,964 passed, 0 failures/errors/skips;
- Checkstyle: 0 violations;
- `git diff --check`: clean.
The PR is mergeable/CLEAN. GitHub has not attached any status checks to the new head yet.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: keep native alert collection leases alive [rocketmq-dashboard]
Posted by "lizhimins (via GitHub)" <gi...@apache.org>.
lizhimins commented on PR #2642:
URL: https://github.com/apache/rocketmq-dashboard/pull/2642#issuecomment-5509005668
Thanks for this work! Since this PR was opened, the mainline has merged #2807, which rewrites `CollectorScheduler.collect()` with a whole-pass timeout budget — this branch now conflicts with it. Could you rebase onto the latest `rocketmq-studio` and reconcile the two designs? Your lease heartbeat/renewal and #2807's pass budget are complementary (the pass budget prevents one round from running forever; your heartbeat prevents long rounds from losing the lease), so the rebased version should keep both: whole-pass deadline plus periodic `renew()` during collection. Once rebased we'll take another look. Note the branch may also need to absorb #2957 (sliding-window collection) which landed later and touches the same scheduler.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: keep native alert collection leases alive [rocketmq-dashboard]
Posted by "RockteMQ-AI (via GitHub)" <gi...@apache.org>.
RockteMQ-AI commented on code in PR #2642:
URL: https://github.com/apache/rocketmq-dashboard/pull/2642#discussion_r3875654579
##########
server/src/main/java/org/apache/rocketmq/studio/cluster/metrics/CollectorScheduler.java:
##########
@@ -120,30 +170,39 @@ public void cleanUpSnapshots() {
snapshotRepository.deleteBefore(Instant.now().minus(retention));
}
- private void collectClusterMetrics(InstanceVO instance) {
+ private void collectClusterMetrics(InstanceVO instance, LeaseHeartbeat heartbeat) {
for (ClusterMetricsCollector collector : clusterCollectors) {
+ if (!heartbeat.isHeld()) {
+ return;
+ }
try {
- persist(collector.supports(instance) ? collector.collect(instance) : List.of());
+ List<MetricSample> samples = collector.supports(instance) ? collector.collect(instance) : List.of();
+ persist(samples, heartbeat);
} catch (RuntimeException error) {
log.warn("Native metric collector failed for instance {}: {}", instance.getName(), error.getMessage());
}
}
}
- private void collectBusinessMetrics(InstanceVO instance) {
+ private void collectBusinessMetrics(InstanceVO instance, LeaseHeartbeat heartbeat) {
for (BusinessMetricsCollector collector : businessCollectors) {
+ if (!heartbeat.isHeld()) {
+ return;
+ }
try {
- persist(collector.supports(instance) ? collector.collect(instance) : List.of());
+ List<MetricSample> samples = collector.supports(instance) ? collector.collect(instance) : List.of();
+ persist(samples, heartbeat);
} catch (RuntimeException error) {
log.warn("Native metric collector failed for instance {}: {}", instance.getName(), error.getMessage());
}
Review Comment:
**[Info]** The `tryAcquire()` re-check inside `persist()` is a good defensive measure, but now that the `LeaseHeartbeat` already handles periodic renewal and `isHeld()` is checked before calling `persist()`, this double-check is somewhat redundant in the happy path. Consider adding a brief comment explaining that this is intentional defense-in-depth (in case the heartbeat interval happens to align poorly with a slow persist call).
##########
server/src/main/java/org/apache/rocketmq/studio/cluster/metrics/CollectorScheduler.java:
##########
@@ -168,13 +228,101 @@ private static ExecutorService newCollectionExecutor(AlertingProperties properti
new ArrayBlockingQueue<>(parallelism), threadFactory, new ThreadPoolExecutor.AbortPolicy());
}
- private static Duration parsePositiveDuration(String value, Duration fallback) {
+ private static ScheduledExecutorService newLeaseRenewalExecutor() {
+ ThreadFactory threadFactory = task -> {
+ Thread thread = new Thread(task, "studio-native-metric-lease-renewer");
+ thread.setDaemon(true);
+ return thread;
+ };
+ return java.util.concurrent.Executors.newSingleThreadScheduledExecutor(threadFactory);
+ }
+
+ private Duration leaseRenewalInterval() {
+ Duration leaseDuration = parsePositiveDuration(properties.getCollectionLeaseDuration(), Duration.ofMinutes(1),
+ "collection lease duration");
+ Duration safeMaximum = leaseDuration.dividedBy(3);
+ if (safeMaximum.isZero() || safeMaximum.isNegative()) {
+ safeMaximum = Duration.ofMillis(1);
+ }
+ Duration configured = parsePositiveDuration(properties.getCollectionLeaseRenewalInterval(), safeMaximum,
Review Comment:
**[Info]** The `LeaseHeartbeat` inner class is well-designed. A short Javadoc on the class would help future readers understand the heartbeat lifecycle at a glance.
##########
server/src/main/java/org/apache/rocketmq/studio/persistence/mapper/RmqAlertCollectionLeaseMapper.java:
##########
@@ -29,4 +29,9 @@ public interface RmqAlertCollectionLeaseMapper extends BaseMapper<RmqAlertCollec
+ "AND (expires_at <= #{now} OR holder_id = #{holderId})")
int acquire(@Param("leaseName") String leaseName, @Param("holderId") String holderId,
@Param("now") LocalDateTime now, @Param("expiresAt") LocalDateTime expiresAt);
+
+ @Update("UPDATE rmq_alert_collection_lease SET expires_at = #{expiresAt}, gmt_modified = #{now} "
+ + "WHERE lease_name = #{leaseName} AND holder_id = #{holderId} AND expires_at > #{now}")
Review Comment:
**[Info]** The `renew` SQL correctly enforces `expires_at > now` to prevent an expired holder from reclaiming the lease. Since both sides use the Java-computed `now` parameter consistently, this is fine for now, but worth keeping in mind if the DB ever switches to using its own `NOW()` for expiry checks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: keep native alert collection leases alive [rocketmq-dashboard]
Posted by "tju-yxq (via GitHub)" <gi...@apache.org>.
tju-yxq commented on PR #2642:
URL: https://github.com/apache/rocketmq-dashboard/pull/2642#issuecomment-5445676069
CI follow-up: after the documentation-only follow-up, run 33119990044 also ended as startup_failure before any job was created. The same repository workflow is failing at startup on the current branch, #2644, the rocketmq-studio push, and unrelated pull requests, so there is no Java/test job output to diagnose for this commit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: keep native alert collection leases alive [rocketmq-dashboard]
Posted by "tju-yxq (via GitHub)" <gi...@apache.org>.
tju-yxq commented on PR #2642:
URL: https://github.com/apache/rocketmq-dashboard/pull/2642#issuecomment-5445641395
Addressed the review suggestions in commit 79db2407: added class-level Javadoc for LeaseHeartbeat and clarified that the persist-time tryAcquire() check is intentional defense-in-depth against a heartbeat race. No runtime behavior changed. Re-ran the focused server tests from server/: CollectorSchedulerTest and MybatisPlusAlertCollectionLeaseTest pass (exit 0); git diff --check is clean.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: keep native alert collection leases alive [rocketmq-dashboard]
Posted by "tju-yxq (via GitHub)" <gi...@apache.org>.
tju-yxq commented on PR #2642:
URL: https://github.com/apache/rocketmq-dashboard/pull/2642#issuecomment-5444371377
Implemented the requested lease-heartbeat behavior for long native alert collection passes.
- empty passes renew the lease instead of allowing it to expire;
- renewal is conditional on the current holder and a non-expired lease;
- renewal loss cancels active collectors and blocks persistence of late results;
- lease duration and renewal interval are exposed in alerting configuration.
Verification on commit `4a5a01a2`: focused tests 9/9 passed; full server suite 1792/1792 passed with 0 failures, 0 errors, and 0 skipped; `git diff --check` passed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: keep native alert collection leases alive [rocketmq-dashboard]
Posted by "lizhimins (via GitHub)" <gi...@apache.org>.
lizhimins merged PR #2642:
URL: https://github.com/apache/rocketmq-dashboard/pull/2642
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org