sodonnel commented on a change in pull request #2709:
URL: https://github.com/apache/ozone/pull/2709#discussion_r722167460
##########
File path:
hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/BlockOutputStreamEntry.java
##########
@@ -76,74 +83,94 @@ private BlockOutputStreamEntry(
this.bufferPool = bufferPool;
}
- long getLength() {
- return length;
- }
-
- Token<OzoneBlockTokenIdentifier> getToken() {
- return token;
- }
-
- long getRemaining() {
- return length - currentPosition;
- }
-
/**
* BlockOutputStream is initialized in this function. This makes sure that
* xceiverClient initialization is not done during preallocation and only
* done when data is written.
* @throws IOException if xceiverClient initialization fails
*/
- private void checkStream() throws IOException {
- if (this.outputStream == null) {
- this.outputStream =
- new RatisBlockOutputStream(blockID, xceiverClientManager,
- pipeline, bufferPool, config, token);
+ void checkStream() throws IOException {
+ if (!isInitialized()) {
+ createOutputStream();
}
}
+ /**
+ * Creates the outputStreams that are necessary to start the write.
+ * Implementors can override this to instantiate multiple streams instead.
+ * @throws IOException
+ */
+ void createOutputStream() throws IOException {
+ outputStream = new RatisBlockOutputStream(blockID, xceiverClientManager,
+ pipeline, bufferPool, config, token);
+ }
@Override
public void write(int b) throws IOException {
checkStream();
- outputStream.write(b);
- this.currentPosition += 1;
+ getOutputStream().write(b);
+ incCurrentPosition();
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
checkStream();
- outputStream.write(b, off, len);
- this.currentPosition += len;
+ getOutputStream().write(b, off, len);
+ incCurrentPosition(len);
+ }
+
+ void writeOnRetry(long len) throws IOException {
+ checkStream();
+ BlockOutputStream out = (BlockOutputStream) getOutputStream();
+ out.writeOnRetry(len);
+ incCurrentPosition(len);
}
@Override
public void flush() throws IOException {
- if (this.outputStream != null) {
- this.outputStream.flush();
+ if (isInitialized()) {
+ getOutputStream().flush();
}
}
@Override
public void close() throws IOException {
- if (this.outputStream != null) {
- this.outputStream.close();
+ if (isInitialized()) {
+ getOutputStream().close();
// after closing the chunkOutPutStream, blockId would have been
// reconstructed with updated bcsId
- this.blockID = ((BlockOutputStream) outputStream).getBlockID();
+ this.blockID = ((BlockOutputStream) getOutputStream()).getBlockID();
}
}
boolean isClosed() {
- if (outputStream != null) {
- return ((BlockOutputStream) outputStream).isClosed();
+ if (isInitialized()) {
+ return ((BlockOutputStream) getOutputStream()).isClosed();
}
return false;
}
+ void cleanup(boolean invalidateClient) throws IOException {
+ checkStream();
+ BlockOutputStream out = (BlockOutputStream) getOutputStream();
+ out.cleanup(invalidateClient);
+
Review comment:
nit: extra line here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]