예제 #1
0
        public async STT.Task RebuildIndexAsync(Node node, CancellationToken cancellationToken, 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 (await TreeLock.AcquireAsync(cancellationToken, node.Path).ConfigureAwait(false))
                        {
                            foreach (var n in NodeEnumerator.GetNodes(node.Path))
                            {
                                await DataStore.SaveIndexDocumentAsync(node, false, false, CancellationToken.None)
                                .ConfigureAwait(false);
                            }
                        }
                    }
                    else
                    {
                        await TreeLock.AssertFreeAsync(cancellationToken, node.Path).ConfigureAwait(false);

                        await DataStore.SaveIndexDocumentAsync(node, false, false, CancellationToken.None)
                        .ConfigureAwait(false);
                    }
                }
                op.Successful = true;
            }
        }
예제 #2
0
        public async STT.Task TreeLock_TSQL_UnderscoreAsync()
        {
            // This test makes sure that it does not cause a problem if a path
            // contains an underscore. Previously this did not work correctly
            // because the SQL LIKE operator treated it as a special character.

            var token = CancellationToken.None;

            await Test(async() =>
            {
                using (await TreeLock.AcquireAsync(token, "/Root/A/BxB/C"))
                {
                    await TreeLock.AssertFreeAsync(token, "/Root/A/B_B");

                    using (await TreeLock.AcquireAsync(token, "/Root/A/B_B"))
                    {
                        await TreeLock.AssertFreeAsync(token, "/Root/A/B_");
                        await TreeLock.AssertFreeAsync(token, "/Root/A/ByB");
                    }

                    var thrown = false;
                    try
                    {
                        await TreeLock.AssertFreeAsync(token, "/Root/A/BxB");
                    }
                    catch (LockedTreeException)
                    {
                        thrown = true;
                    }

                    Assert.IsTrue(thrown, "#1");
                }
            });
        }
예제 #3
0
        private async STT.Task RebuildIndex_NoRecursiveAsync(Node node, bool databaseAndIndex, CancellationToken cancellationToken)
        {
            await TreeLock.AssertFreeAsync(cancellationToken, node.Path).ConfigureAwait(false);

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

            if (databaseAndIndex)
            {
                foreach (var version in head.Versions.Select(v => Node.LoadNodeByVersionId(v.VersionId)))
                {
                    await DataStore.SaveIndexDocumentAsync(version, false, false, cancellationToken)
                    .ConfigureAwait(false);
                }
            }

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

            await CreateActivityAndExecuteAsync(IndexingActivityType.Rebuild, node.Path, node.Id, 0, 0, versioningInfo,
                                                null, cancellationToken).ConfigureAwait(false);
        }
예제 #4
0
        private static async STT.Task <bool> IsLockedAsync(string path, CancellationToken cancellationToken)
        {
            try
            {
                await TreeLock.AssertFreeAsync(cancellationToken, path);

                return(false);
            }
            catch (LockedTreeException)
            {
                return(true);
            }
        }