Beispiel #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;
            }
        }
Beispiel #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");
                }
            });
        }
Beispiel #3
0
        public async STT.Task TreeLock_CannotAcquireAsync()
        {
            var token = CancellationToken.None;

            await Test(async() =>
            {
                var locks = await TreeLock.GetAllLocksAsync(token);
                Assert.AreEqual(0, locks.Count);

                using (await TreeLock.AcquireAsync(token, "/Root/A/B/C"))
                {
                    locks = await TreeLock.GetAllLocksAsync(token);
                    Assert.AreEqual(1, locks.Count);
                    Assert.IsTrue(locks.ContainsValue("/Root/A/B/C"));

                    foreach (var path in new[] { "/Root/A/B/C/D", "/Root/A/B/C", "/Root/A/B", "/Root/A", "/Root" })
                    {
                        try
                        {
                            await TreeLock.AcquireAsync(token, "/Root/A/B/C/D");
                            Assert.Fail($"LockedTreeException was not thrown. Path: {path}");
                        }
                        catch (LockedTreeException)
                        {
                        }

                        locks = await TreeLock.GetAllLocksAsync(token);
                        Assert.AreEqual(1, locks.Count);
                        Assert.IsTrue(locks.ContainsValue("/Root/A/B/C"));
                    }
                }
            });
        }
Beispiel #4
0
        public async STT.Task TreeLock_ReleaseAsync()
        {
            var token = CancellationToken.None;

            await Test(async() =>
            {
                var locks = await TreeLock.GetAllLocksAsync(token);
                Assert.AreEqual(0, locks.Count);

                using (await TreeLock.AcquireAsync(token, "/Root/A/B/C1"))
                {
                    using (await TreeLock.AcquireAsync(token, "/Root/A/B/C2"))
                    {
                        locks = await TreeLock.GetAllLocksAsync(token);
                        Assert.AreEqual(2, locks.Count);
                        Assert.IsTrue(locks.ContainsValue("/Root/A/B/C1"));
                        Assert.IsTrue(locks.ContainsValue("/Root/A/B/C2"));

                        Assert.IsTrue(IsLocked("/Root/A/B/C1/D"));
                        Assert.IsTrue(IsLocked("/Root/A/B/C2/D"));
                        Assert.IsTrue(IsLocked("/Root/A/B/C1"));
                        Assert.IsTrue(IsLocked("/Root/A/B/C2"));
                        Assert.IsTrue(IsLocked("/Root/A/B"));
                        Assert.IsTrue(IsLocked("/Root/A"));
                        Assert.IsTrue(IsLocked("/Root"));
                    }
                    locks = await TreeLock.GetAllLocksAsync(token);
                    Assert.AreEqual(1, locks.Count);
                    Assert.IsTrue(locks.ContainsValue("/Root/A/B/C1"));

                    Assert.IsTrue(await IsLockedAsync("/Root/A/B/C1/D", token));
                    Assert.IsTrue(await IsLockedAsync("/Root/A/B/C1", token));
                    Assert.IsTrue(await IsLockedAsync("/Root/A/B", token));
                    Assert.IsTrue(await IsLockedAsync("/Root/A", token));
                    Assert.IsTrue(await IsLockedAsync("/Root", token));

                    Assert.IsFalse(await IsLockedAsync("/Root/A/B/C2/D", token));
                    Assert.IsFalse(await IsLockedAsync("/Root/A/B/C2", token));
                }
                locks = await TreeLock.GetAllLocksAsync(token);
                Assert.AreEqual(0, locks.Count);

                Assert.IsFalse(await IsLockedAsync("/Root/A/B/C1/D", token));
                Assert.IsFalse(await IsLockedAsync("/Root/A/B/C2/D", token));
                Assert.IsFalse(await IsLockedAsync("/Root/A/B/C1", token));
                Assert.IsFalse(await IsLockedAsync("/Root/A/B/C2", token));
                Assert.IsFalse(await IsLockedAsync("/Root/A/B", token));
                Assert.IsFalse(await IsLockedAsync("/Root/A", token));
                Assert.IsFalse(await IsLockedAsync("/Root", token));
            });
        }
Beispiel #5
0
        private async STT.Task RebuildIndex_RecursiveAsync(Node node, bool databaseAndIndex, CancellationToken cancellationToken)
        {
            using (await TreeLock.AcquireAsync(cancellationToken, node.Path).ConfigureAwait(false))
            {
                await DeleteTreeAsync(node.Path, node.Id, cancellationToken).ConfigureAwait(false);

                if (databaseAndIndex)
                {
                    await DataStore.SaveIndexDocumentAsync(node, false, false, cancellationToken).ConfigureAwait(false);

                    //TODO: [async] make this parallel async (TPL DataFlow TransformBlock)
                    Parallel.ForEach(NodeQuery.QueryNodesByPath(node.Path, true).Nodes,
                                     n => { DataStore.SaveIndexDocumentAsync(node, false, false, CancellationToken.None)
                                            .GetAwaiter().GetResult(); });
                }

                await AddTreeAsync(node.Path, node.Id, cancellationToken).ConfigureAwait(false);
            }
        }
Beispiel #6
0
        public async STT.Task TreeLock_AcquireAndScopeAsync()
        {
            var token = CancellationToken.None;

            await Test(async() =>
            {
                using (await TreeLock.AcquireAsync(CancellationToken.None, "/Root/A/B/C"))
                {
                    var locks = await TreeLock.GetAllLocksAsync(CancellationToken.None);
                    Assert.AreEqual(1, locks.Count);
                    Assert.IsTrue(locks.ContainsValue("/Root/A/B/C"));

                    Assert.IsTrue(await IsLockedAsync("/Root/A/B/C/D", token));
                    Assert.IsTrue(await IsLockedAsync("/Root/A/B/C", token));
                    Assert.IsTrue(await IsLockedAsync("/Root/A/B", token));
                    Assert.IsTrue(await IsLockedAsync("/Root/A", token));
                    Assert.IsTrue(await IsLockedAsync("/Root", token));

                    Assert.IsFalse(await IsLockedAsync("/Root/A/B/X", token));
                    Assert.IsFalse(await IsLockedAsync("/Root/A/X", token));
                    Assert.IsFalse(await IsLockedAsync("/Root/X", token));
                }
            });
        }