-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated BackupDirectorySize interface to get the file count for snaps…
…hots/backups
- Loading branch information
ayushis
committed
Sep 17, 2024
1 parent
10840be
commit bde4768
Showing
8 changed files
with
114 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
priam/src/main/java/com/netflix/priam/backup/IncrementalBackupDirectorySize.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.netflix.priam.backup; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.*; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
|
||
/** Estimates remaining bytes or files to upload in a backup by looking at the file system */ | ||
public class IncrementalBackupDirectorySize implements DirectorySize { | ||
|
||
public long getBytes(String location) { | ||
SummingFileVisitor fileVisitor = new SummingFileVisitor(); | ||
try { | ||
Files.walkFileTree(Paths.get(location), fileVisitor); | ||
} catch (IOException e) { | ||
// BackupFileVisitor is happy with an estimate and won't produce these in practice. | ||
} | ||
return fileVisitor.getTotalBytes(); | ||
} | ||
|
||
public int getFiles(String location) { | ||
SummingFileVisitor fileVisitor = new SummingFileVisitor(); | ||
try { | ||
Files.walkFileTree(Paths.get(location), fileVisitor); | ||
} catch (IOException e) { | ||
// BackupFileVisitor is happy with an estimate and won't produce these in practice. | ||
} | ||
return fileVisitor.getTotalFiles(); | ||
} | ||
|
||
private static final class SummingFileVisitor implements FileVisitor<Path> { | ||
private long totalBytes; | ||
private int totalFiles; | ||
|
||
@Override | ||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { | ||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
@Override | ||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { | ||
if (file.toString().contains(AbstractBackup.INCREMENTAL_BACKUP_FOLDER) && attrs.isRegularFile()) { | ||
totalBytes += attrs.size(); | ||
totalFiles += 1; | ||
} | ||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
@Override | ||
public FileVisitResult visitFileFailed(Path file, IOException exc) { | ||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
@Override | ||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) { | ||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
long getTotalBytes() { | ||
return totalBytes; | ||
} | ||
|
||
int getTotalFiles() { return totalFiles; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters