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 @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
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,28 +597,23 @@ 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);
}

@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 @@ -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());
}
}
}
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
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