コード例 #1
0
ファイル: StateLog.cs プロジェクト: jangocheng/Raft.Net
        public void FlushSleCache()
        {
            if (!rn.entitySettings.DelayedPersistenceIsActive)
            {
                return;
            }



            if (sleCache.Count > 0 || sleCacheIndex > 0 || sleCacheTerm > 0 || sleCacheBusinessLogicIndex > 0)
            {
                rn.VerbosePrint($"{rn.NodeAddress.NodeAddressId}> flushing: {sleCache.Count}");

                using (var t = this.rn.db.GetTransaction())
                {
                    //if (rn.entitySettings.InMemoryEntityStartSyncFromLatestEntity) // for InMemoryEntityStartSyncFromLatestEntity only
                    //{
                    //    var lastSleState = sleCache[sleCacheIndex];
                    //    sleCache.Clear();
                    //    sleCache[sleCacheIndex] = lastSleState;

                    //    if (sleCacheIndex > 0 && sleCacheTerm > 0)
                    //        t.Insert<byte[], byte[]>(tblStateLogEntry, new byte[] { 2 }, sleCacheIndex.ToBytes(sleCacheTerm));

                    //    if (sleCacheBusinessLogicIndex > 0)
                    //        t.Insert<byte[], ulong>(tblStateLogEntry, new byte[] { 3 }, sleCacheBusinessLogicIndex);

                    //    t.Commit();
                    //    return;
                    //}

                    if (sleCache.Count > 0)
                    {
                        foreach (var el in sleCache)
                        {
                            t.Insert <byte[], byte[]>(tblStateLogEntry, new byte[] { 1 }.ToBytes(el.Key, el.Value.Item1), el.Value.Item2.SerializeBiser());
                        }

                        sleCache.Clear();
                    }

                    if (sleCacheIndex > 0 && sleCacheTerm > 0)
                    {
                        t.Insert <byte[], byte[]>(tblStateLogEntry, new byte[] { 2 }, sleCacheIndex.ToBytes(sleCacheTerm));
                    }

                    if (sleCacheBusinessLogicIndex > 0)
                    {
                        t.Insert <byte[], ulong>(tblStateLogEntry, new byte[] { 3 }, sleCacheBusinessLogicIndex);
                    }

                    sleCacheIndex = 0;
                    sleCacheTerm  = 0;
                    sleCacheBusinessLogicIndex = 0;

                    t.Commit();
                }
            }
        }
コード例 #2
0
        public void FlushSleCache()
        {
            if (!rn.nodeSettings.DelayedPersistenceIsActive)
            {
                return;
            }

            if (sleCache.Count > 0 || sleCacheIndex > 0 || sleCacheTerm > 0 || sleCacheBusinessLogicIndex > 0)
            {
                rn.VerbosePrint($"{rn.NodeAddress.NodeAddressId}> flushing: {sleCache.Count}");

                using (var t = db.GetTransaction())
                {
                    if (sleCache.Count > 0)
                    {
                        foreach (var el in sleCache)
                        {
                            t.Insert <byte[], byte[]>(tblStateLogEntry, new byte[] { 1 }.ToBytes(el.Key, el.Value.Item1), el.Value.Item2.SerializeBiser());
                        }

                        sleCache.Clear();
                    }

                    if (sleCacheIndex > 0 && sleCacheTerm > 0)
                    {
                        t.Insert <byte[], byte[]>(tblStateLogEntry, new byte[] { 2 }, sleCacheIndex.ToBytes(sleCacheTerm));
                    }

                    if (sleCacheBusinessLogicIndex > 0)
                    {
                        t.Insert <byte[], ulong>(tblStateLogEntry, new byte[] { 3 }, sleCacheBusinessLogicIndex);
                    }

                    sleCacheIndex = 0;
                    sleCacheTerm  = 0;
                    sleCacheBusinessLogicIndex = 0;

                    t.Commit();
                }
            }
        }