-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
rewrite buildWebBackendConnectionRead to avoid fetching all jobs #16811
Merged
pmossman
merged 6 commits into
master
from
parker/avoid-scanning-jobs-to-show-connection-status
Sep 16, 2022
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b18c708
rewrite buildWebBackendConnectionRead to avoid fetching all jobs
pmossman 9ebdffd
format
pmossman 9883904
query for latest sync job in addition to latest running sync job
pmossman 5b19a71
fix query
pmossman c84b3a4
add test coverage for new methods
pmossman 81d259e
simplify optional logic and add another test case
pmossman 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
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 |
---|---|---|
|
@@ -74,8 +74,6 @@ | |
@Slf4j | ||
public class WebBackendConnectionsHandler { | ||
|
||
private static final Set<JobStatus> TERMINAL_STATUSES = Sets.newHashSet(JobStatus.FAILED, JobStatus.SUCCEEDED, JobStatus.CANCELLED); | ||
|
||
private final ConnectionsHandler connectionsHandler; | ||
private final StateHandler stateHandler; | ||
private final SourceHandler sourceHandler; | ||
|
@@ -128,20 +126,18 @@ private WebBackendConnectionRead buildWebBackendConnectionRead(final ConnectionR | |
final SourceRead source = getSourceRead(connectionRead); | ||
final DestinationRead destination = getDestinationRead(connectionRead); | ||
final OperationReadList operations = getOperationReadList(connectionRead); | ||
final JobReadList syncJobReadList = getSyncJobs(connectionRead); | ||
final Optional<JobRead> latestRunningSyncJob = jobHistoryHandler.getLatestRunningSyncJob(connectionRead.getConnectionId()); | ||
|
||
final WebBackendConnectionRead webBackendConnectionRead = getWebBackendConnectionRead(connectionRead, source, destination, operations) | ||
.catalogId(connectionRead.getSourceCatalogId()) | ||
.isSyncing(syncJobReadList.getJobs() | ||
.stream() | ||
.map(JobWithAttemptsRead::getJob) | ||
.anyMatch(WebBackendConnectionsHandler::isRunningJob)); | ||
setLatestSyncJobProperties(webBackendConnectionRead, syncJobReadList); | ||
return webBackendConnectionRead; | ||
} | ||
.catalogId(connectionRead.getSourceCatalogId()); | ||
|
||
if (latestRunningSyncJob.isPresent()) { | ||
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. Nit for later: could do |
||
webBackendConnectionRead.isSyncing(true); | ||
webBackendConnectionRead.setLatestSyncJobCreatedAt(latestRunningSyncJob.get().getCreatedAt()); | ||
webBackendConnectionRead.setLatestSyncJobStatus(latestRunningSyncJob.get().getStatus()); | ||
} | ||
|
||
private static boolean isRunningJob(final JobRead job) { | ||
return !TERMINAL_STATUSES.contains(job.getStatus()); | ||
return webBackendConnectionRead; | ||
} | ||
|
||
private SourceRead getSourceRead(final ConnectionRead connectionRead) throws JsonValidationException, IOException, ConfigNotFoundException { | ||
|
@@ -185,21 +181,6 @@ private static WebBackendConnectionRead getWebBackendConnectionRead(final Connec | |
.resourceRequirements(connectionRead.getResourceRequirements()); | ||
} | ||
|
||
private JobReadList getSyncJobs(final ConnectionRead connectionRead) throws IOException { | ||
final JobListRequestBody jobListRequestBody = new JobListRequestBody() | ||
.configId(connectionRead.getConnectionId().toString()) | ||
.configTypes(Collections.singletonList(JobConfigType.SYNC)); | ||
return jobHistoryHandler.listJobsFor(jobListRequestBody); | ||
} | ||
|
||
private static void setLatestSyncJobProperties(final WebBackendConnectionRead WebBackendConnectionRead, final JobReadList syncJobReadList) { | ||
syncJobReadList.getJobs().stream().map(JobWithAttemptsRead::getJob).findFirst() | ||
.ifPresent(job -> { | ||
WebBackendConnectionRead.setLatestSyncJobCreatedAt(job.getCreatedAt()); | ||
WebBackendConnectionRead.setLatestSyncJobStatus(job.getStatus()); | ||
}); | ||
} | ||
|
||
public WebBackendConnectionReadList webBackendSearchConnections(final WebBackendConnectionSearch webBackendConnectionSearch) | ||
throws ConfigNotFoundException, IOException, JsonValidationException { | ||
|
||
|
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.
Nit for later: We could do something like
nonTerminalSyncJobsForConnection.stream().findFirst()
which returns an optional -- either the first element is there or the list is empty/there is nothing.