Ejemplo n.º 1
0
        internal static void Commit(bool reopenReader = true)
        {
            var gapData       = MissingActivityHandler.GetGapString();
            var gapString     = gapData.Item1;
            var maxActivityId = gapData.Item2;

            //_writerRestartLock.EnterReadLock();
            //try
            //{
            //    _writer.Commit(IndexManager.CreateCommitUserData(maxActivityId, gapString));
            //    if (reopenReader)
            //        ReopenReader();
            //}
            //finally
            //{
            //    _writerRestartLock.ExitReadLock();
            //}
            using (var wrFrame = IndexWriterFrame.Get(false)) // // Commit
            {
                _writer.Commit(IndexManager.CreateCommitUserData(maxActivityId, gapString));
                if (reopenReader)
                {
                    ReopenReader();
                }
            }

            //in case of shutdown, reopen is not needed
            WriteCommitLog("Committed", null, null, null, null, gapString, maxActivityId);

            Interlocked.Exchange(ref _activities, 0);
            _delayCycle = 0;
        }
Ejemplo n.º 2
0
        internal static void CommitOrDelay()
        {
            // set gapsize perfcounters
            MissingActivityHandler.SetGapSizeCounter();

            var act = _activities;

            if (act == 0 && _delayCycle == 0)
            {
                return;
            }

            if (act < 2)
            {
                WriteCommitLog("Start");
                Commit();
                WriteCommitLog("Stop");
            }
            else
            {
                _delayCycle++;
                if (_delayCycle > RepositoryConfiguration.DelayedCommitCycleMaxCount)
                {
                    WriteCommitLog("Start");
                    Commit();
                    WriteCommitLog("Stop");
                }
            }

            Interlocked.Exchange(ref _activities, 0);
        }
Ejemplo n.º 3
0
        internal static void ExecuteLostIndexingActivities()
        {
            lock (_executingUnprocessedIndexingActivitiesLock)
            {
                var gap = MissingActivityHandler.GetOldestGapAndMoveToNext();

                var i = 0;
                while (i * ACTIVITIESFRAGMENTSIZE < gap.Length)
                {
                    var gapSegment = gap.Skip(i * ACTIVITIESFRAGMENTSIZE).Take(ACTIVITIESFRAGMENTSIZE).ToArray();

                    var activities = IndexingActivityManager.GetUnprocessedActivities(gapSegment);
                    if (activities.Length > 0)
                    {
                        foreach (var act in activities)
                        {
                            act.FromHealthMonitor = true;
                            IndexingActivityManager.ExecuteActivity(act, false, false);
                        }
                    }
                    i++;
                }
            }
        }
Ejemplo n.º 4
0
        /*========================================================================================== Commit */

        internal static void ApplyChanges(int activityId)
        {
            MissingActivityHandler.RemoveActivityAndAddGap(activityId);
            ApplyChanges();
        }
Ejemplo n.º 5
0
        //---- Caller: Startup, ForceRestore
        internal static void ExecuteUnprocessedIndexingActivities(System.IO.TextWriter consoleOut)
        {
            lock (_executingUnprocessedIndexingActivitiesLock)
            {
                try
                {
                    _executingUnprocessedIndexingActivities = true;

                    CommitUserData cud;
                    using (var readerFrame = LuceneManager.GetIndexReaderFrame())
                    {
                        cud = IndexManager.ReadCommitUserData(readerFrame.IndexReader);
                    }
                    MissingActivityHandler.MaxActivityId = cud.LastActivityId;
                    MissingActivityHandler.SetGap(cud.Gap);

                    var logProps = new Dictionary <string, object> {
                        { "LastActivityID", cud.LastActivityId }, { "Size of gap", cud.Gap.Count }
                    };
                    Logger.WriteInformation("Executing unprocessed indexing activities from the stored commit point.",
                                            Logger.EmptyCategoryList, logProps);

                    var i        = 0;
                    var sumCount = 0;

                    // This loop was created to avoid loading too many activities at once that are present in the gap.
                    while (i * ACTIVITIESFRAGMENTSIZE <= cud.Gap.Count)
                    {
                        // get activities from the DB that are in the current gap fragment
                        var gapSegment = cud.Gap.Skip(i * ACTIVITIESFRAGMENTSIZE).Take(ACTIVITIESFRAGMENTSIZE).ToArray();
                        var activities = IndexingActivityManager.GetUnprocessedActivities(gapSegment);
                        ProcessTasks(activities, consoleOut);
                        sumCount += activities.Length;
                        i++;
                    }

                    // Execute activities where activity id is bigger than than our last (activity) task id
                    var maxIdInDb = 0;
                    var newtasks  = IndexingActivityManager.GetUnprocessedActivities(MissingActivityHandler.MaxActivityId, out maxIdInDb, ACTIVITIESFRAGMENTSIZE);
                    while (newtasks.Length > 0)
                    {
                        ProcessTasks(newtasks, consoleOut);
                        sumCount += newtasks.Length;

                        //load the remaining activities, but only if they were created before this operation started
                        var tempMax = 0;
                        newtasks = IndexingActivityManager.GetUnprocessedActivities(MissingActivityHandler.MaxActivityId, out tempMax, ACTIVITIESFRAGMENTSIZE, maxIdInDb);
                    }

                    if (consoleOut != null)
                    {
                        consoleOut.WriteLine("ok.");
                    }

                    logProps.Add("Processed tasks", sumCount);

                    //write the latest max activity id and gap size to log
                    logProps["LastActivityID"] = MissingActivityHandler.MaxActivityId;
                    logProps["Size of gap"]    = MissingActivityHandler.GetGap().Count;

                    Logger.WriteInformation("Executing unprocessed tasks is finished.", Logger.EmptyCategoryList, logProps);
                }
                finally
                {
                    _executingUnprocessedIndexingActivities = false;
                }
            }
        }