Example #1
0
        private static bool ReindexBinaryProperties(int versionId, DateTime timeLimit)
        {
            using (new SystemAccount())
            {
                var node = Node.LoadNodeByVersionId(versionId);
                if (node == null)
                {
                    return(true);
                }

                if (node.VersionModificationDate > timeLimit)
                {
                    Tracer.Write($"SKIP V#{node.VersionId} {node.Version} N#{node.Id} {node.Path}");
                    return(true);
                }

                try
                {
                    Retrier.Retry(3, 2000, typeof(Exception), () =>
                    {
                        var indx = SearchManager.LoadIndexDocumentByVersionId(versionId);
                        DataBackingStore.SaveIndexDocument(node, indx);
                    });
                    Tracer.Write($"Save V#{node.VersionId} {node.Version} N#{node.Id} {node.Path}");
                    return(true);
                }
                catch (Exception e)
                {
                    Tracer.WriteError("Error after 3 attempts: {0}", e);
                    return(false);
                }
            }
        }
Example #2
0
        private void RebuildIndex_NoRecursive(Node node, bool databaseAndIndex)
        {
            TreeLock.AssertFree(node.Path);

            var  head = NodeHead.Get(node.Id);
            bool hasBinary;

            if (databaseAndIndex)
            {
                foreach (var version in head.Versions.Select(v => Node.LoadNodeByVersionId(v.VersionId)))
                {
                    DataBackingStore.SaveIndexDocument(version, false, false, out hasBinary);
                }
            }

            var versioningInfo = new VersioningInfo
            {
                LastDraftVersionId  = head.LastMinorVersionId,
                LastPublicVersionId = head.LastMajorVersionId,
                Delete  = new int[0],
                Reindex = new int[0]
            };

            CreateActivityAndExecute(IndexingActivityType.Rebuild, node.Path, node.Id, 0, 0, null, versioningInfo, null);
        }
Example #3
0
        public void RebuildIndex(Node node, bool recursive = false, IndexRebuildLevel rebuildLevel = IndexRebuildLevel.IndexOnly)
        {
            // do nothing in case of IndexOnly level, because this is a NULL populator
            if (rebuildLevel == IndexRebuildLevel.IndexOnly)
            {
                return;
            }

            using (var op = SnTrace.Index.StartOperation("NullPopulator.RefreshIndex. Version: {0}, VersionId: {1}, recursive: {2}, level: {3}", node.Version, node.VersionId, recursive, rebuildLevel))
            {
                using (new Storage.Security.SystemAccount())
                {
                    if (recursive)
                    {
                        using (TreeLock.Acquire(node.Path))
                        {
                            foreach (var n in NodeEnumerator.GetNodes(node.Path))
                            {
                                DataBackingStore.SaveIndexDocument(n, false, false, out _);
                            }
                        }
                    }
                    else
                    {
                        TreeLock.AssertFree(node.Path);
                        DataBackingStore.SaveIndexDocument(node, false, false, out _);
                    }
                }
                op.Successful = true;
            }
        }
Example #4
0
        public void RebuildIndex(Node node, bool recursive = false, IndexRebuildLevel rebuildLevel = IndexRebuildLevel.IndexOnly)
        {
            if (rebuildLevel == IndexRebuildLevel.IndexOnly)
            {
                return;
            }

            using (var op = SnTrace.Index.StartOperation("NullPopulator.RefreshIndex. Version: {0}, VersionId: {1}, recursive: {2}, level: {3}", node.Version, node.VersionId, recursive, rebuildLevel))
            {
                bool hasBinary;
                using (new SenseNet.ContentRepository.Storage.Security.SystemAccount())
                {
                    if (recursive)
                    {
                        using (SenseNet.ContentRepository.Storage.TreeLock.Acquire(node.Path))
                        {
                            foreach (var n in NodeEnumerator.GetNodes(node.Path))
                            {
                                DataBackingStore.SaveIndexDocument(n, false, false, out hasBinary);
                            }
                        }
                    }
                    else
                    {
                        SenseNet.ContentRepository.Storage.TreeLock.AssertFree(node.Path);
                        DataBackingStore.SaveIndexDocument(node, false, false, out hasBinary);
                    }
                }
                op.Successful = true;
            }
        }
