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

Bug in stream handling in AbstractRepository #9

Open
alkampfergit opened this issue Sep 19, 2016 · 0 comments
Open

Bug in stream handling in AbstractRepository #9

alkampfergit opened this issue Sep 19, 2016 · 0 comments

Comments

@alkampfergit
Copy link
Contributor

alkampfergit commented Sep 19, 2016

[This happens only if you remove snapshot cache from repository, but since snapshot cache is probably something that should be removed, this is an issue to take care of.].

Method OpenStream of AbstractRepository stores opened stream in a dictionary whose key is obtained by StreamId and BucketId and this generates error with snapshot.

Consider this sequence of operation on an aggregate that is at version 10

  • repository.GetById(ID); //no snapshot on disk, Repository opens the stream from 0 to 10
  • aggregate events are applied, aggregate is at version 10.
  • a method of aggregate is called, another event is generated.
  • Save is called and aggregate new event is persisted.

At this moment, since the aggregate is in memory, we could get a snapshot to store in cache. Snapshot is at version 11.

Now with the same instance of the repository issue the GetById(ID) command again and this happens

  • Repository load the snapshot (
  • Method OpenStream finds the stream in _streams dictionary cache, so no stream is loaded.
  • ApplyEventsToAggregate is called, but it uses incorrectly the same stream instance from before, opened at version 0, so all the events are applied to aggregate, causing errors.

A proposed fix is avoiding caching stream inside _stream dictionary with a string key, but using the instance of the aggregate as a key. A stream cached is valid only if the very same instance of aggregate is reused.

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

No branches or pull requests

1 participant