Skip to content

feat: update item version on put#309

Merged
jason-lynch merged 1 commit intomainfrom
feat/put-with-updated-version
Mar 31, 2026
Merged

feat: update item version on put#309
jason-lynch merged 1 commit intomainfrom
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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 66d57b13-f304-461d-9b2e-daad3feff6d7

📥 Commits

Reviewing files that changed from the base of the PR and between fa785be and 2db5030.

📒 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
🚧 Files skipped from review as they are similar to previous changes (3)
  • server/internal/storage/txn.go
  • server/internal/storage/put_test.go
  • server/internal/storage/txn_test.go

📝 Walkthrough

Walkthrough

Adds optional post-put version mutation: new VersionUpdater interface and WithUpdatedVersion() option for put/create/update operations; txn commit extracts etcd PrevKVs and invokes version updates. Tests updated and a storagetest helper file was removed.

Changes

Cohort / File(s) Summary
Storage interface
server/internal/storage/interface.go
Added VersionUpdater interface (UpdateVersionEnabled() bool, UpdateVersion(prevKVs map[string]*mvccpb.KeyValue)), embedded it into PutOp[V Value], and added WithUpdatedVersion() PutOp[V].
Put/create/update implementations
server/internal/storage/put.go
Added shouldUpdateVersion flag, WithUpdatedVersion() methods, UpdateVersionEnabled() / UpdateVersion(...) implementations for putOp, createOp, updateOp; added helpers extractPrevKVs() and updateVersion(); ensure options slice is copied before mutation.
Transaction handling
server/internal/storage/txn.go
After successful commit, extracts prev KVs and calls UpdateVersion(prevKVs) on ops implementing VersionUpdater with updates enabled.
Tests
server/internal/storage/put_test.go, server/internal/storage/txn_test.go
Added subtests using UUID keys to assert .WithUpdatedVersion() increments item.Version() across create/put/update and multi-op transactions; removed commented defer closes.
Removed test helpers
server/internal/storage/storagetest/ops.go
Deleted file that provided fake operation constructors and test helpers for storage ops.

Poem

🐰 A carrot-coded tweak, a tiny hop,
PrevKVs fetched from the etch-and-drop.
Put, create, update — versions rise,
Incremented softly beneath rabbit skies.
Toward tidy stores our whiskers bop.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers Summary and Testing sections but lacks Changes, Checklist, and Notes for Reviewers sections required by the template. Add a bulleted Changes section summarizing file modifications, complete the Checklist with selections, and optionally add Notes for Reviewers to guide the review process.
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 (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: update item version on put' directly and concisely describes the main change—adding version update capability to put operations.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 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

@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
@jason-lynch jason-lynch requested a review from rshoemaker March 30, 2026 15:37
if err != nil {
return fmt.Errorf("failed to put %q: %w", o.key, err)
}
if o.shouldUpdateVersion {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not call updateVersion() here like createOp.Exec() and updateOp.Exec() do?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's a good question. It's just a slightly different output shape. createOp and updateOp use a transaction internally since we need to apply a condition to the operation. That means both of them produce a slice of responses, even though they're only performing one operation. So we're reusing the same code for those as we do with transactions: we iterate over the responses, extract any Put responses, and produce a map[string]*mvccpb.KeyValue of the previous KVs. I considered reusing those functions here, but since they involve a few transformations, it felt cleaner to just duplicate this if/else.

Base automatically changed from refactor/component-logger-constants to main March 31, 2026 17:25
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 feat/put-with-updated-version branch from 64a9954 to 2db5030 Compare March 31, 2026 17:26
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity . 3 duplication

Metric Results
Complexity 0
Duplication 3

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@jason-lynch jason-lynch merged commit 0b4300c into main Mar 31, 2026
3 checks passed
@jason-lynch jason-lynch deleted the feat/put-with-updated-version branch March 31, 2026 18:03
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.

2 participants