lerna-stack / akka-entity-replication

Akka extension for fast recovery from failure with replicating stateful entity on multiple nodes in Cluster
Apache License 2.0
30 stars 1 forks source link

Tracks progress of event sourcing #137

Closed xirc closed 2 years ago

xirc commented 2 years ago

Closes #136

Overview

RaftActor will track a log index (named eventSourcingIndex). This index indicates that CommitLogStoreActor (which is responsible for Event Sourcing) already persisted events with indices lower than or equal to that index. This index enables RaftActor to know the progress of Event Sourcing. This index is periodically exchanged by the new messages ( CommitLogStore.AppendCommittedEntries and CommitLogStore.AppendCommittedEntriesResponse) between RaftActor and CommitLogStoreActor.

RaftActor (only the leader) checks new committed entries (which index should > eventSourcingIndex and <= commitIndex) at a certain period (named committed-log-entries-check-interval or EventSourcingTick) and will send those entries (included to CommitLogStore.AppendCommittedEntries) if available. This periodically checking mechanism prevents halting Event Sourcing. It also allows RaftActor to retry committed entries persisting (the previous persisting failed for some reason like journal failures).

Using eventSourcingIndex RaftActor can know what entry can be removed safely on compaction. More precisely, committed entries that are persisted to the event-sourcing store can be removed safely. By this PR, compaction won't delete entries that are not persisted to the event-sourcing store yet.

By introducing event soucing progress tracking, followers and candidates don't have to send committed entries to the event-sourcing store. This PR removes such sending, which might reduce the required network resource.