Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1272,29 +1272,29 @@ int rewriteConfigRewriteLine(struct rewriteConfigState *state, const char *optio
return 1;
}

/* Write the long long 'bytes' value as a string in a way that is parsable
/* Write the unsigned long long 'bytes' value as a string in a way that is parsable
* inside valkey.conf. If possible uses the GB, MB, KB notation. */
int rewriteConfigFormatMemory(char *buf, size_t len, long long bytes) {
int rewriteConfigFormatMemory(char *buf, size_t len, unsigned long long bytes) {
int gb = 1024 * 1024 * 1024;
int mb = 1024 * 1024;
int kb = 1024;

if (bytes && (bytes % gb) == 0) {
return snprintf(buf, len, "%lldgb", bytes / gb);
return snprintf(buf, len, "%llugb", bytes / gb);
} else if (bytes && (bytes % mb) == 0) {
return snprintf(buf, len, "%lldmb", bytes / mb);
return snprintf(buf, len, "%llumb", bytes / mb);
} else if (bytes && (bytes % kb) == 0) {
return snprintf(buf, len, "%lldkb", bytes / kb);
return snprintf(buf, len, "%llukb", bytes / kb);
} else {
return snprintf(buf, len, "%lld", bytes);
return snprintf(buf, len, "%llu", bytes);
}
}

/* Rewrite a simple "option-name <bytes>" configuration option. */
void rewriteConfigBytesOption(struct rewriteConfigState *state,
const char *option,
long long value,
long long defvalue) {
unsigned long long value,
unsigned long long defvalue) {
char buf[64];
int force = value != defvalue;
sds line;
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/introspection.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,19 @@ test {CONFIG REWRITE handles alias config properly} {
}
} {} {external:skip}

test {CONFIG REWRITE handles large unsigned memory config values} {
start_server {tags {"introspection"}} {
r config set maxmemory 9223372036854775808
r config set maxmemory-clients 100%

r config rewrite
restart_server 0 true false

assert_equal [lindex [r config get maxmemory] 1] 9223372036854775808
assert_equal [lindex [r config get maxmemory-clients] 1] 100%
}
} {} {external:skip}

test {SIGNED MEMORY CONFIG allows negative number} {
start_server {tags {"introspection"}} {
r config set slot-migration-max-failover-repl-bytes -1
Expand Down
Loading