Skip to content

Conversation

ChrisBQu
Copy link
Collaborator

@ChrisBQu ChrisBQu commented Apr 9, 2025

Relevant issue(s)

Resolves #2569
Resolves #2566

Description

It was possible to update a field that was a float PNCounter such that it became so large, or so largely negative, that it overflowed and became Inf or -Inf. This resulted in future Updates to silently fail, and future Get requests to fail with an error. Both behaviors are undesirable. The proposed solution in this fix is to explicitly check for an overflow when incrementing or decrementing a PNCounter.

There existed a second issue, where PNCounters did not always reach consistency when overflowing. This was because of the way addition and subtraction operations are defined to work on infinite values, and how the order in which those operations was performed, actually mattered. However, the path to store infinite values is now blocked, which should eliminate this issue.

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

The tests within tests/integration/mutation/update/crdt/pncounter_test.go have been updated. Specifically, the following two tests:

TestPNCounterUpdate_FloatKindWithPositiveIncrementOverflow_PositiveInf
TestPNCounterUpdate_FloatKindWithDecrementOverflow_NegativeInf

Further, the following two tests have been added:

TestPNCounterCreate_FloatKindWithNegativeInfValue
TestPNCounterCreate_FloatKindWithPositiveInfValue

Specify the platform(s) on which this was tested:

  • Windows

@ChrisBQu ChrisBQu added the bug Something isn't working label Apr 9, 2025
@ChrisBQu ChrisBQu added this to the DefraDB v0.17 milestone Apr 9, 2025
@ChrisBQu ChrisBQu self-assigned this Apr 9, 2025
Copy link

codecov bot commented Apr 9, 2025

Codecov Report

Attention: Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.

Project coverage is 78.62%. Comparing base (dd30b3b) to head (120e711).
Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
internal/core/crdt/counter.go 76.92% 2 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3604      +/-   ##
===========================================
- Coverage    78.67%   78.62%   -0.05%     
===========================================
  Files          405      409       +4     
  Lines        37063    37295     +232     
===========================================
+ Hits         29157    29321     +164     
- Misses        6175     6225      +50     
- Partials      1731     1749      +18     
Flag Coverage Δ
all-tests 78.62% <76.92%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/core/crdt/errors.go 50.00% <ø> (ø)
internal/core/crdt/counter.go 68.94% <76.92%> (+3.39%) ⬆️

... and 27 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd30b3b...120e711. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ChrisBQu ChrisBQu added the area/crdt Related to the (Merkle) CRDT system label Apr 9, 2025
},
},
},
ExpectedError: "error merging delta: operation results in a NaN, Inf, or -Inf value.",
Copy link
Contributor

Choose a reason for hiding this comment

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

thought: maybe it should be part of defradb configuration to allow different behavior for such cases.
Users might want to:

  • return error
  • saturate the value
  • allow infinity

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This would be a major change of direction, I think. Let's discuss it in standup, I think.

@ChrisBQu ChrisBQu requested a review from a team April 10, 2025 18:26
@ChrisBQu ChrisBQu marked this pull request as ready for review April 28, 2025 20:18

newValue := curValue + value

// Disallow increments that cause overflow, and throw error
Copy link
Contributor

Choose a reason for hiding this comment

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

question: I thought we agreed to store infinitely precise floats, merge them, and then return NaN when queried?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I misunderstood. I thought the plan was to go ahead and merge this, and that this change would take place on a separate PR in the future. Clearly, I am mistaken. :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also, I see Fred reacted to the message, but I hope the notifications are not interrupting his vacation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/crdt Related to the (Merkle) CRDT system bug Something isn't working

Projects

None yet

3 participants