示例#1
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);
        }
示例#2
0
        public void TreeLock_TSQL_Underscore()
        {
            // 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.

            Test <object>(() =>
            {
                using (TreeLock.Acquire("/Root/A/BxB/C"))
                {
                    TreeLock.AssertFree("/Root/A/B_B");

                    using (TreeLock.Acquire("/Root/A/B_B"))
                    {
                        TreeLock.AssertFree("/Root/A/B_");
                        TreeLock.AssertFree("/Root/A/ByB");
                    }

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

                    Assert.IsTrue(thrown, "#1");

                    return(null);
                }
            });
        }
示例#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
        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;
            }
        }
示例#5
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;
            }
        }
示例#6
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");
                }
            });
        }
示例#7
0
        public void TreeLock_CannotAcquire()
        {
            Test <object>(() =>
            {
                var locks = TreeLock.GetAllLocks();
                Assert.AreEqual(0, locks.Count);

                using (TreeLock.Acquire("/Root/A/B/C"))
                {
                    locks = TreeLock.GetAllLocks();
                    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
                        {
                            TreeLock.Acquire("/Root/A/B/C/D");
                            Assert.Fail($"LockedTreeException was not thrown. Path: {path}");
                        }
                        catch (LockedTreeException)
                        {
                        }

                        locks = TreeLock.GetAllLocks();
                        Assert.AreEqual(1, locks.Count);
                        Assert.IsTrue(locks.ContainsValue("/Root/A/B/C"));
                    }
                }

                return(null);
            });
        }
示例#8
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"));
                    }
                }
            });
        }
示例#9
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (TextBuffer != null)
                {
                    if (Closing != null)
                    {
                        Closing(this, null);
                    }

                    if (TreeUpdateTask != null)
                    {
                        TreeUpdateTask.Dispose();
                        TreeUpdateTask = null;
                    }

                    if (TreeLock != null)
                    {
                        TreeLock.Dispose();
                        TreeLock = null;
                    }

                    TextBuffer.ChangedHighPriority -= OnTextBufferChanged;
                    TextBuffer = null;
                }
            }
        }
示例#10
0
 private bool IsLocked(string path)
 {
     try
     {
         TreeLock.AssertFree(path);
         return(false);
     }
     catch (LockedTreeException)
     {
         return(true);
     }
 }
示例#11
0
        private static async STT.Task <bool> IsLockedAsync(string path, CancellationToken cancellationToken)
        {
            try
            {
                await TreeLock.AssertFreeAsync(cancellationToken, path);

                return(false);
            }
            catch (LockedTreeException)
            {
                return(true);
            }
        }
示例#12
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));
            });
        }
示例#13
0
        public void TreeLock_Release()
        {
            Test <object>(() =>
            {
                var locks = TreeLock.GetAllLocks();
                Assert.AreEqual(0, locks.Count);

                using (TreeLock.Acquire("/Root/A/B/C1"))
                {
                    using (TreeLock.Acquire("/Root/A/B/C2"))
                    {
                        locks = TreeLock.GetAllLocks();
                        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 = TreeLock.GetAllLocks();
                    Assert.AreEqual(1, locks.Count);
                    Assert.IsTrue(locks.ContainsValue("/Root/A/B/C1"));

                    Assert.IsTrue(IsLocked("/Root/A/B/C1/D"));
                    Assert.IsTrue(IsLocked("/Root/A/B/C1"));
                    Assert.IsTrue(IsLocked("/Root/A/B"));
                    Assert.IsTrue(IsLocked("/Root/A"));
                    Assert.IsTrue(IsLocked("/Root"));

                    Assert.IsFalse(IsLocked("/Root/A/B/C2/D"));
                    Assert.IsFalse(IsLocked("/Root/A/B/C2"));
                }
                locks = TreeLock.GetAllLocks();
                Assert.AreEqual(0, locks.Count);

                Assert.IsFalse(IsLocked("/Root/A/B/C1/D"));
                Assert.IsFalse(IsLocked("/Root/A/B/C2/D"));
                Assert.IsFalse(IsLocked("/Root/A/B/C1"));
                Assert.IsFalse(IsLocked("/Root/A/B/C2"));
                Assert.IsFalse(IsLocked("/Root/A/B"));
                Assert.IsFalse(IsLocked("/Root/A"));
                Assert.IsFalse(IsLocked("/Root"));

                return(null);
            });
        }
示例#14
0
        public AstRoot AcquireReadLock(Guid treeUserId)
        {
            if (TreeLock != null)
            {
                if (TreeLock.AcquireReadLock(treeUserId))
                {
                    return(_astRoot);
                }

                Debug.Fail(String.Format(CultureInfo.CurrentCulture, "Unable to acquire read lock for user {0}", treeUserId));
            }

            return(null);
        }
示例#15
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);
            }
        }
示例#16
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);
            }
        }
示例#17
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);
            }
        }
示例#18
0
        public void TreeLock_AcquireAndScope()
        {
            Test(() =>
            {
                using (TreeLock.Acquire("/Root/A/B/C"))
                {
                    var locks = TreeLock.GetAllLocks();
                    Assert.AreEqual(1, locks.Count);
                    Assert.IsTrue(locks.ContainsValue("/Root/A/B/C"));

                    Assert.IsTrue(IsLocked("/Root/A/B/C/D"));
                    Assert.IsTrue(IsLocked("/Root/A/B/C"));
                    Assert.IsTrue(IsLocked("/Root/A/B"));
                    Assert.IsTrue(IsLocked("/Root/A"));
                    Assert.IsTrue(IsLocked("/Root"));

                    Assert.IsFalse(IsLocked("/Root/A/B/X"));
                    Assert.IsFalse(IsLocked("/Root/A/X"));
                    Assert.IsFalse(IsLocked("/Root/X"));
                }
            });
        }
