Skip to content

Commit

Permalink
RavenDB-23249 - update index progress for all collections
Browse files Browse the repository at this point in the history
  • Loading branch information
grisha-kotler committed Feb 8, 2025
1 parent f960ef5 commit 7e79cbd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
29 changes: 29 additions & 0 deletions src/Raven.Server/Documents/DocumentsStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2247,11 +2247,21 @@ public long GetNumberOfDocumentsToProcess(DocumentsOperationContext context, str
return GetNumberOfItemsToProcess(context, collection, afterEtag, tombstones: false, totalCount: out totalCount, overallDuration);
}

public long GetNumberOfDocumentsToProcess(DocumentsOperationContext context, long afterEtag, out long totalCount, Stopwatch overallDuration)
{
return GetNumberOfItemsToProcess(context, afterEtag, tombstones: false, totalCount: out totalCount, overallDuration);
}

public long GetNumberOfTombstonesToProcess(DocumentsOperationContext context, string collection, long afterEtag, out long totalCount, Stopwatch overallDuration)
{
return GetNumberOfItemsToProcess(context, collection, afterEtag, tombstones: true, totalCount: out totalCount, overallDuration);
}

public long GetNumberOfTombstonesToProcess(DocumentsOperationContext context, long afterEtag, out long totalCount, Stopwatch overallDuration)
{
return GetNumberOfItemsToProcess(context, afterEtag, tombstones: true, totalCount: out totalCount, overallDuration);
}

private long GetNumberOfItemsToProcess(DocumentsOperationContext context, string collection, long afterEtag, bool tombstones, out long totalCount,
Stopwatch overallDuration)
{
Expand Down Expand Up @@ -2287,6 +2297,25 @@ private long GetNumberOfItemsToProcess(DocumentsOperationContext context, string
return table.GetNumberOfEntriesAfter(indexDef, afterEtag, out totalCount, overallDuration);
}

private long GetNumberOfItemsToProcess(DocumentsOperationContext context, long afterEtag, bool tombstones, out long totalCount,
Stopwatch overallDuration)
{
Table table;
TableSchema.FixedSizeKeyIndexDef indexDef;
if (tombstones)
{
table = new Table(TombstonesSchema, context.Transaction.InnerTransaction);
indexDef = TombstonesSchema.FixedSizeIndexes[AllTombstonesEtagsSlice];
}
else
{
table = new Table(DocsSchema, context.Transaction.InnerTransaction);
indexDef = DocsSchema.FixedSizeIndexes[AllDocsEtagsSlice];
}

return table.GetNumberOfEntriesAfter(indexDef, afterEtag, out totalCount, overallDuration);
}

public long GetNumberOfDocuments()
{
using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
Expand Down
14 changes: 9 additions & 5 deletions src/Raven.Server/Documents/Indexes/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3062,13 +3062,17 @@ private void UpdateIndexProgress(QueryOperationContext queryContext, IndexProgre
internal virtual void UpdateProgressStats(QueryOperationContext queryContext, IndexProgress.CollectionStats progressStats, string collectionName,
Stopwatch overallDuration)
{
progressStats.NumberOfItemsToProcess +=
DocumentDatabase.DocumentsStorage.GetNumberOfDocumentsToProcess(
queryContext.Documents, collectionName, progressStats.LastProcessedItemEtag, out var totalCount, overallDuration);
progressStats.NumberOfItemsToProcess += collectionName == Constants.Documents.Collections.AllDocumentsCollection
? DocumentDatabase.DocumentsStorage.GetNumberOfDocumentsToProcess(
queryContext.Documents, progressStats.LastProcessedItemEtag, out var totalCount, overallDuration)
: DocumentDatabase.DocumentsStorage.GetNumberOfDocumentsToProcess(
queryContext.Documents, collectionName, progressStats.LastProcessedItemEtag, out totalCount, overallDuration);
progressStats.TotalNumberOfItems += totalCount;

progressStats.NumberOfTombstonesToProcess +=
DocumentDatabase.DocumentsStorage.GetNumberOfTombstonesToProcess(
progressStats.NumberOfTombstonesToProcess += collectionName == Constants.Documents.Collections.AllDocumentsCollection
? DocumentDatabase.DocumentsStorage.GetNumberOfTombstonesToProcess(
queryContext.Documents, progressStats.LastProcessedTombstoneEtag, out totalCount, overallDuration)
: DocumentDatabase.DocumentsStorage.GetNumberOfTombstonesToProcess(
queryContext.Documents, collectionName, progressStats.LastProcessedTombstoneEtag, out totalCount, overallDuration);
progressStats.TotalNumberOfTombstones += totalCount;
}
Expand Down

0 comments on commit 7e79cbd

Please sign in to comment.