Repository navigation
feat(rados): compound write operations - #4
Conversation
AlexanderSlaa
left a comment
There was a problem hiding this comment.
Thanks for your contribution!
Most of it verified:
- data steps combine in order (
writeFull, thenwriteat offset 0,append,truncate,zero); create({exclusive: false})works on an existing object;- a failed check leaves data, xattrs and omap untouched;
assertExistsfails with ENOENT and creates nothing;assertVersionpasses on the current version and fails with ERANGE on an older one;removeworks inside an operation, and an operation with no steps is a no-op;- a builder can be operated twice, and later steps don't leak into an earlier
operate(); - invalid steps throw
TypeErrorsynchronously.
Two issues:
1. compareXattr compares the other way round from how it reads. With the stored xattr "m":
| call | result |
|---|---|
compareXattr("v", "gt", "a") |
ECANCELED |
compareXattr("v", "gt", "z") |
passes |
compareXattr("v", "lt", "a") |
passes |
librados evaluates value OP stored, but compareXattr(name, "gt", value) reads as "stored > value". A guard like .compareXattr("version", "lt", Buffer.from("5")) would check the opposite of what it says. I'd suggest swapping gt/lt and gte/lte in the comparisons map so the API means stored OP value, or else documenting it clearly. Either way, it's worth settling before this becomes public API.
2. assertVersion with a version newer than the object's fails with EOVERFLOW (75), not ERANGE. The doc comment, README and PR description only mention ERANGE.
Merge note (with #2): after #2, this merges with conflicts only in the README and tests, and WriteOp loses the in-flight guard. I built them together, and setNamespace() was allowed while writeOps were queued. Please use in_flight(state_) in WriteOp when rebasing.
IoContext.writeOp(oid) builds a librados write operation whose steps are
applied to the object atomically by one OSD operation: all of them take
effect or none does. Supported steps: assertExists, assertVersion,
compareXattr, create (exclusive or idempotent), write, writeFull, append,
truncate, zero, remove, setXattr, removeXattr, setOmap and removeOmapKeys.
Without it, writing an object's data and its xattrs takes several calls, and
"create only if absent" needs a stat followed by a write, which races with
other writers. Now that is one call:
await io.writeOp(oid).create({exclusive: true}).writeFull(data)
.setXattr("checksum", sum).operate();
A failed check fails the whole operation before anything is written: EEXIST,
ENOENT, ERANGE (assertVersion) or ECANCELED (compareXattr).
- compareXattr(name, "gt", value) passed when value was greater than the stored xattr, because the OSD evaluates "value OP stored". The ordering operators are now mirrored, so the call means "stored OP value". - assertVersion() fails with EOVERFLOW, not ERANGE, when the object is older than the asserted version; documented both. - writeOp() counts as an operation in flight, so setNamespace() and the other setters refuse with EBUSY while one is queued. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
a189514 to
ef350a1
Compare
# [1.2.0](v1.1.2...v1.2.0) (2026-11-21) ### Features * **rados:** compound write operations ([#4](#4)) ([e16926b](e16926b))
|
🎉 This PR is included in version 1.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
Thanks for your contribution! Merged. I rebased this onto
Your commit is unchanged apart from the conflict resolution: |
This adds
IoContext.writeOp(oid), a builder for a librados write operation. All of its steps apply to the object atomically, in one OSD operation.Without it, writing an object's data together with its xattrs takes several calls that each can fail on their own. "Create only if it doesn't exist" also needs a stat and then a write, which races with other writers.
Supported steps:
assertExists,assertVersion,compareXattr,create(exclusive or idempotent),write,writeFull,append,truncate,zero,remove,setXattr,removeXattr,setOmapandremoveOmapKeys.A failed check fails the whole operation before anything is written:
create({exclusive: true})fails with EEXIST;assertExists()fails with ENOENT;assertVersion()fails with ERANGE;compareXattr()fails with ECANCELED.The integration test checks both that all steps apply and that none do. I confirmed the error codes against a Ceph 21 cluster. The new librados symbols are added to
coverage/api.json.