-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Remerge Progress Bar Read API. #21124
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3782a0b
Revert "Revert "Progress Bar Read APIs (#20937)" (#21115)"
davinchia f3e82e4
checkpoint.
davinchia 797a93d
Handle the case where the job list is empty.
davinchia 0bc358b
Merge branch 'master' into davinchia/fix-progress-bar-read-bug
davinchia c2922db
Merge branch 'master' into davinchia/fix-progress-bar-read-bug
davinchia 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.Iterators; | ||
import com.google.common.collect.Lists; | ||
import com.google.common.collect.Sets; | ||
import com.google.common.collect.UnmodifiableIterator; | ||
import io.airbyte.commons.enums.Enums; | ||
|
@@ -72,6 +73,7 @@ | |
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.jooq.DSLContext; | ||
import org.jooq.Field; | ||
import org.jooq.InsertValuesStepN; | ||
|
@@ -511,6 +513,76 @@ public AttemptStats getAttemptStats(final long jobId, final int attemptNumber) t | |
}); | ||
} | ||
|
||
@Override | ||
public Map<JobAttemptPair, AttemptStats> getAttemptStats(final List<Long> jobIds) throws IOException { | ||
if (jobIds == null || jobIds.isEmpty()) { | ||
return Map.of(); | ||
} | ||
|
||
final var jobIdsStr = StringUtils.join(jobIds, ','); | ||
return jobDatabase.query(ctx -> { | ||
// Instead of one massive join query, separate this query into two queries for better readability | ||
// for now. | ||
// We can combine the queries at a later date if this still proves to be not efficient enough. | ||
final Map<JobAttemptPair, AttemptStats> attemptStats = hydrateSyncStats(jobIdsStr, ctx); | ||
hydrateStreamStats(jobIdsStr, ctx, attemptStats); | ||
return attemptStats; | ||
}); | ||
} | ||
|
||
private static Map<JobAttemptPair, AttemptStats> hydrateSyncStats(final String jobIdsStr, final DSLContext ctx) { | ||
final var attemptStats = new HashMap<JobAttemptPair, AttemptStats>(); | ||
final var syncResults = ctx.fetch( | ||
"SELECT atmpt.attempt_number, atmpt.job_id," | ||
+ "stats.estimated_bytes, stats.estimated_records, stats.bytes_emitted, stats.records_emitted " | ||
+ "FROM sync_stats stats " | ||
+ "INNER JOIN attempts atmpt ON stats.attempt_id = atmpt.id " | ||
+ "WHERE job_id IN ( " + jobIdsStr + ");"); | ||
syncResults.forEach(r -> { | ||
final var key = new JobAttemptPair(r.get(ATTEMPTS.JOB_ID), r.get(ATTEMPTS.ATTEMPT_NUMBER)); | ||
final var syncStats = new SyncStats() | ||
.withBytesEmitted(r.get(SYNC_STATS.BYTES_EMITTED)) | ||
.withRecordsEmitted(r.get(SYNC_STATS.RECORDS_EMITTED)) | ||
.withEstimatedRecords(r.get(SYNC_STATS.ESTIMATED_RECORDS)) | ||
.withEstimatedBytes(r.get(SYNC_STATS.ESTIMATED_BYTES)); | ||
attemptStats.put(key, new AttemptStats(syncStats, Lists.newArrayList())); | ||
}); | ||
return attemptStats; | ||
} | ||
|
||
/** | ||
* This method needed to be called after | ||
* {@link DefaultJobPersistence#hydrateSyncStats(String, DSLContext)} as it assumes hydrateSyncStats | ||
* has prepopulated the map. | ||
*/ | ||
private static void hydrateStreamStats(final String jobIdsStr, final DSLContext ctx, final Map<JobAttemptPair, AttemptStats> attemptStats) { | ||
final var streamResults = ctx.fetch( | ||
"SELECT atmpt.attempt_number, atmpt.job_id, " | ||
+ "stats.stream_name, stats.stream_namespace, stats.estimated_bytes, stats.estimated_records, stats.bytes_emitted, stats.records_emitted " | ||
+ "FROM stream_stats stats " | ||
+ "INNER JOIN attempts atmpt ON atmpt.id = stats.attempt_id " | ||
+ "WHERE attempt_id IN " | ||
+ "( SELECT id FROM attempts WHERE job_id IN ( " + jobIdsStr + "));"); | ||
|
||
streamResults.forEach(r -> { | ||
final var streamSyncStats = new StreamSyncStats() | ||
.withStreamNamespace(r.get(STREAM_STATS.STREAM_NAMESPACE)) | ||
.withStreamName(r.get(STREAM_STATS.STREAM_NAME)) | ||
.withStats(new SyncStats() | ||
.withBytesEmitted(r.get(STREAM_STATS.BYTES_EMITTED)) | ||
.withRecordsEmitted(r.get(STREAM_STATS.RECORDS_EMITTED)) | ||
.withEstimatedRecords(r.get(STREAM_STATS.ESTIMATED_RECORDS)) | ||
.withEstimatedBytes(r.get(STREAM_STATS.ESTIMATED_BYTES))); | ||
|
||
final var key = new JobAttemptPair(r.get(ATTEMPTS.JOB_ID), r.get(ATTEMPTS.ATTEMPT_NUMBER)); | ||
if (!attemptStats.containsKey(key)) { | ||
LOGGER.error("{} stream stats entry does not have a corresponding sync stats entry. This suggest the database is in a bad state.", key); | ||
return; | ||
} | ||
attemptStats.get(key).perStreamStats().add(streamSyncStats); | ||
}); | ||
} | ||
|
||
@Override | ||
public List<NormalizationSummary> getNormalizationSummary(final long jobId, final int attemptNumber) throws IOException { | ||
return jobDatabase | ||
|
@@ -528,6 +600,10 @@ static Long getAttemptId(final long jobId, final int attemptNumber, final DSLCon | |
final Optional<Record> record = | ||
ctx.fetch("SELECT id from attempts where job_id = ? AND attempt_number = ?", jobId, | ||
attemptNumber).stream().findFirst(); | ||
if (record.isEmpty()) { | ||
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. second change from pre-revert |
||
return -1L; | ||
} | ||
|
||
return record.get().get("id", Long.class); | ||
} | ||
|
||
|
@@ -849,7 +925,7 @@ private static Job getJobFromRecord(final Record record) { | |
|
||
private static Attempt getAttemptFromRecord(final Record record) { | ||
return new Attempt( | ||
record.get(ATTEMPT_NUMBER, Long.class), | ||
record.get(ATTEMPT_NUMBER, int.class), | ||
record.get(JOB_ID, Long.class), | ||
Path.of(record.get("log_path", String.class)), | ||
record.get("attempt_output", String.class) == null ? null : Jsons.deserialize(record.get("attempt_output", String.class), JobOutput.class), | ||
|
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
Oops, something went wrong.
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.
first change from pre-revert