sled icon indicating copy to clipboard operation
sled copied to clipboard

safer units of measure

Open spacejam opened this issue 4 years ago • 0 comments

we perform the same calculations on various types all over the place in the sled codebase, in ad-hoc error-prone ways that cost time when debugging, refactoring, or implementing any change that may touch on them.

we frequently convert between SegmentId, Lsn, LogOffset, usize, PageId, i64 and u64.

we can take ideas from https://yoric.github.io/post/uom.rs/, https://docs.rs/uom/0.26.0/uom/index.html, etc...

goals:

  • remove casting
  • remove ad-hoc modulus
  • remove ad-hoc division of Lsn / LogOffset by segment_size to get a SegmentId
  • further remove normalization (already partially addressed with Config::normalize)
  • remove clippy lint bypasses
  • remove -1 as a valid Lsn if possible (may not be, as we use AtomicI64 to track stability, but maybe this is possible to do in a safer way)
  • remove as much use of TryInto / TryFrom as possible

spacejam avatar May 06 '20 10:05 spacejam