Skip to content

Commit

Permalink
HDDS-10781. Do not use OFSPath in O3FS BasicOzoneClientAdapterImpl (a…
Browse files Browse the repository at this point in the history
…pache#6614)

(cherry picked from commit a291682)
  • Loading branch information
chungen0126 authored and xichen01 committed Jul 17, 2024
1 parent f62169e commit dbf4c05
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2143,4 +2143,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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 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);
}

Expand Down Expand Up @@ -652,12 +647,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());
}
}
}
Expand Down Expand Up @@ -696,8 +690,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1301,10 +1301,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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Expand Down

0 comments on commit dbf4c05

Please sign in to comment.