Skip to content

Commit 01b4219

Browse files
committed
HADOOP-19105. factor out start/stop.
This preparing to pull this into a superclass so that all s3a streams get it. Change-Id: I2d67336ce5ef484ab0207e4b45aa224c869926fe
1 parent 13e168e commit 01b4219

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AInputStream.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ public synchronized void close() throws IOException {
717717
if (!closed) {
718718
closed = true;
719719
try {
720-
stopVectoredIOOperations.set(true);
720+
stopVectorOperations();
721721
// close or abort the stream; blocking
722722
closeStream("close() operation", false, true);
723723
// end the client+audit span.
@@ -993,9 +993,7 @@ public void readVectored(final List<? extends FileRange> ranges,
993993
final Consumer<ByteBuffer> release) throws IOException {
994994
LOG.debug("Starting vectored read on path {} for ranges {} ", pathStr, ranges);
995995
checkNotClosed();
996-
if (stopVectoredIOOperations.getAndSet(false)) {
997-
LOG.debug("Reinstating vectored read operation for path {} ", pathStr);
998-
}
996+
maybeStartVectorOperations();
999997
// fail fast on parameters which would otherwise only be checked
1000998
// in threads and/or in failures.
1001999
requireNonNull(allocate , "Null allocator");
@@ -1039,6 +1037,24 @@ public void readVectored(final List<? extends FileRange> ranges,
10391037
" on path {} for ranges {} ", pathStr, ranges);
10401038
}
10411039

1040+
/**
1041+
* Start/restart vector operations if not active.
1042+
* In particular, after an unbuffer(), this performs any
1043+
* initialization required.
1044+
*/
1045+
private void maybeStartVectorOperations() {
1046+
if (stopVectoredIOOperations.getAndSet(false)) {
1047+
LOG.debug("Reinstating vectored read operation for path {} ", pathStr);
1048+
}
1049+
}
1050+
1051+
/**
1052+
* Stop vector operations.
1053+
*/
1054+
private void stopVectorOperations() {
1055+
stopVectoredIOOperations.set(true);
1056+
}
1057+
10421058
/**
10431059
* Read the data from S3 for the bigger combined file range and update all the
10441060
* underlying ranges.
@@ -1558,7 +1574,7 @@ public static long validateReadahead(@Nullable Long readahead) {
15581574
@Override
15591575
public synchronized void unbuffer() {
15601576
try {
1561-
stopVectoredIOOperations.set(true);
1577+
stopVectorOperations();
15621578
closeStream("unbuffer()", false, false);
15631579
} finally {
15641580
streamStatistics.unbuffered();

0 commit comments

Comments
 (0)