Skip to content

Commit

Permalink
Merge pull request #47 from lerna-stack/adjust-public-api
Browse files Browse the repository at this point in the history
Make internal API private
  • Loading branch information
tksugimoto authored Apr 6, 2021
2 parents 68a74c6 + 279a7c3 commit 1a23398
Show file tree
Hide file tree
Showing 47 changed files with 146 additions and 94 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
[Unreleased]: https://github.com/lerna-stack/akka-entity-replication/compare/.v1.0.0...master

### Removed

- Made internal APIs private

⚠️ If you are only using the APIs using in the implementation guide, this change does not affect your application.
Otherwise, some APIs may be unavailable.
Please see the following PR to check APIs that will no longer be available.

https://github.com/lerna-stack/akka-entity-replication/pull/47

## [v1.0.0] - 2021-03-29
[v1.0.0]: https://github.com/lerna-stack/akka-entity-replication/compare/v0.1.1...v1.0.0

- GA release 🚀

## [v0.1.0] - 2021-01-12
[v0.1.0]: https://github.com/lerna-stack/akka-entity-replication/tree/v0.1.1

- Initial release (under development)
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ You can see a sample application using this extension in the following project.

[lerna-stack/akka-entity-replication-sample](https://github.com/lerna-stack/akka-entity-replication-sample)

## Changelog

You can see all the notable changes in [CHANGELOG](CHANGELOG.md).

## License

akka-entity-replication is released under the terms of the [Apache License Version 2.0](./LICENSE).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ object ClusterReplication {

def apply(system: ActorSystem): ClusterReplication = new ClusterReplication(system)

val actorNamePrefix: String = "replicationRegion"
private val actorNamePrefix: String = "replicationRegion"
}

class ClusterReplication(system: ActorSystem) {
class ClusterReplication private (system: ActorSystem) {

import ClusterReplication._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
package lerna.akka.entityreplication
trait ClusterReplicationSerializable extends Serializable
private[entityreplication] trait ClusterReplicationSerializable extends Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ import lerna.akka.entityreplication.raft.model.{ LogEntryIndex, NoOp }
import lerna.akka.entityreplication.raft.protocol.SnapshotOffer
import lerna.akka.entityreplication.raft.snapshot.SnapshotProtocol._

object ReplicationActor {
private[entityreplication] object ReplicationActor {

private val instanceIdCounter = new AtomicInteger(1)
private[this] val instanceIdCounter = new AtomicInteger(1)

private def generateInstanceId(): EntityInstanceId = EntityInstanceId(instanceIdCounter.getAndIncrement())

final case class TakeSnapshot(metadata: EntitySnapshotMetadata, replyTo: ActorRef)
final case class Snapshot(metadata: EntitySnapshotMetadata, state: EntityState)
private[entityreplication] final case class TakeSnapshot(metadata: EntitySnapshotMetadata, replyTo: ActorRef)
private[entityreplication] final case class Snapshot(metadata: EntitySnapshotMetadata, state: EntityState)

private final case object RecoveryTimeout

final case class EntityRecoveryTimeoutException(entityPath: ActorPath) extends RuntimeException
private[entityreplication] final case class EntityRecoveryTimeoutException(entityPath: ActorPath)
extends RuntimeException
}

trait ReplicationActor[StateData] extends Actor with Stash with akka.lerna.StashFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object ReplicationRegion {

private[entityreplication] type ExtractNormalizedShardId = PartialFunction[Msg, NormalizedShardId]

def props(
private[entityreplication] def props(
typeName: String,
entityProps: Props,
settings: ClusterReplicationSettings,
Expand All @@ -61,24 +61,24 @@ object ReplicationRegion {
) =
Props(new ReplicationRegion(typeName, entityProps, settings, extractEntityId, extractShardId, maybeCommitLogStore))

case class CreateShard(shardId: NormalizedShardId) extends ShardRequest
private[entityreplication] case class CreateShard(shardId: NormalizedShardId) extends ShardRequest

final case class Passivate(entityPath: ActorPath, stopMessage: Any)

sealed trait RoutingCommand
final case class Broadcast(message: Any) extends RoutingCommand
final case class BroadcastWithoutSelf(message: Any) extends RoutingCommand
final case class DeliverTo(index: MemberIndex, message: Any) extends RoutingCommand
final case class DeliverSomewhere(message: Any) extends RoutingCommand
private[entityreplication] sealed trait RoutingCommand
private[entityreplication] final case class Broadcast(message: Any) extends RoutingCommand
private[entityreplication] final case class BroadcastWithoutSelf(message: Any) extends RoutingCommand
private[entityreplication] final case class DeliverTo(index: MemberIndex, message: Any) extends RoutingCommand
private[entityreplication] final case class DeliverSomewhere(message: Any) extends RoutingCommand

/**
* [[ReplicationRegion]] 同士の通信で利用。適切なノードにメッセージがルーティング済みであることを表す
* @param message
*/
final case class Routed(message: Any)
private[entityreplication] final case class Routed(message: Any)
}

class ReplicationRegion(
private[entityreplication] class ReplicationRegion(
typeName: String,
entityProps: Props,
settings: ClusterReplicationSettings,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package lerna.akka.entityreplication.model

final case class EntityInstanceId(underlying: Int) extends AnyVal
private[entityreplication] final case class EntityInstanceId(underlying: Int) extends AnyVal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import lerna.akka.entityreplication.ReplicationRegion.EntityId

import java.net.URLEncoder

object NormalizedEntityId {
private[entityreplication] object NormalizedEntityId {
def from(entityId: EntityId): NormalizedEntityId = new NormalizedEntityId(URLEncoder.encode(entityId, "utf-8"))

def of(entityPath: ActorPath): NormalizedEntityId = new NormalizedEntityId(entityPath.name)
Expand All @@ -14,4 +14,4 @@ object NormalizedEntityId {
new NormalizedEntityId(encodedEntityId)
}

final case class NormalizedEntityId private (underlying: String) extends AnyVal
private[entityreplication] final case class NormalizedEntityId private (underlying: String) extends AnyVal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.net.{ URLDecoder, URLEncoder }

import akka.actor.ActorPath

object NormalizedShardId {
private[entityreplication] object NormalizedShardId {
def from(shardId: String): NormalizedShardId = new NormalizedShardId(URLEncoder.encode(shardId, "utf-8"))

private[entityreplication] def from(path: ActorPath) = new NormalizedShardId(path.name)
Expand All @@ -13,6 +13,6 @@ object NormalizedShardId {
new NormalizedShardId(encodedShardId)
}

final case class NormalizedShardId private (underlying: String) extends AnyVal {
private[entityreplication] final case class NormalizedShardId private (underlying: String) extends AnyVal {
def raw: String = URLDecoder.decode(underlying, "utf-8")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package lerna.akka.entityreplication.model

import java.net.URLEncoder

object TypeName {
private[entityreplication] object TypeName {
def from(typeName: String): TypeName = new TypeName(URLEncoder.encode(typeName, "utf-8"))
}

final class TypeName private (val underlying: String) extends AnyVal {
private[entityreplication] final class TypeName private (val underlying: String) extends AnyVal {
override def toString: String = underlying
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import lerna.akka.entityreplication.raft.protocol.{ SuspendEntity, TryCreateEnti
import lerna.akka.entityreplication.raft.snapshot.SnapshotProtocol
import lerna.akka.entityreplication.raft.snapshot.sync.SnapshotSyncManager

trait Candidate { this: RaftActor =>
private[raft] trait Candidate { this: RaftActor =>
import RaftActor._

def candidateBehavior: Receive = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import lerna.akka.entityreplication.raft.snapshot.SnapshotProtocol
import lerna.akka.entityreplication.raft.snapshot.sync.SnapshotSyncManager
import lerna.akka.entityreplication.{ ReplicationActor, ReplicationRegion }

trait Follower { this: RaftActor =>
private[raft] trait Follower { this: RaftActor =>
import RaftActor._

def followerBehavior: Receive = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import lerna.akka.entityreplication.raft.snapshot.SnapshotProtocol
import lerna.akka.entityreplication.raft.snapshot.sync.SnapshotSyncManager
import lerna.akka.entityreplication.{ ReplicationActor, ReplicationRegion }

trait Leader { this: RaftActor =>
private[raft] trait Leader { this: RaftActor =>
import RaftActor._

def leaderBehavior: Receive = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import lerna.akka.entityreplication.raft.snapshot.sync.SnapshotSyncManager
import lerna.akka.entityreplication.util.ActorIds
import lerna.akka.entityreplication.{ ClusterReplicationSerializable, ReplicationActor, ReplicationRegion }

object RaftActor {
private[entityreplication] object RaftActor {

def props(
typeName: TypeName,
Expand Down Expand Up @@ -95,7 +95,7 @@ object RaftActor {
trait NonPersistEventLike extends NonPersistEvent // テスト用
}

class RaftActor(
private[raft] class RaftActor(
typeName: TypeName,
val extractEntityId: PartialFunction[Msg, (NormalizedEntityId, Msg)],
replicationActorProps: Props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import akka.persistence.{ PersistentActor, RecoveryCompleted, SnapshotOffer }
import lerna.akka.entityreplication.raft.PersistentStateData.PersistentState
import lerna.akka.entityreplication.raft.RaftActor._

object RaftActorBase {
private[raft] object RaftActorBase {

object `->` {
def unapply(in: (State, State)) = Some(in)
}
}

trait RaftActorBase extends PersistentActor with ActorLogging {
private[raft] trait RaftActorBase extends PersistentActor with ActorLogging {

type TransitionHandler = PartialFunction[(State, State), Unit]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import lerna.akka.entityreplication.raft.model._
import lerna.akka.entityreplication.raft.routing.MemberIndex
import lerna.akka.entityreplication.raft.snapshot.SnapshotProtocol.EntitySnapshotMetadata

object PersistentStateData {
private[entityreplication] object PersistentStateData {

final case class PersistentState(
currentTerm: Term,
Expand All @@ -16,7 +16,7 @@ object PersistentStateData {
) extends ClusterReplicationSerializable
}

trait PersistentStateData[T <: PersistentStateData[T]] {
private[entityreplication] trait PersistentStateData[T <: PersistentStateData[T]] {
import PersistentStateData._

def currentTerm: Term
Expand All @@ -35,7 +35,7 @@ trait PersistentStateData[T <: PersistentStateData[T]] {
PersistentState(currentTerm, votedFor, replicatedLog, lastSnapshotStatus)
}

trait VolatileStateData[T <: VolatileStateData[T]] {
private[entityreplication] trait VolatileStateData[T <: VolatileStateData[T]] {
def commitIndex: LogEntryIndex
def lastApplied: LogEntryIndex
def snapshottingProgress: SnapshottingProgress
Expand All @@ -47,7 +47,7 @@ trait VolatileStateData[T <: VolatileStateData[T]] {
): T
}

trait FollowerData { self: RaftMemberData =>
private[entityreplication] trait FollowerData { self: RaftMemberData =>
def leaderMember: Option[MemberIndex]

def initializeFollowerData(): RaftMemberData = {
Expand Down Expand Up @@ -101,7 +101,7 @@ trait FollowerData { self: RaftMemberData =>
protected def updateFollowerVolatileState(leaderMember: Option[MemberIndex] = leaderMember): RaftMemberData
}

trait CandidateData { self: RaftMemberData =>
private[entityreplication] trait CandidateData { self: RaftMemberData =>
def acceptedMembers: Set[MemberIndex]

def initializeCandidateData(): RaftMemberData = {
Expand All @@ -122,7 +122,7 @@ trait CandidateData { self: RaftMemberData =>
protected def updateCandidateVolatileState(acceptedMembers: Set[MemberIndex]): RaftMemberData
}

trait LeaderData { self: RaftMemberData =>
private[entityreplication] trait LeaderData { self: RaftMemberData =>
def nextIndex: Option[NextIndex]
def matchIndex: MatchIndex
def clients: Map[LogEntryIndex, ClientContext]
Expand Down Expand Up @@ -205,7 +205,7 @@ trait LeaderData { self: RaftMemberData =>
): RaftMemberData
}

object RaftMemberData {
private[entityreplication] object RaftMemberData {
import PersistentStateData._

def apply(persistentState: PersistentState): RaftMemberData = {
Expand Down Expand Up @@ -248,7 +248,7 @@ object RaftMemberData {
)
}

trait RaftMemberData
private[entityreplication] trait RaftMemberData
extends PersistentStateData[RaftMemberData]
with VolatileStateData[RaftMemberData]
with FollowerData
Expand Down Expand Up @@ -347,7 +347,7 @@ trait RaftMemberData

}

final case class RaftMemberDataImpl(
private[entityreplication] final case class RaftMemberDataImpl(
currentTerm: Term,
votedFor: Option[MemberIndex],
replicatedLog: ReplicatedLog,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import lerna.akka.entityreplication.model.{ EntityInstanceId, NormalizedEntityId
import lerna.akka.entityreplication.raft.model.{ LogEntry, LogEntryIndex }
import lerna.akka.entityreplication.raft.snapshot.SnapshotProtocol.EntitySnapshot

object RaftProtocol {
private[entityreplication] object RaftProtocol {

final case class RequestRecovery(entityId: NormalizedEntityId)
final case class RecoveryState(events: Seq[LogEntry], snapshot: Option[EntitySnapshot])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import scala.jdk.DurationConverters._
import scala.concurrent.duration.{ Duration, FiniteDuration }
import scala.util.Random

object RaftSettings {
private[entityreplication] object RaftSettings {
def apply(root: Config) = new RaftSettings(root)
}

class RaftSettings(root: Config) {
class RaftSettings private[raft] (root: Config) {

val config: Config = root.getConfig("lerna.akka.entityreplication.raft")

val electionTimeout: FiniteDuration = config.getDuration("election-timeout").toScala

def randomizedElectionTimeout(): FiniteDuration = randomized(electionTimeout)
private[raft] def randomizedElectionTimeout(): FiniteDuration = randomized(electionTimeout)

val heartbeatInterval: FiniteDuration = config.getDuration("heartbeat-interval").toScala

Expand All @@ -29,7 +29,7 @@ class RaftSettings(root: Config) {
/**
* 75% - 150% of duration
*/
def randomized(duration: FiniteDuration): FiniteDuration = {
private[this] def randomized(duration: FiniteDuration): FiniteDuration = {
val randomizedDuration = duration * (randomizedMinFactor + randomizedMaxFactor * Random.nextDouble())
FiniteDuration(randomizedDuration.toNanos, NANOSECONDS)
}
Expand Down Expand Up @@ -76,7 +76,8 @@ class RaftSettings(root: Config) {

val compactionLogSizeCheckInterval: FiniteDuration = config.getDuration("compaction.log-size-check-interval").toScala

def randomizedCompactionLogSizeCheckInterval(): FiniteDuration = randomized(compactionLogSizeCheckInterval)
private[raft] def randomizedCompactionLogSizeCheckInterval(): FiniteDuration =
randomized(compactionLogSizeCheckInterval)

val snapshotSyncCopyingParallelism: Int = config.getInt("snapshot-sync.snapshot-copying-parallelism")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package lerna.akka.entityreplication.raft.eventsourced
import lerna.akka.entityreplication.model.NormalizedShardId
import lerna.akka.entityreplication.raft.model.LogEntryIndex

trait CommitLogStore {
private[entityreplication] trait CommitLogStore {
private[raft] def save(
shardId: NormalizedShardId,
index: LogEntryIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private[entityreplication] final case class Save(
committedEvent: Any,
) extends ClusterReplicationSerializable

object CommitLogStoreActor {
private[entityreplication] object CommitLogStoreActor {

def startClusterSharding(typeName: TypeName, system: ActorSystem): ActorRef = {
val clusterSharding = ClusterSharding(system)
Expand All @@ -44,7 +44,7 @@ object CommitLogStoreActor {
private def props(typeName: TypeName): Props = Props(new CommitLogStoreActor(typeName))
}

class CommitLogStoreActor(typeName: TypeName) extends PersistentActor {
private[entityreplication] class CommitLogStoreActor(typeName: TypeName) extends PersistentActor {
// TODO: 複数 Raft(typeName) に対応するために typeName ごとに cassandra-journal.keyspace を分ける
override def journalPluginId: String =
context.system.settings.config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import lerna.akka.entityreplication.ClusterReplicationSerializable
/**
* index を揃えるために InternalEvent も永続化必要
*/
case object InternalEvent extends ClusterReplicationSerializable
private[entityreplication] case object InternalEvent extends ClusterReplicationSerializable
Loading

0 comments on commit 1a23398

Please sign in to comment.