Skip to content

feat: update item version on put#309

Open
jason-lynch wants to merge 1 commit intorefactor/component-logger-constantsfrom
feat/put-with-updated-version
Open

feat: update item version on put#309
jason-lynch wants to merge 1 commit intorefactor/component-logger-constantsfrom
feat/put-with-updated-version

Conversation

@jason-lynch
Copy link
Copy Markdown
Member

Summary

Adds a new feature to storage.Put operations to optionally update the value version after the put succeeds. This mechanism works whether the operation is executed by itself or within a transaction. The version is used as a constraint in update operations, so this feature enables us to hold a reference to a value and perform multiple update operations on it without needing to get the value from Etcd in between.

We had some unused mock operations in the storagetest package, and I opted to remove them in this commit rather than update them for this change.

Testing

This feature is used by the next PR in this sequence. In this PR, it's only used in the unit/narrow integration tests, so there are no functional changes.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 20, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b7e7ddea-205d-4e89-a65f-af15ea049849

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR introduces version updating capabilities to put operations in the storage layer. A new VersionUpdater interface enables operations to request post-write version updates based on previous etcd key-value data. Implementations across put, create, and update operations support this functionality, with transaction execution applying updates during commit.

Changes

Cohort / File(s) Summary
Version Updater Interface
server/internal/storage/interface.go
Introduced VersionUpdater interface with UpdateVersionEnabled() and UpdateVersion(prevKVs) methods. Added WithUpdatedVersion() method to PutOp[V Value] and embedded VersionUpdater interface.
Put Operation Implementation
server/internal/storage/put.go
Implemented version updating across putOp, createOp, and updateOp with shouldUpdateVersion flag and helper functions extractPrevKVs() and updateVersion(). Updated Exec to capture previous key-value data from etcd responses and apply version updates. Adjusted putOps to avoid mutating caller-provided options slice.
Transaction Version Updates
server/internal/storage/txn.go
Enhanced txn.Commit() to extract previous key-value data and invoke UpdateVersion() on operations that have version updating enabled.
Version Update Tests
server/internal/storage/put_test.go, server/internal/storage/txn_test.go
Added subtests validating version increment behavior in put/create/update operations and transactions with WithUpdatedVersion(). Tests verify version transitions and multi-operation transaction semantics.
Removed Test Helpers
server/internal/storage/storagetest/ops.go
Removed entire test helper file containing seven fake operation constructors and implementations for storage operations.

Poem

🐰 Hop hop, the versions dance with glee,
From etcd's store, they're wild and free!
Each put and create now track the past,
With versions updated, forever to last,
Our whiskers twitch at this feature so keen,
The finest version updates we've seen! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: update item version on put' clearly and concisely summarizes the main feature addition in the changeset.
Description check ✅ Passed The description covers Summary, Changes, and Testing sections and explains the feature purpose and scope, but is missing Checklist items and Issue link.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/put-with-updated-version

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jason-lynch
Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 20, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@server/internal/storage/interface.go`:
- Around line 137-139: Fix the minor typo in the UpdateVersion method comment:
replace "upate" with "update" in the comment that currently reads "and upate its
item's versions" so the sentence correctly reads "and update its item's
versions"; the comment is adjacent to the UpdateVersion(prevKVs
map[string]*mvccpb.KeyValue) declaration referencing prevKVs and
mvccpb.KeyValue.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 266eee22-9a52-4e02-abf1-30b153218a23

📥 Commits

Reviewing files that changed from the base of the PR and between 0eba7c4 and fa785be.

📒 Files selected for processing (6)
  • server/internal/storage/interface.go
  • server/internal/storage/put.go
  • server/internal/storage/put_test.go
  • server/internal/storage/storagetest/ops.go
  • server/internal/storage/txn.go
  • server/internal/storage/txn_test.go
💤 Files with no reviewable changes (1)
  • server/internal/storage/storagetest/ops.go

Adds a new feature to `storage.Put` operations to optionally update the
value version after the put succeeds. This mechanism works whether the
operation is executed by itself or within a transaction. The version is
used as a constraint in update operations, so this feature enables us to
hold a reference to a value and perform multiple update operations on it
without needing to get the value from Etcd in between.

We had some unused mock operations in the `storagetest` package, and I
opted to remove them in this commit rather than update them for this
change.
@jason-lynch jason-lynch force-pushed the refactor/component-logger-constants branch from 0eba7c4 to 08cb7d1 Compare March 24, 2026 00:16
@jason-lynch jason-lynch force-pushed the feat/put-with-updated-version branch from fa785be to 64a9954 Compare March 24, 2026 00:16
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

Successfully merging this pull request may close these issues.

1 participant