示例#19
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));
                }
            });
        }
示例#20
0
        /// <summary>
        /// {@inheritDoc}
        /// </summary>
        public virtual bool Enter()
        {
            if (Log.isLoggable(PlatformLogger.Level.FINE))
            {
                Log.fine("enter(): blockingEDT=" + KeepBlockingEDT.Get() + ", blockingCT=" + KeepBlockingCT.Get());
            }

            if (!KeepBlockingEDT.CompareAndSet(false, true))
            {
                Log.fine("The secondary loop is already running, aborting");
                return(false);
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final Runnable run = new Runnable()
            Runnable run = new RunnableAnonymousInnerClassHelper(this);

            // We have two mechanisms for blocking: if we're on the
            // dispatch thread, start a new event pump; if we're
            // on any other thread, call wait() on the treelock

            Thread currentThread = Thread.CurrentThread;

            if (currentThread == DispatchThread)
            {
                if (Log.isLoggable(PlatformLogger.Level.FINEST))
                {
                    Log.finest("On dispatch thread: " + DispatchThread);
                }
                if (Interval != 0)
                {
                    if (Log.isLoggable(PlatformLogger.Level.FINEST))
                    {
                        Log.finest("scheduling the timer for " + Interval + " ms");
                    }
                    Timer.Schedule(TimerTask = new TimerTaskAnonymousInnerClassHelper(this), Interval);
                }
                // Dispose SequencedEvent we are dispatching on the the current
                // AppContext, to prevent us from hang - see 4531693 for details
                SequencedEvent currentSE = KeyboardFocusManager.CurrentKeyboardFocusManager.CurrentSequencedEvent;
                if (currentSE != null)
                {
                    if (Log.isLoggable(PlatformLogger.Level.FINE))
                    {
                        Log.fine("Dispose current SequencedEvent: " + currentSE);
                    }
                    currentSE.Dispose();
                }
                // In case the exit() method is called before starting
                // new event pump it will post the waking event to EDT.
                // The event will be handled after the the new event pump
                // starts. Thus, the enter() method will not hang.
                //
                // Event pump should be privileged. See 6300270.
                AccessController.doPrivileged(new PrivilegedActionAnonymousInnerClassHelper(this, run));
            }
            else
            {
                if (Log.isLoggable(PlatformLogger.Level.FINEST))
                {
                    Log.finest("On non-dispatch thread: " + currentThread);
                }
                lock (TreeLock)
                {
                    if (Filter != null)
                    {
                        DispatchThread.AddEventFilter(Filter);
                    }
                    try
                    {
                        EventQueue eq = DispatchThread.EventQueue;
                        eq.PostEvent(new PeerEvent(this, run, PeerEvent.PRIORITY_EVENT));
                        KeepBlockingCT.Set(true);
                        if (Interval > 0)
                        {
                            long currTime = DateTimeHelperClass.CurrentUnixTimeMillis();
                            while (KeepBlockingCT.Get() && ((ExtCondition != null) ? ExtCondition.Evaluate() : true) && (currTime + Interval > DateTimeHelperClass.CurrentUnixTimeMillis()))
                            {
                                Monitor.Wait(TreeLock, TimeSpan.FromMilliseconds(Interval));
                            }
                        }
                        else
                        {
                            while (KeepBlockingCT.Get() && ((ExtCondition != null) ? ExtCondition.Evaluate() : true))
                            {
                                TreeLock.Wait();
                            }
                        }
                        if (Log.isLoggable(PlatformLogger.Level.FINE))
                        {
                            Log.fine("waitDone " + KeepBlockingEDT.Get() + " " + KeepBlockingCT.Get());
                        }
                    }
                    catch (InterruptedException e)
                    {
                        if (Log.isLoggable(PlatformLogger.Level.FINE))
                        {
                            Log.fine("Exception caught while waiting: " + e);
                        }
                    }
                    finally
                    {
                        if (Filter != null)
                        {
                            DispatchThread.RemoveEventFilter(Filter);
                        }
                    }
                    // If the waiting process has been stopped because of the
                    // time interval passed or an exception occurred, the state
                    // should be changed
                    KeepBlockingEDT.Set(false);
                    KeepBlockingCT.Set(false);
                }
            }

            return(true);
        }
示例#21
0
 public override string ToString()
 {
     return(String.Format(CultureInfo.CurrentCulture, "IsDirty: {0} {1} Changes: {2}", IsDirty, TreeLock.ToString(), TreeUpdateTask.ChangesPending));
 }
示例#22
0
 public bool ReleaseWriteLock()
 {
     return(TreeLock.ReleaseWriteLock());
 }
示例#23
0
 public bool AcquireWriteLock()
 {
     return(TreeLock.AcquireWriteLock());
 }
示例#24
0
 public bool ReleaseReadLock(Guid treeUserId)
 {
     return(TreeLock.ReleaseReadLock(treeUserId));
 }
示例#25
0
 /// <summary>
 /// Makes current thread owner of the tree.
 /// Normally only one thread can access the tree.
 /// </summary>
 internal void TakeThreadOwnerShip()
 {
     _ownerThread = Thread.CurrentThread.ManagedThreadId;
     TreeUpdateTask.TakeThreadOwnership();
     TreeLock.TakeThreadOwnership();
 }