Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracks progress of event sourcing #137

Merged
merged 21 commits into from
Mar 17, 2022
Merged

Conversation

xirc
Copy link
Contributor

@xirc xirc commented Mar 14, 2022

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.

Taichi Yamakawa added 9 commits March 14, 2022 14:21
AppendCommittedEntries and its reply message AppendCommittedEntriesResponse allows
* RaftActor can request saving multiple committed log entries to CommitLogStoreActor at one message.
* RaftActor can fetch the last index of committed log entries that CommitLogStoreActor saved.
This feature enables the compaction won't delete committed entries that are not persisted to the event sourcing store (aka CommitLogStore) yet.
… entries

Even if the compaction continues, the remaining entries will trigger new compaction
at the next tick. This repeated compaction might consume unnecessary resources.
This sending is not needed since RaftActor sends
CommitLogStoreActor.AppendCommittedEntries periodically instead.
RaftActor will retry failed AppendCommittedEntries, which makes
RaftActorStore.save, and the related settings and classes unnecessary.
* Remove inlined settings for maintainability
* Remove raft.eventsourced.commit-log-store settings
It's impossible to contain too-many entries into a single AppendCommittedEntries
since one message size is limited. To address this limitation, RaftActor splits entries
into batches and sends a  AppendCommittedEntries per each batch.
CommitLogStore and ShardedCommitLogStore can be removed since they are package private.
Use CommitLogStoreActor.AppendCommittedEntries instead.
@xirc xirc force-pushed the event-sourcing-progress-tacking branch from e9a1d42 to 01754e0 Compare March 15, 2022 00:36
Taichi Yamakawa added 6 commits March 15, 2022 09:54
…-threshold

If preserve-log-size equals to or is greater than log-size-threshold, compaction won't happen.
Add event-sourcing progress tracking feature.
log-size-threshold should be larger than preserve-log-size.
@xirc xirc marked this pull request as ready for review March 15, 2022 05:33
@xirc xirc requested a review from negokaz March 15, 2022 05:33
@xirc xirc added this to the v2.1.0 milestone Mar 15, 2022
Copy link
Contributor

@negokaz negokaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xirc Awesome! 👍
I left some comments.

Copy link
Contributor

@negokaz negokaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! LGTM 👍

@negokaz negokaz merged commit cc3458b into master Mar 17, 2022
@negokaz negokaz deleted the event-sourcing-progress-tacking branch March 17, 2022 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Event Sourcing might halt if CommitLogStore is not available for a long period
2 participants