Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -542,7 +542,21 @@ public Iterator<? extends OzoneKey> listKeys(String keyPrefix,
* @throws IOException
*/
public void deleteKey(String key) throws IOException {
proxy.deleteKey(volumeName, name, key);
proxy.deleteKey(volumeName, name, key, false);
}

/**
* Ozone FS api to delete a directory. Sub directories will be deleted if
* recursive flag is true, otherwise it will be non-recursive.
*
* @param key Name of the key to be deleted.
* @param recursive recursive deletion of all sub path keys if true,
* otherwise non-recursive
* @throws IOException
*/
public void deleteDirectory(String key, boolean recursive)
throws IOException {
proxy.deleteKey(volumeName, name, key, recursive);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,12 @@ OzoneInputStream getKey(String volumeName, String bucketName, String keyName)
* @param volumeName Name of the Volume
* @param bucketName Name of the Bucket
* @param keyName Name of the Key
* @param recursive recursive deletion of all sub path keys if true,
* otherwise non-recursive
* @throws IOException
*/
void deleteKey(String volumeName, String bucketName, String keyName)
void deleteKey(String volumeName, String bucketName, String keyName,
boolean recursive)
throws IOException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ public OzoneInputStream getKey(

@Override
public void deleteKey(
String volumeName, String bucketName, String keyName)
String volumeName, String bucketName, String keyName, boolean recursive)
throws IOException {
verifyVolumeName(volumeName);
verifyBucketName(bucketName);
Expand All @@ -740,6 +740,7 @@ public void deleteKey(
.setVolumeName(volumeName)
.setBucketName(bucketName)
.setKeyName(keyName)
.setRecursive(recursive)
.build();
ozoneManagerClient.deleteKey(keyArgs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ public enum ResultCodes {

PARTIAL_RENAME,

QUOTA_EXCEEDED
QUOTA_EXCEEDED,

DIRECTORY_NOT_EMPTY

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ public final class OmKeyArgs implements Auditable {
private boolean refreshPipeline;
private boolean sortDatanodesInPipeline;
private List<OzoneAcl> acls;
private boolean recursive;

@SuppressWarnings("parameternumber")
private OmKeyArgs(String volumeName, String bucketName, String keyName,
long dataSize, ReplicationType type, ReplicationFactor factor,
List<OmKeyLocationInfo> locationInfoList, boolean isMultipart,
String uploadID, int partNumber,
Map<String, String> metadataMap, boolean refreshPipeline,
List<OzoneAcl> acls, boolean sortDatanode) {
List<OzoneAcl> acls, boolean sortDatanode, boolean recursive) {
this.volumeName = volumeName;
this.bucketName = bucketName;
this.keyName = keyName;
Expand All @@ -70,6 +71,7 @@ private OmKeyArgs(String volumeName, String bucketName, String keyName,
this.refreshPipeline = refreshPipeline;
this.acls = acls;
this.sortDatanodesInPipeline = sortDatanode;
this.recursive = recursive;
}

public boolean getIsMultipartKey() {
Expand Down Expand Up @@ -140,6 +142,10 @@ public boolean getSortDatanodes() {
return sortDatanodesInPipeline;
}

public boolean isRecursive() {
return recursive;
}

@Override
public Map<String, String> toAuditMap() {
Map<String, String> auditMap = new LinkedHashMap<>();
Expand Down Expand Up @@ -198,6 +204,7 @@ public static class Builder {
private boolean refreshPipeline;
private boolean sortDatanodesInPipeline;
private List<OzoneAcl> acls;
private boolean recursive;

public Builder setVolumeName(String volume) {
this.volumeName = volume;
Expand Down Expand Up @@ -274,11 +281,16 @@ public Builder setSortDatanodesInPipeline(boolean sort) {
return this;
}

public Builder setRecursive(boolean isRecursive) {
this.recursive = isRecursive;
return this;
}

public OmKeyArgs build() {
return new OmKeyArgs(volumeName, bucketName, keyName, dataSize, type,
factor, locationInfoList, isMultipartKey, multipartUploadID,
multipartUploadPartNumber, metadata, refreshPipeline, acls,
sortDatanodesInPipeline);
sortDatanodesInPipeline, recursive);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,8 @@ public void deleteKey(OmKeyArgs args) throws IOException {
KeyArgs keyArgs = KeyArgs.newBuilder()
.setVolumeName(args.getVolumeName())
.setBucketName(args.getBucketName())
.setKeyName(args.getKeyName()).build();
.setKeyName(args.getKeyName())
.setRecursive(args.isRecursive()).build();
req.setKeyArgs(keyArgs);

OMRequest omRequest = createOMRequest(Type.DeleteKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.InvalidPathException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathIsNotEmptyDirectoryException;
import org.apache.hadoop.fs.Trash;
import org.apache.hadoop.fs.contract.ContractTestUtils;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
Expand Down Expand Up @@ -380,7 +381,7 @@ private void testDeleteCreatesFakeParentDir() throws Exception {
}


private void testRecursiveDelete() throws Exception {
protected void testRecursiveDelete() throws Exception {
Path grandparent = new Path("/gdir1");

for (int i = 1; i <= 10; i++) {
Expand All @@ -389,6 +390,24 @@ private void testRecursiveDelete() throws Exception {
ContractTestUtils.touch(fs, child);
}

// delete a dir with sub-file
try {
FileStatus[] parents = fs.listStatus(grandparent);
Assert.assertTrue(parents.length > 0);
fs.delete(parents[0].getPath(), false);
Assert.fail("Must throw exception as dir is not empty!");
} catch (PathIsNotEmptyDirectoryException pde) {
// expected
}

// delete a dir with sub-file
try {
fs.delete(grandparent, false);
Assert.fail("Must throw exception as dir is not empty!");
} catch (PathIsNotEmptyDirectoryException pde) {
// expected
}

// Delete the grandparent, which should delete all keys.
fs.delete(grandparent, true);

Expand Down Expand Up @@ -451,7 +470,7 @@ private void checkPath(Path path) {
}
}

private void testFileDelete() throws Exception {
protected void testFileDelete() throws Exception {
Path grandparent = new Path("/testBatchDelete");
Path parent = new Path(grandparent, "parent");
Path childFolder = new Path(parent, "childFolder");
Expand Down Expand Up @@ -783,12 +802,8 @@ protected void testRenameToNewSubDirShouldNotExist() throws Exception {
final Path baPath = new Path(fs.getUri().toString() + "/b/a");
fs.mkdirs(baPath);

try {
fs.rename(aSourcePath, bDestinPath);
Assert.fail("Should fail as new destination dir exists!");
} catch (FileAlreadyExistsException faee) {
// expected as new sub-path /b/a already exists.
}
Assert.assertFalse("New destin sub-path /b/a already exists",
fs.rename(aSourcePath, bDestinPath));

// Case-5.b) Rename file from /a/b/c/file1 to /a.
// Should be failed since /a/file1 exists.
Expand All @@ -802,12 +817,8 @@ protected void testRenameToNewSubDirShouldNotExist() throws Exception {

final Path aDestinPath = new Path(fs.getUri().toString() + "/a");

try {
fs.rename(abcFile1, aDestinPath);
Assert.fail("Should fail as new destination file exists!");
} catch (FileAlreadyExistsException faee) {
// expected as new sub-path /a/file1 already exists.
}
Assert.assertFalse("New destin sub-path /b/a already exists",
fs.rename(abcFile1, aDestinPath));
}

/**
Expand All @@ -822,12 +833,8 @@ protected void testRenameDirToFile() throws Exception {
ContractTestUtils.touch(fs, file1Destin);
Path abcRootPath = new Path(fs.getUri().toString() + "/a/b/c");
fs.mkdirs(abcRootPath);
try {
fs.rename(abcRootPath, file1Destin);
Assert.fail("key already exists /root_dir/file1");
} catch (FileAlreadyExistsException faee) {
// expected
}
Assert.assertFalse("key already exists /root_dir/file1",
fs.rename(abcRootPath, file1Destin));
}

/**
Expand Down
Loading