[Issue #6] Add event versioning validation #34
Reference in New Issue
Block a user
Delete Branch "issue-6-event-versioning-validation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
This PR adds event versioning validation to ensure events have monotonically increasing versions per actor, maintaining event stream integrity.
Changes
ErrVersionConflictsentinel error andVersionConflictErrortype with ActorID, CurrentVersion, and AttemptedVersion detailsInMemoryEventStore.SaveEventthat rejects events with version <= current latestJetStreamEventStore.SaveEventwith version caching for performanceVersion Semantics
VersionConflictErrorreturned on validation failureUnwrap()to work witherrors.Is(err, ErrVersionConflict)Closes #6
AI Code Review
Summary
This PR successfully implements event versioning validation with comprehensive error handling, proper concurrency control, and excellent test coverage. The implementation is production-ready with clear semantics and helpful documentation.
Findings
Code Quality
ErrVersionConflict) and detailed error (VersionConflictError) that implementsUnwrap()for idiomatic error handlingsync.RWMutexin InMemoryEventStore and version caching in JetStreamEventStoreSaveSnapshot,GetLatestSnapshot) that weren't mentioned in the PR description - these appear to be a bonus additionPotential Bugs
TestSaveEvent_ConcurrentWritesToSameActor) verifies exactly one writer succeeds when 100 goroutines raceSecurity Concerns
Style Notes
Test Coverage
store/memory_test.goConsistentHashRing(appears unrelated to issue #6 but welcome)Verdict
LGTM
This implementation is well-designed, thoroughly tested, and ready for production use. The version validation maintains event stream integrity while the optimistic concurrency pattern enables safe concurrent writes. Documentation is clear and examples are helpful for users of the library.