Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -129,7 +129,7 @@ public void cleanup() {
Path root = new Path("/");
FileStatus[] fileStatuses = fs.listStatus(root);
for (FileStatus fileStatus : fileStatuses) {
fs.delete(fileStatus.getPath(), true);
fs.delete(fileStatus.getPath(), false);
}
} catch (IOException ex) {
fail("Failed to cleanup files.");
Expand Down Expand Up @@ -191,7 +191,8 @@ public void testDeleteVolumeAndBucket() throws Exception {

OMMetrics omMetrics = cluster.getOzoneManager().getMetrics();
long prevDeletes = omMetrics.getNumKeyDeletes();
Assert.assertTrue(fs.delete(volumePath, true));
Assert.assertTrue(fs.delete(bucketPath, true));
Assert.assertTrue(fs.delete(volumePath, false));
long deletes = omMetrics.getNumKeyDeletes();
Assert.assertEquals(prevDeletes + 1, deletes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ public void createVolumeAndBucket() throws IOException {

@After
public void cleanup() throws IOException {
fs.delete(volumePath, true);
fs.delete(bucketPath, true);
fs.delete(volumePath, false);
}

public static FileSystem getFs() {
Expand Down Expand Up @@ -546,9 +547,9 @@ public void testListStatusIteratorInBucket() throws Exception {

@Test
public void testListStatusIteratorWithPathNotFound() throws Exception {
Path root = new Path("/test");
Path path = new Path("/test/test1/test2");
try {
ofs.listStatusIterator(root);
ofs.listStatusIterator(path);
Assert.fail("Should have thrown OMException");
} catch (OMException omEx) {
Assert.assertEquals("Volume test is not found",
Expand Down Expand Up @@ -1514,14 +1515,6 @@ public void testDeleteVolumeBucketAndKey() throws IOException {
Assert.assertTrue(fs.delete(volumePath3, false));
// Verify the volume is deleted
Assert.assertFalse(volumeExist(volumeStr3));

// Test recursively delete volume
// Create test volume, bucket and key
fs.mkdirs(dirPath3);
// Delete volume recursively
Assert.assertTrue(fs.delete(volumePath3, true));
// Verify the volume is deleted
Assert.assertFalse(volumeExist(volumeStr3));
}

private void createSymlinkSrcDestPaths(String srcVol,
Expand Down Expand Up @@ -1561,7 +1554,7 @@ public void testSymlinkList() throws Exception {
try (GenericTestUtils.SystemOutCapturer capture =
new GenericTestUtils.SystemOutCapturer()) {
String linkPathStr = rootPath + destVolume;
ToolRunner.run(shell, new String[]{"-ls", "-R", linkPathStr});
ToolRunner.run(shell, new String[]{"-ls", linkPathStr});
Assert.assertTrue(capture.getOutput().contains("drwxrwxrwx"));
Assert.assertTrue(capture.getOutput().contains(linkPathStr +
OZONE_URI_DELIMITER + srcBucket));
Expand Down Expand Up @@ -1599,8 +1592,10 @@ public void testSymlinkList() throws Exception {
// due to bug - HDDS-7884
fs.delete(new Path(OZONE_URI_DELIMITER + destVolume +
OZONE_URI_DELIMITER + srcBucket));
fs.delete(new Path(OZONE_URI_DELIMITER + srcVolume), true);
fs.delete(new Path(OZONE_URI_DELIMITER + destVolume), true);
fs.delete(new Path(OZONE_URI_DELIMITER + srcVolume +
OZONE_URI_DELIMITER + srcBucket));
fs.delete(new Path(OZONE_URI_DELIMITER + srcVolume), false);
fs.delete(new Path(OZONE_URI_DELIMITER + destVolume), false);
}
}

Expand Down Expand Up @@ -1707,8 +1702,10 @@ public void testSymlinkPosixDelete() throws Exception {
// due to bug - HDDS-7884
fs.delete(new Path(OZONE_URI_DELIMITER + destVolume + OZONE_URI_DELIMITER
+ srcBucket));
fs.delete(new Path(OZONE_URI_DELIMITER + srcVolume), true);
fs.delete(new Path(OZONE_URI_DELIMITER + destVolume), true);
fs.delete(new Path(OZONE_URI_DELIMITER + srcVolume + OZONE_URI_DELIMITER
+ srcBucket));
fs.delete(new Path(OZONE_URI_DELIMITER + srcVolume), false);
fs.delete(new Path(OZONE_URI_DELIMITER + destVolume), false);
}
}

Expand Down Expand Up @@ -1741,8 +1738,8 @@ public void testDeleteBucketLink() throws Exception {
// confirm non recursive delete of volume with link fails
deleteNonRecursivelyAndFail(linkVolumePath);

// confirm recursive delete of volume with link works
fs.delete(linkVolumePath, true);
fs.delete(linkPath, true);
fs.delete(linkVolumePath, false);

// confirm vol1 data is unaffected
Assert.assertTrue(dir1Status.equals(fs.getFileStatus(dirPath1)));
Expand All @@ -1753,7 +1750,8 @@ public void testDeleteBucketLink() throws Exception {
assertTrue(exception.getMessage().contains("File not found."));

// Cleanup
fs.delete(volumePath1, true);
fs.delete(bucketPath1, true);
fs.delete(volumePath1, false);

}

Expand Down Expand Up @@ -2289,7 +2287,7 @@ public void testGetFileStatus() throws Exception {
assertThrows(OMException.class,
() -> ofs.getFileStatus(new Path(volume, bucketNameLocal)));
// Cleanup
ofs.delete(volume, true);
ofs.delete(volume, false);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ public void testDeleteVolumeAndBucket() throws IOException {
*/

long prevDeletes = getOMMetrics().getNumKeyDeletes();
Assert.assertTrue(getFs().delete(volumePath1, true));
Assert.assertTrue(getFs().delete(bucketPath2, true));
Assert.assertTrue(getFs().delete(volumePath1, false));
long deletes = getOMMetrics().getNumKeyDeletes();
Assert.assertTrue(deletes == prevDeletes + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,27 @@ public void testRmRootRecursive() {
public void testRmNonEmptyRootDirNonRecursive() {
// OFS doesn't support creating files directly under root
}

@Override
public void testRmEmptyRootDirNonRecursive() {
// Internally test deletes volume recursively
// Which is not supported
}

@Override
public void testListEmptyRootDirectory() {
// Internally test deletes volume recursively
// Which is not supported
}

@Override
public void testSimpleRootListing() {
// Recursive list is not supported
}

@Override
public void testMkDirDepth1() {
// Internally test deletes volume recursively
// Which is not supported
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ public void testLinkBucketOrphan() throws Exception {
getClientConfForOFS(hostPrefix, cluster.getConf());
OzoneFsShell shell = new OzoneFsShell(clientConf);

try (FileSystem fs = FileSystem.get(clientConf)) {
try {
int res;
// Test orphan link bucket when source volume removed
res = ToolRunner.run(shell, new String[]{"-mkdir", "-p",
Expand All @@ -675,17 +675,29 @@ public void testLinkBucketOrphan() throws Exception {
"/linkvol/linkbuck"};
execute(ozoneShell, args);

res = ToolRunner.run(shell, new String[]{"-rm", "-R", "-f",
"-skipTrash", hostPrefix + "/vol1"});
assertEquals(0, res);
args =
new String[] {"volume", "delete", "vol1", "-r", "--yes"};
execute(ozoneShell, args);
out.reset();
OMException omExecution = assertThrows(OMException.class,
() -> client.getObjectStore().getVolume("vol1"));
assertEquals(VOLUME_NOT_FOUND, omExecution.getResult());

res = ToolRunner.run(shell, new String[]{"-ls", "-R",
res = ToolRunner.run(shell, new String[]{"-ls",
hostPrefix + "/linkvol"});
assertEquals(0, res);

res = ToolRunner.run(shell, new String[]{"-rm", "-R", "-f",
"-skipTrash", hostPrefix + "/linkvol"});
assertEquals(0, res);
args = new String[] {"bucket", "delete", "linkvol"
+ OZONE_URI_DELIMITER + "linkbuck"};
execute(ozoneShell, args);
out.reset();

args = new String[] {"volume", "delete", "linkvol"};
execute(ozoneShell, args);
out.reset();
omExecution = assertThrows(OMException.class,
() -> client.getObjectStore().getVolume("linkvol"));
assertEquals(VOLUME_NOT_FOUND, omExecution.getResult());

// Test orphan link bucket when only source bucket removed
res = ToolRunner.run(shell, new String[]{"-mkdir", "-p",
Expand All @@ -704,9 +716,17 @@ public void testLinkBucketOrphan() throws Exception {
"-skipTrash", hostPrefix + "/vol1/bucket1"});
assertEquals(0, res);

res = ToolRunner.run(shell, new String[]{"-rm", "-R", "-f",
"-skipTrash", hostPrefix + "/linkvol"});
assertEquals(0, res);
args = new String[] {"bucket", "delete", "linkvol"
+ OZONE_URI_DELIMITER + "linkbuck"};
execute(ozoneShell, args);
out.reset();

args = new String[] {"volume", "delete", "linkvol"};
execute(ozoneShell, args);
out.reset();
omExecution = assertThrows(OMException.class,
() -> client.getObjectStore().getVolume("linkvol"));
assertEquals(VOLUME_NOT_FOUND, omExecution.getResult());
} finally {
shell.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,14 @@ public boolean delete(Path f, boolean recursive) throws IOException {

// Handle delete volume
if (ofsPath.isVolume()) {
return deleteVolume(f, recursive, ofsPath);
if (recursive) {
LOG.warn("Recursive volume delete using ofs is not supported");
throw new IOException("Recursive volume delete using " +
"ofs is not supported. " +
"Instead use 'ozone sh volume delete -r -skipTrash " +
"-id <OM_SERVICE_ID> <Volume_URI>' command");
}
return deleteVolume(f, ofsPath);
}

// delete bucket
Expand Down Expand Up @@ -781,7 +788,7 @@ private void deleteBucketFromVolume(Path f, OFSPath ofsPath)
}
}

private boolean deleteVolume(Path f, boolean recursive, OFSPath ofsPath)
private boolean deleteVolume(Path f, OFSPath ofsPath)
throws IOException {
// verify volume exist
try {
Expand All @@ -792,18 +799,6 @@ private boolean deleteVolume(Path f, boolean recursive, OFSPath ofsPath)
}

String volumeName = ofsPath.getVolumeName();
if (recursive) {
// Delete all buckets first
OzoneVolume volume =
adapterImpl.getObjectStore().getVolume(volumeName);
Iterator<? extends OzoneBucket> it = volume.listBuckets("");
String prefixVolumePathStr = addTrailingSlashIfNeeded(f.toString());
while (it.hasNext()) {
OzoneBucket bucket = it.next();
String nextBucket = prefixVolumePathStr + bucket.getName();
delete(new Path(nextBucket), true);
}
}
try {
adapterImpl.getObjectStore().deleteVolume(volumeName);
return true;
Expand Down Expand Up @@ -1127,6 +1122,15 @@ public RemoteIterator<LocatedFileStatus> listLocatedStatus(Path f)
@Override
public RemoteIterator<FileStatus> listStatusIterator(Path f)
throws IOException {
OFSPath ofsPath = new OFSPath(f,
OzoneConfiguration.of(getConfSource()));
if (ofsPath.isRoot() || ofsPath.isVolume()) {
LOG.warn("Recursive root/volume list using ofs is not supported");
throw new IOException("Recursive list root/volume " +
"using ofs is not supported. " +
"Instead use 'ozone sh key list " +
"<Volume_URI>' command");
}
return new OzoneFileStatusIterator<>(f);
}

Expand Down