Applied commands get reapplied after restart
I have developed and key-value store with Bbolt. when testing, I noticed the previously applied commands get applied again after restart. I also tested this with the basic example in the repo. For an in-memory (volatile) key-value store this is fine. But for a persisted one this is creating duplicated values. I mean my raft commands are not idempotent so I want to make sure it only gets applied once. Please, could you tell me how I do this?
Is there a way to tell to set the current node appliedIndex right after applying?
As I can see in the log, the apply index is always zero.
Note: I am just starting with a single node for now.
I have read this (https://github.com/shaj13/raft/issues/7), it's related but could not understand its relation to the snapshot
On a design note, how are you handling errors during apply?
My intuition was that the StateMache.Apply(data []byte) should return an error that informs the engine that we could not apply and therefore need to retry the same entry sequence. if no error appliedIndex gets updated forward.
I may be missing key understanding here, just trying to solidify my intuition around raft and this implementation. Thanks
@kotyara85 Maybe your experience from this (https://github.com/shaj13/raft/issues/7) issue can help here
Go it resolved here https://github.com/hashicorp/raft/issues/523
When Raft restarts, it re-applies all replicated logs, either from the write-ahead log or from a snapshot. Therefore application should clear its persistent database on startup, if it maintains one, to avoid replay conflicts or duplication.