-
Notifications
You must be signed in to change notification settings - Fork 8.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HADOOP-19348. Integrate analytics accelerator into S3A. #7334
base: trunk
Are you sure you want to change the base?
Changes from 3 commits
9c8e753
eadf0dd
63daf56
d45beae
dc2dc63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,8 +91,7 @@ | |
import org.apache.hadoop.util.functional.Tuples; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static org.apache.hadoop.fs.s3a.Constants.BUFFER_DIR; | ||
import static org.apache.hadoop.fs.s3a.Constants.HADOOP_TMP_DIR; | ||
import static org.apache.hadoop.fs.s3a.Constants.*; | ||
import static org.apache.hadoop.fs.s3a.S3AUtils.extractException; | ||
import static org.apache.hadoop.fs.s3a.S3AUtils.getPutRequestLength; | ||
import static org.apache.hadoop.fs.s3a.S3AUtils.isThrottleException; | ||
|
@@ -948,7 +947,7 @@ | |
* All stream factory initialization required after {@code Service.init()}, | ||
* after all other services have themselves been initialized. | ||
*/ | ||
private void finishStreamFactoryInit() { | ||
private void finishStreamFactoryInit() throws Exception { | ||
// must be on be invoked during service initialization | ||
Preconditions.checkState(isInState(STATE.INITED), | ||
"Store is in wrong state: %s", getServiceState()); | ||
|
@@ -974,7 +973,7 @@ | |
/** | ||
* This operation is not implemented, as | ||
* is this class which invokes it on the actual factory. | ||
* @param factoryBindingParameters@throws UnsupportedOperationException always | ||
Check failure on line 976 in hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/S3AStoreImpl.java
|
||
*/ | ||
@Override /* ObjectInputStreamFactory */ | ||
public void bind(final FactoryBindingParameters factoryBindingParameters) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.hadoop.fs.s3a.impl.streams; | ||
|
||
import java.io.EOFException; | ||
import java.io.IOException; | ||
|
||
import org.apache.hadoop.fs.FSExceptionMessages; | ||
import org.apache.hadoop.fs.StreamCapabilities; | ||
import org.apache.hadoop.fs.s3a.Retries; | ||
import org.apache.hadoop.fs.s3a.S3ObjectAttributes; | ||
import software.amazon.s3.analyticsaccelerator.S3SeekableInputStreamFactory; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import software.amazon.s3.analyticsaccelerator.S3SeekableInputStream; | ||
import software.amazon.s3.analyticsaccelerator.util.S3URI; | ||
|
||
public class AnalyticsStream extends ObjectInputStream implements StreamCapabilities { | ||
|
||
private S3SeekableInputStream inputStream; | ||
private long lastReadCurrentPos = 0; | ||
private volatile boolean closed; | ||
|
||
public static final Logger LOG = LoggerFactory.getLogger(AnalyticsStream.class); | ||
|
||
public AnalyticsStream(final ObjectReadParameters parameters, final S3SeekableInputStreamFactory s3SeekableInputStreamFactory) { | ||
super(InputStreamType.Analytics, parameters); | ||
S3ObjectAttributes s3Attributes = parameters.getObjectAttributes(); | ||
this.inputStream = s3SeekableInputStreamFactory.createStream(S3URI.of(s3Attributes.getBucket(), s3Attributes.getKey())); | ||
} | ||
|
||
/** | ||
* Indicates whether the given {@code capability} is supported by this stream. | ||
* | ||
* @param capability the capability to check. | ||
* @return true if the given {@code capability} is supported by this stream, false otherwise. | ||
*/ | ||
@Override | ||
public boolean hasCapability(String capability) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int read() throws IOException { | ||
throwIfClosed(); | ||
int bytesRead; | ||
try { | ||
bytesRead = inputStream.read(); | ||
} catch (IOException ioe) { | ||
onReadFailure(ioe); | ||
throw ioe; | ||
} | ||
return bytesRead; | ||
} | ||
|
||
@Override | ||
public void seek(long pos) throws IOException { | ||
throwIfClosed(); | ||
if (pos < 0) { | ||
throw new EOFException(FSExceptionMessages.NEGATIVE_SEEK | ||
+ " " + pos); | ||
} | ||
inputStream.seek(pos); | ||
} | ||
|
||
|
||
@Override | ||
public synchronized long getPos() { | ||
if (!closed) { | ||
lastReadCurrentPos = inputStream.getPos(); | ||
} | ||
return lastReadCurrentPos; | ||
} | ||
|
||
|
||
/** | ||
* Reads the last n bytes from the stream into a byte buffer. Blocks until end of stream is | ||
* reached. Leaves the position of the stream unaltered. | ||
* | ||
* @param buf buffer to read data into | ||
* @param off start position in buffer at which data is written | ||
* @param len the number of bytes to read; the n-th byte should be the last byte of the stream. | ||
* @return the total number of bytes read into the buffer | ||
* @throws IOException if an I/O error occurs | ||
*/ | ||
public int readTail(byte[] buf, int off, int len) throws IOException { | ||
throwIfClosed(); | ||
int bytesRead; | ||
try { | ||
bytesRead = inputStream.readTail(buf, off, len); | ||
} catch (IOException ioe) { | ||
onReadFailure(ioe); | ||
throw ioe; | ||
} | ||
return bytesRead; | ||
} | ||
|
||
@Override | ||
public int read(byte[] buf, int off, int len) throws IOException { | ||
throwIfClosed(); | ||
int bytesRead; | ||
try { | ||
bytesRead = inputStream.read(buf, off, len); | ||
} catch (IOException ioe) { | ||
onReadFailure(ioe); | ||
throw ioe; | ||
} | ||
return bytesRead; | ||
} | ||
|
||
|
||
@Override | ||
public boolean seekToNewSource(long l) throws IOException { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int available() throws IOException { | ||
throwIfClosed(); | ||
return super.available(); | ||
} | ||
|
||
@Override | ||
protected boolean isStreamOpen() { | ||
return !isClosed(); | ||
} | ||
|
||
protected boolean isClosed() { | ||
return inputStream == null; | ||
} | ||
|
||
@Override | ||
protected void abortInFinalizer() { | ||
try { | ||
close(); | ||
} catch (IOException ignored) { | ||
|
||
} | ||
} | ||
|
||
@Override | ||
public synchronized void close() throws IOException { | ||
if(!closed) { | ||
closed = true; | ||
try { | ||
inputStream.close(); | ||
inputStream = null; | ||
super.close(); | ||
} catch (IOException ioe) { | ||
LOG.debug("Failure closing stream {}: ", getKey()); | ||
throw ioe; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Close the stream on read failure. | ||
* No attempt to recover from failure | ||
* | ||
* @param ioe exception caught. | ||
*/ | ||
@Retries.OnceTranslated | ||
private void onReadFailure(IOException ioe) throws IOException { | ||
if (LOG.isDebugEnabled()) { | ||
LOG.debug("Got exception while trying to read from stream {}, " + | ||
"not trying to recover:", | ||
getKey(), ioe); | ||
} else { | ||
LOG.info("Got exception while trying to read from stream {}, " + | ||
"not trying to recover:", | ||
getKey(), ioe); | ||
} | ||
this.close(); | ||
} | ||
|
||
|
||
protected void throwIfClosed() throws IOException { | ||
if (closed) { | ||
throw new IOException(getKey() + ": " + FSExceptionMessages.STREAM_IS_CLOSED); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
java doc