/// <summary> /// + /// Only Follower makes it. Clears its current Log /// Clearing /// </summary> /// <param name="logEntryId"></param> public void ClearStateLogStartingFromCommitted() { if (LastCommittedIndex == 0 || LastCommittedIndexTerm == 0) { return; } if (rn.entitySettings.InMemoryEntity) { lock (inMem.Sync) { inMem.Remove( inMem.SelectForwardFromTo(LastCommittedIndex, LastCommittedIndexTerm, false, ulong.MaxValue, ulong.MaxValue).ToList() ); } return; } FlushSleCache(); using (var t = this.rn.db.GetTransaction()) { //Removing from the persisted all keys equal or bigger then suppled Log foreach (var el in t.SelectForwardFromTo <byte[], byte[]>(tblStateLogEntry, new byte[] { 1 }.ToBytes(LastCommittedIndex, LastCommittedIndexTerm), false, new byte[] { 1 }.ToBytes(ulong.MaxValue, ulong.MaxValue), true, true)) { t.RemoveKey <byte[]>(tblStateLogEntry, el.Key); } t.Commit(); } }
/// <summary> /// /// </summary> internal static void test1() { //IndexTermDict<string>.test1(); //Console.ReadLine(); //return; IndexTermDict <string> inMem = new IndexTermDict <string>(); ulong index = 1; ulong term = 1; inMem.Add(index, term, index.ToString() + "_" + term.ToString()); index = 2; term = 1; inMem.Add(index, term, index.ToString() + "_" + term.ToString()); index = 2; term = 2; inMem.Add(index, term, index.ToString() + "_" + term.ToString()); index = 2; term = 3; inMem.Add(index, term, index.ToString() + "_" + term.ToString()); index = 3; term = 2; inMem.Add(index, term, index.ToString() + "_" + term.ToString()); index = 3; term = 1; inMem.Add(index, term, index.ToString() + "_" + term.ToString()); index = 3; term = 3; inMem.Add(index, term, index.ToString() + "_" + term.ToString()); Console.WriteLine("---------------Tests---------------------"); if (inMem.Select(13, 1, out var billy)) { Console.WriteLine(billy); } else { Console.WriteLine("billy not found"); } Console.WriteLine("------------------------------------"); foreach (var el in inMem.SelectForwardFromTo(0, 0, true, 1000, 1000)) { Console.WriteLine($"v: {el.Item3}"); } Console.WriteLine("------------------------------------"); foreach (var el in inMem.SelectForwardFromTo(2, 2, false, 3, 2)) { Console.WriteLine($"v: {el.Item3}"); } //Console.WriteLine("------------------------------------"); //foreach (var el in inMem.SelectBackwardFromTo(3, 2, false, 2, 2)) //{ // Console.WriteLine($"v: {el.Item3}"); //} Console.WriteLine("-----------After deletion-------------------------"); inMem.Remove(inMem.SelectForwardFromTo(2, 2, false, 3, 2).ToList()); foreach (var el in inMem.SelectForwardFromTo(0, 0, true, 1000, 1000)) { Console.WriteLine($"v: {el.Item3}"); } Console.ReadLine(); return; }