Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

import static org.apache.hadoop.ozone.container.common.utils.StorageVolumeUtil.onFailure;

/**
* This class is used to get the DataChannel for streaming.
*/
Expand Down Expand Up @@ -158,7 +160,12 @@ ContainerProtos.Type getType() {
public int write(ReferenceCountedObject<ByteBuffer> referenceCounted)
throws IOException {
assertOpen();
return writeBuffers(referenceCounted, buffers, super::writeFileChannel);
try {
return writeBuffers(referenceCounted, buffers, super::writeFileChannel);
} catch (IOException e) {
volumeOnFailure();
throw e;
}
}

static int writeBuffers(ReferenceCountedObject<ByteBuffer> src,
Expand Down Expand Up @@ -198,8 +205,13 @@ void assertOpen() throws IOException {
@Override
public void close() throws IOException {
if (closed.compareAndSet(false, true)) {
putBlockRequest.set(closeBuffers(buffers, super::writeFileChannel));
super.close();
try {
putBlockRequest.set(closeBuffers(buffers, super::writeFileChannel));
super.close();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should super.close() be out of the try-catch?

} catch (IOException e) {
volumeOnFailure();
throw e;
}
}
}

Expand Down Expand Up @@ -274,4 +286,8 @@ private static ContainerCommandRequestProto readPutBlockRequest(ByteBuffer b)
}
return request;
}

private void volumeOnFailure() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't think it is ideal to create function for one liner.

onFailure(getContainerData().getVolume());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guohao-rosicky , thanks for working on this!

Let's move this method up and rename it to checkVolume.

+++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/impl/StreamDataChannelBase.java
@@ -22,6 +22,7 @@
 import org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException;
 import org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics;
 import org.apache.hadoop.ozone.container.common.impl.ContainerData;
+import org.apache.hadoop.ozone.container.common.utils.StorageVolumeUtil;
 import org.apache.ratis.statemachine.StateMachine;
 
 import java.io.File;
@@ -64,6 +65,10 @@ private FileChannel getChannel() {
     return randomAccessFile.getChannel();
   }
 
+  void checkVolume() {
+    StorageVolumeUtil.onFailure(containerData.getVolume());
+  }
+
   @Override
   public final void force(boolean metadata) throws IOException {
     getChannel().force(metadata);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ private FileChannel getChannel() {
return randomAccessFile.getChannel();
}

public ContainerData getContainerData() {
return containerData;
}

@Override
public final void force(boolean metadata) throws IOException {
getChannel().force(metadata);
Expand Down