diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTest.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTest.java index 1cc7ee21a6ba..332e70612e8a 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTest.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTest.java @@ -2154,4 +2154,26 @@ private void assertCounter(long value, String key) { assertEquals(value, statistics.getLong(key).longValue()); } + @Test + void testSnapshotRead() throws Exception { + // Init data + Path snapPath1 = fs.createSnapshot(new Path("/"), "snap1"); + + Path file1 = new Path("/key1"); + Path file2 = new Path("/key2"); + ContractTestUtils.touch(fs, file1); + ContractTestUtils.touch(fs, file2); + Path snapPath2 = fs.createSnapshot(new Path("/"), "snap2"); + + Path file3 = new Path("/key3"); + ContractTestUtils.touch(fs, file3); + Path snapPath3 = fs.createSnapshot(new Path("/"), "snap3"); + + FileStatus[] f1 = fs.listStatus(snapPath1); + FileStatus[] f2 = fs.listStatus(snapPath2); + FileStatus[] f3 = fs.listStatus(snapPath3); + assertEquals(0, f1.length); + assertEquals(2, f2.length); + assertEquals(3, f3.length); + } } diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTestWithFSO.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTestWithFSO.java index f0ff1ab43b49..98039b82db9c 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTestWithFSO.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTestWithFSO.java @@ -497,7 +497,7 @@ public void testCreateFile() throws Exception { @Test public void testLeaseRecoverable() throws Exception { // Create a file - Path parent = new Path("/d1/d2/"); + Path parent = new Path("/d1"); Path source = new Path(parent, "file1"); LeaseRecoverable fs = (LeaseRecoverable)getFs(); diff --git a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneClientAdapterImpl.java b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneClientAdapterImpl.java index 3d426ed03498..cd8f5dd76bdf 100644 --- a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneClientAdapterImpl.java +++ b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneClientAdapterImpl.java @@ -45,7 +45,6 @@ import org.apache.hadoop.hdds.security.SecurityConfig; import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport; import org.apache.hadoop.io.Text; -import org.apache.hadoop.ozone.OFSPath; import org.apache.hadoop.ozone.OmUtils; import org.apache.hadoop.ozone.OzoneConfigKeys; import org.apache.hadoop.ozone.client.ObjectStore; @@ -598,18 +597,14 @@ public FileChecksum getFileChecksum(String keyName, long length) @Override public String createSnapshot(String pathStr, String snapshotName) throws IOException { - OFSPath ofsPath = new OFSPath(pathStr, config); - return objectStore.createSnapshot(ofsPath.getVolumeName(), - ofsPath.getBucketName(), - snapshotName); + return objectStore.createSnapshot(volume.getName(), bucket.getName(), snapshotName); } @Override public void renameSnapshot(String pathStr, String snapshotOldName, String snapshotNewName) throws IOException { - OFSPath ofsPath = new OFSPath(pathStr, config); - objectStore.renameSnapshot(ofsPath.getVolumeName(), - ofsPath.getBucketName(), + objectStore.renameSnapshot(volume.getName(), + bucket.getName(), snapshotOldName, snapshotNewName); } @@ -617,9 +612,8 @@ public void renameSnapshot(String pathStr, String snapshotOldName, String snapsh @Override public void deleteSnapshot(String pathStr, String snapshotName) throws IOException { - OFSPath ofsPath = new OFSPath(pathStr, config); - objectStore.deleteSnapshot(ofsPath.getVolumeName(), - ofsPath.getBucketName(), + objectStore.deleteSnapshot(volume.getName(), + bucket.getName(), snapshotName); } @@ -662,12 +656,11 @@ public SnapshotDiffReport getSnapshotDiffReport(Path snapshotDir, } finally { // delete the temp snapshot if (takeTemporaryToSnapshot || takeTemporaryFromSnapshot) { - OFSPath snapPath = new OFSPath(snapshotDir.toString(), config); if (takeTemporaryToSnapshot) { - OzoneClientUtils.deleteSnapshot(objectStore, toSnapshot, snapPath); + OzoneClientUtils.deleteSnapshot(objectStore, toSnapshot, volume.getName(), bucket.getName()); } if (takeTemporaryFromSnapshot) { - OzoneClientUtils.deleteSnapshot(objectStore, fromSnapshot, snapPath); + OzoneClientUtils.deleteSnapshot(objectStore, fromSnapshot, volume.getName(), bucket.getName()); } } } @@ -706,8 +699,7 @@ public void setTimes(String key, long mtime, long atime) throws IOException { @Override public boolean isFileClosed(String pathStr) throws IOException { incrementCounter(Statistic.INVOCATION_IS_FILE_CLOSED, 1); - OFSPath ofsPath = new OFSPath(pathStr, config); - if (!ofsPath.isKey()) { + if (StringUtils.isEmpty(pathStr)) { throw new IOException("not a file"); } OzoneFileStatus status = bucket.getFileStatus(pathStr); diff --git a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneClientAdapterImpl.java b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneClientAdapterImpl.java index 3bbae134db51..b22852b654cc 100644 --- a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneClientAdapterImpl.java +++ b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneClientAdapterImpl.java @@ -1317,10 +1317,10 @@ public SnapshotDiffReport getSnapshotDiffReport(Path snapshotDir, } finally { // delete the temp snapshot if (takeTemporaryToSnapshot) { - OzoneClientUtils.deleteSnapshot(objectStore, toSnapshot, ofsPath); + OzoneClientUtils.deleteSnapshot(objectStore, toSnapshot, volume, bucket); } if (takeTemporaryFromSnapshot) { - OzoneClientUtils.deleteSnapshot(objectStore, fromSnapshot, ofsPath); + OzoneClientUtils.deleteSnapshot(objectStore, fromSnapshot, volume, bucket); } } } diff --git a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/OzoneClientUtils.java b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/OzoneClientUtils.java index 4cb9084b2b91..383ad6db495b 100644 --- a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/OzoneClientUtils.java +++ b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/OzoneClientUtils.java @@ -25,7 +25,6 @@ import org.apache.hadoop.hdds.protocol.proto.HddsProtos; import org.apache.hadoop.fs.FileChecksum; import org.apache.hadoop.hdds.scm.OzoneClientConfig; -import org.apache.hadoop.ozone.OFSPath; import org.apache.hadoop.ozone.client.checksum.BaseFileChecksumHelper; import org.apache.hadoop.ozone.client.ObjectStore; import org.apache.hadoop.ozone.client.OzoneBucket; @@ -270,14 +269,14 @@ public static int limitValue(int confValue, String confName, int maxLimit) { } public static void deleteSnapshot(ObjectStore objectStore, - String snapshot, OFSPath snapPath) { + String snapshot, String volumeName, String bucketName) { try { - objectStore.deleteSnapshot(snapPath.getVolumeName(), - snapPath.getBucketName(), snapshot); + objectStore.deleteSnapshot(volumeName, + bucketName, snapshot); } catch (IOException exception) { LOG.warn("Failed to delete the temp snapshot with name {} in bucket" + " {} and volume {} after snapDiff op. Exception : {}", snapshot, - snapPath.getBucketName(), snapPath.getVolumeName(), + bucketName, volumeName, exception.getMessage()); } }