Skip to content
Merged
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 @@ -95,7 +95,7 @@ public Pair<String, Boolean> reprocess(OMMetadataManager omMetadataManager) {
if (!statusFSO && !statusOBS) {
return new ImmutablePair<>(getTaskName(), false);
}
writeCountsToDB(true, fileSizeCountMap);
writeCountsToDB(fileSizeCountMap);
LOG.debug("Completed a 'reprocess' run of FileSizeCountTask.");
return new ImmutablePair<>(getTaskName(), true);
}
Expand All @@ -112,7 +112,7 @@ private boolean reprocessBucketLayout(BucketLayout bucketLayout,
handlePutKeyEvent(kv.getValue(), fileSizeCountMap);
// The time complexity of .size() method is constant time, O(1)
if (fileSizeCountMap.size() >= 100000) {
writeCountsToDB(true, fileSizeCountMap);
writeCountsToDB(fileSizeCountMap);
fileSizeCountMap.clear();
}
}
Expand Down Expand Up @@ -198,7 +198,7 @@ public Pair<String, Boolean> process(OMUpdateEventBatch events) {
value.getClass().getName(), updatedKey);
}
}
writeCountsToDB(false, fileSizeCountMap);
writeCountsToDB(fileSizeCountMap);
LOG.debug("{} successfully processed in {} milliseconds",
getTaskName(), (System.currentTimeMillis() - startTime));
return new ImmutablePair<>(getTaskName(), true);
Expand All @@ -209,10 +209,11 @@ public Pair<String, Boolean> process(OMUpdateEventBatch events) {
* using the dao.
*
*/
private void writeCountsToDB(boolean isDbTruncated,
Map<FileSizeCountKey, Long> fileSizeCountMap) {
private void writeCountsToDB(Map<FileSizeCountKey, Long> fileSizeCountMap) {

List<FileCountBySize> insertToDb = new ArrayList<>();
List<FileCountBySize> updateInDb = new ArrayList<>();
boolean isDbTruncated = isFileCountBySizeTableEmpty(); // Check if table is empty

fileSizeCountMap.keySet().forEach((FileSizeCountKey key) -> {
FileCountBySize newRecord = new FileCountBySize();
Expand Down Expand Up @@ -295,6 +296,15 @@ private void handleDeleteKeyEvent(String key, OmKeyInfo omKeyInfo,
}
}

/**
* Checks if the FILE_COUNT_BY_SIZE table is empty.
*
* @return true if the table is empty, false otherwise.
*/
private boolean isFileCountBySizeTableEmpty() {
return dslContext.fetchCount(FILE_COUNT_BY_SIZE) == 0;
}

private static class FileSizeCountKey {
private String volume;
private String bucket;
Expand Down