aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-11-15 21:26:04 -0800
committerChris Lu <chris.lu@gmail.com>2020-11-15 21:26:04 -0800
commit61d96fde011f81fb1addfd1a6599a4081c14b5e2 (patch)
tree1c4515f26d9e1ee994375991d7a93fb715ceb685
parentaf658ea97016c95c09938bed7d728ef06740a389 (diff)
downloadseaweedfs-61d96fde011f81fb1addfd1a6599a4081c14b5e2.tar.xz
seaweedfs-61d96fde011f81fb1addfd1a6599a4081c14b5e2.zip
protect against edge cases when locations expires
-rw-r--r--other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java14
1 files changed, 10 insertions, 4 deletions
diff --git a/other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java b/other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java
index a9ddd51db..2b530d2dd 100644
--- a/other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java
+++ b/other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java
@@ -28,20 +28,26 @@ public class SeaweedRead {
List<ChunkView> chunkViews = viewFromVisibles(visibleIntervals, position, bufferLength);
+ Map<String, FilerProto.Locations> knownLocations = new HashMap<>();
+
FilerProto.LookupVolumeRequest.Builder lookupRequest = FilerProto.LookupVolumeRequest.newBuilder();
for (ChunkView chunkView : chunkViews) {
String vid = parseVolumeId(chunkView.fileId);
- if (volumeIdCache.getLocations(vid)==null){
+ FilerProto.Locations locations = volumeIdCache.getLocations(vid);
+ if (locations == null) {
lookupRequest.addVolumeIds(vid);
+ } else {
+ knownLocations.put(vid, locations);
}
}
- if (lookupRequest.getVolumeIdsCount()>0){
+ if (lookupRequest.getVolumeIdsCount() > 0) {
FilerProto.LookupVolumeResponse lookupResponse = filerGrpcClient
.getBlockingStub().lookupVolume(lookupRequest.build());
Map<String, FilerProto.Locations> vid2Locations = lookupResponse.getLocationsMapMap();
- for (Map.Entry<String,FilerProto.Locations> entry : vid2Locations.entrySet()) {
+ for (Map.Entry<String, FilerProto.Locations> entry : vid2Locations.entrySet()) {
volumeIdCache.setLocations(entry.getKey(), entry.getValue());
+ knownLocations.put(entry.getKey(), entry.getValue());
}
}
@@ -57,7 +63,7 @@ public class SeaweedRead {
startOffset += gap;
}
- FilerProto.Locations locations = volumeIdCache.getLocations(parseVolumeId(chunkView.fileId));
+ FilerProto.Locations locations = knownLocations.get(parseVolumeId(chunkView.fileId));
if (locations == null || locations.getLocationsCount() == 0) {
LOG.error("failed to locate {}", chunkView.fileId);
// log here!