Beispiel #1
0
        public static IndexingActivityHistory GetHistory()
        {
            IndexingActivityHistory result;
            var list = new List <IndexingActivityHistoryItem>(_history.Length);

            lock (_lock)
            {
                for (int i = _position; i < _history.Length; i++)
                {
                    if (_history[i] != null)
                    {
                        list.Add(_history[i]);
                    }
                }
                for (int i = 0; i < _position; i++)
                {
                    if (_history[i] != null)
                    {
                        list.Add(_history[i]);
                    }
                }

                result = new IndexingActivityHistory()
                {
                    State  = IndexingActivityQueue.GetCurrentState(),
                    Recent = list.ToArray()
                };
            }
            return(result);
        }
Beispiel #2
0
        public static void ExecuteActivity(LuceneIndexingActivity activity, bool waitForComplete, bool distribute)
        {
            if (distribute)
            {
                activity.Distribute();
            }

            // If there are too many activities in the queue, we have to drop at least the inner
            // data of the activity to prevent memory overflow. We still have to wait for the
            // activity to finish, but the inner data can (and will) be loaded from the db when
            // the time comes for this activity to be executed.
            if (IndexingActivityQueue.IsOverloaded())
            {
                SnTrace.Index.Write("IAQ OVERLOAD drop activity FromPopulator A:" + activity.Id);
                activity.IndexDocumentData = null;
            }

            // all activities must be executed through the activity queue's API
            IndexingActivityQueue.ExecuteActivity(activity);

            if (waitForComplete)
            {
                activity.WaitForComplete();
            }
        }
Beispiel #3
0
 // for testing purposes we need a parameterless method because ElapsedEventArgs has only internal constructor
 private static void Timer_Elapsed()
 {
     if (RepositoryInstance.ContentQueryIsAllowed)
     {
         var timerEnabled = _timer.Enabled;
         _timer.Enabled = false;
         try
         {
             IndexingActivityQueue.HealthCheck();
         }
         catch (Exception ex) // logged
         {
             SnLog.WriteException(ex);
         }
         finally
         {
             _timer.Enabled = timerEnabled;
         }
     }
 }
Beispiel #4
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" : "");

                foreach (LuceneIndexingActivity activity in new IndexingActivityLoader(state.Gaps, false))
                {
                    WaitIfOverloaded();
                    IndexingActivityQueue.ExecuteActivity(activity);
                }
            }

            var lastId     = TerminationHistory.GetLastTerminatedId();
            var lastDbId   = LuceneManager.GetLastStoredIndexingActivityId();
            var newerCount = lastDbId - lastId;

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

                foreach (LuceneIndexingActivity activity in new IndexingActivityLoader(lastId + 1, lastDbId, false))
                {
                    WaitIfOverloaded();
                    IndexingActivityQueue.ExecuteActivity(activity);
                }
            }
        }
Beispiel #5
0
        public static IndexingActivityHistory Reset()
        {
            IndexingActivityHistory result;

            lock (_lock)
            {
                for (int i = 0; i < _history.Length; i++)
                {
                    _history[i] = null;
                }

                _position   = 0;
                _unfinished = 0;

                result = new IndexingActivityHistory()
                {
                    State  = IndexingActivityQueue.GetCurrentState(),
                    Recent = new IndexingActivityHistoryItem[0]
                };
            }
            return(result);
        }
Beispiel #6
0
        private static void Startup(System.IO.TextWriter consoleOut)
        {
            // we positively start the message cluster
            int dummy  = SenseNet.ContentRepository.DistributedApplication.Cache.Count;
            var dummy2 = SenseNet.ContentRepository.DistributedApplication.ClusterChannel;

            if (SenseNet.ContentRepository.RepositoryInstance.RestoreIndexOnStartup())
            {
                BackupTools.RestoreIndex(false, consoleOut);
            }

            CreateWriterAndReader();

            IndexingActivityQueue.Startup(consoleOut);

            Warmup();

            var commitStart = new ThreadStart(CommitWorker);
            var t           = new Thread(commitStart);

            t.Start();

            SnTrace.Index.Write("LM: 'CommitWorker' thread started. ManagedThreadId: {0}", t.ManagedThreadId);
        }
Beispiel #7
0
        private static void WaitIfOverloaded(bool startProcessing = false)
        {
            // We prevent memory overflow by limiting the number of activities that we
            // keep in memory. This method waits for the queue to be able to process
            // new activities.
            var logCount = 1;

            while (IndexingActivityQueue.IsOverloaded())
            {
                // In case of startup, we have to start processing activities that are
                // already in the queue so that new ones can be added later.
                if (startProcessing)
                {
                    DependencyManager.ActivityEnqueued();
                }

                if (logCount++ % 10 == 1)
                {
                    SnTrace.Index.Write("IAQ OVERLOAD waiting {0} milliseconds.", IndexingOverloadWaitingTime * 10);
                }

                Thread.Sleep(IndexingOverloadWaitingTime);
            }
        }
Beispiel #8
0
        private static void ShutDown(bool log)
        {
            if (!_running)
            {
                return;
            }
            if (Paused)
            {
                throw GetPausedException();
            }

            using (var op = SnTrace.Index.StartOperation("LUCENEMANAGER SHUTDOWN"))
            {
                if (_writer != null)
                {
                    _stopCommitWorker = true;

                    lock (_commitLock)
                        Commit(false);

                    using (var op2 = SnTrace.Index.StartOperation("LM.CloseReaders"))
                    {
                        using (var wrFrame = IndexWriterFrame.Get(true)) // // ShutDown
                        {
                            if (_reader != null)
                            {
                                _reader.Close();
                            }
                            if (_writer != null)
                            {
                                _writer.Close();
                            }
                            _running = false;
                        }
                        op2.Successful = true;
                    }
                    op.Successful = true;
                }
            }


            if (log)
            {
                SnLog.WriteInformation("LuceneManager has stopped. Max task id and exceptions: " + IndexingActivityQueue.GetCurrentCompletionState());
            }
        }
Beispiel #9
0
 internal static CompletionState GetCurrent()
 {
     return(IndexingActivityQueue.GetCurrentCompletionState());
 }