From fda8e60e740a81a48c6b643fbedfc986c4e57cc0 Mon Sep 17 00:00:00 2001 From: ragnar Date: Mon, 2 Dec 2024 13:55:51 +0100 Subject: [PATCH] remove LogHack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit what part about that name makes someone believe that it should have been used further … ? --- .../src/main/scala/probench/Node.scala | 31 +++++++++---------- .../.jvm/src/test/scala/MembershipSuite.scala | 4 +-- .../experiments/protocols/Membership.scala | 8 +---- .../test/rdts/protocols/MembershipTest.scala | 5 +-- 4 files changed, 19 insertions(+), 29 deletions(-) diff --git a/Modules/Examples/Protocol Benchmarks/src/main/scala/probench/Node.scala b/Modules/Examples/Protocol Benchmarks/src/main/scala/probench/Node.scala index 04b382af4..990b47362 100644 --- a/Modules/Examples/Protocol Benchmarks/src/main/scala/probench/Node.scala +++ b/Modules/Examples/Protocol Benchmarks/src/main/scala/probench/Node.scala @@ -4,7 +4,7 @@ import com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec import probench.data.* import rdts.base.{Bottom, LocalUid, Uid} import rdts.datatypes.experiments.protocols.simplified.Paxos -import rdts.datatypes.experiments.protocols.{LogHack, Membership} +import rdts.datatypes.experiments.protocols.Membership import rdts.dotted.Dotted import rdts.syntax.DeltaBuffer @@ -13,17 +13,16 @@ import scala.util.chaining.scalaUtilChainingOps object Time { - val logger = LogHack(false) - var current: Long = System.nanoTime() - def report(name: => String = ""): Unit = logger.info { - synchronized { - val last = current - current = System.nanoTime() - s"$name took ${(current - last).doubleValue / 1000_000}ms" + def report(name: => String = ""): Unit = if false then + println { + synchronized { + val last = current + current = System.nanoTime() + s"$name took ${(current - last).doubleValue / 1000_000}ms" + } } - } } class Node(val name: Uid, val initialClusterIds: Set[Uid]) { @@ -31,7 +30,6 @@ class Node(val name: Uid, val initialClusterIds: Set[Uid]) { private type ClusterState = Membership[Request, Paxos, Paxos] given localUid: LocalUid = LocalUid(name) - given LogHack = new LogHack(false) val clientDataManager: ProDataManager[ClientNodeState] = ProDataManager[ClientNodeState]( @@ -77,11 +75,12 @@ class Node(val name: Uid, val initialClusterIds: Set[Uid]) { Time.report(s"[$tid] cluster changed") - def timeStep(msg: => String): Unit = Time.logger.info { - val current = last - last = System.nanoTime() - s"[$tid] $msg after ${(last - current).doubleValue / 1000_000}ms" - } + def timeStep(msg: => String): Unit = if false then + println { + val current = last + last = System.nanoTime() + s"[$tid] $msg after ${(last - current).doubleValue / 1000_000}ms" + } val delta = newState.upkeep() val upkept: ClusterState = newState.merge(delta) @@ -129,7 +128,7 @@ class Node(val name: Uid, val initialClusterIds: Set[Uid]) { } timeStep("done") - Time.logger.info(s"[$tid] total ${(System.nanoTime() - start).doubleValue / 1000_000}ms") + if false then println(s"[$tid] total ${(System.nanoTime() - start).doubleValue / 1000_000}ms") } export clientDataManager.addLatentConnection as addClientConnection diff --git a/Modules/RDTs/.jvm/src/test/scala/MembershipSuite.scala b/Modules/RDTs/.jvm/src/test/scala/MembershipSuite.scala index e2da45176..5d512e673 100644 --- a/Modules/RDTs/.jvm/src/test/scala/MembershipSuite.scala +++ b/Modules/RDTs/.jvm/src/test/scala/MembershipSuite.scala @@ -3,7 +3,7 @@ import org.scalacheck.Prop.propBoolean import org.scalacheck.{Arbitrary, Gen, Prop} import rdts.base.{Bottom, Lattice, LocalUid, Uid} import rdts.datatypes.experiments.protocols.simplified.GeneralizedPaxos -import rdts.datatypes.experiments.protocols.{Consensus, LogHack, Membership, simplified} +import rdts.datatypes.experiments.protocols.{Consensus, Membership, simplified} import scala.util.Try class MembershipSuite extends munit.ScalaCheckSuite { @@ -121,7 +121,7 @@ class MembershipSpec[A: Arbitrary, C[_]: Consensus, D[_]: Consensus]( case class Upkeep(id: LocalUid) extends ACommand(id): override def nextLocalState(states: Map[LocalUid, Membership[A, C, D]]): Membership[A, C, D] = - val delta = states(id).upkeep()(using id, LogHack(logging)) + val delta = states(id).upkeep()(using id) Lattice.merge(states(id), delta) override def postCondition(state: State, result: Try[Result]): Prop = diff --git a/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/protocols/Membership.scala b/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/protocols/Membership.scala index c3b856317..ef3f0f007 100644 --- a/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/protocols/Membership.scala +++ b/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/protocols/Membership.scala @@ -7,10 +7,6 @@ import rdts.time.Time import scala.collection.immutable.NumericRange -class LogHack(on: Boolean) { - inline def info(arg: => String): Unit = if on then println(arg) else () -} - case class Membership[A, C[_], D[_]]( counter: Time, membersConsensus: C[Set[Uid]], @@ -65,14 +61,13 @@ case class Membership[A, C[_], D[_]]( def isMember(using LocalUid, Consensus[C], Consensus[D]): Boolean = currentMembers.contains(replicaId) - def upkeep()(using rid: LocalUid, logger: LogHack, cc: Consensus[C], cd: Consensus[D]): Membership[A, C, D] = + def upkeep()(using rid: LocalUid, cc: Consensus[C], cd: Consensus[D]): Membership[A, C, D] = if !isMember then return unchanged // do nothing if we are not a member anymore val newMembers = membersConsensus.merge(membersConsensus.upkeep()) val newInner = innerConsensus.merge(innerConsensus.upkeep()) (newMembers.read, newInner.read) match // member consensus reached -> members have changed case (Some(members), _) => - logger.info { s"Member consensus reached on members $members" } copy( counter = counter + 1, membersConsensus = Consensus[C].empty, @@ -83,7 +78,6 @@ case class Membership[A, C[_], D[_]]( // inner consensus is reached case (None, Some(value)) if !membershipChanging => val newLog = Map(counter -> value) - logger.info { s"$rid: Inner consensus reached on value $value, log: $newLog" } copy( counter = counter + 1, membersConsensus = Consensus[C].empty, diff --git a/Modules/RDTs/src/test/scala/test/rdts/protocols/MembershipTest.scala b/Modules/RDTs/src/test/scala/test/rdts/protocols/MembershipTest.scala index 18119719c..511318876 100644 --- a/Modules/RDTs/src/test/scala/test/rdts/protocols/MembershipTest.scala +++ b/Modules/RDTs/src/test/scala/test/rdts/protocols/MembershipTest.scala @@ -2,7 +2,7 @@ package test.rdts.protocols import rdts.base.LocalUid import rdts.datatypes.experiments.protocols.simplified.{MultiRoundVoting, Paxos, SimpleVoting} -import rdts.datatypes.experiments.protocols.{LogHack, Membership} +import rdts.datatypes.experiments.protocols.{Membership} class MembershipTest extends munit.FunSuite { @@ -12,7 +12,6 @@ class MembershipTest extends munit.FunSuite { val id4 = LocalUid.gen() test("Membership happy path") { - given LogHack(false) var membership = Membership.init[Int, Paxos, Paxos](Set(id1, id2, id3).map(_.uid)) // id1 writes -> prepare assert(membership.isMember(using id1)) @@ -52,7 +51,6 @@ class MembershipTest extends munit.FunSuite { } test("Membership with member change") { - given LogHack(false) var membership = Membership.init[Int, Paxos, Paxos](Set(id1, id2, id3).map(_.uid)) // id1 writes -> prepare assert(membership.isMember(using id1)) @@ -98,7 +96,6 @@ class MembershipTest extends munit.FunSuite { } test("Fixed counterexample from suite") { - given LogHack(false) var membership1 = Membership.init[Int, Paxos, Paxos](Set(id1, id2, id3, id4).map(_.uid)) var membership2 = Membership.init[Int, Paxos, Paxos](Set(id1, id2, id3, id4).map(_.uid)) // id1 writes -> prepare