-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
HBASE-24898 Use EnvironmentEdge.currentTime() instead of System.currentTimeMillis() in CurrentHourProvider #2272
Conversation
Set to -1 to disable off-peak.</description> | ||
</property> | ||
<property> | ||
<name>hbase.offpeak.end.hour</name> | ||
<value>-1</value> | ||
<description>The end of off-peak hours, expressed as an integer between 0 and 23, inclusive. Set | ||
<description>The end of off-peak hours, expressed as an integer between 0 and 24, exclusive. Set |
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.
How is this exclusive
for 24 based on return 0 <= hour && hour <= 24;
condition?
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.
@Override public boolean isOffPeakHour(int targetHour) { if (startHour <= endHour) { return startHour <= targetHour && targetHour < endHour; } return targetHour < endHour || startHour <= targetHour; }
See the code, it will be "return 0 <= hour && hour < 24"
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
…ntTimeMillis() in CurrentHourProvider
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
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.
Looks right by me.
@Apache9 this look like what you expected here?
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.
Let's do this first.
But I'm not sure if we could control the return value of CurrentHourProvider? In nextTick method, we will not use EnvironmentEdge.currentTime() so it will still return the current time? |
Oh, no, seems you are right, the changing is not enough. |
Maybe we can set the time.
|
Seems it is ok, will add a unit test for CurrentHourProvider later. |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
return tick.currentHour; | ||
} | ||
|
||
CurrentHourProvider.tick = tick = nextTick(); | ||
return tick.currentHour; | ||
} | ||
|
||
protected static void forceUpdateTickForTest() { |
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.
I think this can be done by implementing a special EnvironmentEdge? Where we will return a pre defined sequence of timestamp.
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.
Do you mean like this:
if (EnvironmentEdgeManager.currentTime() <= 23) { return (int)EnvironmentEdgeManager.currentTime(); }
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.
Then we can inject a special value.
EnvironmentEdgeManager.injectEdge(()->0L); assertEquals(0, CurrentHourProvider.getCurrentHour()); EnvironmentEdgeManager.injectEdge(()->15L); assertEquals(15, CurrentHourProvider.getCurrentHour());
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.
class MockEnvironmentEdge implements EnvironmentEdge {
private final Queue<Long> times = new ArrayDeque<>();
public void inject(long timestamp) {
times.addLast(timestamp);
}
public long currentTime() {
return times.pollFirst();
}
}
EnvironmentEdgeManager.injectEdge(new MockEnvironmentEdge());
Something like this.
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.
A bit confusion of why we need a queue?
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.
You can use any Collections you want. The point here, is that you can inject multiple values at once, and also you can implement more complicated logic in the currentTime method, so you do not need to add a forceUpdateTickForTest method.
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.
Oh, but i think the test failure above is caused by injectEdge in other test, if EnvironmentEdgeManager.currentTime() < tick.expirationTimeInMillis, then it will return the previous currentHour, it is why i want force update the tick.
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.
How about the way i mentioned above, a bit magic, but seems bring smallest impact.
if (EnvironmentEdgeManager.currentTime() <= 23) {
return (int)EnvironmentEdgeManager.currentTime();
}
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.
Then just make the tick field as package private and add a VisibleForTesting annotation? Just change it directly in UT.
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.
Also the nextTick(), let see the qa result for the recent build first.
Seems QA stuck in build#3, can you help to stop it? Thanks. @Apache9 |
💔 -1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
Digged more, and i think the failure in fact caused by timezone, let see the new build for verify. |
🎊 +1 overall
This message was automatically generated. |
* | ||
* @return Current timezone. | ||
*/ | ||
default TimeZone currentTimeZone() { |
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.
A timestamp does not need TimeZone I assume?
@Test | ||
public void testWithEnvironmentEdge() { | ||
// set 1597895561000 with timezone GMT+08:00, represent 2020-08-20 11:52:41, should return 11 | ||
EnvironmentEdge edgeForHour11 = new EnvironmentEdge() { |
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.
I would like to do this in a oppsite way, that is, based on the current time zone, we adjust the currentTime, so we will return the same hour.
In general, we should try our best to not add additional logic to normal code only if we want to write a UT.
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.
Make sense, let me try.
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
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.
+1
Good.
🎊 +1 overall
This message was automatically generated. |
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.
+1, better than dealing with TimeZone
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
…ntTimeMillis() in CurrentHourProvider Closes #2272 Signed-off-by: Nick Dimiduk <[email protected]> Signed-off-by: Duo Zhang <[email protected]> Signed-off-by: Viraj Jasani <[email protected]>
…ntTimeMillis() in CurrentHourProvider Closes #2272 Signed-off-by: Nick Dimiduk <[email protected]> Signed-off-by: Duo Zhang <[email protected]> Signed-off-by: Viraj Jasani <[email protected]>
…ntTimeMillis() in CurrentHourProvider Closes #2272 Signed-off-by: Nick Dimiduk <[email protected]> Signed-off-by: Duo Zhang <[email protected]> Signed-off-by: Viraj Jasani <[email protected]>
…ntTimeMillis() in CurrentHourProvider Closes #2272 Co-authored-by: Viraj Jasani <[email protected]> Signed-off-by: Nick Dimiduk <[email protected]> Signed-off-by: Duo Zhang <[email protected]> Signed-off-by: Viraj Jasani <[email protected]>
…ntTimeMillis() in CurrentHourProvider Closes apache#2272 Signed-off-by: Nick Dimiduk <[email protected]> Signed-off-by: Duo Zhang <[email protected]> Signed-off-by: Viraj Jasani <[email protected]>
…ntTimeMillis() in CurrentHourProvider Closes apache#2272 Signed-off-by: Nick Dimiduk <[email protected]> Signed-off-by: Duo Zhang <[email protected]> Signed-off-by: Viraj Jasani <[email protected]> (cherry picked from commit 9dea961) Change-Id: Ia6ab97f57505a21ba684d56201ffd3226d537e1b
No description provided.