|
@ -56,9 +56,12 @@ public class SeaweedRead { |
|
|
HttpClient client = HttpClientBuilder.create().build(); |
|
|
HttpClient client = HttpClientBuilder.create().build(); |
|
|
HttpGet request = new HttpGet( |
|
|
HttpGet request = new HttpGet( |
|
|
String.format("http://%s/%s", locations.getLocations(0).getUrl(), chunkView.fileId)); |
|
|
String.format("http://%s/%s", locations.getLocations(0).getUrl(), chunkView.fileId)); |
|
|
request.setHeader(HttpHeaders.ACCEPT_ENCODING, ""); |
|
|
|
|
|
request.setHeader(HttpHeaders.RANGE, |
|
|
|
|
|
String.format("bytes=%d-%d", chunkView.offset, chunkView.offset + chunkView.size)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!chunkView.isFullChunk){ |
|
|
|
|
|
request.setHeader(HttpHeaders.ACCEPT_ENCODING, ""); |
|
|
|
|
|
request.setHeader(HttpHeaders.RANGE, |
|
|
|
|
|
String.format("bytes=%d-%d", chunkView.offset, chunkView.offset + chunkView.size)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
HttpResponse response = client.execute(request); |
|
|
HttpResponse response = client.execute(request); |
|
@ -86,11 +89,13 @@ public class SeaweedRead { |
|
|
long stop = offset + size; |
|
|
long stop = offset + size; |
|
|
for (VisibleInterval chunk : visibleIntervals) { |
|
|
for (VisibleInterval chunk : visibleIntervals) { |
|
|
if (chunk.start <= offset && offset < chunk.stop && offset < stop) { |
|
|
if (chunk.start <= offset && offset < chunk.stop && offset < stop) { |
|
|
|
|
|
boolean isFullChunk = chunk.isFullChunk && chunk.start == offset && chunk.stop <= stop; |
|
|
views.add(new ChunkView( |
|
|
views.add(new ChunkView( |
|
|
chunk.fileId, |
|
|
chunk.fileId, |
|
|
offset - chunk.start, |
|
|
offset - chunk.start, |
|
|
Math.min(chunk.stop, stop) - offset, |
|
|
Math.min(chunk.stop, stop) - offset, |
|
|
offset |
|
|
|
|
|
|
|
|
offset, |
|
|
|
|
|
isFullChunk |
|
|
)); |
|
|
)); |
|
|
offset = Math.min(chunk.stop, stop); |
|
|
offset = Math.min(chunk.stop, stop); |
|
|
} |
|
|
} |
|
@ -123,7 +128,8 @@ public class SeaweedRead { |
|
|
chunk.getOffset(), |
|
|
chunk.getOffset(), |
|
|
chunk.getOffset() + chunk.getSize(), |
|
|
chunk.getOffset() + chunk.getSize(), |
|
|
chunk.getFileId(), |
|
|
chunk.getFileId(), |
|
|
chunk.getMtime() |
|
|
|
|
|
|
|
|
chunk.getMtime(), |
|
|
|
|
|
true |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
// easy cases to speed up |
|
|
// easy cases to speed up |
|
@ -142,7 +148,8 @@ public class SeaweedRead { |
|
|
v.start, |
|
|
v.start, |
|
|
chunk.getOffset(), |
|
|
chunk.getOffset(), |
|
|
v.fileId, |
|
|
v.fileId, |
|
|
v.modifiedTime |
|
|
|
|
|
|
|
|
v.modifiedTime, |
|
|
|
|
|
false |
|
|
)); |
|
|
)); |
|
|
} |
|
|
} |
|
|
long chunkStop = chunk.getOffset() + chunk.getSize(); |
|
|
long chunkStop = chunk.getOffset() + chunk.getSize(); |
|
@ -151,7 +158,8 @@ public class SeaweedRead { |
|
|
chunkStop, |
|
|
chunkStop, |
|
|
v.stop, |
|
|
v.stop, |
|
|
v.fileId, |
|
|
v.fileId, |
|
|
v.modifiedTime |
|
|
|
|
|
|
|
|
v.modifiedTime, |
|
|
|
|
|
false |
|
|
)); |
|
|
)); |
|
|
} |
|
|
} |
|
|
if (chunkStop <= v.start || v.stop <= chunk.getOffset()) { |
|
|
if (chunkStop <= v.start || v.stop <= chunk.getOffset()) { |
|
@ -197,21 +205,24 @@ public class SeaweedRead { |
|
|
public final long stop; |
|
|
public final long stop; |
|
|
public final long modifiedTime; |
|
|
public final long modifiedTime; |
|
|
public final String fileId; |
|
|
public final String fileId; |
|
|
|
|
|
public final boolean isFullChunk; |
|
|
|
|
|
|
|
|
public VisibleInterval(long start, long stop, String fileId, long modifiedTime) { |
|
|
|
|
|
|
|
|
public VisibleInterval(long start, long stop, String fileId, long modifiedTime, boolean isFullChunk) { |
|
|
this.start = start; |
|
|
this.start = start; |
|
|
this.stop = stop; |
|
|
this.stop = stop; |
|
|
this.modifiedTime = modifiedTime; |
|
|
this.modifiedTime = modifiedTime; |
|
|
this.fileId = fileId; |
|
|
this.fileId = fileId; |
|
|
|
|
|
this.isFullChunk = isFullChunk; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public String toString() { |
|
|
public String toString() { |
|
|
return "VisibleIntervalq{" + |
|
|
|
|
|
|
|
|
return "VisibleInterval{" + |
|
|
"start=" + start + |
|
|
"start=" + start + |
|
|
", stop=" + stop + |
|
|
", stop=" + stop + |
|
|
", modifiedTime=" + modifiedTime + |
|
|
", modifiedTime=" + modifiedTime + |
|
|
", fileId='" + fileId + '\'' + |
|
|
", fileId='" + fileId + '\'' + |
|
|
|
|
|
", isFullChunk=" + isFullChunk + |
|
|
'}'; |
|
|
'}'; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -221,12 +232,14 @@ public class SeaweedRead { |
|
|
public final long offset; |
|
|
public final long offset; |
|
|
public final long size; |
|
|
public final long size; |
|
|
public final long logicOffset; |
|
|
public final long logicOffset; |
|
|
|
|
|
public final boolean isFullChunk; |
|
|
|
|
|
|
|
|
public ChunkView(String fileId, long offset, long size, long logicOffset) { |
|
|
|
|
|
|
|
|
public ChunkView(String fileId, long offset, long size, long logicOffset, boolean isFullChunk) { |
|
|
this.fileId = fileId; |
|
|
this.fileId = fileId; |
|
|
this.offset = offset; |
|
|
this.offset = offset; |
|
|
this.size = size; |
|
|
this.size = size; |
|
|
this.logicOffset = logicOffset; |
|
|
this.logicOffset = logicOffset; |
|
|
|
|
|
this.isFullChunk = isFullChunk; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -236,6 +249,7 @@ public class SeaweedRead { |
|
|
", offset=" + offset + |
|
|
", offset=" + offset + |
|
|
", size=" + size + |
|
|
", size=" + size + |
|
|
", logicOffset=" + logicOffset + |
|
|
", logicOffset=" + logicOffset + |
|
|
|
|
|
", isFullChunk=" + isFullChunk + |
|
|
'}'; |
|
|
'}'; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|