Skip to content

Commit 2f1b057

Browse files
author
0x000001A4
committed
Checkpoint submitted version
1 parent 0bbfeb2 commit 2f1b057

8 files changed

Lines changed: 48 additions & 18 deletions

File tree

BankServer/INSTRUCTIONS.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## How to run
2+
3+
1 - Open the solution with Visual Studio (the solution is inside BoneyBank folder), and build it.
4+
2 - Right click over PuppetMaster and start a new instance.
5+
All terminals (3 boney and 1 Bank) should be opened.
6+
7+
## What was implemented
8+
9+
- Any number of Boney servers running Paxos (default config files starts up 3 Boneys)
10+
- 1 Bank (must have processID of 4 in the config files since it was hardcoded for this delivery)
11+
- Periodic compareAndSwap requests sent from Bank to Boneys for each Timer Tick
12+
- Perfect Channels
13+
- Logger printing all messages (Proposers, Acceptors, Learners) for each Boney

BankServer/configuration_sample.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ P 4 bank http://127.0.0.1:10008
55
P 7 client
66
P 8 client
77
S 3
8-
T 12:10:15
8+
T 23:53:30
99
D 5000
10-
F 1 (1, F, NS) (2, N, NS) (3, N, NS) (4, N, NS)
10+
F 1 (1, N, NS) (2, N, NS) (3, N, NS) (4, N, NS)
1111
F 2 (1, N, NS) (2, N, NS) (3, N, NS) (4, N, NS)
1212
F 3 (1, N, NS) (2, N, NS) (3, N, NS) (4, N, NS)

BankServer/domain/SlotTimer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public SlotTimer(IUpdatable updatable, uint slotDuration, string initialTime)
1818
DateTime dateTime = DateTime.ParseExact(initialTime, "HH:mm:ss",
1919
CultureInfo.InvariantCulture);
2020
var span = dateTime - DateTime.Now;
21-
//if (span.TotalMilliseconds < 0) throw new Exception("The starting time in configuration file must be after the current time."); DECOMENT WHEN NOT DEBUGGING!!!!!
22-
_clock = new System.Timers.Timer() { Interval = 1/*span.TotalMilliseconds*/, AutoReset = false };
21+
if (span.TotalMilliseconds < 0) throw new Exception("The starting time in configuration file must be after the current time."); // DECOMENT WHEN NOT DEBUGGING!!!!!
22+
_clock = new System.Timers.Timer() { Interval = span.TotalMilliseconds, AutoReset = false };
2323
_updatable = updatable;
2424
_slotDuration = slotDuration;
2525
}

BoneyServer/configuration_sample.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ P 4 bank http://127.0.0.1:10008
55
P 7 client
66
P 8 client
77
S 3
8-
T 12:10:15
8+
T 23:53:30
99
D 5000
10-
F 1 (1, F, NS) (2, N, NS) (3, N, NS) (4, N, NS)
10+
F 1 (1, N, NS) (2, N, NS) (3, N, NS) (4, N, NS)
1111
F 2 (1, N, NS) (2, N, NS) (3, N, NS) (4, N, NS)
12-
F 3 (1, N, NS) (2, N, NS) (3, N, NS) (4, N, NS)
12+
F 3 (1, N, NS) (2, N, NS) (3, N, NS) (4, N, NS)

BoneyServer/domain/SlotTimer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public SlotTimer(IUpdatable updatable, uint slotDuration, string initialTime)
1818
DateTime dateTime = DateTime.ParseExact(initialTime, "HH:mm:ss",
1919
CultureInfo.InvariantCulture);
2020
var span = dateTime - DateTime.Now;
21-
//if (span.TotalMilliseconds < 0) throw new Exception("The starting time in configuration file must be after the current time."); DECOMENT WHEN NOT DEBUGGING!!!!!
22-
_clock = new System.Timers.Timer() { Interval = 1/*span.TotalMilliseconds*/, AutoReset = false };
21+
if (span.TotalMilliseconds < 0) throw new Exception("The starting time in configuration file must be after the current time."); // DECOMENT WHEN NOT DEBUGGING!!!!!
22+
_clock = new System.Timers.Timer() { Interval = span.TotalMilliseconds, AutoReset = false };
2323
_updatable = updatable;
2424
_slotDuration = slotDuration;
2525

BoneyServer/domain/paxos/Paxos.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ internal class Paxos : IMultiPaxos
3434
private uint? _leaderProcessID; // The process it suspects to be the leader
3535
private List<string> _boneyAdress;
3636

37-
public static uint Instance { get; set; }
37+
private uint Instance { get; set; } = 0;
3838

3939
public Paxos(uint sourceProcessID, uint numOfSlots, List<string> boneysAdress)
4040
{
41-
Instance = 0;
4241
_numberOfBoneyServers = boneysAdress.Count();
4342
_sourceLeaderNumber = sourceProcessID;
4443
_sourceProcessID = sourceProcessID;
@@ -63,7 +62,6 @@ public Paxos(uint sourceProcessID, uint numOfSlots, List<string> boneysAdress)
6362

6463
public void Start(PaxosValue value, string address, uint primary)
6564
{
66-
Logger.LogDebug($"Antes do lock");
6765
lock (this)
6866
{
6967
uint slot = value.Slot;
@@ -200,12 +198,18 @@ private bool iAmLeader() {
200198

201199
private void createInstancesUpTo(uint instance)
202200
{
203-
int currentSize = _paxosInstances.Count();
204-
int instancesToAdd = (int)instance - currentSize + 1;
205-
Instance += (uint)instancesToAdd;
206-
for (int i = 0; i < instancesToAdd; i++)
201+
lock(this)
207202
{
208-
_paxosInstances.Add(new PaxosInstance());
203+
int currentSize = _paxosInstances.Count();
204+
int instancesToAdd = (int)instance - currentSize + 1;
205+
if (instancesToAdd > 0)
206+
{
207+
Instance += (uint)instancesToAdd;
208+
for (int i = 0; i < instancesToAdd; i++)
209+
{
210+
_paxosInstances.Add(new PaxosInstance());
211+
}
212+
}
209213
}
210214
}
211215
}

INSTRUCTIONS.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## How to run
2+
3+
1 - Open the solution with Visual Studio (the solution is inside BoneyBank folder), and build it.
4+
2 - Right click over PuppetMaster and start a new instance.
5+
All terminals (3 boney and 1 Bank) should be opened.
6+
7+
## What was implemented
8+
9+
- Any number of Boney servers running Paxos (default config files starts up 3 Boneys)
10+
- 1 Bank (must have processID of 4 in the config files since it was hardcoded for this delivery)
11+
- Periodic compareAndSwap requests sent from Bank to Boneys for each Timer Tick
12+
- Logger printing all messages (Proposers, Acceptors, Learners) for each Boney
13+
- Perfect channels between BankServer and BoneyServers that assure that frozen process receive messages later and respond to senders

PuppetMaster/configuration_sample.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ P 5 bank http://127.0.0.1:10008
66
P 7 client
77
P 8 client
88
S 3
9-
T 12:10:15
9+
T 23:53:30
1010
D 5000
1111
F 1 (1, N, NS) (2, F, S) (3, N, NS) (4, N, NS) (5, N, NS)
1212
F 2 (1, N, NS) (2, F, S) (3, N, NS) (4, F, NS) (5, N, NS)

0 commit comments

Comments
 (0)