2018-10-29 17:19:37 +08:00
|
|
|
/*
|
2020-01-02 07:24:59 -05:00
|
|
|
* Copyright (C) 2009-2020 Lightbend Inc. <https://www.lightbend.com>
|
2015-05-17 12:28:47 +02:00
|
|
|
*/
|
2018-03-13 23:45:55 +09:00
|
|
|
|
2015-05-17 12:28:47 +02:00
|
|
|
package akka.cluster.ddata
|
|
|
|
|
|
|
|
|
|
import akka.actor.Address
|
|
|
|
|
import akka.cluster.Member
|
|
|
|
|
import akka.cluster.UniqueAddress
|
2017-02-07 11:21:56 +01:00
|
|
|
import akka.annotation.InternalApi
|
2019-03-19 08:12:51 +01:00
|
|
|
import akka.util.unused
|
2015-05-17 12:28:47 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
*/
|
2017-02-07 11:21:56 +01:00
|
|
|
@InternalApi private[akka] object PruningState {
|
2017-01-11 13:19:45 +01:00
|
|
|
final case class PruningInitialized(owner: UniqueAddress, seen: Set[Address]) extends PruningState {
|
|
|
|
|
override def addSeen(node: Address): PruningState = {
|
|
|
|
|
if (seen(node) || owner.address == node) this
|
|
|
|
|
else copy(seen = seen + node)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
final case class PruningPerformed(obsoleteTime: Long) extends PruningState {
|
|
|
|
|
def isObsolete(currentTime: Long): Boolean = obsoleteTime <= currentTime
|
2019-03-19 08:12:51 +01:00
|
|
|
def addSeen(@unused node: Address): PruningState = this
|
2017-01-11 13:19:45 +01:00
|
|
|
}
|
2015-05-17 12:28:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
*/
|
2017-02-07 11:21:56 +01:00
|
|
|
@InternalApi private[akka] sealed trait PruningState {
|
2015-05-17 12:28:47 +02:00
|
|
|
import PruningState._
|
|
|
|
|
|
|
|
|
|
def merge(that: PruningState): PruningState =
|
2017-01-11 13:19:45 +01:00
|
|
|
(this, that) match {
|
2019-02-09 15:25:39 +01:00
|
|
|
case (p1: PruningPerformed, p2: PruningPerformed) => if (p1.obsoleteTime >= p2.obsoleteTime) this else that
|
|
|
|
|
case (_: PruningPerformed, _) => this
|
|
|
|
|
case (_, _: PruningPerformed) => that
|
|
|
|
|
case (PruningInitialized(thisOwner, thisSeen), PruningInitialized(thatOwner, thatSeen)) =>
|
2017-01-11 13:19:45 +01:00
|
|
|
if (thisOwner == thatOwner)
|
2019-03-11 10:38:24 +01:00
|
|
|
PruningInitialized(thisOwner, thisSeen.union(thatSeen))
|
2017-01-11 13:19:45 +01:00
|
|
|
else if (Member.addressOrdering.compare(thisOwner.address, thatOwner.address) > 0)
|
2015-05-17 12:28:47 +02:00
|
|
|
that
|
|
|
|
|
else
|
|
|
|
|
this
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-19 08:12:51 +01:00
|
|
|
def addSeen(node: Address): PruningState
|
2015-05-17 12:28:47 +02:00
|
|
|
}
|