-
Notifications
You must be signed in to change notification settings - Fork 10
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
Unexpected behaviour on snapshot #389
Comments
Thank you for submitting this issue and welcome to the edomata community! |
package dev.hnaderi.example
import cats.data.EitherNec
import cats.effect.IO
import cats.effect.IOApp
import cats.effect.kernel.Resource
import dev.hnaderi.example.accounts.*
import edomata.core.CommandMessage
import java.time.Instant
import java.util.UUID
extension [T](e: IO[T]) {
def print(lbl: String) = IO.println(lbl) >> e.flatTap(IO.println)
}
object Main extends IOApp.Simple {
private def newID = UUID.randomUUID().toString()
def run: IO[Unit] = Resource
.both(Application[IO](), Application[IO]())
.use((app1, app2) =>
for {
address <- IO.randomUUID.map(_.toString()).print("ADDRESS:")
printA = app1.accounts.storage.repository
.get(address)
.print("STATE ON A")
printB = app2.accounts.storage.repository
.get(address)
.print("STATE ON B")
_ <- app1.accounts
.service(
CommandMessage(
newID,
Instant.now(),
address,
Command.Open
)
)
.print("OPEN ON A")
_ <- printA
_ <- app2.accounts
.service(
CommandMessage(
newID,
Instant.now(),
address,
Command.Deposit(100)
)
)
.print("DEPOSIT ON B")
_ <- printB
_ <- printA
_ <- app1.accounts
.service(
CommandMessage(
newID,
Instant.now(),
address,
Command.Deposit(50)
)
)
.print("DEPOSIT ON A")
_ <- printB
_ <- printA
} yield ()
)
}
|
"Did you disable cache on all the instances, or just on B?" Just on B. |
"The maximum snapshot version should be the number event for the entity in a journal" Is this consistent with:
I interpret your statement that the version should be the same for the snapshot and the event. |
No, the event versioning starts from zero and snapshots from one. It might seem confusing at first, but it has a simple logic behind it:
|
Ok, thanks. But what about item 4: Note that this service (B) has not yet been involved at all and it does not use caching. I hear that you were not able to recreate the results, but I also cannot see how your application does the same as my setup. (I will take a closer look later!) |
@niklasuhrberg I finally managed to reproduce the problem. I haven't found the root cause yet. |
Thanks a lot for that! |
@niklasuhrberg The problem is now fixed with |
@hnaderi Thanks so much for the fast response and fix. |
I have reproduced what seems to be erroneous behaviour using the steps below:
Start two servers A and B. B disables cache.
Snapshot created on closing A.
Snapshot now has version N and last event has version N-1
Create one more event using already running service B => new event gets version N. Now both the snapshot and the last event have the same version, but the snapshot does not include the information in the event with version number N.
Get the state from service B (using Backend.respository.get(id)) => the state does not contain information in the event issued right before in 4.
Start another instance C and get state => result does not include event with version N
Also issuing a command fails, no more event gets persisted. This goes for both servers.
If the version number of the snapshot is now lowered by one, the services retrieves the correct state, i.e. taking all events into account.
But, issuing commands still fails with the log "service raised an error: class edomata.backend.BackendError$MaxRetryExceeded$"
8 was anticipated, but I was surprised by 9.
The service becomes unusable once this state has materialized.
The text was updated successfully, but these errors were encountered: