Example #1
0
        /// <inheritdoc />
        public void AppendSetData(IPersistedData data, long txtime, byte[] prevData, IMutableStat prevStat)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (prevStat == null)
            {
                throw new ArgumentNullException("prevStat");
            }

            if (this.changelist == null)
            {
                this.changelist = this.createChangeList();
            }

            data.AppendSetData(this.changelist);

            if (this.changelist != null)
            {
                this.changelist.SetTime(txtime);
            }

            if (this.isLockDown)
            {
                return;
            }

            this.RunOnAbort(() =>
            {
                data.Data = prevData;
                data.Stat = prevStat;
            });
        }
Example #2
0
        /// <inheritdoc />
        public void AppendCreate(IPersistedDataFactory <Node> factory, IPersistedData data, long txtime)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (this.changelist == null)
            {
                this.changelist = this.createChangeList();
            }

            data.AppendCreate(this.changelist);

            if (this.changelist != null)
            {
                this.changelist.SetTime(txtime);
            }

            if (this.isLockDown)
            {
                return;
            }

            this.RunOnAbort(() =>
            {
                factory.Delete(data);
            });
        }
Example #3
0
        /// <summary>
        /// Record creation of that this instance of <see cref="IPersistedData"/>.
        /// </summary>
        /// <param name="changeList">The <see cref="IChangeList"/> associated with the creation</param>
        private void OnCreate(IChangeList changeList)
        {
            var list = (ChangeList)changeList;

            PersistenceEventSource.Log.RecordAddition(list.Id, this.Id, this.Name, this.Stat.Czxid);
            list.RecordAdd(this);
        }
Example #4
0
        /// <summary>
        /// Record an update to this instance of <see cref="IPersistedData"/>.
        /// </summary>
        /// <param name="changeList">The <see cref="IChangeList"/> associated with the update</param>
        private void OnUpdate(IChangeList changeList)
        {
            var list = (ChangeList)changeList;

            PersistenceEventSource.Log.RecordUpdate(list.Id, this.Id, this.Name, this.Stat.Mzxid, this.Stat.Pzxid);
            list.RecordUpdate(this);
        }
Example #5
0
        /// <summary>
        /// Record removal of this instance of <see cref="IPersistedData"/>.
        /// </summary>
        /// <param name="changeList">The <see cref="IChangeList"/> associated with the removal</param>
        private void OnRemove(IChangeList changeList)
        {
            var list = (ChangeList)changeList;

            PersistenceEventSource.Log.RecordRemoval(list.Id, this.Id, this.Name);
            list.RecordRemove(this);
        }
Example #6
0
        /// <summary>
        /// Associates an update (where a child was added to this instnace) with the given <see cref="IChangeList"/>.
        /// </summary>
        /// <param name="changeList">The <see cref="IChangeList"/> to associate with</param>
        /// <param name="child">The child that was added</param>
        public void AppendAddChild(IChangeList changeList, IPersistedData child)
        {
            if (child == null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            PersistenceEventSource.Log.PersistedDataAppendAddChild(this.Id, this.Name, child.Id, child.Name);
            this.OnUpdate(changeList);
        }
Example #7
0
        /// <summary>
        ///  Associates the removal of this instance with the given <see cref="IChangeList"/>.
        /// </summary>
        /// <param name="changeList">The <see cref="IChangeList"/> to associate with</param>
        /// <param name="parent">The parent of this instance</param>
        /// <param name="isRecursive">If <c>true</c> the removal was recursive</param>
        public void AppendRemove(IChangeList changeList, IPersistedData parent, bool isRecursive = false)
        {
            PersistenceEventSource.Log.PersistedDataAppendRemove(this.Id, this.Name, isRecursive);

            // Log the change that this node, or the child, is removed.
            this.OnRemove(changeList);

            // Log the change on the parent, including Mzxid/Mtime in stat.
            ((PersistedData)parent).OnUpdate(changeList);
        }
Example #8
0
        /// <inheritdoc />
        public void AppendRemove(IPersistedData parent, IPersistedData child, long txtime, IMutableStat prevChildStat, IMutableStat prevParentStat, Action recordUndeleteAction)
        {
            if (child == null)
            {
                throw new ArgumentNullException("child");
            }

            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }

            if (prevChildStat == null)
            {
                throw new ArgumentNullException("prevChildStat");
            }

            if (prevParentStat == null)
            {
                throw new ArgumentNullException("prevParentStat");
            }

            if (recordUndeleteAction == null)
            {
                throw new ArgumentNullException("recordUndeleteAction");
            }

            if (this.changelist == null)
            {
                this.changelist = this.createChangeList();
            }

            child.AppendRemove(this.changelist, parent);

            if (this.changelist != null)
            {
                this.changelist.SetTime(txtime);
            }

            if (this.isLockDown)
            {
                return;
            }

            this.RunOnAbort(() =>
            {
                this.ValidateLockList(parent, Perm.WRITE, null, Perm.NONE);

                recordUndeleteAction();

                parent.Node.AddChild(child.Node);
                child.Stat  = prevChildStat;
                parent.Stat = prevParentStat;
            });
        }
