Exemple #1
0
 private void CommitTo(int newCommitCount)
 {
     serialLock.AssertIsLockedByMe();
     try
     {
         if (commitCount < newCommitCount)
         {
             lastCommit = DateTime.Now;
             LogMinorEvent("Committing " + commitCount + ".." + newCommitCount + ", history length " + log.Count);
             for (int i = commitCount; i < newCommitCount; i++)
             {
                 PrivateEntry e = log[i];
                 if (e == null)
                 {
                     LogMinorEvent("Skipping removed entry at #" + i);
                 }
                 else
                 {
                     if (DebugState != null)
                     {
                         DebugState.SignalExecution(i, e.Entry.Term, this);
                     }
                     if (!e.WasExecuted)
                     {
                         commitCount = Math.Max(commitCount, i + 1);
                         LogMinorEvent("Executing " + e.Entry);
                         e.Execute(this);
                         committed.TryRemove(e.Entry.CommitID);
                     }
                 }
             }
             //Debug.Assert(commitCount == newCommitCount);
             if (IsLeader)
             {
                 Broadcast(new AppendEntries(this));
                 nextActionAt = NextHeartbeat;
             }
         }
     }
     catch (Exception ex)
     {
     }
 }