Snapshot events threshold

I am working with Snapshots and have noticed that the Snapshot is created before the configured threshold. When I set the threshold to 4, the snapshot is created right when the 3rd event is placed. 3 events took place and the snapshot is created. The 4th event did not take place yet.

Is it a little bug or it works as designed?

Hi @interested-dev, do you mean for the first snapshot or for the following ones? Or both?

I think for both. I have set the threshold of event count to 3, generated 4 events, and have got 2 log messages “Snapshot created”.

UPDATE

I have check it now with Axon Server version 4.5 and I got the same result. For the event count threshold set to 3, I get 2 snapshots created after generating 4 events. A new snapshot is created as soon as event 2 is processed.

Are you sure it’s 4 events and not 5?

I am asking because the snapshot itself counts as 1 event.
So, I would expect one snapshot to be created on the 3rd event and the next one on the 5th event (snapshot + 2 events, making it 3 events in total).

If that is not the case, I will try to investigate further.
I am finishing a code-samples on our repo about snapshots, hope that helps as well.

Hmm… If Snapshot event is counted, then I think it works correctly. I did not expect Snapshot event to be counted.

Can you please mentioned what would be needed to create snapshot event? I tried to set threshold count =2 events and in aggregate mentioned the snapshotTrigger but still i am not seeing any shanpshot event in database

Swarup, try sending a couple of commands that this Aggregate class can handle. Every time this Aggregate handles a command, it will also publish an Event right? So, this will help you generate two domain events that should trigger a snapshot event. The snapshot event will trigger automatically when the threshold is reached.

Also, make sure that the name in the @Aggregate(snapshotTriggerDefinition = “NAME”) matches the Bean name created.

1 Like