Skip to content

Commit 7629647

Browse files
authored
Merge pull request #179 from lerna-stack/revise-logs-of-sending-replication-results
Add diagnostic info to logs of sending replication results
2 parents c18e940 + 4321e1c commit 7629647

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Add function extracting shard id from entity id to lerna.akka.entityreplication.typed.ClusterReplication
1919
[PR#172](https://github.com/lerna-stack/akka-entity-replication/pull/172)
2020
- Add function of Disabling raft actor [PR#173](https://github.com/lerna-stack/akka-entity-replication/pull/173)
21+
- Add diagnostic info to logs of sending replication results
22+
[PR#179](https://github.com/lerna-stack/akka-entity-replication/pull/179)
2123

2224
### Fixed
2325
- RaftActor might delete committed entries

src/main/scala/lerna/akka/entityreplication/raft/RaftActor.scala

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,15 @@ private[raft] class RaftActor(
304304
.handleCommittedLogEntriesAndClients { entries =>
305305
entries.foreach {
306306
case (logEntry, Some(client)) =>
307-
if (log.isDebugEnabled)
308-
log.debug("=== [Leader] committed {} and will notify it to {} ===", logEntry, client)
307+
if (log.isDebugEnabled) {
308+
log.debug(
309+
s"=== [${currentState}] Committed event" +
310+
s" (index=[${logEntry.index}], term=[${logEntry.term.term}]," +
311+
s" entityId=[${logEntry.event.entityId.map(_.raw)}]," +
312+
s" type=[${logEntry.event.event.getClass.getName}])" +
313+
s" and sending ReplicationSucceeded to [$client] ===",
314+
)
315+
}
309316
client.forward(ReplicationSucceeded(logEntry.event.event, logEntry.index, client.instanceId))
310317
case (logEntry, None) =>
311318
// 復旧中の commit or リーダー昇格時に未コミットのログがあった場合の commit
@@ -494,11 +501,27 @@ private[raft] class RaftActor(
494501
logEntry.event match {
495502
case EntityEvent(_, NoOp) => // NoOp は replicationActor には関係ないので転送しない
496503
case EntityEvent(Some(entityId), event) =>
497-
if (log.isDebugEnabled) log.debug("=== [{}] applying {} to ReplicationActor ===", currentState, event)
498-
replicationActor(entityId) ! Replica(logEntry)
504+
val targetReplicationActor = replicationActor(entityId)
505+
if (log.isDebugEnabled) {
506+
log.debug(
507+
s"=== [${currentState}] Sending Replica to apply event" +
508+
s" (index=[${logEntry.index}], term=[${logEntry.term.term}]," +
509+
s" entityId=[${entityId.raw}]," +
510+
s" eventType=[${event.getClass.getName}])" +
511+
s" to ReplicationActor [$targetReplicationActor] ===",
512+
)
513+
}
514+
targetReplicationActor ! Replica(logEntry)
499515
case EntityEvent(None, event) =>
500-
if (log.isWarningEnabled)
501-
log.warning("=== [{}] {} was not applied, because it is not assigned any entity ===", currentState, event)
516+
if (log.isWarningEnabled) {
517+
log.warning(
518+
"[{}] event [index=[{}], term=[{}], type={}] was not applied, because it is not assigned any entity",
519+
currentState,
520+
logEntry.index,
521+
logEntry.term.term,
522+
event.getClass.getName,
523+
)
524+
}
502525
}
503526

504527
def handleSnapshotTick(): Unit = {

0 commit comments

Comments
 (0)