This is an automated email from the ASF dual-hosted git repository.
weichiu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 16439f67e0 HDDS-7947. Disallow overwriting a hsync'ed key (#4778)
16439f67e0 is described below
commit 16439f67e0953da5bffdb415ff64ddeea2b29fbe
Author: Wei-Chiu Chuang <[email protected]>
AuthorDate: Wed May 31 17:56:59 2023 -0700
HDDS-7947. Disallow overwriting a hsync'ed key (#4778)
---
.../java/org/apache/hadoop/fs/ozone/TestHSync.java | 33 ++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestHSync.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestHSync.java
index d3fe1cda0b..070a15fa7b 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestHSync.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestHSync.java
@@ -21,10 +21,12 @@ package org.apache.hadoop.fs.ozone;
import java.io.Closeable;
import java.io.IOException;
import java.security.GeneralSecurityException;
+import java.security.PrivilegedExceptionAction;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicReference;
+import org.apache.hadoop.fs.FileAlreadyExistsException;
import org.apache.hadoop.hdds.utils.IOUtils;
import org.apache.hadoop.conf.StorageUnit;
import org.apache.hadoop.crypto.CipherSuite;
@@ -53,6 +55,7 @@ import org.apache.hadoop.ozone.client.io.KeyOutputStream;
import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.util.Time;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
@@ -69,6 +72,7 @@ import static
org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_SCHEME;
import static
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_DEFAULT_BUCKET_LAYOUT;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ADDRESS_KEY;
import static
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY;
+import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -169,6 +173,7 @@ public class TestHSync {
final String dir = OZONE_ROOT + bucket.getVolumeName()
+ OZONE_URI_DELIMITER + bucket.getName();
+
final byte[] data = new byte[1];
ThreadLocalRandom.current().nextBytes(data);
@@ -184,6 +189,34 @@ public class TestHSync {
}
}
+ @Test
+ public void testOverwriteHSyncFile() throws Exception {
+ // Set the fs.defaultFS
+ final String rootPath = String.format("%s://%s/",
+ OZONE_OFS_URI_SCHEME, CONF.get(OZONE_OM_ADDRESS_KEY));
+ CONF.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, rootPath);
+
+ final String dir = OZONE_ROOT + bucket.getVolumeName()
+ + OZONE_URI_DELIMITER + bucket.getName();
+
+ try (FileSystem fs = FileSystem.get(CONF)) {
+ final Path file = new Path(dir, "fileoverwrite");
+ try (FSDataOutputStream os = fs.create(file, false)) {
+ os.hsync();
+ UserGroupInformation ugi = UserGroupInformation.createUserForTesting(
+ "user2", new String[] {"group1"});
+ assertThrows(FileAlreadyExistsException.class,
+ () -> ugi.doAs((PrivilegedExceptionAction<Void>) () -> {
+ try (FSDataOutputStream os1 = fs.create(file, false)) {
+ os1.hsync();
+ }
+ return null;
+ }));
+ os.hsync();
+ }
+ }
+ }
+
static void runTestHSync(FileSystem fs, Path file, int initialDataSize)
throws Exception {
try (StreamWithLength out = new StreamWithLength(
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]