xianjingfeng commented on code in PR #424:
URL: https://github.com/apache/incubator-uniffle/pull/424#discussion_r1049352676
##########
server/src/main/java/org/apache/uniffle/server/storage/LocalStorageManager.java:
##########
@@ -139,32 +140,55 @@ public class LocalStorageManager extends
SingleStorageManager {
@Override
public Storage selectStorage(ShuffleDataFlushEvent event) {
- LocalStorage storage =
localStorages.get(ShuffleStorageUtils.getStorageIndex(
- localStorages.size(),
- event.getAppId(),
- event.getShuffleId(),
- event.getStartPartition()));
- if (storage.containsWriteHandler(event.getAppId(), event.getShuffleId(),
event.getStartPartition())
- && storage.isCorrupted()) {
- LOG.error("storage " + storage.getBasePath() + " is corrupted");
- }
- if (storage.isCorrupted()) {
- storage = getRepairedStorage(event.getAppId(), event.getShuffleId(),
event.getStartPartition());
+ String appId = event.getAppId();
+ int shuffleId = event.getShuffleId();
+ int partitionId = event.getStartPartition();
+
+ try {
+ LocalStorage storage =
partitionsOfStorage.get(appId).get(shuffleId).get(partitionId);
+ if (storage.isCorrupted()) {
+ throw new RuntimeException("LocalStorage: " + storage.getBasePath() +
" is corrupted.");
+ }
+ return storage;
+ } catch (NullPointerException npe) {
+ // Ignore
}
+
+ // Firstly getting the storage based on its (appId, shuffleId,
partitionId) hash value
+ LocalStorage storage =
+ localStorages
+ .stream()
+ .filter(x -> x.canWrite() && !x.isCorrupted())
+ .collect(Collectors.toList())
+ .get(
+ ShuffleStorageUtils.getStorageIndex(
+ localStorages.size(),
+ appId,
+ shuffleId,
+ partitionId
+ )
+ );
event.setUnderStorage(storage);
+
+ // store it to cache.
+ partitionsOfStorage.putIfAbsent(appId, Maps.newConcurrentMap());
+ partitionsOfStorage.get(appId).putIfAbsent(shuffleId,
Maps.newConcurrentMap());
+ partitionsOfStorage.get(appId).get(shuffleId).put(partitionId, storage);
return storage;
}
@Override
public Storage selectStorage(ShuffleDataReadEvent event) {
+ String appId = event.getAppId();
+ int shuffleId = event.getShuffleId();
+ int partitionId = event.getStartPartition();
- LocalStorage storage =
localStorages.get(ShuffleStorageUtils.getStorageIndex(
- localStorages.size(),
- event.getAppId(),
- event.getShuffleId(),
- event.getStartPartition()));
- if (storage.isCorrupted()) {
- storage = getRepairedStorage(event.getAppId(), event.getShuffleId(),
event.getStartPartition());
+ LocalStorage storage = null;
+ try {
+ storage = partitionsOfStorage.get(appId).get(shuffleId).get(partitionId);
+ } catch (NullPointerException npe) {
Review Comment:
I have no other good ideas. WDYT. @jerqi I think when it relate to reading
and writing, we should give priority to performance.
--
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]