Skip to content

Commit

Permalink
HDDS-11322. [hsync] Block ECKeyOutputStream from calling hsync and hf…
Browse files Browse the repository at this point in the history
…lush (apache#7098)
  • Loading branch information
smengcl authored Aug 20, 2024
1 parent 2d3ba80 commit 41d7059
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.hadoop.fs.FSExceptionMessages;
import org.apache.hadoop.hdds.client.ECReplicationConfig;
import org.apache.hadoop.hdds.scm.OzoneClientConfig;
Expand Down Expand Up @@ -420,6 +421,16 @@ public void flush() {
LOG.debug("ECKeyOutputStream does not support flush.");
}

@Override
public void hflush() {
throw new NotImplementedException("ECKeyOutputStream does not support hflush.");
}

@Override
public void hsync() {
throw new NotImplementedException("ECKeyOutputStream does not support hsync.");
}

private void closeCurrentStreamEntry()
throws IOException {
final ECBlockOutputStreamEntryPool blockOutputStreamEntryPool = getBlockOutputStreamEntryPool();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.hadoop.ozone.client.rpc;

import org.apache.commons.lang3.NotImplementedException;
import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.client.DefaultReplicationConfig;
import org.apache.hadoop.hdds.client.ECReplicationConfig;
Expand Down Expand Up @@ -67,6 +68,7 @@
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;

/**
Expand Down Expand Up @@ -123,6 +125,8 @@ protected static void init(boolean zeroCopyEnabled) throws Exception {
conf.setBoolean(OzoneConfigKeys.OZONE_EC_GRPC_ZERO_COPY_ENABLED,
zeroCopyEnabled);
conf.setInt(ScmConfigKeys.OZONE_SCM_RATIS_PIPELINE_LIMIT, 10);
// "Enable" hsync to verify that hsync would be blocked by ECKeyOutputStream
conf.setBoolean(OzoneConfigKeys.OZONE_FS_HSYNC_ENABLED, true);

ClientConfigForTesting.newBuilder(StorageUnit.BYTES)
.setBlockSize(blockSize)
Expand Down Expand Up @@ -469,4 +473,18 @@ private byte[] getInputBytes(int offset, int bufferChunks, int numChunks) {
return inputData;
}

@Test
public void testBlockedHflushAndHsync() throws Exception {
// Expect ECKeyOutputStream hflush and hsync calls to throw exception
try (OzoneOutputStream oOut = TestHelper.createKey(
keyString, new ECReplicationConfig(3, 2, ECReplicationConfig.EcCodec.RS, chunkSize),
inputSize, objectStore, volumeName, bucketName)) {
assertInstanceOf(ECKeyOutputStream.class, oOut.getOutputStream());
KeyOutputStream kOut = (KeyOutputStream) oOut.getOutputStream();

assertThrows(NotImplementedException.class, () -> kOut.hflush());
assertThrows(NotImplementedException.class, () -> kOut.hsync());
}
}

}

0 comments on commit 41d7059

Please sign in to comment.