Skip to content

Commit

Permalink
change file length() and add some info
Browse files Browse the repository at this point in the history
Signed-off-by: zombee0 <flylucas_10@163.com>
  • Loading branch information
zombee0 committed Mar 7, 2023
1 parent f7156ed commit f9e4e7b
Showing 1 changed file with 16 additions and 3 deletions.
Expand Up @@ -478,16 +478,23 @@ public int read(ByteBuffer buf) throws IOException {
private static class CachingInputFile implements InputFile {
private final ContentCache contentCache;
private final InputFile wrappedInputFile;
private int getFrom;
private long length;
private long cachedEntryLength;
private int cachedEntrySize;

private CachingInputFile(ContentCache cache, InputFile inFile) {
this.contentCache = cache;
this.wrappedInputFile = inFile;
getFrom = 0;
length = 0;
}

@Override
public long getLength() {
return contentCache.getLength(location()) == -1 ?
wrappedInputFile.getLength() : contentCache.getLength(location());
long len = contentCache.getLength(location());
length = len == -1 ? wrappedInputFile.getLength() : len;
return length;
}

@Override
Expand Down Expand Up @@ -526,11 +533,14 @@ private CacheEntry newCacheEntry() {
if (contentCache.isExistOnDiskCache(location())) {
LOG.debug(location() + " hit on disk cache");
stream = contentCache.getDiskSeekableStream(location());
getFrom = 1;
if (stream == null) {
getFrom = 2;
LOG.debug(location() + " load from remote");
stream = wrappedInputFile.newStream();
}
} else {
getFrom = 2;
LOG.debug(location() + " load from remote");
stream = wrappedInputFile.newStream();
}
Expand Down Expand Up @@ -563,6 +573,8 @@ private CacheEntry newCacheEntry() {
private SeekableInputStream cachedStream() throws IOException {
try {
CacheEntry entry = contentCache.get(location(), k -> newCacheEntry());
cachedEntryLength = entry.length;
cachedEntrySize = entry.buffers.size();
Preconditions.checkNotNull(entry, "CacheEntry should not be null when there is no RuntimeException occurs");
return ByteBufferInputStream.wrap(entry.buffers);
} catch (UncheckedIOException ex) {
Expand All @@ -574,7 +586,8 @@ private SeekableInputStream cachedStream() throws IOException {

@Override
public String toString() {
return location();
return location() + ", get From: " + getFrom + ", length: " + length + ", CacheEntryLength: " + cachedEntryLength +
", CacheEntrySize: " + cachedEntrySize;
}
}
}

0 comments on commit f9e4e7b

Please sign in to comment.