Skip to content

Vint encoiding and duration refactor#415

Open
adespawn wants to merge 3 commits intoscylladb:mainfrom
adespawn:long-too-long
Open

Vint encoiding and duration refactor#415
adespawn wants to merge 3 commits intoscylladb:mainfrom
adespawn:long-too-long

Conversation

@adespawn
Copy link
Contributor

Refactor the VintEncoding and duration to use BigInt instead of Long for the internal uses. No changes to the duration public API were made.
For duration I also refactor util.format into `${}` syntax

Fixes: #378
Refs: #41

@adespawn
Copy link
Contributor Author

adespawn commented Mar 18, 2026

Oh, there appearst to be a bug in the DSx driver that I just caught with this change:

When we go to addNanos the nanos is stripped of the - sign. DSx when parsing the "9223372036854775808" created "-9223372036854775808" Long value, as representing +9223372036854775808 is not possible in 64 bit type. This then allowed the driver to pass validate64 check as we were comparing -9223372036854775808<=9223372036854775807 which was true. Now, after using bigint, we properly parse it into +9223372036854775808, which fails the validation check.

@wprzytula wprzytula marked this pull request as draft March 18, 2026 15:07
@adespawn adespawn requested a review from Copilot March 19, 2026 14:52
@adespawn adespawn marked this pull request as ready for review March 19, 2026 14:52
@adespawn adespawn self-assigned this Mar 19, 2026
@adespawn adespawn added this to the GA milestone Mar 19, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR modernizes internal VInt encoding/decoding and Duration’s internal nanosecond arithmetic by moving from Long to native bigint, while keeping the Duration public API (e.g., duration.nanoseconds returning Long) intact. It also replaces several util.format() calls in duration parsing/validation with template literals.

Changes:

  • Refactor utils.VIntCoding read/write paths to operate on bigint (including zig-zag encode/decode).
  • Update Duration serialization/deserialization and builder math to use bigint internally for nanoseconds.
  • Replace util.format() usage in duration parsing/validation errors with template literals.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
lib/utils.js Refactors VIntCoding implementation to use bigint instead of Long.
lib/types/duration.js Switches internal nanosecond math + VInt interactions to bigint; updates error formatting strings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Update Vint encoding to use BigInt instead of Long.
Replace internal uses of Long to BigInt. This does not change the API
of the class. Replace util.format() to "`${}`" syntax.
In the DSx code, when addNanos received ABS(MIN_INT64)
[ex. when parsing MIN_INT64 ns duration], it pared it into 64 bit type,
which quietly converted it into MIN_INT64, rather than the expected ABS(MIN_INT64).
This then allowed it to pass the check in `validateNanos`, as we were
comparing negative value instead of the expected positive value.

With the replacement of Long in favour of BigInt, we now correctly
parse ABS(MIN_INT64) when creating a BigInt. This leads to incorrectly
trigger the validate64 error check when parsing MIN_INT64 ns duration.

This commit adds a check that take into account the difference between
ABS(MIN_INT64) and MAX_INT64, by accepting ABS(MIN_INT64) only for negative durations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modernise VIntCoding

2 participants