Skip to content

Commit

Permalink
HDDS-5279. OFS mkdir -p does not work when Volume is not pre-created (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
smengcl authored Jul 29, 2021
1 parent 5da8b22 commit 1c6e0fb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.ozone.OFSPath;
import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.OzoneConfigKeys;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.hadoop.ozone.TestDataUtil;
import org.apache.hadoop.ozone.client.ObjectStore;
Expand Down Expand Up @@ -108,16 +109,19 @@ public class TestRootedOzoneFileSystem {
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(
new Object[]{true, true},
new Object[]{true, false},
new Object[]{false, true},
new Object[]{false, false});
new Object[]{true, true, true},
new Object[]{true, true, false},
new Object[]{true, false, false},
new Object[]{false, true, false},
new Object[]{false, false, false}
);
}

public TestRootedOzoneFileSystem(boolean setDefaultFs,
boolean enableOMRatis) {
boolean enableOMRatis, boolean isAclEnabled) {
enabledFileSystemPaths = setDefaultFs;
omRatisEnabled = enableOMRatis;
enableAcl = isAclEnabled;
}

public static FileSystem getFs() {
Expand All @@ -134,6 +138,7 @@ public static Path getBucketPath() {
private static boolean enabledFileSystemPaths;
private static boolean omRatisEnabled;
private static boolean isBucketFSOptimized = false;
private static boolean enableAcl;

private static OzoneConfiguration conf;
private static MiniOzoneCluster cluster = null;
Expand Down Expand Up @@ -165,6 +170,7 @@ public static void init() throws Exception {
conf.setBoolean(OMConfigKeys.OZONE_OM_ENABLE_FILESYSTEM_PATHS,
enabledFileSystemPaths);
}
conf.setBoolean(OzoneConfigKeys.OZONE_ACL_ENABLED, enableAcl);
cluster = MiniOzoneCluster.newBuilder(conf)
.setNumDatanodes(3)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ public class TestRootedOzoneFileSystemWithFSO
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(
new Object[]{true, true},
new Object[]{true, false});
new Object[]{true, true, false},
new Object[]{true, false, false}
);
}

public TestRootedOzoneFileSystemWithFSO(boolean setDefaultFs,
boolean enableOMRatis) throws Exception {
super(setDefaultFs, enableOMRatis);
boolean enableOMRatis, boolean enableAcl) {
super(setDefaultFs, enableOMRatis, enableAcl);
}

@BeforeClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,31 +223,23 @@ private OzoneBucket getBucket(String volumeStr, String bucketStr,
try {
bucket = proxy.getBucketDetails(volumeStr, bucketStr);
} catch (OMException ex) {
// Note: always create bucket if volumeStr matches "tmp" so -put works
if (createIfNotExist) {
// Note: getBucketDetails always throws BUCKET_NOT_FOUND, even if
// the volume doesn't exist.
if (ex.getResult().equals(BUCKET_NOT_FOUND)) {
OzoneVolume volume;
// getBucketDetails can throw VOLUME_NOT_FOUND when the parent volume
// doesn't exist and ACL is enabled; it can only throw BUCKET_NOT_FOUND
// when ACL is disabled. Both exceptions need to be handled.
switch (ex.getResult()) {
case VOLUME_NOT_FOUND:
case BUCKET_NOT_FOUND:
try {
volume = proxy.getVolumeDetails(volumeStr);
} catch (OMException getVolEx) {
if (getVolEx.getResult().equals(VOLUME_NOT_FOUND)) {
// Volume doesn't exist. Create it
try {
objectStore.createVolume(volumeStr);
} catch (OMException newVolEx) {
// Ignore the case where another client created the volume
if (!newVolEx.getResult().equals(VOLUME_ALREADY_EXISTS)) {
throw newVolEx;
}
}
} else {
throw getVolEx;
objectStore.createVolume(volumeStr);
} catch (OMException newVolEx) {
// Ignore the case where another client created the volume
if (!newVolEx.getResult().equals(VOLUME_ALREADY_EXISTS)) {
throw newVolEx;
}
// Try get volume again
volume = proxy.getVolumeDetails(volumeStr);
}

OzoneVolume volume = proxy.getVolumeDetails(volumeStr);
// Create the bucket
try {
volume.createBucket(bucketStr);
Expand All @@ -257,6 +249,10 @@ private OzoneBucket getBucket(String volumeStr, String bucketStr,
throw newBucEx;
}
}
break;
default:
// Throw unhandled exception
throw ex;
}
// Try get bucket again
bucket = proxy.getBucketDetails(volumeStr, bucketStr);
Expand Down

0 comments on commit 1c6e0fb

Please sign in to comment.