Skip to content
New issue

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

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

Already on GitHub? # to your account

Eventstore snapshot #396

Merged
merged 3 commits into from
Dec 8, 2022
Merged

Eventstore snapshot #396

merged 3 commits into from
Dec 8, 2022

Conversation

klowdo
Copy link
Collaborator

@klowdo klowdo commented Nov 25, 2022

Description

This adds snapshot capability to eventstore and aggregatestore. With given strategy saves a snapshot of aggregate and loads next time and remaining events wich can increase load times of long-living aggregates

Affected Components

  • Event Store(Mongodb, memory)
  • AggregateSttore

Related Issues

None

Solution and Design

A eventstore implemtation can now implement eh.SnapshotStore an now store snaphots of current state in aggregate.

every aggregate that want to be snapshotted needs to implement eh.Snapshotable

type Snapshotable interface {
	CreateSnapshot() *Snapshot
	ApplySnapshot(snapshot *Snapshot)
}

Loading

When aggretate i requested to be loaded the store checks if aggretate implements eh.Snapshotable and tries to find latest snapshot for aggregate. Loads and applies snapshot then loads all events that is not applies in current snapshot.

Saving

When aggretate i requested to be saved the store checks if aggretate implements eh.Snapshotable and if the strategy return true we create a snapshot ans saves it alongside the events.

Steps to test and verify

  1. Add Strategy to aggregatestore
    • EveryNumberEventSnapshotStrateg <- set to every 1
    • PeriodSnapshotStrategy
    • NoSnapshotStrategy
  2. Implement ehSnapshotable in longliving aggregate
  3. check mongo db snapshot collection

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.06%) to 67.542% when pulling 4f802e8 on klowdo:eventstore-snapshot into f8fe1ad on looplab:main.

@klowdo klowdo merged commit c851bec into looplab:main Dec 8, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants