Skip to content

Commit

Permalink
Use synchronized collection
Browse files Browse the repository at this point in the history
  • Loading branch information
mnpoonia committed Sep 17, 2024
1 parent b33878a commit 1e21b43
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ private static List<File> resolveAndArchive(FileSystem fs, Path baseArchiveDir,
LOG.trace("Created archive directory {}", baseArchiveDir);
}

List<File> failures = new ArrayList<>();
List<File> failures = Collections.synchronizedList(new ArrayList<>());
String startTime = Long.toString(start);
List<File> filesOnly = new ArrayList<>();
for (File file : toArchive) {
Expand All @@ -467,7 +467,7 @@ private static List<File> resolveAndArchive(FileSystem fs, Path baseArchiveDir,
ExecutorService executorService = Executors.newFixedThreadPool(25);
Map<File, Future<Boolean>> futures = new HashMap<>();
// In current baseDir all files will be process concurrently
for(File file : filesOnly) {
for (File file : filesOnly) {
LOG.trace("Archiving {}", file);
Future<Boolean> archiveTask =
executorService.submit(() -> resolveAndArchiveFile(baseArchiveDir, file, startTime));
Expand All @@ -486,17 +486,16 @@ private static List<File> resolveAndArchive(FileSystem fs, Path baseArchiveDir,
for (Map.Entry<File, Future<Boolean>> fileFutureEntry : futures.entrySet()) {
try {
boolean fileCleaned = fileFutureEntry.getValue().get();
if(!fileCleaned) {
LOG.warn(
"Couldn't archive %s into backup directory: %s".formatted(fileFutureEntry.getKey(),
baseArchiveDir));
if (!fileCleaned) {
LOG.warn("Couldn't archive %s into backup directory: %s"
.formatted(fileFutureEntry.getKey(), baseArchiveDir));
failures.add(fileFutureEntry.getKey());
}
} catch (InterruptedException e) {
LOG.warn("HFileArchive Cleanup thread was interrupted");
} catch (ExecutionException e) {
// this is IOException
LOG.warn("Failed to archive {}",fileFutureEntry.getKey() , e);
LOG.warn("Failed to archive {}", fileFutureEntry.getKey(), e);
failures.add(fileFutureEntry.getKey());
}

Expand Down

0 comments on commit 1e21b43

Please sign in to comment.