Skip to content

Commit

Permalink
remove LogHack
Browse files Browse the repository at this point in the history
what part about that name makes someone believe that it should have been used further … ?
  • Loading branch information
rmgk committed Dec 2, 2024
1 parent 6cc3496 commit fda8e60
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -13,25 +13,23 @@ 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]) {

private type ClusterState = Membership[Request, Paxos, Paxos]

given localUid: LocalUid = LocalUid(name)
given LogHack = new LogHack(false)

val clientDataManager: ProDataManager[ClientNodeState] =
ProDataManager[ClientNodeState](
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Modules/RDTs/.jvm/src/test/scala/MembershipSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fda8e60

Please sign in to comment.