public void Initialize()
        {
            //TODO: Remove this entire check for 8.1.2
            var examineEnabled = _mainDom.Register(() => {});

            if (!examineEnabled)
            {
                return;
            }

            foreach (var index in _pdfIndexCreator.Create())
            {
                //TODO: Remove this block for 8.1.2 since Umbraco will ensure the locks are removed
                if (index is LuceneIndex luceneIndex)
                {
                    var dir = luceneIndex.GetLuceneDirectory();
                    if (IndexWriter.IsLocked(dir))
                    {
                        _logger.Info(typeof(ExaminePdfComponent),
                                     "Forcing index {IndexerName} to be unlocked since it was left in a locked state",
                                     luceneIndex.Name);
                        IndexWriter.Unlock(dir);
                    }
                }

                _examineManager.AddIndex(index);
            }

            MediaCacheRefresher.CacheUpdated += MediaCacheRefresherUpdated;
        }
        /// <summary>
        /// Boots the messenger.
        /// </summary>
        private SyncBootState?InitializeWithMainDom()
        {
            // weight:10, must release *before* the published snapshot service, because once released
            // the service will *not* be able to properly handle our notifications anymore.
            const int weight = 10;

            var registered = _mainDom.Register(
                release: () =>
            {
                lock (_locko)
                {
                    _cancellationTokenSource.Cancel();     // no more syncs
                }

                // Wait a max of 3 seconds and then return, so that we don't block
                // the entire MainDom callbacks chain and prevent the AppDomain from
                // properly releasing MainDom - a timeout here means that one refresher
                // is taking too much time processing, however when it's done we will
                // not update lastId and stop everything.
                var idle = _syncIdle.WaitOne(3000);
                if (idle == false)
                {
                    Logger.LogWarning("The wait lock timed out, application is shutting down. The current instruction batch will be re-processed.");
                }
            },
                weight: weight);

            if (registered == false)
            {
                // return null if we cannot initialize
                return(null);
            }

            return(InitializeColdBootState());
        }
Esempio n. 3
0
        /// <summary>
        /// Used to lazily check if Examine Index handling is enabled
        /// </summary>
        /// <returns></returns>
        private bool IsEnabled()
        {
            //let's deal with shutting down Examine with MainDom
            var examineShutdownRegistered = _mainDom.Register(release: () =>
            {
                using (_profilingLogger.TraceDuration <ExamineUmbracoIndexingHandler>("Examine shutting down"))
                {
                    _examineManager.Dispose();
                }
            });

            if (!examineShutdownRegistered)
            {
                _logger.LogInformation("Examine shutdown not registered, this AppDomain is not the MainDom, Examine will be disabled");

                //if we could not register the shutdown examine ourselves, it means we are not maindom! in this case all of examine should be disabled!
                Suspendable.ExamineEvents.SuspendIndexers(_logger);
                return(false); //exit, do not continue
            }

            _logger.LogDebug("Examine shutdown registered with MainDom");

            var registeredIndexers = _examineManager.Indexes.OfType <IUmbracoIndex>().Count(x => x.EnableDefaultEventHandler);

            _logger.LogInformation("Adding examine event handlers for {RegisteredIndexers} index providers.", registeredIndexers);

            // don't bind event handlers if we're not suppose to listen
            if (registeredIndexers == 0)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Lazily populates the stores only when they are first requested
        /// </summary>
        internal void EnsureCaches() => LazyInitializer.EnsureInitialized(
            ref _isReady,
            ref _isReadSet,
            ref _isReadyLock,
            () =>
        {
            // lock this entire call, we only want a single thread to be accessing the stores at once and within
            // the call below to mainDom.Register, a callback may occur on a threadpool thread to MainDomRelease
            // at the same time as we are trying to write to the stores. MainDomRelease also locks on _storesLock so
            // it will not be able to close the stores until we are done populating (if the store is empty)
            lock (_storesLock)
            {
                if (!_options.IgnoreLocalDb)
                {
                    _mainDom.Register(MainDomRegister, MainDomRelease);

                    // stores are created with a db so they can write to it, but they do not read from it,
                    // stores need to be populated, happens in OnResolutionFrozen which uses _localDbExists to
                    // figure out whether it can read the databases or it should populate them from sql

                    _logger.LogInformation("Creating the content store, localContentDbExists? {LocalContentDbExists}", _localContentDbExists);
                    _contentStore = new ContentStore(_publishedSnapshotAccessor, _variationContextAccessor, _loggerFactory.CreateLogger("ContentStore"), _loggerFactory, _publishedModelFactory, _localContentDb);
                    _logger.LogInformation("Creating the media store, localMediaDbExists? {LocalMediaDbExists}", _localMediaDbExists);
                    _mediaStore = new ContentStore(_publishedSnapshotAccessor, _variationContextAccessor, _loggerFactory.CreateLogger("ContentStore"), _loggerFactory, _publishedModelFactory, _localMediaDb);
                }
                else
                {
                    _logger.LogInformation("Creating the content store (local db ignored)");
                    _contentStore = new ContentStore(_publishedSnapshotAccessor, _variationContextAccessor, _loggerFactory.CreateLogger("ContentStore"), _loggerFactory, _publishedModelFactory);
                    _logger.LogInformation("Creating the media store (local db ignored)");
                    _mediaStore = new ContentStore(_publishedSnapshotAccessor, _variationContextAccessor, _loggerFactory.CreateLogger("ContentStore"), _loggerFactory, _publishedModelFactory);
                }

                _domainStore = new SnapDictionary <int, Domain>();

                var okContent = false;
                var okMedia   = false;

                SyncBootState bootState = _syncBootStateAccessor.GetSyncBootState();

                try
                {
                    if (bootState != SyncBootState.ColdBoot && _localContentDbExists)
                    {
                        okContent = LockAndLoadContent(() => LoadContentFromLocalDbLocked(true));
                        if (!okContent)
                        {
                            _logger.LogWarning("Loading content from local db raised warnings, will reload from database.");
                        }
                    }

                    if (bootState != SyncBootState.ColdBoot && _localMediaDbExists)
                    {
                        okMedia = LockAndLoadMedia(() => LoadMediaFromLocalDbLocked(true));
                        if (!okMedia)
                        {
                            _logger.LogWarning("Loading media from local db raised warnings, will reload from database.");
                        }
                    }

                    if (!okContent)
                    {
                        LockAndLoadContent(() => LoadContentFromDatabaseLocked(true));
                    }

                    if (!okMedia)
                    {
                        LockAndLoadMedia(() => LoadMediaFromDatabaseLocked(true));
                    }

                    LockAndLoadDomains();
                }
                catch (Exception ex)
                {
                    _logger.LogCritical(ex, "Panic, exception while loading cache data.");
                    throw;
                }

                return(true);
            }
        });