New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support cron timer to arrange the period heartbeat executor invoke time #16900
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
74c24a4
Support cron timer to arrange the period heartbeat executor invoke time.
maobaolong 3594e2f
Fix style issue
maobaolong a76226b
Address a bundle of comments
maobaolong 7e0ff27
Merge master and resolve conflict
maobaolong bf521c3
Fix style issue
maobaolong 0343936
Refactor to unify interval supplier and cron supplier
maobaolong 5b83589
Refactor to unify interval supplier and cron supplier
maobaolong 2d5c311
Fix style issue and do refactor follow review comment
maobaolong ef89064
Fix style issue and do refactor follow review comment
maobaolong ea14379
Fix ut
maobaolong File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
core/common/src/main/java/alluxio/heartbeat/CronExpressionIntervalSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package alluxio.heartbeat; | ||
|
||
import org.apache.logging.log4j.core.util.CronExpression; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.Date; | ||
|
||
/** | ||
* Calculate the next interval by given cron expression. | ||
*/ | ||
public class CronExpressionIntervalSupplier implements SleepIntervalSupplier { | ||
private final long mInterval; | ||
private final CronExpression mCron; | ||
|
||
/** | ||
* Constructs a new {@link CronExpressionIntervalSupplier}. | ||
* | ||
* @param cronExpression the cron expression | ||
* @param fixedInterval the fixed interval | ||
*/ | ||
public CronExpressionIntervalSupplier(CronExpression cronExpression, long fixedInterval) { | ||
mInterval = fixedInterval; | ||
mCron = cronExpression; | ||
} | ||
|
||
@Override | ||
public long getNextInterval(long mPreviousTickedMs, long nowTimeStampMillis) { | ||
long nextInterval = 0; | ||
long executionTimeMs = nowTimeStampMillis - mPreviousTickedMs; | ||
if (executionTimeMs < mInterval) { | ||
nextInterval = mInterval - executionTimeMs; | ||
} | ||
Date now = Date.from(Instant.ofEpochMilli(nowTimeStampMillis + nextInterval)); | ||
if (mCron.isSatisfiedBy(now)) { | ||
return nextInterval; | ||
} | ||
return nextInterval + Duration.between( | ||
now.toInstant(), mCron.getNextValidTimeAfter(now).toInstant()).toMillis(); | ||
} | ||
|
||
@Override | ||
public long getRunLimit(long mPreviousTickedMs) { | ||
Date now = Date.from(Instant.ofEpochMilli(mPreviousTickedMs)); | ||
return Duration.between(now.toInstant(), | ||
mCron.getNextInvalidTimeAfter(now).toInstant()).toMillis(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
core/common/src/main/java/alluxio/heartbeat/FixedIntervalSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package alluxio.heartbeat; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.helpers.NOPLogger; | ||
|
||
/** | ||
* Fixed interval supplier. | ||
*/ | ||
public class FixedIntervalSupplier implements SleepIntervalSupplier { | ||
|
||
private final long mInterval; | ||
protected final Logger mLogger; | ||
|
||
/** | ||
* Constructs a new {@link FixedIntervalSupplier}. | ||
* | ||
* @param fixedInterval the fixed interval | ||
* @param logger the logger | ||
*/ | ||
public FixedIntervalSupplier(long fixedInterval, Logger logger) { | ||
mInterval = fixedInterval; | ||
mLogger = logger; | ||
} | ||
|
||
/** | ||
* Constructs a new {@link FixedIntervalSupplier}. | ||
* | ||
* @param fixedInterval the fixed interval | ||
*/ | ||
public FixedIntervalSupplier(long fixedInterval) { | ||
this(fixedInterval, NOPLogger.NOP_LOGGER); | ||
} | ||
|
||
@Override | ||
public long getNextInterval(long mPreviousTickedMs, long nowTimeStampMillis) { | ||
if (mPreviousTickedMs == -1) { | ||
return -1; | ||
} | ||
long executionTimeMs = nowTimeStampMillis - mPreviousTickedMs; | ||
if (executionTimeMs > mInterval) { | ||
mLogger.warn("{} last execution took {} ms. Longer than the interval {}", | ||
Thread.currentThread().getName(), executionTimeMs, mInterval); | ||
return 0; | ||
} | ||
return mInterval - executionTimeMs; | ||
} | ||
|
||
@Override | ||
public long getRunLimit(long mPreviousTickedMs) { | ||
return mInterval; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who stops this heartbeat if the limitTime has been exceeded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stopped by Heartbeat implementation