mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
cache vid locations
This commit is contained in:
parent
b684c312d2
commit
daf8c0c8ce
|
@ -6,7 +6,6 @@ import org.slf4j.LoggerFactory;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class FileChunkManifest {
|
public class FileChunkManifest {
|
||||||
|
|
||||||
|
@ -51,13 +50,17 @@ public class FileChunkManifest {
|
||||||
|
|
||||||
private static byte[] fetchChunk(final FilerGrpcClient filerGrpcClient, FilerProto.FileChunk chunk) throws IOException {
|
private static byte[] fetchChunk(final FilerGrpcClient filerGrpcClient, FilerProto.FileChunk chunk) throws IOException {
|
||||||
|
|
||||||
FilerProto.LookupVolumeRequest.Builder lookupRequest = FilerProto.LookupVolumeRequest.newBuilder();
|
|
||||||
String vid = "" + chunk.getFid().getVolumeId();
|
String vid = "" + chunk.getFid().getVolumeId();
|
||||||
lookupRequest.addVolumeIds(vid);
|
FilerProto.Locations locations = filerGrpcClient.vidLocations.get(vid);
|
||||||
FilerProto.LookupVolumeResponse lookupResponse = filerGrpcClient
|
if (locations == null) {
|
||||||
.getBlockingStub().lookupVolume(lookupRequest.build());
|
FilerProto.LookupVolumeRequest.Builder lookupRequest = FilerProto.LookupVolumeRequest.newBuilder();
|
||||||
Map<String, FilerProto.Locations> vid2Locations = lookupResponse.getLocationsMapMap();
|
lookupRequest.addVolumeIds(vid);
|
||||||
FilerProto.Locations locations = vid2Locations.get(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(
|
SeaweedRead.ChunkView chunkView = new SeaweedRead.ChunkView(
|
||||||
FilerClient.toFileId(chunk.getFid()), // avoid deprecated chunk.getFileId()
|
FilerClient.toFileId(chunk.getFid()), // avoid deprecated chunk.getFileId()
|
||||||
|
|
|
@ -9,6 +9,8 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.net.ssl.SSLException;
|
import javax.net.ssl.SSLException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class FilerGrpcClient {
|
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 ManagedChannel channel;
|
||||||
private final SeaweedFilerGrpc.SeaweedFilerBlockingStub blockingStub;
|
private final SeaweedFilerGrpc.SeaweedFilerBlockingStub blockingStub;
|
||||||
private final SeaweedFilerGrpc.SeaweedFilerStub asyncStub;
|
private final SeaweedFilerGrpc.SeaweedFilerStub asyncStub;
|
||||||
|
|
Loading…
Reference in a new issue