Skip to content
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

S3 uploader + executor cleanup efficiency improvements #2083

Merged
merged 3 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
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 @@ -72,26 +72,25 @@ public TaskCleanupResult cleanup(boolean cleanupTaskAppDirectory, boolean cleanu
return finishTaskCleanup(dockerCleanSuccess);
}


if (!cleanupTaskAppDirectory) {
log.info("Not finishing cleanup because taskApp directory is being preserved");
return TaskCleanupResult.WAITING;
}

boolean cleanupTaskAppDirectorySuccess = cleanupTaskAppDirectory();
boolean logTearDownSuccess = taskLogManager.teardown();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the important line to move @baconmania . This shouldn't delete any log files, so the previous logging PR is still in effect. But it moves the task app directory cleanup to the end, so that we don't wait forever to clean logs just because we haven't cleaned taskapp yet


log.info("Cleaned up task app directory ({}) and rotated logs ({})", cleanupTaskAppDirectorySuccess, logTearDownSuccess);
log.info("Rotated and marked logs for upload for {} ({})", taskDirectory, logTearDownSuccess);

if (!cleanupLogs) {
log.info("Not finishing cleanup because log files will be preserved for 15 minutes after task termination");
log.debug("Not finishing cleanup because log files will be preserved for 15 minutes after task termination");
return TaskCleanupResult.WAITING;
}

boolean rotatedLogfileDeleteSuccess = checkForLogrotateAdditionalFilesToDelete(taskDefinition);

log.info("Deleted rotated logfiles ({})", rotatedLogfileDeleteSuccess);

if (!cleanupTaskAppDirectory) {
log.debug("Not finishing cleanup because taskApp directory is being preserved");
return TaskCleanupResult.WAITING;
}

boolean cleanupTaskAppDirectorySuccess = cleanupTaskAppDirectory();
log.info("Cleaned up task app directory ({})", cleanupTaskAppDirectorySuccess);

if (logTearDownSuccess && cleanupTaskAppDirectorySuccess) {
return finishTaskCleanup(dockerCleanSuccess);
} else {
Expand All @@ -112,12 +111,12 @@ private TaskCleanupResult finishTaskCleanup(boolean dockerCleanSuccess) {
public boolean cleanTaskDefinitionFile() {
Path taskDefinitionPath = configuration.getTaskDefinitionPath(taskDefinition.getTaskId());

log.info("Successful cleanup, deleting file {}", taskDefinitionPath);
log.debug("Successful cleanup, deleting file {}", taskDefinitionPath);

try {
boolean deleted = Files.deleteIfExists(taskDefinitionPath);

log.info("File deleted ({})", deleted);
log.debug("File deleted ({})", deleted);

return true;
} catch (IOException e) {
Expand All @@ -129,7 +128,7 @@ public boolean cleanTaskDefinitionFile() {
private boolean cleanupTaskAppDirectory() {
final String pathToDelete = taskDefinition.getTaskAppDirectory();

log.info("Deleting: {}", pathToDelete);
log.debug("Deleting: {}", pathToDelete);

try {
final List<String> cmd = ImmutableList.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public JsonObjectFileHelper(ObjectMapper objectMapper) {
public <T> Optional<T> read(Path file, Logger log, Class<T> clazz) throws IOException {
final long start = System.currentTimeMillis();

log.info("Reading {}", file);
log.trace("Reading {}", file);

byte[] bytes = new byte[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void processWatchKey(WatchKey watchKey) throws IOException {
WatchEvent.Kind<?> kind = event.kind();

if (!watchEvents.contains(kind)) {
LOG.trace("Ignoring an {} event to {}", event.context());
LOG.trace("Ignoring an {} event to {}", event.kind(), event.context());
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public S3Artifact getS3Artifact() {
}

private boolean download() throws Exception {
LOG.info("Beginning download {} after {}", artifactDownloadRequest, JavaUtils.duration(start));
LOG.trace("Beginning download {} after {}", artifactDownloadRequest, JavaUtils.duration(start));

if (continuation.isExpired()) {
LOG.info("Continuation expired for {}, aborting...", artifactDownloadRequest.getTargetDirectory());
LOG.trace("Continuation expired for {}, aborting...", artifactDownloadRequest.getTargetDirectory());
return false;
}

Expand All @@ -71,7 +71,7 @@ private boolean download() throws Exception {
artifactManager.copy(fetched, targetDirectory, artifactDownloadRequest.getS3Artifact().getFilename());
}

LOG.info("Finishing request {} after {}", artifactDownloadRequest.getTargetDirectory(), JavaUtils.duration(start));
LOG.debug("Finishing request {} after {}", artifactDownloadRequest.getTargetDirectory(), JavaUtils.duration(start));

getResponse().getOutputStream().close();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private boolean addDownloadRequest() {
return false;
}

LOG.info("Queing new downloader for {} ({} handlers, {} active threads, {} queue size, {} max) after {}", artifactDownloadRequest, downloadRequestToHandler.size(),
LOG.trace("Queing new downloader for {} ({} handlers, {} active threads, {} queue size, {} max) after {}", artifactDownloadRequest, downloadRequestToHandler.size(),
downloadService.getActiveCount(), downloadService.getQueue().size(), configuration.getNumDownloaderThreads(), JavaUtils.duration(start));

ListenableFuture<?> future = listeningDownloadWrapper.submit(newHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private int checkUploads() {
futures.put(uploader, CompletableFuture.supplyAsync(performUploadSupplier(uploader, isFinished, false), executorService));
}

LOG.info("Waiting on {} future(s)", futures.size());
LOG.debug("Waiting on {} future(s)", futures.size());

final long now = System.currentTimeMillis();
final Set<SingularityUploader> expiredUploaders = Sets.newHashSetWithExpectedSize(initialExpectedSize);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.hubspot.singularity.s3uploader;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
Expand Down Expand Up @@ -114,7 +116,7 @@ int uploadBatch(List<Path> toUpload) {
context.stop();
}
} else {
LOG.info("{} is in use by another process, will retry upload later", file);
LOG.debug("{} is in use by another process, will retry upload later", file);
}
}

Expand Down Expand Up @@ -156,6 +158,8 @@ List<Path> filesToUpload(boolean isFinished) throws IOException {
throw new RuntimeException(ioe);
}
});
} catch (UncheckedIOException|NoSuchFileException nsfe) {
LOG.debug("Parent file {} did not exist, skipping", directory);
Comment on lines +161 to +162
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because some directories we scanned contain tmp files, so even though we checked for the directory directly above this, it's possible it got deleted out from under us before we started the filesystem walk

}
return toUpload;
}
Expand Down