aboutsummaryrefslogtreecommitdiff
path: root/other/java
diff options
context:
space:
mode:
authorhilimd <68371223+hilimd@users.noreply.github.com>2020-07-30 09:46:44 +0800
committerGitHub <noreply@github.com>2020-07-30 09:46:44 +0800
commit4a88cca543cb487e04c13703d263c3f19f4c1e92 (patch)
treee0b7f3b3e5728fe0d11503e4580987a026d161d9 /other/java
parent92c32f9d46c6cf817ca447b20c4919dfd7978624 (diff)
parent5080bc1d6964cc71044333edc7ee36c1c1f06adb (diff)
downloadseaweedfs-4a88cca543cb487e04c13703d263c3f19f4c1e92.tar.xz
seaweedfs-4a88cca543cb487e04c13703d263c3f19f4c1e92.zip
Merge pull request #6 from chrislusf/master
sync
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
-rw-r--r--other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java7
-rw-r--r--other/java/client/src/main/java/seaweedfs/client/SeaweedWrite.java3
4 files changed, 17 insertions, 13 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..28c2f47fc 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.debug("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;
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 f0490540d..05457ed48 100644
--- a/other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java
+++ b/other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java
@@ -15,7 +15,7 @@ public class SeaweedRead {
private static final Logger LOG = LoggerFactory.getLogger(SeaweedRead.class);
- static ChunkCache chunkCache = new ChunkCache(0);
+ static ChunkCache chunkCache = new ChunkCache(4);
// returns bytesRead
public static long read(FilerGrpcClient filerGrpcClient, List<VisibleInterval> visibleIntervals,
@@ -62,6 +62,7 @@ public class SeaweedRead {
if (chunkData == null) {
chunkData = doFetchFullChunkData(chunkView, locations);
+ chunkCache.setChunk(chunkView.fileId, chunkData);
}
int len = (int) chunkView.size;
@@ -69,8 +70,6 @@ public class SeaweedRead {
chunkView.fileId, chunkData.length, chunkView.offset, buffer.length, startOffset, len);
System.arraycopy(chunkData, (int) chunkView.offset, buffer, startOffset, len);
- chunkCache.setChunk(chunkView.fileId, chunkData);
-
return len;
}
@@ -109,6 +108,8 @@ public class SeaweedRead {
}
}
+ LOG.debug("doFetchFullChunkData fid:{} chunkData.length:{}", chunkView.fileId, data.length);
+
return data;
}
diff --git a/other/java/client/src/main/java/seaweedfs/client/SeaweedWrite.java b/other/java/client/src/main/java/seaweedfs/client/SeaweedWrite.java
index 5f4d888bd..d3cecab75 100644
--- a/other/java/client/src/main/java/seaweedfs/client/SeaweedWrite.java
+++ b/other/java/client/src/main/java/seaweedfs/client/SeaweedWrite.java
@@ -61,9 +61,6 @@ public class SeaweedWrite {
String etag = multipartUpload(targetUrl, auth, bytes, bytesOffset, bytesLength, cipherKey);
- // cache fileId ~ bytes
- SeaweedRead.chunkCache.setChunk(fileId, bytes);
-
LOG.debug("write file chunk {} size {}", targetUrl, bytesLength);
return FilerProto.FileChunk.newBuilder()