diff --git a/src/main/java/it/unitn/disi/ds1/qtop/Client.java b/src/main/java/it/unitn/disi/ds1/qtop/Client.java index 72b59e3..566e228 100644 --- a/src/main/java/it/unitn/disi/ds1/qtop/Client.java +++ b/src/main/java/it/unitn/disi/ds1/qtop/Client.java @@ -232,8 +232,7 @@ private void onReadAck(@NotNull Utils.ReadValue msg) { ); LOGGER.log( LogLevel.INFO, - "[CLIENT-" + (this.clientId - this.numberOfNodes) + "] read done from node " + getSender() + " of " + - "value " + value + ", local operation id: " + msg.nRequest() + "[CLIENT-" + (this.clientId - this.numberOfNodes) + "] read done from " + Utils.matchNodeID(this.getSender()) + " of " + "value " + value + ", local operation id: " + msg.nRequest() ); } diff --git a/src/main/java/it/unitn/disi/ds1/qtop/Node.java b/src/main/java/it/unitn/disi/ds1/qtop/Node.java index 2164454..ed6ed3a 100644 --- a/src/main/java/it/unitn/disi/ds1/qtop/Node.java +++ b/src/main/java/it/unitn/disi/ds1/qtop/Node.java @@ -553,10 +553,14 @@ private void onTimeOut(@NotNull TimeOut msg) { private void onElection(@NotNull Election msg) { logger.log( LogLevel.DEBUG, - "[NODE-" + this.nodeId + "] received election message from [NODE-" + this.getSender() + "] with " + - "params < e:" + msg.highestEpoch() + ", i:" + msg.highestIteration() + ">, best " + "candidate" - + " received:" + msg.bestCandidateId() + "[NODE-" + this.nodeId + "] received election message from " + Utils.matchNodeID(this.getSender()) + + " with " + "params < e:" + msg.highestEpoch() + ", i:" + msg.highestIteration() + ">, best " + "candidate" + " received:" + msg.bestCandidateId() ); + if (this.crashType == CrashType.NODE_BEFORE_ELECTION_ACK) + { + this.crash(); + return; + } this.tell( this.getSender(), new ElectionACK(), @@ -601,7 +605,7 @@ else if (msg.isBetterThanLocalData( { logger.log( LogLevel.DEBUG, - "[NODE-" + this.nodeId + "] is not going to forward election message from " + this.getSender() + "[NODE-" + this.nodeId + "] is not going to forward election message from " + Utils.matchNodeID(this.getSender()) ); } } @@ -629,6 +633,10 @@ else if (msg.isBetterThanLocalData( ); } } + if (this.crashType == CrashType.NODE_AFTER_ELECTION_MESSAGE) + { + this.crash(); + } } /** @@ -658,6 +666,10 @@ private void startElection() { latest, idDest ); + if (this.crashType == CrashType.NODE_AFTER_ELECTION_MESSAGE) + { + this.crash(); + } } } @@ -673,7 +685,7 @@ private void onElectionAck(ElectionACK msg) { ); logger.log( LogLevel.DEBUG, - "[NODE-" + this.nodeId + "] received election ACK from [NODE-" + this.getSender() + "]" + "[NODE-" + this.nodeId + "] received election ACK from " + Utils.matchNodeID(this.getSender()) ); } @@ -859,6 +871,8 @@ private void onCrashRequest(@NotNull CrashRequest msg) { case NODE_AFTER_WRITE_REQUEST: case NODE_AFTER_VOTE_REQUEST: case NODE_AFTER_VOTE_CAST: + case NODE_BEFORE_ELECTION_ACK: + case NODE_AFTER_ELECTION_MESSAGE: this.crashType = msg.crashType(); logger.log( LogLevel.INFO, diff --git a/src/main/java/it/unitn/disi/ds1/qtop/Simulation.java b/src/main/java/it/unitn/disi/ds1/qtop/Simulation.java index f5168f0..2c1b79e 100644 --- a/src/main/java/it/unitn/disi/ds1/qtop/Simulation.java +++ b/src/main/java/it/unitn/disi/ds1/qtop/Simulation.java @@ -104,8 +104,10 @@ public void addCrashNode(int crashType) { case 2 -> Utils.CrashType.NODE_AFTER_WRITE_REQUEST; case 3 -> Utils.CrashType.NODE_AFTER_VOTE_REQUEST; case 4 -> Utils.CrashType.NODE_AFTER_VOTE_CAST; - case 5 -> Utils.CrashType.COORDINATOR_ON_VOTE_REQUEST; - case 6 -> Utils.CrashType.COORDINATOR_ON_DECISION_RESPONSE; + case 5 -> Utils.CrashType.NODE_BEFORE_ELECTION_ACK; + case 6 -> Utils.CrashType.NODE_AFTER_ELECTION_MESSAGE; + case 7 -> Utils.CrashType.COORDINATOR_ON_VOTE_REQUEST; + case 8 -> Utils.CrashType.COORDINATOR_ON_DECISION_RESPONSE; default -> Utils.CrashType.NO_CRASH; }; // Crash messages are instantaneous diff --git a/src/main/java/it/unitn/disi/ds1/qtop/UserInterface.java b/src/main/java/it/unitn/disi/ds1/qtop/UserInterface.java index 3f1afc0..400e3ec 100644 --- a/src/main/java/it/unitn/disi/ds1/qtop/UserInterface.java +++ b/src/main/java/it/unitn/disi/ds1/qtop/UserInterface.java @@ -106,8 +106,10 @@ public void clientMenu() { System.out.println("2. NODE - After write request"); System.out.println("3. NODE - After vote request received"); System.out.println("4. NODE - After vote casted"); - System.out.println("5. COORDINATOR - During the multicast of a vote request"); - System.out.println("6. COORDINATOR - During the multicast of a decision response"); + System.out.println("5. NODE - Before an election ack is sent"); + System.out.println("6. NODE - After an election message is sent/forwarded"); + System.out.println("7. COORDINATOR - During the multicast of a vote request"); + System.out.println("8. COORDINATOR - During the multicast of a decision response"); int crashType = scanner.nextInt(); controller.crashNode(crashType); break; diff --git a/src/main/java/it/unitn/disi/ds1/qtop/Utils.java b/src/main/java/it/unitn/disi/ds1/qtop/Utils.java index 90fe998..1df4424 100644 --- a/src/main/java/it/unitn/disi/ds1/qtop/Utils.java +++ b/src/main/java/it/unitn/disi/ds1/qtop/Utils.java @@ -6,6 +6,8 @@ import java.io.Serializable; import java.util.HashMap; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Class that contains all the utility classes and messages used by the actors. @@ -149,6 +151,15 @@ public enum CrashType { * Receiver crash after casting a vote. */ NODE_AFTER_VOTE_CAST, + /** + * Receiver crash when a node receives an election message. + * Does NOT reply with an ACK + */ + NODE_BEFORE_ELECTION_ACK, + /** + * Receiver crash after a node sends an Election message. + */ + NODE_AFTER_ELECTION_MESSAGE, /** * Probabilistic crash during a vote request multicast. */ @@ -159,6 +170,31 @@ public enum CrashType { COORDINATOR_ON_DECISION_RESPONSE, } + /** + * Method to match the ID of a node and build a fancy string out of it. + * There are two cases: + *