aboutsummaryrefslogtreecommitdiff
path: root/other/java
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-07-29 18:25:52 -0700
committerChris Lu <chris.lu@gmail.com>2020-07-29 18:25:52 -0700
commitdaf8c0c8ce4c507264a175912d4693415f40f606 (patch)
treeb1139b96d2502ae0c538fc95a749503085a41a40 /other/java
parentb684c312d232f4b8ffa3bb276033fd69c469d354 (diff)
downloadseaweedfs-daf8c0c8ce4c507264a175912d4693415f40f606.tar.xz
seaweedfs-daf8c0c8ce4c507264a175912d4693415f40f606.zip
cache vid locations
Diffstat (limited to 'other/java')
-rw-r--r--other/java/client/src/main/java/seaweedfs/client/FileChunkManifest.java17
-rw-r--r--other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java3
2 files changed, 13 insertions, 7 deletions
diff --git a/other/java/client/src/main/java/seaweedfs/client/FileChunkManifest.java b/other/java/client/src/main/java/seaweedfs/client/FileChunkManifest.java
index d8d29ede8..a15671f46 100644
--- a/other/java/client/src/main/java/seaweedfs/client/FileChunkManifest.java
+++ b/other/java/client/src/main/java/seaweedfs/client/FileChunkManifest.java
@@ -6,7 +6,6 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
public class FileChunkManifest {
@@ -51,13 +50,17 @@ public class FileChunkManifest {
private static byte[] fetchChunk(final FilerGrpcClient filerGrpcClient, FilerProto.FileChunk chunk) throws IOException {
- FilerProto.LookupVolumeRequest.Builder lookupRequest = FilerProto.LookupVolumeRequest.newBuilder();
String vid = "" + chunk.getFid().getVolumeId();
- lookupRequest.addVolumeIds(vid);
- FilerProto.LookupVolumeResponse lookupResponse = filerGrpcClient
- .getBlockingStub().lookupVolume(lookupRequest.build());
- Map<String, FilerProto.Locations> vid2Locations = lookupResponse.getLocationsMapMap();
- FilerProto.Locations locations = vid2Locations.get(vid);
+ FilerProto.Locations locations = filerGrpcClient.vidLocations.get(vid);
+ if (locations == null) {
+ FilerProto.LookupVolumeRequest.Builder lookupRequest = FilerProto.LookupVolumeRequest.newBuilder();
+ lookupRequest.addVolumeIds(vid);
+ FilerProto.LookupVolumeResponse lookupResponse = filerGrpcClient
+ .getBlockingStub().lookupVolume(lookupRequest.build());
+ locations = lookupResponse.getLocationsMapMap().get(vid);
+ filerGrpcClient.vidLocations.put(vid, locations);
+ LOG.warn("fetchChunk vid:{} locations:{}", vid, locations);
+ }
SeaweedRead.ChunkView chunkView = new SeaweedRead.ChunkView(
FilerClient.toFileId(chunk.getFid()), // avoid deprecated chunk.getFileId()
diff --git a/other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java b/other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java
index 57b67f6b0..1a719f3c0 100644
--- a/other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java
+++ b/other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java
@@ -9,6 +9,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLException;
+import java.util.Map;
+import java.util.HashMap;
import java.util.concurrent.TimeUnit;
public class FilerGrpcClient {
@@ -24,6 +26,7 @@ public class FilerGrpcClient {
}
}
+ public final Map<String, FilerProto.Locations> vidLocations = new HashMap<>();
private final ManagedChannel channel;
private final SeaweedFilerGrpc.SeaweedFilerBlockingStub blockingStub;
private final SeaweedFilerGrpc.SeaweedFilerStub asyncStub;