mirror of
https://github.com/fluencelabs/redis
synced 2025-03-22 10:30:49 +00:00
CONFIG REWRITE: when rewriting amount of bytes use GB, MB, KB if possible.
This commit is contained in:
parent
c590e18d15
commit
8a44e6c490
38
src/config.c
38
src/config.c
@ -1231,13 +1231,34 @@ void rewriteConfigRewriteLine(struct rewriteConfigState *state, char *option, sd
|
|||||||
sdsfree(o);
|
sdsfree(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Write the long long 'bytes' value as a string in a way that is parsable
|
||||||
|
* inside redis.conf. If possible uses the GB, MB, KB notation. */
|
||||||
|
int rewriteConfigFormatMemory(char *buf, size_t len, 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);
|
||||||
|
} else if (bytes && (bytes % mb) == 0) {
|
||||||
|
return snprintf(buf,len,"%lldmb",bytes/mb);
|
||||||
|
} else if (bytes && (bytes % kb) == 0) {
|
||||||
|
return snprintf(buf,len,"%lldkb",bytes/kb);
|
||||||
|
} else {
|
||||||
|
return snprintf(buf,len,"%lld",bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Rewrite a simple "option-name <bytes>" configuration option. */
|
/* Rewrite a simple "option-name <bytes>" configuration option. */
|
||||||
void rewriteConfigBytesOption(struct rewriteConfigState *state, char *option, long long value, long long defvalue) {
|
void rewriteConfigBytesOption(struct rewriteConfigState *state, char *option, long long value, long long defvalue) {
|
||||||
|
char buf[64];
|
||||||
int force = value != defvalue;
|
int force = value != defvalue;
|
||||||
/* TODO: check if we can write it using MB, GB, or other suffixes. */
|
sds line;
|
||||||
sds line = sdscatprintf(sdsempty(),"%s %lld",option,value);
|
|
||||||
|
|
||||||
|
rewriteConfigFormatMemory(buf,sizeof(buf),value);
|
||||||
|
line = sdscatprintf(sdsempty(),"%s %s",option,buf);
|
||||||
rewriteConfigRewriteLine(state,option,line,force);
|
rewriteConfigRewriteLine(state,option,line,force);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Rewrite a yes/no option. */
|
/* Rewrite a yes/no option. */
|
||||||
@ -1401,12 +1422,15 @@ void rewriteConfigClientoutputbufferlimitOption(struct rewriteConfigState *state
|
|||||||
(server.client_obuf_limits[j].soft_limit_seconds !=
|
(server.client_obuf_limits[j].soft_limit_seconds !=
|
||||||
clientBufferLimitsDefaults[j].soft_limit_seconds);
|
clientBufferLimitsDefaults[j].soft_limit_seconds);
|
||||||
sds line;
|
sds line;
|
||||||
|
char hard[64], soft[64];
|
||||||
|
|
||||||
line = sdscatprintf(sdsempty(),"%s %s %llu %llu %ld",
|
rewriteConfigFormatMemory(hard,sizeof(hard),
|
||||||
option,
|
server.client_obuf_limits[j].hard_limit_bytes);
|
||||||
getClientLimitClassName(j),
|
rewriteConfigFormatMemory(soft,sizeof(soft),
|
||||||
server.client_obuf_limits[j].hard_limit_bytes,
|
server.client_obuf_limits[j].soft_limit_bytes);
|
||||||
server.client_obuf_limits[j].soft_limit_bytes,
|
|
||||||
|
line = sdscatprintf(sdsempty(),"%s %s %s %s %ld",
|
||||||
|
option, getClientLimitClassName(j), hard, soft,
|
||||||
(long) server.client_obuf_limits[j].soft_limit_seconds);
|
(long) server.client_obuf_limits[j].soft_limit_seconds);
|
||||||
rewriteConfigRewriteLine(state,option,line,force);
|
rewriteConfigRewriteLine(state,option,line,force);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user