Browse Source

Merge "Adds the lazy seek"

tags/6.0.0.0b2^0
Jenkins Gerrit Code Review 3 years ago
parent
commit
d95ffe7014
1 changed files with 22 additions and 0 deletions
  1. +22
    -0
      hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeInputStream.java

+ 22
- 0
hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeInputStream.java View File

@@ -89,6 +89,8 @@ class SwiftNativeInputStream extends FSInputStream {
*/
private long rangeOffset = 0;

private long nextReadPosition = 0;

public SwiftNativeInputStream(SwiftNativeFileSystemStore storeNative,
FileSystem.Statistics statistics, Path path, long bufferSize)
throws IOException {
@@ -138,6 +140,7 @@ class SwiftNativeInputStream extends FSInputStream {
verifyOpen();
int result = -1;
try {
seekStream();
result = httpStream.read();
} catch (IOException e) {
String msg = "IOException while reading " + path
@@ -297,6 +300,13 @@ class SwiftNativeInputStream extends FSInputStream {
*/
@Override
public synchronized void seek(long targetPos) throws IOException {
if (targetPos < 0) {
throw new IOException("Negative Seek offset not supported");
}
nextReadPosition = targetPos;
}

public synchronized void realSeek(long targetPos) throws IOException {
if (targetPos < 0) {
throw new IOException("Negative Seek offset not supported");
}
@@ -344,6 +354,18 @@ class SwiftNativeInputStream extends FSInputStream {
fillBuffer(targetPos);
}

/**
* Lazy seek.
* @throws IOException
*/
private void seekStream() throws IOException {
if (httpStream != null && nextReadPosition == pos) {
// already at specified position
return;
}
realSeek(nextReadPosition);
}

/**
* Fill the buffer from the target position
* If the target position == current position, the


Loading…
Cancel
Save