diff --git a/src/navigators/smart/paxosatwar/Consensus.java b/src/navigators/smart/paxosatwar/Consensus.java index 27fe37475fcc009e4295b9d491f15a25234c495b..c1724192a66b4d27e22f109f0b6f63c90f1be056 100644 --- a/src/navigators/smart/paxosatwar/Consensus.java +++ b/src/navigators/smart/paxosatwar/Consensus.java @@ -74,12 +74,11 @@ public class Consensus { */ public byte[] getDecision() { - System.out.println("[Consensus.getDecision]"); if(decision == null) { waitForPropose(); decision = decisionRound.propValue; } - System.out.println("[/Consensus.getDecision]"); + return decision; } @@ -89,12 +88,10 @@ public class Consensus { */ public Object getDeserializedDecision() { - System.out.println("[Consensus.getDeserializedDecision]"); if(deserializedDecision == null) { waitForPropose(); deserializedDecision = decisionRound.deserializedPropValue; } - System.out.println("[/Consensus.getDeserializedDecision]"); return deserializedDecision; } diff --git a/src/navigators/smart/paxosatwar/executionmanager/ExecutionManager.java b/src/navigators/smart/paxosatwar/executionmanager/ExecutionManager.java index b6652a9bdd1c61470af07081719a2bcbf9838c78..de3e73f02c7b62f945fcfc379e7f2a2aee9a2483 100644 --- a/src/navigators/smart/paxosatwar/executionmanager/ExecutionManager.java +++ b/src/navigators/smart/paxosatwar/executionmanager/ExecutionManager.java @@ -240,12 +240,10 @@ public final class ExecutionManager { type = ""; break; } - System.out.println("Esta a obter estado? " + isRetrievingState); - Logger.println("Recebi uma mensagem do eid " + consId + " do tipo " + type); - Logger.println("Estou no EID " + currentConsId); - Logger.println("Ultimo EID " + lastConsId); - Logger.println("Paxos highmark " + paxosHighMark); - Logger.println("Revival highmark " + revivalHighMark); + if (isRetrievingState) Logger.println("(ExecutionManager.checkLimits) I'm waiting for a state"); + Logger.println("(ExecutionManager.checkLimits) I received a message for execution " + consId + " of type " + type); + Logger.println("(ExecutionManager.checkLimits) I'm at execution " + currentConsId); + Logger.println("(ExecutionManager.checkLimits) My last las execution is" + lastConsId); boolean canProcessTheMessage = false; @@ -289,8 +287,8 @@ public final class ExecutionManager { consId > (lastConsId + 1) ) { - System.out.println(""); - Logger.println("(ExecutionManager.checkLimits) adding message for execution "+consId+" to out of context"); + + Logger.println("(ExecutionManager.checkLimits) Message for execution "+consId+" is out of context, adding it to out of context set"); //store it as an ahead of time message (out of context) addOutOfContextMessage(msg); } else { @@ -318,8 +316,7 @@ public final class ExecutionManager { //TODO: at this point a new state should be recovered from other correct replicas /** ISTO E CODIGO DO JOAO, PARA TRATAR DA TRANSFERENCIA DE ESTADO */ - System.out.println(""); - Logger.println("(ExecutionManager.checkLimits) adding message for execution "+consId+" to out of context"); + Logger.println("(ExecutionManager.checkLimits) Message for execution "+consId+" is beyond the paxos highmark, adding it to out of context set"); addOutOfContextMessage(msg); tomLayer.requestState(me, getOtherAcceptors(), msg.getSender(), consId); /******************************************************************/ diff --git a/src/navigators/smart/paxosatwar/roles/Acceptor.java b/src/navigators/smart/paxosatwar/roles/Acceptor.java index cb291221b8cd482e4f636316ae39688b178b77f4..326dd09bccf3cf022375659321953049e6e2fc20 100644 --- a/src/navigators/smart/paxosatwar/roles/Acceptor.java +++ b/src/navigators/smart/paxosatwar/roles/Acceptor.java @@ -203,28 +203,27 @@ public class Acceptor { // If message's round is 0, and the sender is the leader for the message's round, // execute the propose int teste = leaderModule.getLeader(eid, msg.getRound()); - System.out.println("Quem e o lider: " + teste); + if (msg.getRound() == 0 && teste == p) { - System.out.println("A executar executePropose (1)"); + executePropose(round, value); } else { Proof proof = (Proof) msg.getProof(); if (proof != null) { - System.out.println("As provas nao estao a nulo"); + // Get valid proofs CollectProof[] collected = verifier.checkValid(eid, msg.getRound() - 1, proof.getProofs()); if (verifier.isTheLeader(p, collected)) { // Is the replica that sent this message the leader? - System.out.println("O proprio lider enviou esta mensagem"); - + leaderModule.addLeaderInfo(eid, msg.getRound(), p); // Is the proposed value good according to the PaW algorithm? if (value != null && (verifier.good(value, collected, true))) { - System.out.println("A executar executePropose (2)"); + executePropose(round, value); } else if (checkAndDiscardConsensus(eid, collected, true)) { leaderModule.addLeaderInfo(eid, 0, p); @@ -237,7 +236,7 @@ public class Acceptor { if (tomLayer.getInExec() == eid + 1) { // Is this message from the previous execution? Execution nextExecution = manager.getExecution(eid + 1); nextExecution.removeRounds(nextRoundNumber - 1); - System.out.println("A executar executePropose (3)"); + executePropose(nextExecution.getRound(nextRoundNumber), value); } else { nextProp = new AcceptedPropose(eid + 1, round.getNumber(), value, proof); @@ -489,7 +488,7 @@ public class Acceptor { execution.lock.lock(); Logger.println("(Acceptor.timeout) timeout for round " + round.getNumber() + " of consensus " + execution.getId()); - System.out.println(round); + //System.out.println(round); if (!round.getExecution().isDecided() && !round.isFrozen() && !round.isRemoved()) { doFreeze(round); diff --git a/src/navigators/smart/statemanagment/StateManager.java b/src/navigators/smart/statemanagment/StateManager.java index cc01d5faa7f25da0b9edfa6f38c6ee594a0eaf0c..85c392729963ac0dbe0eade5db5ec4ef645324d7 100644 --- a/src/navigators/smart/statemanagment/StateManager.java +++ b/src/navigators/smart/statemanagment/StateManager.java @@ -93,7 +93,7 @@ public class StateManager { count++; } } - //System.out.println("Replicas counted for eid " + eid + ": " + count); + return count > f; } public boolean moreThenF_Replies() { diff --git a/src/navigators/smart/tom/core/DeliveryThread.java b/src/navigators/smart/tom/core/DeliveryThread.java index 73dcd874c3652159577c5ccb4ac35150f3a7eb32..a280931d6f3b08e1d0d1090350f3323ecebf4575 100644 --- a/src/navigators/smart/tom/core/DeliveryThread.java +++ b/src/navigators/smart/tom/core/DeliveryThread.java @@ -84,12 +84,12 @@ public class DeliveryThread extends Thread { public void deliverLock() { deliverLock.lock(); - Logger.println("Obti o deliver lock"); + Logger.println("(DeliveryThread.deliverLock) Deliver lock obtained"); } public void deliverUnlock() { deliverLock.unlock(); - Logger.println("Soltei o deliver lock"); + Logger.println("(DeliveryThread.deliverUnlock) Deliver Released"); } public void canDeliver() { @@ -99,14 +99,14 @@ public class DeliveryThread extends Thread { //deliverLock.lock(); - System.out.println("Vou actualizar-me"); + int lastCheckpointEid = state.getLastCheckpointEid(); + int lastEid = state.getLastEid(); - receiver.setState(state.getState()); + Logger.println("(DeliveryThread.update) I'm going to update myself from EID " + lastCheckpointEid + " to EID " + lastEid); - tomLayer.lm.addLeaderInfo(state.getLastCheckpointEid(), state.getLastCheckpointRound(), state.getLastCheckpointLeader()); + receiver.setState(state.getState()); - int lastCheckpointEid = state.getLastCheckpointEid(); - int lastEid = state.getLastEid(); + tomLayer.lm.addLeaderInfo(lastCheckpointEid, state.getLastCheckpointRound(), state.getLastCheckpointLeader()); for (int eid = lastCheckpointEid + 1; eid <= lastEid; eid++) { @@ -351,8 +351,6 @@ public class DeliveryThread extends Thread { if (cons.getId() > 2) { int stableConsensus = cons.getId() - 3; - System.out.println("Last stable consensus: " + stableConsensus); - tomLayer.lm.removeStableConsenusInfos(stableConsensus); tomLayer.execManager.removeExecution(stableConsensus); } @@ -385,9 +383,8 @@ public class DeliveryThread extends Thread { /** ISTO E CODIGO DO JOAO, PARA TRATAR DOS CHECKPOINTS */ - System.out.println("[DeliveryThread.run]"); - System.out.println("Acabei de entregar o batch do EID " + cons.getId()); - System.out.println("[/DeliveryThread.run]"); + Logger.println("(DeliveryThread.run) I just delivered the batch of EID " + cons.getId()); + if (conf.getCheckpoint_period() > 0) { if ((cons.getId() > 0) && ((cons.getId() % conf.getCheckpoint_period()) == 0)) { Logger.println("(DeliveryThread.run) Performing checkpoint for consensus " + cons.getId()); diff --git a/src/navigators/smart/tom/core/OutOfContextMessageThread.java b/src/navigators/smart/tom/core/OutOfContextMessageThread.java index 996de2c34489f934a9151f1b7402fbb1a9a1c734..89c0348267b22cf5ce5f7862e36cf75fe438500f 100644 --- a/src/navigators/smart/tom/core/OutOfContextMessageThread.java +++ b/src/navigators/smart/tom/core/OutOfContextMessageThread.java @@ -34,35 +34,16 @@ public class OutOfContextMessageThread extends Thread { private TOMLayer tomLayer; // TOM layer /** ISTO E CODIGO DO JOAO, PARA TRATAR DA TRANSFERENCIA DE ESTADO */ - private int updateCount = 0; private ReentrantLock outOfContextLock = new ReentrantLock(); - private ReentrantLock updatesLock = new ReentrantLock(); - - public void addUpdate() { - updatesLock.lock(); - updateCount++; - updatesLock.unlock(); - } - - private void removeUpdate() { - updatesLock.lock(); - updateCount--; - updatesLock.unlock(); - } - - private int UpdatesCount() { - updatesLock.lock(); - int value = updateCount; - updatesLock.unlock(); - return value; - } public void OutOfContextLock() { outOfContextLock.lock(); + //Logger.println("(OutOfContextMessageThread.OutOfContextLock) Out of context lock obtained"); } public void OutOfContextUnlock() { outOfContextLock.unlock(); + //Logger.println("(OutOfContextMessageThread.OutOfContextUnlock) Out of context lock released"); } /******************************************************************/ @@ -91,8 +72,6 @@ public class OutOfContextMessageThread extends Thread { if (execution == null || !execution.isDecided()) { /** ISTO E CODIGO DO JOAO, PARA TRATAR DA TRANSFERENCIA DE ESTADO */ - //if (UpdatesCount() > 0) removeUpdate(); - //else if (!outOfContextLock.isLocked()) /******************************************************************/ tomLayer.waitForPaxosToFinish(); diff --git a/src/navigators/smart/tom/core/TOMLayer.java b/src/navigators/smart/tom/core/TOMLayer.java index 29a9a046902db68f2b1e4ff759ed0c5e04aeba85..f5223ec8a994c777495480e4ee20c578eb267f97 100644 --- a/src/navigators/smart/tom/core/TOMLayer.java +++ b/src/navigators/smart/tom/core/TOMLayer.java @@ -910,6 +910,8 @@ public final class TOMLayer extends Thread implements RequestReceiver { lockState.lock(); + Logger.println("(TOMLayer.saveState) Saving state of EID " + lastEid + ", round " + decisionRound + " and leader " + leader); + log.newCheckpoint(state); log.setLastEid(-1); log.setLastCheckpointEid(lastEid); @@ -932,13 +934,17 @@ public final class TOMLayer extends Thread implements RequestReceiver { /************************* TESTE *************************/ lockState.unlock(); + + Logger.println("(TOMLayer.saveState) Finished saving state of EID " + lastEid + ", round " + decisionRound + " and leader " + leader); } public void saveBatch(byte[] batch, int lastEid, int decisionRound, int leader) { StateLog log = stateManager.getLog(); lockState.lock(); - + + Logger.println("(TOMLayer.saveBatch) Saving batch of EID " + lastEid + ", round " + decisionRound + " and leader " + leader); + log.addMessageBatch(batch, decisionRound, leader); log.setLastEid(lastEid); @@ -959,29 +965,33 @@ public final class TOMLayer extends Thread implements RequestReceiver { /************************* TESTE *************************/ lockState.unlock(); + + Logger.println("(TOMLayer.saveBatch) Finished saving batch of EID " + lastEid + ", round " + decisionRound + " and leader " + leader); } /** ISTO E CODIGO DO JOAO, PARA TRATAR DA TRANSFERENCIA DE ESTADO */ public void requestState(int me, int[] otherAcceptors, int sender, int eid) { - /************************* TESTE *************************/ + /************************* TESTE ************************* System.out.println("[TOMLayer.requestState]"); System.out.println("Mensagem adiantada! (eid " + eid + " vindo de " + sender + ") "); /************************* TESTE *************************/ if (stateManager.getWaiting() == -1) { + Logger.println("(TOMLayer.requestState) I'm not waiting for any state, so I will keep record of this message"); stateManager.addEID(sender, eid); - /************************* TESTE *************************/ + /************************* TESTE ************************* System.out.println("Nao estou a espera"); System.out.println("Numero de mensagens recebidas para este EID de replicas diferentes: " + stateManager.moreThenF_EIDs(eid)); /************************* TESTE *************************/ if (stateManager.getLastEID() < eid && stateManager.moreThenF_EIDs(eid)) { - /************************* TESTE *************************/ + Logger.println("(TOMLayer.requestState) I have now more than " + conf.getF() + " messages for EID " + eid + " which are beyond EID " + stateManager.getLastEID()); + /************************* TESTE ************************* System.out.println("Recebi mais de " + conf.getF() + " mensagens para eid " + eid + " que sao posteriores a " + stateManager.getLastEID()); /************************* TESTE *************************/ @@ -992,7 +1002,8 @@ public final class TOMLayer extends Thread implements RequestReceiver { SMMessage smsg = new SMMessage(me, eid - 1, TOMUtil.SM_REQUEST, null); communication.send(otherAcceptors, smsg); - /************************* TESTE *************************/ + Logger.println("(TOMLayer.saveBatch) I just sent a request to the other replicas for the state up to EID " + (eid - 1)); + /************************* TESTE ************************* System.out.println("Enviei um pedido!"); System.out.println("Quem envia: " + smsg.getSender()); @@ -1003,7 +1014,7 @@ public final class TOMLayer extends Thread implements RequestReceiver { /************************* TESTE *************************/ } } - /************************* TESTE *************************/ + /************************* TESTE ************************* System.out.println("[/TOMLayer.requestState]"); /************************* TESTE *************************/ } @@ -1012,7 +1023,8 @@ public final class TOMLayer extends Thread implements RequestReceiver { lockState.lock(); - /************************* TESTE *************************/ + Logger.println("(TOMLayer.SMRequestDeliver) I received a state request for EID " + msg.getEid() + " from replica " + msg.getSender()); + /************************* TESTE ************************* System.out.println("[TOMLayer.SMRequestDeliver]"); System.out.println("Recebi um pedido de estado!"); System.out.println("Estado pedido: " + msg.getEid()); @@ -1025,7 +1037,8 @@ public final class TOMLayer extends Thread implements RequestReceiver { lockState.unlock(); if (state == null) { - /************************* TESTE *************************/ + Logger.println("(TOMLayer.SMRequestDeliver) I don't have the state requested :-("); + /************************* TESTE ************************* System.out.println("Nao tenho o estado pedido!"); /************************* TESTE *************************/ state = new TransferableState(); @@ -1035,20 +1048,21 @@ public final class TOMLayer extends Thread implements RequestReceiver { SMMessage smsg = new SMMessage(execManager.getProcessId(), msg.getEid(), TOMUtil.SM_REPLY, state); communication.send(targets, smsg); - /************************* TESTE *************************/ + Logger.println("(TOMLayer.SMRequestDeliver) I sent the state for checkpoint " + state.getLastCheckpointEid() + " with batches until EID " + state.getLastEid()); + /************************* TESTE ************************* System.out.println("Quem envia: " + smsg.getSender()); System.out.println("Que tipo: " + smsg.getType()); System.out.println("Que EID: " + smsg.getEid()); //System.exit(0); /************************* TESTE *************************/ - /************************* TESTE *************************/ + /************************* TESTE ************************* System.out.println("[/TOMLayer.SMRequestDeliver]"); /************************* TESTE *************************/ } public void SMReplyDeliver(SMMessage msg) { - /************************* TESTE *************************/ + /************************* TESTE ************************* System.out.println("[TOMLayer.SMReplyDeliver]"); System.out.println("Recebi uma resposta de uma replica!"); System.out.println("[reply] Esta resposta tem o estado? " + msg.getState().hasState()); @@ -1070,17 +1084,22 @@ public final class TOMLayer extends Thread implements RequestReceiver { else System.out.println("[reply] Nao ha estado"); /************************* TESTE *************************/ + Logger.println("(TOMLayer.SMReplyDeliver) I received a state reply for EID " + msg.getEid() + " from replica " + msg.getSender()); + if (stateManager.getWaiting() != -1 && msg.getEid() == stateManager.getWaiting()) { - /************************* TESTE *************************/ + /************************* TESTE ************************* System.out.println("A resposta e referente ao eid que estou a espera! (" + msg.getEid() + ")"); /************************* TESTE *************************/ + Logger.println("(TOMLayer.SMReplyDeliver) The reply is for the EID that I want!"); + stateManager.addState(msg.getSender(),msg.getState()); if (stateManager.moreThenF_Replies()) { - /************************* TESTE *************************/ + Logger.println("(TOMLayer.SMReplyDeliver) I have more than " + conf.getF() + " equal replies!"); + /************************* TESTE ************************* System.out.println("Ja tenho mais que " + conf.getF() + " respostas iguais!"); /************************* TESTE *************************/ @@ -1088,7 +1107,7 @@ public final class TOMLayer extends Thread implements RequestReceiver { if (state != null) { - /************************* TESTE *************************/ + /************************* TESTE ************************* System.out.println("As respostas desse estado são validas!"); System.out.println("[state] Esta resposta tem o estado? " + state.hasState()); @@ -1112,10 +1131,13 @@ public final class TOMLayer extends Thread implements RequestReceiver { //System.exit(0); /************************* TESTE *************************/ + Logger.println("(TOMLayer.SMReplyDeliver) The state of those replies is good!"); + lockState.lock(); + stateManager.getLog().update(state); - /************************* TESTE *************************/ + /************************* TESTE ************************* System.out.println("[log] Estado pedido: " + msg.getEid()); System.out.println("[log] EID do ultimo checkpoint: " + stateManager.getLog().getLastCheckpointEid()); System.out.println("[log] EID do ultimo batch recebido: " + stateManager.getLog().getLastEid()); @@ -1135,18 +1157,18 @@ public final class TOMLayer extends Thread implements RequestReceiver { lockState.unlock(); - System.out.println("Desbloqueei o lock para o log do estado"); + //System.out.println("Desbloqueei o lock para o log do estado"); dt.deliverLock(); - System.out.println("Bloqueei o lock entre esta thread e a delivery thread"); + //System.out.println("Bloqueei o lock entre esta thread e a delivery thread"); ot.OutOfContextLock(); - System.out.println("Bloqueei o lock entre esta thread e a out of context thread"); + //System.out.println("Bloqueei o lock entre esta thread e a out of context thread"); stateManager.setWaiting(-1); - System.out.println("Ja nao estou a espera de nenhum estado, e vou actualizar-me"); + //System.out.println("Ja nao estou a espera de nenhum estado, e vou actualizar-me"); dt.update(state); @@ -1159,8 +1181,9 @@ public final class TOMLayer extends Thread implements RequestReceiver { } else if ((conf.getN() / 2) < stateManager.getReplies()) { - - /************************* TESTE *************************/ + + Logger.println("(TOMLayer.SMReplyDeliver) I have more than " + conf.getN() + " messages that are no good!"); + /************************* TESTE ************************* System.out.println("Tenho mais de 2F respostas que nao servem para nada!"); //System.exit(0); /************************* TESTE *************************/ @@ -1170,7 +1193,7 @@ public final class TOMLayer extends Thread implements RequestReceiver { } } } - /************************* TESTE *************************/ + /************************* TESTE ************************* System.out.println("[/TOMLayer.SMReplyDeliver]"); /************************* TESTE *************************/ } @@ -1180,7 +1203,7 @@ public final class TOMLayer extends Thread implements RequestReceiver { } public void setNoExec() { - Logger.println("(TOMLayer.setInExec_Update) modifying inExec from " + this.inExecution + " to " + -1); + Logger.println("(TOMLayer.setNoExec) modifying inExec from " + this.inExecution + " to " + -1); proposeLock.lock(); this.inExecution = -1;