Skip to content

Commit 0828906

Browse files
committed
log(elastic/index builder): add est time remaining
1 parent a06a229 commit 0828906

File tree

1 file changed

+22
-3
lines changed
  • metadata-io/src/main/java/com/linkedin/metadata/search/elasticsearch/indexbuilder

1 file changed

+22
-3
lines changed

metadata-io/src/main/java/com/linkedin/metadata/search/elasticsearch/indexbuilder/ESIndexBuilder.java

+22-3
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ private void reindex(ReindexConfig indexState) throws Throwable {
411411
boolean reindexTaskCompleted = false;
412412
Pair<Long, Long> documentCounts = getDocumentCounts(indexState.name(), tempIndexName);
413413
long documentCountsLastUpdated = System.currentTimeMillis();
414+
long previousDocCount = documentCounts.getSecond();
415+
long estimatedMinutesRemaining = 0;
414416

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

422424
Pair<Long, Long> tempDocumentsCount = getDocumentCounts(indexState.name(), tempIndexName);
423425
if (!tempDocumentsCount.equals(documentCounts)) {
424-
documentCountsLastUpdated = System.currentTimeMillis();
426+
long currentTime = System.currentTimeMillis();
427+
long timeElapsed = currentTime - documentCountsLastUpdated;
428+
long docsIndexed = tempDocumentsCount.getSecond() - previousDocCount;
429+
430+
// Calculate indexing rate (docs per millisecond)
431+
double indexingRate = timeElapsed > 0 ? (double) docsIndexed / timeElapsed : 0;
432+
433+
// Calculate remaining docs and estimated time
434+
long remainingDocs = tempDocumentsCount.getFirst() - tempDocumentsCount.getSecond();
435+
long estimatedMillisRemaining =
436+
indexingRate > 0 ? (long) (remainingDocs / indexingRate) : 0;
437+
estimatedMinutesRemaining = estimatedMillisRemaining / (1000 * 60);
438+
439+
documentCountsLastUpdated = currentTime;
425440
documentCounts = tempDocumentsCount;
441+
previousDocCount = documentCounts.getSecond();
426442
}
427443

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

437453
} else {
454+
float progressPercentage =
455+
100 * (1.0f * documentCounts.getSecond()) / documentCounts.getFirst();
438456
log.warn(
439-
"Task: {} - Document counts do not match {} != {}. Complete: {}%",
457+
"Task: {} - Document counts do not match {} != {}. Complete: {}%. Estimated time remaining: {} minutes",
440458
parentTaskId,
441459
documentCounts.getFirst(),
442460
documentCounts.getSecond(),
443-
100 * (1.0f * documentCounts.getSecond()) / documentCounts.getFirst());
461+
progressPercentage,
462+
estimatedMinutesRemaining);
444463

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

0 commit comments

Comments
 (0)