-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
YARN-10885. Make FederationStateStoreFacade#getApplicationHomeSubCluster use JCache. #4701
Conversation
💔 -1 overall
This message was automatically generated. |
@@ -169,7 +169,7 @@ public void testGetPoliciesConfigurations() throws YarnException { | |||
} | |||
|
|||
@Test | |||
public void testGetHomeSubClusterForApp() throws YarnException { | |||
public void getApplicationHomeSubCluster() throws YarnException { |
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 we use test for the method name
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 will fix it.
ApplicationId applicationId = ApplicationId.fromString(appId); | ||
GetApplicationHomeSubClusterResponse response = | ||
stateStore.getApplicationHomeSubCluster( | ||
GetApplicationHomeSubClusterRequest.newInstance(applicationId)); |
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.
The indentation is not correct.
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 create a method that takes string and does the appId transformation inside.
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.
Thanks for your suggestion, I will fix it.
if (isCachingEnabled()) { | ||
Map<ApplicationId, SubClusterId> cacheAppSubCluster = | ||
(Map<ApplicationId, SubClusterId>) | ||
cache.get(buildGetApplicationHomeSubClusterRequest(appId.toString())); |
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.
Extract things a little.
buildGetApplicationHomeSubClusterRequest could also take ApplicationId.
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 will fix it.
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.
Still left.
💔 -1 overall
This message was automatically generated. |
@goiri Please help to review the code again, thank you very much! |
if (isCachingEnabled()) { | ||
Map<ApplicationId, SubClusterId> cacheAppSubCluster = | ||
(Map<ApplicationId, SubClusterId>) | ||
cache.get(buildGetApplicationHomeSubClusterRequest(appId.toString())); |
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.
Still left.
@@ -513,6 +525,32 @@ public Map<String, SubClusterPolicyConfiguration> invoke( | |||
return cacheRequest; | |||
} | |||
|
|||
@SuppressWarnings("unchecked") | |||
private Object buildGetApplicationHomeSubClusterRequest(String appId) { |
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.
Can we cast it 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.
Thanks for your suggestion, I will modify the code.
response.getApplicationHomeSubCluster(); | ||
SubClusterId subClusterId = applicationHomeSubCluster.getHomeSubCluster(); | ||
|
||
Map<String, SubClusterId> appSubCluster = new HashMap<>(); |
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.
Can you return a singleton map?
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 will fix it.
facade.addApplicationHomeSubCluster(appHomeSubCluster); | ||
|
||
SubClusterId subClusterIdCache = facade.getApplicationHomeSubCluster(appId); | ||
Assert.assertEquals(subClusterIdCache, subClusterIdAdd); |
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 do we make sure we went through the cache?
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.
This is related to this test class.
This test class uses junit's Parameterized, which will be tested twice. The cache effective configuration is initialized in the constructor. The first setting cache does not take effect, and the second setting cache takes effect.
@RunWith(Parameterized.class)
public class TestFederationStateStoreFacade {
public TestFederationStateStoreFacade(Boolean isCachingEnabled) {
conf = new Configuration();
if (!(isCachingEnabled.booleanValue())) {
conf.setInt(YarnConfiguration.FEDERATION_CACHE_TIME_TO_LIVE_SECS, 0);
}
}
}
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 refactored the test for getting objects from Cache. If the test case enables Cache mode, the comparison will be as follows:
Whether the object obtained directly from the Cache and the object obtained from the Facade are the same.
💔 -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. |
@goiri Please help to review the code again, thank you very much! |
🎊 +1 overall
This message was automatically generated. |
@goiri Please help to review the code again, thank you very much! |
if (isCachingEnabled()) { | ||
Object value = | ||
cache.get(buildGetApplicationHomeSubClusterRequest(appId.toString())); | ||
if(value instanceof SubClusterId){ |
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.
Space missing
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.
Thanks for your suggestion, I will fix it.
try { | ||
if (isCachingEnabled()) { | ||
Object value = | ||
cache.get(buildGetApplicationHomeSubClusterRequest(appId.toString())); |
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.
Add ApplicationId as the argument and tostring inside.
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 will modify the code.
🎊 +1 overall
This message was automatically generated. |
@goiri Please help to review the code again, Thank you very much! |
stateStore.getApplicationHomeSubCluster( | ||
try { | ||
if (isCachingEnabled()) { | ||
Object value = |
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.
This fits in one line.
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.
Thanks for your help reviewing the code, I will fix it.
if (value instanceof SubClusterId) { | ||
return (SubClusterId) value; | ||
} else { | ||
throw new YarnException("Cannot be converted to SubClusterId."); |
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.
Maybe add the type of the original.
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.
This part of the code does need cast, I simplified the code.
The main reasons are as follows:
The key and value used by the Cache defined here are both Object types.
private Cache<Object, Object> cache;
input -> { | ||
GetApplicationHomeSubClusterResponse response = | ||
stateStore.getApplicationHomeSubCluster( | ||
GetApplicationHomeSubClusterRequest.newInstance(applicationId)); |
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.
Extract the request and probably do indentation like:
CacheRequest<String, SubClusterId> cacheRequest = new CacheRequest<>(
cacheKey,
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 will fix it.
|
||
ApplicationHomeSubCluster appHomeSubCluster = | ||
ApplicationHomeSubCluster.newInstance(appId, subClusterId1); | ||
SubClusterId subClusterIdAdd = |
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.
One line?
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 will fix it.
🎊 +1 overall
This message was automatically generated. |
input -> { | ||
GetApplicationHomeSubClusterResponse response = | ||
stateStore.getApplicationHomeSubCluster( | ||
GetApplicationHomeSubClusterRequest.newInstance(applicationId)); |
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.
Extract to req
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.
Thanks for your suggestion, I will fix it.
stateStore.getApplicationHomeSubCluster( | ||
GetApplicationHomeSubClusterRequest.newInstance(applicationId)); | ||
|
||
ApplicationHomeSubCluster applicationHomeSubCluster = |
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.
appHomeSubCluster and one line
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 will fix it.
@goiri Please help to review the code again, thank you very much! |
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
@goiri Thank you very much for helping to review the code! |
JIRA: YARN-10885. add FederationStateStoreFacade#getApplicationHomeSubCluster use JCache.
JunitTest will be added later.