Example #5
0
        private void RefreshIndexDocumentInfoOneNode(Node node)
        {
            var  versionId = node.VersionId;
            bool hasBinary;

            DataBackingStore.SaveIndexDocument(node, false, out hasBinary);
        }
        // caller: IndexPopulator.Populator
        public void RebuildIndexDirectly(string path, IndexRebuildLevel level = IndexRebuildLevel.IndexOnly)
        {
            if (level == IndexRebuildLevel.DatabaseAndIndex)
            {
                using (var op2 = SnTrace.Index.StartOperation("IndexPopulator: Rebuild index documents."))
                {
                    using (new SystemAccount())
                    {
                        var node = Node.LoadNode(path);
                        DataBackingStore.SaveIndexDocument(node, false, false, out _);

                        Parallel.ForEach(NodeQuery.QueryNodesByPath(node.Path, true).Nodes,
                                         n => { DataBackingStore.SaveIndexDocument(n, false, false, out _); });
                    }
                    op2.Successful = true;
                }
            }

            using (var op = SnTrace.Index.StartOperation("IndexPopulator: Rebuild index."))
            {
                IndexManager.IndexingEngine.WriteIndex(
                    new[] { new SnTerm(IndexFieldName.InTree, path) },
                    null,
                    SearchManager.LoadIndexDocumentsByPath(path, IndexManager.GetNotIndexedNodeTypes())
                    .Select(d =>
                {
                    var indexDoc = IndexManager.CompleteIndexDocument(d);
                    OnNodeIndexed(d.Path);
                    return(indexDoc);
                }));
                op.Successful = true;
            }
        }
Example #7
0
        private void RefreshIndexDocumentInfoOneNode(Node node)
        {
            var versionId = node.VersionId;

            DataBackingStore.SaveIndexDocument(node);
            if (RepositoryInstance.ContentQueryIsAllowed)
            {
                ExecuteActivity(CreateActivity(IndexingActivityType.UpdateDocument, node.Id, node.VersionId, node.VersionTimestamp, null, null));//UNDONE: SingleVersion
            }
        }
Example #8
0
        private void RefreshIndexDocumentInfoOneNode(Node node)
        {
            var  versionId = node.VersionId;
            bool hasBinary;

            DataBackingStore.SaveIndexDocument(node, false, out hasBinary);
            if (RepositoryInstance.ContentQueryIsAllowed)
            {
                ExecuteActivity(CreateActivity(IndexingActivityType.UpdateDocument, node.Id, node.VersionId, node.VersionTimestamp, null, null));
            }
        }
Example #9
0
        private void ReindexNode(Node node)
        {
            var indx = DataBackingStore.SaveIndexDocument(node, true, false, out var hasBinary);

            if (hasBinary)
            {
                CreateBinaryReindexTask(node,
                                        indx.IsLastPublic ? 1 : indx.IsLastDraft ? 2 : 3);
            }
            _reindexMetadataProgress++;
        }
Example #10
0
        private static void SaveInitialIndexDocuments()
        {
            LogWriteLine("Create initial index documents.");
            var idSet = DataProvider.LoadIdsOfNodesThatDoNotHaveIndexDocument();
            var nodes = Node.LoadNodes(idSet);

            foreach (var node in nodes)
            {
                DataBackingStore.SaveIndexDocument(node);
                LogWriteLine("    ", node.Path);
            }
            LogWriteLine("Ok.");
        }
Example #11
0
        private static void SaveInitialIndexDocuments()
        {
            LogWriteLine("Create initial index documents.");
            var  idSet = SenseNet.ContentRepository.Storage.Data.DataProvider.LoadIdsOfNodesThatDoNotHaveIndexDocument();
            var  nodes = Node.LoadNodes(idSet);
            bool hasBinary;

            foreach (var node in nodes)
            {
                DataBackingStore.SaveIndexDocument(node, false, out hasBinary);
                LogWriteLine("    ", node.Path);
            }
            LogWriteLine("Ok.");
        }
Example #12
0
        private void RebuildIndex_Recursive(Node node, bool databaseAndIndex)
        {
            using (TreeLock.Acquire(node.Path))
            {
                DeleteTree(node.Path, node.Id);
                if (databaseAndIndex)
                {
                    DataBackingStore.SaveIndexDocument(node, false, false, out _);

                    Parallel.ForEach(NodeQuery.QueryNodesByPath(node.Path, true).Nodes,
                                     n => { DataBackingStore.SaveIndexDocument(n, false, false, out _); });
                }

                AddTree(node.Path, node.Id);
            }
        }
Example #13
0
        protected void SaveInitialIndexDocuments()
        {
            var idSet = DataProvider.LoadIdsOfNodesThatDoNotHaveIndexDocument(0, 11000);
            var nodes = Node.LoadNodes(idSet);

            if (nodes.Count == 0)
            {
                return;
            }

            foreach (var node in nodes)
            {
                // ReSharper disable once UnusedVariable
                DataBackingStore.SaveIndexDocument(node, false, false, out var hasBinary);
            }
        }
