Skip to content

Fix issue #211. Allow key_stddev and key_median options to be set values - #212

Merged
YaacovHazan merged 1 commit into
redis:masterfrom
clkbug:allow-larger-key-median-and-stddev
Apr 20, 2023
Merged

YaacovHazan merged 1 commit into
redis:masterfrom
clkbug:allow-larger-key-median-and-stddev

Conversation

@clkbug

@clkbug clkbug commented Apr 14, 2023

Copy link
Copy Markdown
Contributor

I have fixed issue 211.
This changed key_stddev and key_median to read as unsigned long long.
In real-world use cases, the key ranges will be wide enough that the fractional portions will not matter.

Comment thread memtier_benchmark.cpp Outdated
case o_key_stddev:
endptr = NULL;
cfg->key_stddev = (unsigned int) strtof(optarg, &endptr);
cfg->key_stddev = strtoull(optarg, &endptr, 10);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't like the loss of fractional part. Specifically in stddev.
But anyway I think the problem is just the wrong use of 32bit float instead of double (although even 32bit float can hold values much larger than 32bit integer).
I.e. strtod should solve it and keep both thr fractional part and a huge range.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i missed the fact that we had casting ((unsigned int)), so we didn't have fractional part anyway.
but that casting is actually the problem (not the strtof), so it was maybe enough to just drop the casting.
but if we change these lines, let's got with strtod (changing to strtoull would be a breaking change, since old commands that used to work, will now error)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I understand.
I have changed it to use strtod.

@clkbug
clkbug force-pushed the allow-larger-key-median-and-stddev branch from 2bf9737 to c5f2ddc Compare April 17, 2023 13:03
@YaacovHazan
YaacovHazan merged commit d6083ed into redis:master Apr 20, 2023
@YaacovHazan

Copy link
Copy Markdown
Collaborator

@clkbug Thank you

fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
Follow the #212 precedent of not breaking existing command lines:
strtoul() accepted leading whitespace and a single '+' harmlessly, so
parse_unsigned() (and parse_port(), which wraps it) skips isspace() and
one '+' before requiring a digit. A '-' anywhere before the digits,
empty input, trailing junk, ERANGE and values above max are still
rejected, so the #705/#695 bypasses ("\n-18446744073709551000", "-1",
"", 4294967296) still fail.

-n/-c/-t/--test-time now print "must be a positive integer" for any
malformed value (including trailing junk like "5x"), "must be greater
than zero" only for 0, and "must be <= max" when too large.

The errno-leak test now fails loudly if --key-maximum stops accepting
overflow (#725), and README notes the stricter numeric parsing,
including that an empty --max-reconnect-attempts= is now an error.

Refs #705, #695

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
Follow the #212 precedent of not breaking existing command lines:
strtoul() accepted leading whitespace and a single '+' harmlessly, so
parse_unsigned() (and parse_port(), which wraps it) skips isspace() and
one '+' before requiring a digit. A '-' anywhere before the digits,
empty input, trailing junk, ERANGE and values above max are still
rejected, so the #705/#695 bypasses ("\n-18446744073709551000", "-1",
"", 4294967296) still fail.

-n/-c/-t/--test-time now print "must be a positive integer" for any
malformed value (including trailing junk like "5x"), "must be greater
than zero" only for 0, and "must be <= max" when too large.

The errno-leak test now fails loudly if --key-maximum stops accepting
overflow (#725), and README notes the stricter numeric parsing,
including that an empty --max-reconnect-attempts= is now an error.

Refs #705, #695

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
Follow the #212 precedent of not breaking existing command lines:
strtoul() accepted leading whitespace and a single '+' harmlessly, so
parse_unsigned() (and parse_port(), which wraps it) skips isspace() and
one '+' before requiring a digit. A '-' anywhere before the digits,
empty input, trailing junk, ERANGE and values above max are still
rejected, so the #705/#695 bypasses ("\n-18446744073709551000", "-1",
"", 4294967296) still fail.

-n/-c/-t/--test-time now print "must be a positive integer" for any
malformed value (including trailing junk like "5x"), "must be greater
than zero" only for 0, and "must be <= max" when too large.

