-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[b/356461225] Add HDFS progress logging #534
Draft
dawidxc
wants to merge
3
commits into
main
Choose a base branch
from
hdfs-progress
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...rc/main/java/com/google/edwmigration/dumper/application/dumper/PartialProgressLogger.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,28 @@ | ||
/* | ||
* Copyright 2022-2024 Google LLC | ||
* Copyright 2013-2021 CompilerWorks | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.edwmigration.dumper.application.dumper; | ||
|
||
/** Logger for the progress of the long-running task. */ | ||
public interface PartialProgressLogger { | ||
|
||
/** | ||
* Logs progress, including the partial progress of a long-running task. | ||
* | ||
* @param partialProgressMessage message describing the progress of the long-running task | ||
*/ | ||
void logProgress(String partialProgressMessage); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
*/ | ||
package com.google.edwmigration.dumper.application.dumper.connector.hdfs; | ||
|
||
import com.google.common.primitives.Longs; | ||
import com.google.edwmigration.dumper.application.dumper.PartialProgressLogger; | ||
import com.google.edwmigration.dumper.application.dumper.task.AbstractTask; | ||
import com.google.edwmigration.dumper.plugin.lib.dumper.spi.HdfsPermissionExtractionDumpFormat.PermissionExtraction; | ||
import java.io.Closeable; | ||
|
@@ -40,10 +42,16 @@ final class ScanContext implements Closeable { | |
private static final DateTimeFormatter DATE_FORMAT = | ||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS").withZone(ZoneOffset.UTC); | ||
|
||
private static final Duration LOG_PROGRESS_DELAY = Duration.ofSeconds(10); | ||
|
||
private final DistributedFileSystem dfs; | ||
private final DFSClient dfsClient; | ||
private final CSVPrinter csvPrinter; | ||
private final Instant instantScanBegin; | ||
private final long totalDirectoryCount; | ||
private final PartialProgressLogger partialProgressLogger; | ||
|
||
private long lastLogTime; | ||
private LongAdder timeSpentInListStatus = new LongAdder(); | ||
private LongAdder numFilesByListStatus = new LongAdder(); | ||
|
||
|
@@ -59,12 +67,19 @@ final class ScanContext implements Closeable { | |
@GuardedBy("csvPrinter") | ||
private long numDirsWalked = 0L; | ||
|
||
ScanContext(DistributedFileSystem dfs, @WillClose Writer outputSink) throws IOException { | ||
ScanContext( | ||
DistributedFileSystem dfs, | ||
@WillClose Writer outputSink, | ||
long totalDirectoryCount, | ||
PartialProgressLogger partialProgressLogger) | ||
throws IOException { | ||
this.dfs = dfs; | ||
this.dfsClient = dfs.getClient(); | ||
this.csvPrinter = | ||
AbstractTask.FORMAT.withHeader(PermissionExtraction.Header.class).print(outputSink); | ||
this.instantScanBegin = Instant.now(); | ||
this.totalDirectoryCount = totalDirectoryCount; | ||
this.partialProgressLogger = partialProgressLogger; | ||
} | ||
|
||
@Override | ||
|
@@ -80,13 +95,12 @@ FileStatus[] listDirectory(FileStatus dir) throws IOException { | |
return files; | ||
} | ||
|
||
void beginWalkDir(FileStatus dir) {} | ||
|
||
/* | ||
* CsvPrint the directory attributes of the specified dir | ||
* and incrementally update the scan statistics (this is what the rest of the parameters are for) | ||
*/ | ||
void endWalkDir(FileStatus dir, long nFiles, long nDirs, long accumFileSize) throws IOException { | ||
logProgress(); | ||
String absolutePath = dir.getPath().toUri().getPath(); | ||
HdfsFileStatus hdfsFileStatus = dfsClient.getFileInfo(absolutePath); | ||
String strModificationTime = | ||
|
@@ -116,6 +130,16 @@ void endWalkDir(FileStatus dir, long nFiles, long nDirs, long accumFileSize) thr | |
} | ||
} | ||
|
||
private void logProgress() { | ||
long now = System.currentTimeMillis(); | ||
if (now - lastLogTime > LOG_PROGRESS_DELAY.toMillis()) { | ||
lastLogTime = now; | ||
long percentFinished = | ||
Longs.constrainToRange(this.numDirsWalked * 100 / totalDirectoryCount, 0, 99); | ||
partialProgressLogger.logProgress("HDFS scan " + percentFinished + "% completed"); | ||
} | ||
} | ||
|
||
void walkFile(FileStatus file) throws IOException { | ||
String absolutePath = file.getPath().toUri().getPath(); | ||
HdfsFileStatus hdfsFileStatus = dfsClient.getFileInfo(absolutePath); | ||
|
@@ -152,24 +176,22 @@ String getFormattedStats() { | |
: Duration.ZERO; | ||
|
||
final long numFilesDivisor = numFiles > 0 ? numFiles : 1; | ||
StringBuilder sb = | ||
new StringBuilder() | ||
.append("[HDFS Permission extraction stats]") | ||
.append("\nTotal: num files&dirs: " + numFiles) | ||
.append("\n num dirs found: " + numDirs) | ||
.append("\n num dirs walkd: " + numDirsWalked) | ||
.append("\nTotal File Size: " + accumulatedFileSize) | ||
.append("\nAvg File Size: " + accumulatedFileSize / numFilesDivisor) | ||
.append("\nTotal time: ") | ||
.append(timeSinceScanBegin.getSeconds() + "s") | ||
.append("\nTotal time in listStatus(..): ") | ||
.append(timeSpentInListStatus.getSeconds() + "s") | ||
.append("\nAvg time per file in listStatus(..): ") | ||
.append(avgTimeSpentInListStatusPerFile.toMillis() + "ms") | ||
.append("\nAvg time per doc: ") | ||
.append(timeSinceScanBegin.dividedBy(numFilesDivisor).toMillis() + "ms\n") | ||
.append("\n[/HDFS Permission extraction stats]"); | ||
|
||
return sb.toString(); | ||
return new StringBuilder() | ||
.append("[HDFS Permission extraction stats]") | ||
.append("\nTotal: num files&dirs: " + numFiles) | ||
.append("\n num dirs found: " + numDirs) | ||
.append("\n num dirs walked: " + numDirsWalked) | ||
.append("\nTotal File Size: " + accumulatedFileSize) | ||
.append("\nAvg File Size: " + accumulatedFileSize / numFilesDivisor) | ||
.append("\nTotal time: ") | ||
.append(timeSinceScanBegin.getSeconds() + "s") | ||
.append("\nTotal time in listStatus(..): ") | ||
.append(timeSpentInListStatus.getSeconds() + "s") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be a chained append(), not a String-+ in the middle, as that creates an extra StringBuilder and String. |
||
.append("\nAvg time per file in listStatus(..): ") | ||
.append(avgTimeSpentInListStatusPerFile.toMillis() + "ms") | ||
.append("\nAvg time per doc: ") | ||
.append(timeSinceScanBegin.dividedBy(numFilesDivisor).toMillis() + "ms\n") | ||
.append("\n[/HDFS Permission extraction stats]") | ||
.toString(); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of this looks very similar to the shared/common code in [Concurrent]RecordProgressMonitor. Would it be possible to use that?