Skip to content

Commit a9bebd9

Browse files
committed
Release 1.4
1 parent d5b0377 commit a9bebd9

File tree

22 files changed

+659
-58
lines changed

22 files changed

+659
-58
lines changed

Deployment/!!!Raft.nuspec

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>Raft</id>
5-
<version>1.3.0</version>
5+
<version>1.4.0</version>
66
<title>Raft.NET dotnet consensus algorithm implementation</title>
77
<authors>Alex Solovyov</authors>
88
<owners>tiesky.com / Alex Solovyov</owners>
9-
<licenseUrl>https://github.com/hhblaze/Raft.Net/blob/master/LICENSE</licenseUrl>
9+
<license type="file">LICENSE.txt</license>
1010
<projectUrl>https://github.com/hhblaze/Raft.Net</projectUrl>
1111
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1212
<description>Implementation of the RAFT consensus algorithm among TCP peers with disk or memory persistence</description>
1313
<summary>Raft.NET dotnet consensus algorithm implementation</summary>
14-
<releaseNotes>updated DBreeze, faster Biser.NET decoding</releaseNotes>
14+
<releaseNotes>fixed and optimized In-Memory implementation, added async implementation AddLogEntryAsync</releaseNotes>
1515
<copyright>Copyright © 2018 tiesky.com / Alex Solovyov</copyright>
1616
<language>es-US</language>
1717
<tags>RAFT Raft.NET dotnet dbreeze netcore netstandard net framework</tags>
1818
<dependencies>
19-
<dependency id="DBreeze" version="1.91.4" />
19+
<dependency id="DBreeze" version="1.95.0" />
2020
</dependencies>
2121
</metadata>
2222
<files>
23+
<file src="Raft\LICENSE.txt" target="LICENSE.txt" />
2324
<file src="Raft\bin\Release\Raft.dll" target="lib\net45\Raft.dll" />
2425
<file src="Raft\bin\Release\Raft.xml" target="lib\net45\Raft.xml" />
2526
<file src="Raft\bin\Release-NET47\Raft.dll" target="lib\net47\Raft.dll" />

Deployment/Raft.1.4.0.nupkg

149 KB
Binary file not shown.

Raft/Async/AsyncResponseHandler.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,24 @@ public static byte[] GetMessageId()
2727
return DateTime.UtcNow.To_8_bytes_array().Concat(MessageIdCnt.To_8_bytes_array_BigEndian());
2828
}
2929
}
30+
31+
public static void ResponseCrateCleanUp(object userToken)
32+
{
33+
try
34+
{
35+
DateTime now = DateTime.UtcNow;
36+
37+
foreach (var el in df.Where(r => now.Subtract(r.Value.created).TotalMilliseconds >= r.Value.TimeoutsMs).ToList())
38+
{
39+
el.Value.IsRespOk = false;
40+
el.Value.Set_MRE();
41+
}
42+
43+
}
44+
catch (Exception ex)
45+
{
46+
47+
}
48+
}
3049
}
3150
}

Raft/LICENSE.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
BSD 2-Clause License
2+
3+
Copyright (c) 2018, Alexey Solovyov / tiesky.com
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Raft/RaftNode.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ public RaftNode(RaftEntitySettings settings, DBreezeEngine dbEngine, IRaftComSen
145145
//Starting time master
146146
this.TM = new TimeMaster(log);
147147
//Starting state logger
148-
NodeStateLog = new StateLog(this);
148+
NodeStateLog = new StateLog(this);
149+
150+
//Adding AddLogEntryAsync cleanup
151+
this.TM.FireEventEach(10000, AsyncResponseHandler.ResponseCrateCleanUp, null, false);
149152
}
150153

151154
int disposed = 0;
@@ -172,7 +175,9 @@ public void Dispose()
172175
// db = null;
173176
//}
174177
}
175-
178+
179+
180+
176181

177182
/// <summary>
178183
/// We need this value to calculate majority while leader election

Raft/StateMachine/StateLog.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,8 @@ public void AddToLogFollower(StateLogEntrySuggestion suggestion)
10011001

10021002
}
10031003

1004-
if (this.LastCommittedIndex < rn.LeaderHeartbeat.LastStateLogCommittedIndex)
1004+
//if (this.LastCommittedIndex < rn.LeaderHeartbeat.LastStateLogCommittedIndex)
1005+
if (rn.LeaderHeartbeat != null && this.LastCommittedIndex < rn.LeaderHeartbeat.LastStateLogCommittedIndex)
10051006
{
10061007
rn.SyncronizeWithLeader(true);
10071008
}

Raft/Transport/TcpRaftNode.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,7 @@ public async Task<bool> AddLogEntryAsync(byte[] data, string entityName = "defau
362362

363363
switch(aler.AddResult)
364364
{
365-
case AddLogEntryResult.eAddLogEntryResult.ERROR_OCCURED:
366-
case AddLogEntryResult.eAddLogEntryResult.NO_LEADER_YET:
367-
368-
resp.Dispose_MRE();
369-
AsyncResponseHandler.df.TryRemove(msgIdStr, out resp);
370-
371-
return false;
365+
372366
case AddLogEntryResult.eAddLogEntryResult.LOG_ENTRY_IS_CACHED:
373367
case AddLogEntryResult.eAddLogEntryResult.NODE_NOT_A_LEADER:
374368

@@ -381,18 +375,23 @@ public async Task<bool> AddLogEntryAsync(byte[] data, string entityName = "defau
381375
{
382376
if (resp.IsRespOk)
383377
return true;
384-
385-
//return new Tuple<bool, byte[]>(true, resp.res); //???? returning externalId or even nothing
386378
}
387379

388380
break;
389-
381+
default:
382+
//case AddLogEntryResult.eAddLogEntryResult.ERROR_OCCURED:
383+
//case AddLogEntryResult.eAddLogEntryResult.NO_LEADER_YET:
384+
385+
resp.Dispose_MRE();
386+
AsyncResponseHandler.df.TryRemove(msgIdStr, out resp);
387+
388+
return false;
390389
}
391390
}
392391

393392
//return new AddLogEntryResult { AddResult = AddLogEntryResult.eAddLogEntryResult.NODE_NOT_FOUND_BY_NAME };
394393
//return new Tuple<bool, byte[]>(false, null);
395-
return true;
394+
return false;
396395
}
397396

398397

Raft/_NodeTest/bin/Debug/Raft.dll

512 Bytes
Binary file not shown.

Raft/_NodeTest/bin/Debug/Raft.pdb

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)