Example #9
0
        /// <summary>
        /// aborts the changes and locklist if needed
        /// </summary>
        private void CompleteAbortion()
        {
            this.MarkForAbort();

            if (this.changelist != null)
            {
                this.onCommit = null;
                this.changelist.Abort();
                this.changelist = null;
            }

            this.lockCollections.Release();
        }
Example #10
0
 public FilteredChangeList(IChangeList wrappedList, IChangeFilter filter)
 {
     if (wrappedList == null)
     {
         throw new ArgumentNullException(nameof(wrappedList));
     }
     if (filter == null)
     {
         throw new ArgumentNullException(nameof(filter));
     }
     m_WrappedList = wrappedList;
     m_Filter = filter;
 }
Example #11
0
        /// <summary>
        /// Initializes a locklist, enclosing the ability of locking nodes, and creating a "replicated action" underneath
        /// </summary>
        /// <param name="auth">the authorization token</param>
        /// <param name="over">the overrides, optional</param>
        public void Initialize(ISessionAuth auth, IOperationOverrides over)
        {
            // we provision transactions at construction, which means they can commit in a different
            // order than monotonical increasing (if Tx1 starts becore Tx2 but Tx2 finishes before Tx1 does)
            this.SetTxIdAndTime(over);

            this.isLockDown = false;

            this.changelist = null;

            this.onAbort = null;

            this.readonlyInterfaceRequiresLocks = true;

            this.sessionAuth = auth;
        }
Example #12
0
        /// <inheritdoc />
        public void AppendAddChild(IPersistedData parent, IPersistedData child, long txtime, IMutableStat prevStat)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }

            if (child == null)
            {
                throw new ArgumentNullException("child");
            }

            if (prevStat == null)
            {
                throw new ArgumentNullException("prevStat");
            }

            if (this.changelist == null)
            {
                this.changelist = this.createChangeList();
            }

            parent.AppendAddChild(this.changelist, child);
            child.AppendSetParent(parent);

            if (this.changelist != null)
            {
                this.changelist.SetTime(txtime);
            }

            if (this.isLockDown)
            {
                return;
            }

            this.RunOnAbort(() =>
            {
                this.ValidateLockList(parent, Perm.WRITE, null, Perm.NONE);

                parent.Node.RemoveChild(child.Name);
                parent.Stat = prevStat;
            });
        }
Example #13
0
        /// <inheritdoc />
        public void AppendRemoveNodeAndAllChildren(IPersistedData child, long txtime, Action recordUndeleteAction)
        {
            if (child == null)
            {
                throw new ArgumentNullException("child");
            }

            if (recordUndeleteAction != null)
            {
                this.RunOnAbort(recordUndeleteAction);
            }

            if (this.changelist == null)
            {
                this.changelist = this.createChangeList();
            }

            child.AppendRemove(this.changelist, child.Parent, true);

            if (this.changelist != null)
            {
                this.changelist.SetTime(txtime);
            }
        }
Example #14
0
 public bool IncludeInResult(IChangeList changeList) => true;
Example #15
0
 /// <summary>
 /// Appends the remove child operation to the changelist.
 /// </summary>
 /// <param name="chgs">The changelist object, or null if none exists yet.</param>
 /// <param name="child">The child being removed.</param>
 public void AppendRemoveChild(IChangeList chgs, IPersistedData child)
 {
 }
Example #16
0
 /// <summary>
 /// Appends the create.
 /// </summary>
 /// <param name="chgs">The CHGS.</param>
 public void AppendCreate(IChangeList chgs)
 {
 }
