Skip to content

Commit

Permalink
log(elastic/index builder): add est time remaining (datahub-project#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
anshbansal authored and llance committed Jan 13, 2025
1 parent 00aeca4 commit 29ae13c
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ private void reindex(ReindexConfig indexState) throws Throwable {
boolean reindexTaskCompleted = false;
Pair<Long, Long> documentCounts = getDocumentCounts(indexState.name(), tempIndexName);
long documentCountsLastUpdated = System.currentTimeMillis();
long previousDocCount = documentCounts.getSecond();
long estimatedMinutesRemaining = 0;

while (System.currentTimeMillis() < timeoutAt) {
log.info(
Expand All @@ -421,8 +423,22 @@ private void reindex(ReindexConfig indexState) throws Throwable {

Pair<Long, Long> tempDocumentsCount = getDocumentCounts(indexState.name(), tempIndexName);
if (!tempDocumentsCount.equals(documentCounts)) {
documentCountsLastUpdated = System.currentTimeMillis();
long currentTime = System.currentTimeMillis();
long timeElapsed = currentTime - documentCountsLastUpdated;
long docsIndexed = tempDocumentsCount.getSecond() - previousDocCount;

// Calculate indexing rate (docs per millisecond)
double indexingRate = timeElapsed > 0 ? (double) docsIndexed / timeElapsed : 0;

// Calculate remaining docs and estimated time
long remainingDocs = tempDocumentsCount.getFirst() - tempDocumentsCount.getSecond();
long estimatedMillisRemaining =
indexingRate > 0 ? (long) (remainingDocs / indexingRate) : 0;
estimatedMinutesRemaining = estimatedMillisRemaining / (1000 * 60);

documentCountsLastUpdated = currentTime;
documentCounts = tempDocumentsCount;
previousDocCount = documentCounts.getSecond();
}

if (documentCounts.getFirst().equals(documentCounts.getSecond())) {
Expand All @@ -435,12 +451,15 @@ private void reindex(ReindexConfig indexState) throws Throwable {
break;

} else {
float progressPercentage =
100 * (1.0f * documentCounts.getSecond()) / documentCounts.getFirst();
log.warn(
"Task: {} - Document counts do not match {} != {}. Complete: {}%",
"Task: {} - Document counts do not match {} != {}. Complete: {}%. Estimated time remaining: {} minutes",
parentTaskId,
documentCounts.getFirst(),
documentCounts.getSecond(),
100 * (1.0f * documentCounts.getSecond()) / documentCounts.getFirst());
progressPercentage,
estimatedMinutesRemaining);

long lastUpdateDelta = System.currentTimeMillis() - documentCountsLastUpdated;
if (lastUpdateDelta > (300 * 1000)) {
Expand Down

0 comments on commit 29ae13c

Please sign in to comment.