-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
POC: Feat/make indexing more resiliant #16546
Open
bielu
wants to merge
2
commits into
umbraco:v13/dev
Choose a base branch
from
bielu:feat/make-indexing-more-resiliant
base: v13/dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
30 changes: 30 additions & 0 deletions
30
src/Umbraco.Infrastructure/Examine/IIndexRebuildStatusManager.cs
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Examine; | ||
|
||
namespace Umbraco.Cms.Infrastructure.Examine; | ||
|
||
public interface IIndexRebuildStatusManager | ||
{ | ||
IndexStatus? GetRebuildingIndexStatus(string index); | ||
void SetReindexStatus(IIndex index, IEnumerable<IIndexPopulator> where); | ||
|
||
public void UpdatePopulatorStatus(string index, string populator, bool isRunning, int currentBatch, int totalBatches); | ||
} | ||
|
||
public class IndexStatus | ||
{ | ||
public bool IsRebuilding { get; set; } | ||
public IEnumerable<PopulatorStatus>? PopulatorStatuses { get; set; } | ||
} | ||
|
||
public class PopulatorStatus | ||
{ | ||
public PopulatorStatus(string name) | ||
{ | ||
Name = name; | ||
} | ||
|
||
public string Name { get; set; } | ||
public bool IsRunning { get; set; } | ||
public int CurrentBatch { get; set; } | ||
public int TotalBatches { get; set; } | ||
} |
92 changes: 92 additions & 0 deletions
92
src/Umbraco.Infrastructure/Examine/IndexRebuildStatusManager.cs
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using Examine; | ||
|
||
namespace Umbraco.Cms.Infrastructure.Examine; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class IndexRebuildStatusManager : IIndexRebuildStatusManager | ||
{ | ||
private readonly IExamineManager _examineManager; | ||
IDictionary<string, IndexStatus> _rebuildingStatus = new Dictionary<string, IndexStatus>(); | ||
|
||
public IndexRebuildStatusManager(IExamineManager examineManager) | ||
{ | ||
_examineManager = examineManager; | ||
foreach (var index in examineManager.Indexes) | ||
{ | ||
_rebuildingStatus.Add(index.Name, new IndexStatus()); | ||
} | ||
} | ||
|
||
public IndexStatus? GetRebuildingIndexStatus(string index) => | ||
_rebuildingStatus.TryGetValue(index, out var status) ? status : null; | ||
|
||
public void SetReindexStatus(IIndex index, IEnumerable<IIndexPopulator> where) | ||
{ | ||
if (!_rebuildingStatus.TryGetValue(index.Name, out var status)) | ||
{ | ||
status = new IndexStatus(); | ||
_rebuildingStatus.Add(index.Name, status); | ||
} | ||
|
||
status.IsRebuilding = true; | ||
status.PopulatorStatuses = where.Select(x => new PopulatorStatus(x.GetType().Name)); | ||
} | ||
|
||
public void UpdatePopulatorStatus( | ||
string index, | ||
string populator, | ||
bool isRunning, | ||
int currentBatch, | ||
int totalBatches) | ||
{ | ||
var examineIndex = _examineManager.GetIndex(index); | ||
|
||
if (_rebuildingStatus.TryGetValue(index, out var status)) | ||
{ | ||
var populatorStatus = status?.PopulatorStatuses?.FirstOrDefault(x => x.Name == populator); | ||
if (populatorStatus != null) | ||
{ | ||
populatorStatus.IsRunning = isRunning; | ||
populatorStatus.CurrentBatch = currentBatch; | ||
populatorStatus.TotalBatches = totalBatches; | ||
} | ||
|
||
examineIndex.IndexItems( | ||
[ | ||
new ValueSet( | ||
populator, | ||
"populator", | ||
new Dictionary<string, object>() | ||
{ | ||
{ "isRunning", isRunning }, | ||
{ "currentBatch", currentBatch }, | ||
{ "totalBatches", totalBatches } | ||
}) | ||
]); | ||
return; | ||
} | ||
var currentStatus= new IndexStatus(); | ||
_rebuildingStatus.Add(index,currentStatus); | ||
var newPopulatorStatus = new PopulatorStatus(populator) | ||
{ | ||
IsRunning = isRunning, | ||
CurrentBatch = currentBatch, | ||
TotalBatches = totalBatches | ||
}; | ||
currentStatus.PopulatorStatuses = new List<PopulatorStatus> { newPopulatorStatus }; | ||
examineIndex.IndexItems( | ||
[ | ||
new ValueSet( | ||
populator, | ||
"populator", | ||
new Dictionary<string, object>() | ||
{ | ||
{ "isRunning", isRunning }, | ||
{ "currentBatch", currentBatch }, | ||
{ "totalBatches", totalBatches } | ||
}) | ||
]); | ||
} | ||
Check warning on line 91 in src/Umbraco.Infrastructure/Examine/IndexRebuildStatusManager.cs CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v13/dev)❌ New issue: Excess Number of Function Arguments
|
||
} |
Oops, something went wrong.
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.
My recommended approach would be to do this: Shazwazza/Examine#372 (comment)
The only real way to know if the indexing is done in a resilient way would be to have an actual document in the index certifying that rebuilding is successful instead of relying on in-memory cache which is problematic.
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.
@Shazwazza I am not 100% convinced about usage of additional index, as we both know less indexes is actually better with lucene. I am thinking maybe we should use additonal sql table, as it will be eqally resiliant as using index, but it will not require us to create index, what you think?
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.
@bielu Sorry, I probably wasn't clear in my suggestion. We don't want to use an extra index to store any data, we can just use a marker document within the index. For example:
__Populated: y
Then the rebuild checker, just checks if the document count for
__Populated: y
== 1There 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.
@Shazwazza that's make sense now! We can also extend it to check what populator are registered to show how many of them is done! I will make update to this pr
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.
@Shazwazza i started changing implementation of this service to use examine underhood, can you have quick look and check if that is what you had in mind?
as in this way now we can also repeat failed batches (but i think I will need play around little more)