Example #17
0
 /// <summary>
 /// Appends the remove.
 /// </summary>
 /// <param name="chgs">The CHGS.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="isRecursive">if true the deletion is recursive</param>
 public void AppendRemove(IChangeList chgs, IPersistedData parent, bool isRecursive = false)
 {
 }
Example #18
0
 /// <summary>
 /// Associates a poison pill with the given <see cref="IChangeList"/>
 /// </summary>
 /// <param name="spec">The poison pill spec</param>
 /// <param name="changeList">The <see cref="IChangeList"/> to associate with</param>
 public void AppendPoison(string spec, IChangeList changeList)
 {
     PersistenceEventSource.Log.PersistedDataAppendPoison(this.Id, this.Name, spec);
 }
Example #19
0
 /// <summary>
 /// Appends the set acl.
 /// </summary>
 /// <param name="chgs">The CHGS.</param>
 public void AppendSetAcl(IChangeList chgs)
 {
 }
Example #20
0
 /// <summary>
 ///  Associates an update (where data was set on this instance) with the given <see cref="IChangeList"/>.
 /// </summary>
 /// <param name="changeList">The <see cref="IChangeList"/> to associate with</param>
 public void AppendSetData(IChangeList changeList)
 {
     PersistenceEventSource.Log.PersistedDataAppendSetData(this.Id, this.Name);
     this.OnUpdate(changeList);
 }
Example #21
0
 /// <summary>
 /// Ensures the data is fresh before reading it. May block the call until it is fresh
 /// </summary>
 /// <param name="chgs">The changelist.</param>
 public void AppendRead(IChangeList chgs)
 {
     PersistenceEventSource.Log.PersistedDataAppendRead(this.Id, this.Name);
 }
Example #22
0
 /// <summary>
 /// Appends the set data.
 /// </summary>
 /// <param name="chgs">The CHGS.</param>
 public void AppendSetData(IChangeList chgs)
 {
 }
Example #23
0
 /// <summary>
 /// Appends a poison pill for this node to the changelist.
 /// </summary>
 /// <param name="spec">Poison pill specification</param>
 /// <param name="chgs">The changelist.</param>
 public void AppendPoison(string spec, IChangeList chgs)
 {
 }
Example #24
0
        /// <summary>
        /// closes this locklist, and commits changes and unlocks all if context gets down to 0
        /// </summary>
        /// <param name="task">async task to indicate the completion of the replication on output</param>
        /// <returns>true if it needs to be disposed</returns>
        public bool Complete(out Task task)
        {
            ManualResetEvent ev = null;

            bool abort = this.IsMarkedForAbort();

            task = Task.FromResult(0);

            try
            {
                // if this is an abort and we are not in the topmost context, lock down this object so nothing else can be done other that unwind and abort
                if (abort)
                {
                    if (this.onAbort != null)
                    {
                        // CAREFUL! this iteration will execute IN REVERSE ORDER. Because elements were inserted each on the first place!!!
                        foreach (Action elem in this.onAbort)
                        {
                            elem();
                        }
                    }

                    if (this.changelist != null)
                    {
                        this.changelist.Abort();
                    }
                }
                else
                {
                    List <Action> actions = this.onCommit;
                    this.onCommit = null;

                    // execute all oncommit actions now
                    if (actions != null)
                    {
                        foreach (Action act in actions)
                        {
                            act();
                        }
                    }

                    if (this.changelist != null && !this.onlyOnEphemeral)
                    {
                        try
                        {
                            if (this.FinishSynchronous)
                            {
                                ev = ManualResetEventPool.InstancePool.GetOne();
                                this.changelist.CommitSync(this.TxId, ev, out task);
                            }
                            else
                            {
                                this.changelist.Commit(this.TxId, out task);
                            }
                        }
                        catch (Exception e)
                        {
                            RmAssert.Fail("Commit failed: " + e);
                        }

                        RingMasterServerInstrumentation.Instance.OnTxCommitted();
                    }
                }
            }
            finally
            {
                // make sure we unlock the tree in all cases
                this.changelist = null;
                this.onAbort    = null;
                this.onCommit   = null;

                this.lockCollections.Release();
            }

            if (ev != null)
            {
                ManualResetEventPool.InstancePool.WaitOneAndReturn(ref ev);
            }

            return(true);
        }
Example #25
0
 /// <summary>
 /// Ensures the data is fresh before reading it. May block the call until it is fresh
 /// </summary>
 /// <param name="chgs">The changelist.</param>
 public void AppendRead(IChangeList chgs)
 {
 }