Skip to content

Commit

Permalink
DRILL-4154 - Update timestamp of directory after files are upgraded
Browse files Browse the repository at this point in the history
  • Loading branch information
parthchandra committed Dec 8, 2015
1 parent 7acd3e9 commit 76ffad4
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/main/java/org/apache/drill/upgrade/Upgrade_12_13.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ private void init() throws IOException {
}

//get a list of files to process
private void getFiles(String path, List<FileStatus> fileStatuses) throws IOException {
private void getFiles(String path, List<FileStatus> fileStatuses, List<FileStatus> dirs) throws IOException {
Path p = Path.getPathWithoutSchemeAndAuthority(new Path(path));
FileStatus fileStatus = fs.getFileStatus(p);
if (fileStatus.isDirectory()) {
dirs.add(fileStatus);
for (FileStatus f : fs.listStatus(p, new UpgradePathFilter())) {
getFiles(f.getPath().toString(), fileStatuses);
getFiles(f.getPath().toString(), fileStatuses, dirs);
}
} else {
if (fileStatus.isFile()) {
Expand Down Expand Up @@ -150,6 +151,17 @@ private void removeBackupFile(FileStatus fileStatus) throws IOException {
fs.delete(new Path(tmpFileDir + "/" + fileStatus.getPath().getName()));
}

private void touchDirs(List<FileStatus> dirs){
long ts = System.currentTimeMillis();
for(FileStatus d : dirs){
try {
fs.setTimes(d.getPath(), ts, ts);
} catch (IOException e) {
logger.debug("Unable to update directory timestamp [ {} ].", d.toString());
}
}
}

private boolean upgradeFile(FileStatus fileStatus, ParquetMetadata metadata) throws IOException {
backupFile(fileStatus);
boolean ret = updateFile(fileStatus, metadata);
Expand Down Expand Up @@ -217,8 +229,9 @@ public static void main(String[] args) {
for (String path : dirs) {
logger.info("Executing Upgrade_12_13 on " + path);
List<FileStatus> fileStatuses = new ArrayList<FileStatus>();
List<FileStatus> dirStatuses = new ArrayList<FileStatus>();
try {
upgrade_12_13.getFiles(path, fileStatuses);
upgrade_12_13.getFiles(path, fileStatuses, dirStatuses);
} catch (IOException e) {
logger.error("Failed to get list of file(s). Skipping. (" + e.getMessage() + ")");
}
Expand Down Expand Up @@ -252,6 +265,8 @@ public static void main(String[] args) {
.println("FAILURE : " + fileStatus.getPath().toString() + ". Cause: " + e.getMessage());
}
}
logger.debug("Updating directory timestamps");
upgrade_12_13.touchDirs(dirStatuses);
}
System.out.println("Done");
} else {
Expand Down

0 comments on commit 76ffad4

Please sign in to comment.