Example #14
0
        private void RebuildIndex_Recursive(Node node, bool databaseAndIndex)
        {
            bool hasBinary;

            using (TreeLock.Acquire(node.Path))
            {
                DeleteTree(node.Path, node.Id, true);
                if (databaseAndIndex)
                {
                    foreach (var n in NodeQuery.QueryNodesByPath(node.Path, true).Nodes)
                    {
                        DataBackingStore.SaveIndexDocument(n, false, false, out hasBinary);
                    }
                }
                PopulateTree(node.Path, node.Id);
            }
        }
Example #15
0
            private bool SaveInitialIndexDocuments()
            {
                Log(ImportLogLevel.Progress, "Create initial index documents.");
                var idSet = DataProvider.LoadIdsOfNodesThatDoNotHaveIndexDocument();
                var nodes = Node.LoadNodes(idSet);
                var count = 0;

                foreach (var node in nodes)
                {
                    bool hasBinary;
                    DataBackingStore.SaveIndexDocument(node, false, out hasBinary);
                    Log(ImportLogLevel.Verbose, "  " + node.Path);
                    count++;
                }
                Log(ImportLogLevel.Verbose, "Ok.");
                return(count > 0);
            }
Example #16
0
        private TestLuceneActivity CreateLucActivity(int versionId, bool large)
        {
            var lucActivity = new TestLuceneActivity();

            lucActivity.VersionId = versionId;
            var node        = Node.LoadNodeByVersionId(versionId) as GenericContent;
            var description = "a";

            if (large)
            {
                // create a large description
                var sb  = new StringBuilder();
                var rnd = new Random();
                for (var i = 0; i < 200000; i++)
                {
                    sb.Append(CreateRandomWord(rnd.Next(20)));
                    sb.Append(" ");
                }
                description = sb.ToString();
            }

            node.Description = description;
            node.Save();
            node = Node.LoadNodeByVersionId(versionId) as GenericContent;

            bool hasBinary;

            lucActivity.IndexDocumentData = DataBackingStore.SaveIndexDocument(node, false, out hasBinary);

            if (large)
            {
                Assert.IsTrue(lucActivity.IndexDocumentData.IndexDocumentInfoSize > RepositoryConfiguration.MsmqIndexDocumentSizeLimit, "Created IndexDocument is expected to be large but it is only " + lucActivity.IndexDocumentData.IndexDocumentInfoSize.ToString() + " bytes");
            }
            else
            {
                Assert.IsTrue(lucActivity.IndexDocumentData.IndexDocumentInfoSize < RepositoryConfiguration.MsmqIndexDocumentSizeLimit, "Created IndexDocument is expected to be small but it is " + lucActivity.IndexDocumentData.IndexDocumentInfoSize.ToString() + " bytes");
            }

            return(lucActivity);
        }
Example #17
0
        // caller: IndexPopulator.Populator
        public void RebuildIndexDirectly(string path, IndexRebuildLevel level = IndexRebuildLevel.IndexOnly)
        {
            if (level == IndexRebuildLevel.DatabaseAndIndex)
            {
                using (var op2 = SnTrace.Index.StartOperation("IndexPopulator: Rebuild index documents."))
                {
                    using (new SystemAccount())
                    {
                        foreach (var node in Node.LoadNode(path).LoadVersions())
                        {
                            DataBackingStore.SaveIndexDocument(node, false, false, out _);
                            OnIndexDocumentRefreshed(node.Path, node.Id, node.VersionId, node.Version.ToString());
                        }

                        Parallel.ForEach(NodeQuery.QueryNodesByPath(path, true).Nodes,
                                         n =>
                        {
                            foreach (var node in n.LoadVersions())
                            {
                                DataBackingStore.SaveIndexDocument(node, false, false, out _);
                                OnIndexDocumentRefreshed(node.Path, node.Id, node.VersionId, node.Version.ToString());
                            }
                        });
                    }
                    op2.Successful = true;
                }
            }

            using (var op = SnTrace.Index.StartOperation("IndexPopulator: Rebuild index."))
            {
                IndexManager.IndexingEngine.WriteIndex(
                    new[] { new SnTerm(IndexFieldName.InTree, path) },
                    null,
                    LoadIndexDocumentsByPath(path));
                op.Successful = true;
            }
        }
Example #18
0
        private void RefreshIndexDocumentInfoOneNode(Node node)
        {
            var versionId = node.VersionId;

            DataBackingStore.SaveIndexDocument(node);
        }