|
@ -6,6 +6,7 @@ import org.apache.http.HttpResponse; |
|
|
import org.apache.http.client.HttpClient; |
|
|
import org.apache.http.client.HttpClient; |
|
|
import org.apache.http.client.methods.HttpGet; |
|
|
import org.apache.http.client.methods.HttpGet; |
|
|
import org.apache.http.impl.client.DefaultHttpClient; |
|
|
import org.apache.http.impl.client.DefaultHttpClient; |
|
|
|
|
|
import org.apache.http.impl.client.HttpClientBuilder; |
|
|
import org.apache.http.util.EntityUtils; |
|
|
import org.apache.http.util.EntityUtils; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
@ -78,7 +79,7 @@ public class SeaweedRead { |
|
|
|
|
|
|
|
|
private static byte[] doFetchFullChunkData(ChunkView chunkView, FilerProto.Locations locations) throws IOException { |
|
|
private static byte[] doFetchFullChunkData(ChunkView chunkView, FilerProto.Locations locations) throws IOException { |
|
|
|
|
|
|
|
|
HttpClient client = new DefaultHttpClient(); |
|
|
|
|
|
|
|
|
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)); |
|
|
|
|
|
|
|
@ -99,7 +100,7 @@ public class SeaweedRead { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (chunkView.isGzipped) { |
|
|
|
|
|
|
|
|
if (chunkView.isCompressed) { |
|
|
data = Gzip.decompress(data); |
|
|
data = Gzip.decompress(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -129,7 +130,7 @@ public class SeaweedRead { |
|
|
offset, |
|
|
offset, |
|
|
isFullChunk, |
|
|
isFullChunk, |
|
|
chunk.cipherKey, |
|
|
chunk.cipherKey, |
|
|
chunk.isGzipped |
|
|
|
|
|
|
|
|
chunk.isCompressed |
|
|
)); |
|
|
)); |
|
|
offset = Math.min(chunk.stop, stop); |
|
|
offset = Math.min(chunk.stop, stop); |
|
|
} |
|
|
} |
|
@ -165,7 +166,7 @@ public class SeaweedRead { |
|
|
chunk.getMtime(), |
|
|
chunk.getMtime(), |
|
|
true, |
|
|
true, |
|
|
chunk.getCipherKey().toByteArray(), |
|
|
chunk.getCipherKey().toByteArray(), |
|
|
chunk.getIsGzipped() |
|
|
|
|
|
|
|
|
chunk.getIsCompressed() |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
// easy cases to speed up |
|
|
// easy cases to speed up |
|
@ -187,7 +188,7 @@ public class SeaweedRead { |
|
|
v.modifiedTime, |
|
|
v.modifiedTime, |
|
|
false, |
|
|
false, |
|
|
v.cipherKey, |
|
|
v.cipherKey, |
|
|
v.isGzipped |
|
|
|
|
|
|
|
|
v.isCompressed |
|
|
)); |
|
|
)); |
|
|
} |
|
|
} |
|
|
long chunkStop = chunk.getOffset() + chunk.getSize(); |
|
|
long chunkStop = chunk.getOffset() + chunk.getSize(); |
|
@ -199,7 +200,7 @@ public class SeaweedRead { |
|
|
v.modifiedTime, |
|
|
v.modifiedTime, |
|
|
false, |
|
|
false, |
|
|
v.cipherKey, |
|
|
v.cipherKey, |
|
|
v.isGzipped |
|
|
|
|
|
|
|
|
v.isCompressed |
|
|
)); |
|
|
)); |
|
|
} |
|
|
} |
|
|
if (chunkStop <= v.start || v.stop <= chunk.getOffset()) { |
|
|
if (chunkStop <= v.start || v.stop <= chunk.getOffset()) { |
|
@ -247,16 +248,16 @@ public class SeaweedRead { |
|
|
public final String fileId; |
|
|
public final String fileId; |
|
|
public final boolean isFullChunk; |
|
|
public final boolean isFullChunk; |
|
|
public final byte[] cipherKey; |
|
|
public final byte[] cipherKey; |
|
|
public final boolean isGzipped; |
|
|
|
|
|
|
|
|
public final boolean isCompressed; |
|
|
|
|
|
|
|
|
public VisibleInterval(long start, long stop, String fileId, long modifiedTime, boolean isFullChunk, byte[] cipherKey, boolean isGzipped) { |
|
|
|
|
|
|
|
|
public VisibleInterval(long start, long stop, String fileId, long modifiedTime, boolean isFullChunk, byte[] cipherKey, boolean isCompressed) { |
|
|
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; |
|
|
this.isFullChunk = isFullChunk; |
|
|
this.cipherKey = cipherKey; |
|
|
this.cipherKey = cipherKey; |
|
|
this.isGzipped = isGzipped; |
|
|
|
|
|
|
|
|
this.isCompressed = isCompressed; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -268,7 +269,7 @@ public class SeaweedRead { |
|
|
", fileId='" + fileId + '\'' + |
|
|
", fileId='" + fileId + '\'' + |
|
|
", isFullChunk=" + isFullChunk + |
|
|
", isFullChunk=" + isFullChunk + |
|
|
", cipherKey=" + Arrays.toString(cipherKey) + |
|
|
", cipherKey=" + Arrays.toString(cipherKey) + |
|
|
", isGzipped=" + isGzipped + |
|
|
|
|
|
|
|
|
", isCompressed=" + isCompressed + |
|
|
'}'; |
|
|
'}'; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -280,16 +281,16 @@ public class SeaweedRead { |
|
|
public final long logicOffset; |
|
|
public final long logicOffset; |
|
|
public final boolean isFullChunk; |
|
|
public final boolean isFullChunk; |
|
|
public final byte[] cipherKey; |
|
|
public final byte[] cipherKey; |
|
|
public final boolean isGzipped; |
|
|
|
|
|
|
|
|
public final boolean isCompressed; |
|
|
|
|
|
|
|
|
public ChunkView(String fileId, long offset, long size, long logicOffset, boolean isFullChunk, byte[] cipherKey, boolean isGzipped) { |
|
|
|
|
|
|
|
|
public ChunkView(String fileId, long offset, long size, long logicOffset, boolean isFullChunk, byte[] cipherKey, boolean isCompressed) { |
|
|
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; |
|
|
this.isFullChunk = isFullChunk; |
|
|
this.cipherKey = cipherKey; |
|
|
this.cipherKey = cipherKey; |
|
|
this.isGzipped = isGzipped; |
|
|
|
|
|
|
|
|
this.isCompressed = isCompressed; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -301,7 +302,7 @@ public class SeaweedRead { |
|
|
", logicOffset=" + logicOffset + |
|
|
", logicOffset=" + logicOffset + |
|
|
", isFullChunk=" + isFullChunk + |
|
|
", isFullChunk=" + isFullChunk + |
|
|
", cipherKey=" + Arrays.toString(cipherKey) + |
|
|
", cipherKey=" + Arrays.toString(cipherKey) + |
|
|
", isGzipped=" + isGzipped + |
|
|
|
|
|
|
|
|
", isCompressed=" + isCompressed + |
|
|
'}'; |
|
|
'}'; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|