-
Notifications
You must be signed in to change notification settings - Fork 48
Check for RavenDB index errors and delay start until no stale indexes #2485
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
Closed
ramonsmits
wants to merge
3
commits into
ravendb-health-reporter
from
prevent-or-delay-start-when-index-issues
Closed
Changes from all commits
Commits
Show all changes
3 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| namespace ServiceControl.Infrastructure.RavenDB | ||
| { | ||
| using System; | ||
| using System.Text; | ||
| using System.Threading; | ||
| using NServiceBus.Logging; | ||
| using Raven.Abstractions.Data; | ||
| using Raven.Client.Embedded; | ||
| using Raven.Database; | ||
| using Raven.Json.Linq; | ||
|
|
||
|
|
@@ -16,5 +19,48 @@ public static void Query<TState>(this DocumentDatabase db, string index, IndexQu | |
| onItem(doc, state); | ||
| } | ||
| } | ||
|
|
||
| public static void ThrowWhenIndexErrors(this EmbeddableDocumentStore documentStore) | ||
| { | ||
| var statistics = documentStore.DatabaseCommands.GetStatistics(); | ||
|
|
||
| if (statistics.Errors.Length > 0) | ||
| { | ||
| var text = new StringBuilder(); | ||
| text.AppendLine("Detected RavenDB index errors, please start maintenance mode and resolve the following issues:"); | ||
| foreach (var indexError in statistics.Errors) | ||
| { | ||
| text.AppendLine($"- Index [{indexError.IndexName}] error: {indexError.Error} (Action: {indexError.Action}, Doc: {indexError.Document}, At: {indexError.Timestamp})"); | ||
| } | ||
| throw new Exception(text.ToString()); | ||
|
Member
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. should we consider creating a specific exception? Something like "RavenDBHasStaleIndexes"? |
||
| } | ||
| } | ||
|
|
||
| public static void WaitUntilNoStaleIndexes(this EmbeddableDocumentStore documentStore) | ||
| { | ||
| var interval = TimeSpan.FromMinutes(1); | ||
| var next = DateTime.MinValue; | ||
| string[] staleIndexes; | ||
|
|
||
| // Check for the number of stale indexes every second, but report only an update only every 1 minutes | ||
| while ((staleIndexes = documentStore.DatabaseCommands.GetStatistics().StaleIndexes).Length > 0) | ||
| { | ||
| var now = DateTime.UtcNow; | ||
| if (next < now) | ||
| { | ||
| var text = new StringBuilder(); | ||
| text.AppendLine("Stale indexes detected, delaying start until all indexes are non-stale. DO NOT KILL THIS PROCESS! Operation can run for a very long time!"); | ||
| foreach (var staleIndex in staleIndexes) | ||
| { | ||
| text.AppendLine($"- {staleIndex}"); | ||
| } | ||
| Log.Warn(text.ToString()); | ||
| next = now + interval; | ||
| } | ||
| Thread.Sleep(1000); | ||
| } | ||
| } | ||
|
|
||
| static ILog Log = LogManager.GetLogger(typeof(Extensions).Namespace); | ||
| } | ||
| } | ||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.