advancedxy commented on code in PR #481:
URL: https://github.com/apache/incubator-uniffle/pull/481#discussion_r1070798646
##########
server/src/main/java/org/apache/uniffle/server/storage/HdfsStorageManager.java:
##########
@@ -119,23 +119,20 @@ public Checker getStorageChecker() {
@Override
public void registerRemoteStorage(String appId, RemoteStorageInfo
remoteStorageInfo) {
String remoteStorage = remoteStorageInfo.getPath();
- Map<String, String> remoteStorageConf = remoteStorageInfo.getConfItems();
- if (!pathToStorages.containsKey(remoteStorage)) {
+ pathToStorages.computeIfAbsent(remoteStorage, key -> {
+ Map<String, String> remoteStorageConf = remoteStorageInfo.getConfItems();
Configuration remoteStorageHadoopConf = new Configuration(hadoopConf);
if (remoteStorageConf != null && remoteStorageConf.size() > 0) {
for (Map.Entry<String, String> entry : remoteStorageConf.entrySet()) {
remoteStorageHadoopConf.setStrings(entry.getKey(), entry.getValue());
}
}
- pathToStorages.putIfAbsent(remoteStorage, new HdfsStorage(remoteStorage,
remoteStorageHadoopConf));
- // registerRemoteStorage may be called in different threads,
- // make sure metrics won't be created duplicated
- // there shouldn't have performance issue because
- // it will be called only few times according to the number of remote
storage
- String storageHost = pathToStorages.get(remoteStorage).getStorageHost();
+ HdfsStorage hdfsStorage = new HdfsStorage(remoteStorage,
remoteStorageHadoopConf);
+ String storageHost = hdfsStorage.getStorageHost();
ShuffleServerMetrics.addDynamicCounterForRemoteStorage(storageHost);
- }
- appIdToStorages.putIfAbsent(appId, pathToStorages.get(remoteStorage));
+ return hdfsStorage;
+ });
+ appIdToStorages.computeIfAbsent(appId, key ->
pathToStorages.get(remoteStorage));
Review Comment:
> Anyway, this is a performance improvement
Good to know. I was forgetting the performance difference. Although,
`putIfAbsent` is more cleaner in most cases.
>Similar above problems exist in current codebase, maybe we could create
some issues as good first issue.
Yes, please create some new issues.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]