The errno-leak test now fails loudly if --key-maximum stops accepting
overflow (#725), and README notes the stricter numeric parsing,
including that an empty --max-reconnect-attempts= is now an error.

Refs #705, #695

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
13 numeric options used strtoul()/strtoull() and a narrowing cast with
no range or format check (#705, #695). Negative values wrapped to huge
ones ("-1", or "\n-18446744073709551000" which slipped past the old
leading-'-' check), values above the option's type were silently
truncated (-c 4294967296 became 0), overflow was ignored, and an empty
value meant 0, e.g. --max-reconnect-attempts= meaning "unlimited".

All of them now go through one parser, parse_unsigned(), and
parse_port() is built on it:
- leading whitespace and a single '+' are accepted, as strtoul() always
  accepted them, so existing command lines keep working (the reasoning
  of #212);
- any '-', an empty value, trailing junk, overflow and values above the
  option's maximum are rejected with exit 2;
- the "unset" sentinels are excluded (-n <= ULLONG_MAX-1,
  --connection-stage-timeout <= UINT_MAX-1).

Messages for -n/-c/-t/--test-time: "must be a positive integer" for
malformed input, "must be greater than zero" for 0, "must be <= MAX"
when too large. Port options (-p, --uri, --read-server, the prometheus
port) follow the same rule, which restores what releases before the
unreleased #699 accepted.

Release note: an empty --max-reconnect-attempts= is now an error; pass
0 for unlimited.

Tests cover every bypass vector per option, the accepted relaxed forms,
the sentinels, the messages and stale-errno handling; they fail on
master. The remaining unchecked options are tracked in #725.

Fixes #705
Fixes #695

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira pushed a commit that referenced this pull request Oct 16, 2026
…et at their real bounds

Review of #748:
- --key-maximum=18446744073709551615 with the default --key-minimum 0 is
  a full 64-bit range. random_range() computed rn % (max - min + 1),
  which wraps to % 0 (SIGFPE with R:R), and gaussian_distribution_range()
  rejected every sample against max + 1 == 0, so G:G hung (it ignores
  SIGTERM). Treat a wrapped span as "any rn", compare against max + 1 in
  double, and clamp the result so a double >= 2^64 is never converted.
  Sequential and parallel patterns were checked and do not wrap.
- --multi-key-get is capped at 16777214, the largest value for which
  keylist's unsigned 256 * (N + 1) buffer size does not wrap, instead
  of 1000000: values that used to work keep working (#212). --help and
  the man page note the ~272 bytes per key per client.
- --data-offset is capped at (1 << 29) - 1 in the parser, so its
  "must be <= N" is true; the later "data-offset too long" check in
  main() is gone.
- --rate-limiting errors say "rate-limiting must be ...".
- README: the message change for --pipeline, -d and
  --reconnect-interval.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
…et at their real bounds

Review of #748:
- --key-maximum=18446744073709551615 with the default --key-minimum 0 is
  a full 64-bit range. random_range() computed rn % (max - min + 1),
  which wraps to % 0 (SIGFPE with R:R), and gaussian_distribution_range()
  rejected every sample against max + 1 == 0, so G:G hung (it ignores
  SIGTERM). Treat a wrapped span as "any rn", compare against max + 1 in
  double, and clamp the result so a double >= 2^64 is never converted.
  Sequential and parallel patterns were checked and do not wrap.
- --multi-key-get is capped at 16777214, the largest value for which
  keylist's unsigned 256 * (N + 1) buffer size does not wrap, instead
  of 1000000: values that used to work keep working (#212). --help and
  the man page note the ~272 bytes per key per client.
- --data-offset is capped at (1 << 29) - 1 in the parser, so its
  "must be <= N" is true; the later "data-offset too long" check in
  main() is gone.
- --rate-limiting errors say "rate-limiting must be ...".
- README: the message change for --pipeline, -d and
  --reconnect-interval.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
redis://user:pw@:6379 (or redis://user:pw@) with no -s/-S fell back to
the default server on master. Erroring out on it broke input that used
to work, which the project avoids (#212). Keep the fallback and say
where the run goes instead:
  warning: --uri has no host; connecting to the default server localhost:6379.
The warning never includes the credentials.

Still reject the case that is clearly wrong: an empty host where the
"credentials" contain '/', '?' or '#', i.e. the '@' was a stray one
after the path (redis://host:6379/1@). That never authenticated
anything meaningful. It is now the only new URI rejection.

Tests: the host-less case warns, connects to the default server and is
redacted; the stray-'@' case is still rejected.

Refs #731

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
…et at their real bounds

Review of #748:
- --key-maximum=18446744073709551615 with the default --key-minimum 0 is
  a full 64-bit range. random_range() computed rn % (max - min + 1),
  which wraps to % 0 (SIGFPE with R:R), and gaussian_distribution_range()
  rejected every sample against max + 1 == 0, so G:G hung (it ignores
  SIGTERM). Treat a wrapped span as "any rn", compare against max + 1 in
  double, and clamp the result so a double >= 2^64 is never converted.
  Sequential and parallel patterns were checked and do not wrap.
- --multi-key-get is capped at 16777214, the largest value for which
  keylist's unsigned 256 * (N + 1) buffer size does not wrap, instead
  of 1000000: values that used to work keep working (#212). --help and
  the man page note the ~272 bytes per key per client.
- --data-offset is capped at (1 << 29) - 1 in the parser, so its
  "must be <= N" is true; the later "data-offset too long" check in
  main() is gone.
- --rate-limiting errors say "rate-limiting must be ...".
- README: the message change for --pipeline, -d and
  --reconnect-interval.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
… JSON only with scanning

Review of #748:
- strtoul("-0") never wrapped, so "-0" and "-00" always meant what was
  typed. Following #212 (keep working command lines working),
  parse_unsigned() now accepts one '-' when the value is zero and still
  rejects every real negative ("-1", "-0x", "+-0", negative overflow).
  This applies to every option on the helper, including #721's (which
  had rejected "-0" on unreleased master only). 0 keeps its meaning
  per option: accepted where valid, "must be greater than zero" where
  not; port options still reject 0. The only breaking change left is
  empty values.
- config_print_to_json() writes scan_incremental_max_iterations only
  with --scan-incremental-iteration, like the staircase keys.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 17, 2026
redis://user:pw@:6379 (or redis://user:pw@) with no -s/-S fell back to
the default server on master. Erroring out on it broke input that used
to work, which the project avoids (#212). Keep the fallback and say
where the run goes instead:
  warning: --uri has no host; connecting to the default server localhost:6379.
The warning never includes the credentials.

Still reject the case that is clearly wrong: an empty host where the
"credentials" contain '/', '?' or '#', i.e. the '@' was a stray one
after the path (redis://host:6379/1@). That never authenticated
anything meaningful. It is now the only new URI rejection.

Tests: the host-less case warns, connects to the default server and is
redacted; the stray-'@' case is still rejected.

Refs #731

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 17, 2026
redis://user:pw@:6379 (or redis://user:pw@) with no -s/-S fell back to
the default server on master. Erroring out on it broke input that used
to work, which the project avoids (#212). Keep the fallback and say
where the run goes instead:
  warning: --uri has no host; connecting to the default server localhost:6379.
The warning never includes the credentials.

Still reject the case that is clearly wrong: an empty host where the
"credentials" contain '/', '?' or '#', i.e. the '@' was a stray one
after the path (redis://host:6379/1@). That never authenticated
anything meaningful. It is now the only new URI rejection.

Tests: the host-less case warns, connects to the default server and is
redacted; the stray-'@' case is still rejected.

Refs #731

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 17, 2026
… back

redis://host:6379/1@ (a stray '@' after the path) and redis://u:a/b@
were still rejected with "missing host in URI". On master both ran
against the default server, so rejecting them broke input that used to
run (#212). The stray-'@' form only ever sent a meaningless AUTH, and
telling it apart from a raw '/' in a password is #732's job. Give them
the same host-less warning and default-server fallback as every other
empty host. This PR now rejects no URI that master accepted.

Tests: the two rejection tests become warn-and-fallback tests, still
redacted. -p keeps their fallback off localhost:6379, and the known-limit
test uses a fixed closed port in the test range (it skips if something
listens there) instead of binding and releasing an ephemeral one.

Refs #731

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

3 participants