Esempio n. 1
0
        internal static void HealthCheck()
        {
            if (IsWorking())
            {
                SnTrace.Index.Write("IAQ: Health check triggered but ignored.");
                return;
            }

            SnTrace.Index.Write("IAQ: Health check triggered.");

            var state      = TerminationHistory.GetCurrentState();
            var gapsLength = state.Gaps.Length;

            if (gapsLength > 0)
            {
                SnTrace.IndexQueue.Write("IAQ: Health checker is processing {0} gap{1}.", gapsLength, gapsLength > 1 ? "s" : "");

                var notLoadedIds = state.Gaps.ToList();
                foreach (var indexingActivity in new IndexingActivityLoader(state.Gaps, false))
                {
                    var activity = (IndexingActivityBase)indexingActivity;
                    WaitIfOverloaded();
                    ExecuteActivity(activity);
                    notLoadedIds.Remove(activity.Id);
                }

                if (notLoadedIds.Count > 0)
                {
                    TerminationHistory.RemoveGaps(notLoadedIds);
                    SnTrace.IndexQueue.Write("IAQ: Health checker ignores the following activity ids after processing the gaps: {0}", notLoadedIds);
                }
            }

            var lastId   = TerminationHistory.GetLastTerminatedId();
            var lastDbId = IndexManager.GetLastStoredIndexingActivityId();

            if (lastId < lastDbId)
            {
                SnTrace.IndexQueue.Write("IAQ: Health checker is processing activities from {0} to {1}", (lastId + 1), lastDbId);

                foreach (var indexingActivity in new IndexingActivityLoader(lastId + 1, lastDbId, false))
                {
                    var activity = (IndexingActivityBase)indexingActivity;
                    WaitIfOverloaded();
                    ExecuteActivity(activity);
                }
            }
        }
Esempio n. 2
0
        public static void Startup(System.IO.TextWriter consoleOut)
        {
            // initialize from index
            var cud = IndexManager.IndexingEngine.ReadActivityStatusFromIndexAsync(CancellationToken.None).GetAwaiter().GetResult();

            var gapsLength = cud.Gaps?.Length ?? 0;

            var lastDatabaseId = IndexManager.GetLastStoredIndexingActivityId();

            using (var op = SnTrace.Index.StartOperation("IAQ: InitializeFromIndex. LastIndexedActivityId: {0}, LastDatabaseId: {1}, TotalUnprocessed: {2}"
                                                         , cud.LastActivityId, lastDatabaseId, lastDatabaseId - cud.LastActivityId + gapsLength))
            {
                Startup(lastDatabaseId, cud.LastActivityId, cud.Gaps, consoleOut);

                op.Successful = true;
            }

            IndexHealthMonitor.Start(consoleOut);
        }