klcopp commented on a change in pull request #3102:
URL: https://github.com/apache/hive/pull/3102#discussion_r833132738
##########
File path: ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/Cleaner.java
##########
@@ -444,57 +444,23 @@ private boolean removeFiles(String location,
ValidWriteIdList writeIdList, Compa
// Including obsolete directories for partitioned tables can result in
data loss.
obsoleteDirs = dir.getAbortedDirectories();
}
-
- if (obsoleteDirs.isEmpty()
- && !hasDataBelowWatermark(dir, fs, path, ci.highestWriteId,
writeIdList.getHighWatermark())) {
- LOG.info(idWatermark(ci) + " nothing to remove below watermark " +
ci.highestWriteId + ", ");
- return true;
- }
StringBuilder extraDebugInfo = new
StringBuilder("[").append(obsoleteDirs.stream()
.map(Path::getName).collect(Collectors.joining(",")));
- boolean success = remove(location, ci, obsoleteDirs, true, fs,
extraDebugInfo);
+ remove(location, ci, obsoleteDirs, true, fs, extraDebugInfo);
if (dir.getObsolete().size() > 0) {
AcidMetricService.updateMetricsFromCleaner(ci.dbname, ci.tableName,
ci.partName, dir.getObsolete(), conf,
txnHandler);
}
- return success;
- }
-
- private boolean hasDataBelowWatermark(AcidDirectory acidDir, FileSystem fs,
Path path, long highWatermark,
- long minOpenTxn)
- throws IOException {
- Set<Path> acidPaths = new HashSet<>();
- for (ParsedDelta delta : acidDir.getCurrentDirectories()) {
- acidPaths.add(delta.getPath());
- }
- if (acidDir.getBaseDirectory() != null) {
- acidPaths.add(acidDir.getBaseDirectory());
- }
- FileStatus[] children = fs.listStatus(path, p -> {
- return !acidPaths.contains(p);
- });
- for (FileStatus child : children) {
- if (isFileBelowWatermark(child, highWatermark, minOpenTxn)) {
- return true;
- }
- }
- return false;
- }
-
- private boolean isFileBelowWatermark(FileStatus child, long highWatermark,
long minOpenTxn) {
- Path p = child.getPath();
- String fn = p.getName();
- if (!child.isDirectory()) {
+ // Make sure there are no leftovers below the compacted highestWriteId
+ conf.set(ValidTxnList.VALID_TXNS_KEY, new ValidReadTxnList().toString());
+ dir = AcidUtils.getAcidState(fs, path, conf,
+ new ValidReaderWriteIdList(ci.getFullTableName(), new long[0], new
BitSet(), ci.highestWriteId, Long.MAX_VALUE),
+ Ref.from(false), false, hdfsDirSnapshots);
+
+ if (dir.getObsolete().isEmpty()) {
Review comment:
Might want to check for aborted directories too
##########
File path: ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/Cleaner.java
##########
@@ -444,57 +444,23 @@ private boolean removeFiles(String location,
ValidWriteIdList writeIdList, Compa
// Including obsolete directories for partitioned tables can result in
data loss.
obsoleteDirs = dir.getAbortedDirectories();
}
-
- if (obsoleteDirs.isEmpty()
- && !hasDataBelowWatermark(dir, fs, path, ci.highestWriteId,
writeIdList.getHighWatermark())) {
- LOG.info(idWatermark(ci) + " nothing to remove below watermark " +
ci.highestWriteId + ", ");
- return true;
- }
StringBuilder extraDebugInfo = new
StringBuilder("[").append(obsoleteDirs.stream()
.map(Path::getName).collect(Collectors.joining(",")));
- boolean success = remove(location, ci, obsoleteDirs, true, fs,
extraDebugInfo);
+ remove(location, ci, obsoleteDirs, true, fs, extraDebugInfo);
if (dir.getObsolete().size() > 0) {
AcidMetricService.updateMetricsFromCleaner(ci.dbname, ci.tableName,
ci.partName, dir.getObsolete(), conf,
txnHandler);
}
- return success;
- }
-
- private boolean hasDataBelowWatermark(AcidDirectory acidDir, FileSystem fs,
Path path, long highWatermark,
- long minOpenTxn)
- throws IOException {
- Set<Path> acidPaths = new HashSet<>();
- for (ParsedDelta delta : acidDir.getCurrentDirectories()) {
- acidPaths.add(delta.getPath());
- }
- if (acidDir.getBaseDirectory() != null) {
- acidPaths.add(acidDir.getBaseDirectory());
- }
- FileStatus[] children = fs.listStatus(path, p -> {
- return !acidPaths.contains(p);
- });
- for (FileStatus child : children) {
- if (isFileBelowWatermark(child, highWatermark, minOpenTxn)) {
- return true;
- }
- }
- return false;
- }
-
- private boolean isFileBelowWatermark(FileStatus child, long highWatermark,
long minOpenTxn) {
- Path p = child.getPath();
- String fn = p.getName();
- if (!child.isDirectory()) {
+ // Make sure there are no leftovers below the compacted highestWriteId
+ conf.set(ValidTxnList.VALID_TXNS_KEY, new ValidReadTxnList().toString());
+ dir = AcidUtils.getAcidState(fs, path, conf,
+ new ValidReaderWriteIdList(ci.getFullTableName(), new long[0], new
BitSet(), ci.highestWriteId, Long.MAX_VALUE),
+ Ref.from(false), false, hdfsDirSnapshots);
+
+ if (dir.getObsolete().isEmpty()) {
+ LOG.info(idWatermark(ci) + " All cleared below the watermark: " +
ci.highestWriteId + " from " + location);
Review comment:
It might be nice to have an informative log line about uncleared files
(highest write id, mintxnid, CompactionInfo, number of files, maybe even file
names).
In that case, maybe the "All cleared below the watermark" message could be
debug-level, since we can insinuate there's nothing else to clean?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]