Repository navigation
Support setlocale via CONFIG operation. - #11059
Conversation
Move setlocale() to initServer(). Modify annotations.
oranagra
left a comment
There was a problem hiding this comment.
@redis/core-team please approve a new config.
|
maybe a |
|
we discussed it in core team meeting, and decide to make it more forward compatible, that is change the @yourtree do you like to implement it? you can refer to |
Sure, I'll do that. |
|
What do you think of the categories that we need to support? I mean, some of them are GNU extensions which are available since glibc 2.2, according to https://man7.org/linux/man-pages/man7/locale.7.html. Shall we support only what the C standards specify or just all of them? @soloestoy |
|
@yourtree I mean you can change the config's format as |
|
I got the format part. What I wanna do is to check the validity of category parameters before calling |
|
we don't need support all categories now, we only allow |
Got it. |
|
sorry to jump in late (i was busy elsewhere). maybe in this case, since it's a plain list of key+value (unlike the soft,hard,time triplet in client buffers), its saner though. |
If you have any type of infrastructure ontop of configs, adding custom ones is very annoying since almost all of them are key/values except this one. If a config really is a coherent config with multiple parts, that seems okay. I don't really think this is though. I would prefer we just have a bunch of string configs for each locale value that can be updated, similar to what Oran suggested. |
|
I've actually implemented it to support multi-arguments and I'm doing some test work. It runs like this Above is a reference and I agree with @oranagra though. Adding multiple string configs seems better than adding a MULTI_ARG_CONFIG. It's better to do the same thing with the same config even if the version is different. It's up to the team whether to accept it or not. |
|
ok, so that means we just need to rename the configs in this PR from |
|
I'm ok with |
|
Updated. |
| is down, doesn't affect pubsub global. */ | ||
| long reply_buffer_peak_reset_time; /* The amount of time (in milliseconds) to wait between reply buffer peak resets */ | ||
| int reply_buffer_resizing_enabled; /* Is reply buffer resizing enabled (1 by default) */ | ||
| /* Local environment*/ |
There was a problem hiding this comment.
| /* Local environment*/ | |
| /* Local environment */ |
| return 1; | ||
| } | ||
|
|
||
|
|
|
|
||
| /* Make sure the locale is set on startup based on the config file. */ | ||
| if (setlocale(LC_COLLATE,server.locale_collate) == NULL) { | ||
| serverLog(LL_WARNING, "Failed to configure LOCALE. %s", strerror(errno)); |
There was a problem hiding this comment.
| serverLog(LL_WARNING, "Failed to configure LOCALE. %s", strerror(errno)); | |
| serverLog(LL_WARNING, "Failed to configure LOCALE: %s", strerror(errno)); |
There was a problem hiding this comment.
usually, on system errors, i'll argue that it's ok.. i.e. the people looking at this will be quick to realize that's ENOENT, and that they should look setlocale man page (it's far better to have that info, than not have it).
btw, i don't see any reference to errno in the man page at all!?
however, in this case if it's a plain user typo, or attempting to use a locale that's not supported, maybe we should print something more friendly.
i suppose it should be the same message we return in CONFIG SET command for an unsupported input (in which we didn't print the errno).
so maybe we should handle ENOENT separately from other errors?
can you check if this API is at all using errno?
There was a problem hiding this comment.
I've browsed the source code of setlocale.c. There's indeed usage of errno but it seems that only EINVAL is used in this and other related APIs ( e.g. _nl_find_locale(), not quite sure about some implicit references, see https://code.woboq.org/userspace/glibc/locale/setlocale.c.html#setlocale), and I'm uncertain when the value of errno was assigned to ENOENT. I agree to print something more intuitive, maybe like serverLog(LL_WARNING, "Failed to configure LOCALE for invalid locale name.");
There was a problem hiding this comment.
i see it was discussed here: https://stackoverflow.com/questions/33668695/setlocale-raising-errno-while-a-non-null-value-is-returned and the conclusion is that setlocale doesn't (or shouldn't) mess with errno.
let's drop using it and replace it with the string you suggested.
There was a problem hiding this comment.
Ok, I'll replace then.
I get Redis to start properly only I comment out 'locale-collate'. |
|
@yymm120 this feature is gonna be part of a future release (probably redis 7.2), wasn't part of 7.0.4. |
| /* Make sure the locale is set on startup based on the config file. */ | ||
| if (setlocale(LC_COLLATE,server.locale_collate) == NULL) { | ||
| serverLog(LL_WARNING, "Failed to configure LOCALE for invalid locale name."); | ||
| exit(1); | ||
| } |
There was a problem hiding this comment.
i found a odd issue:
if i set ulimit -Sv 100000, then it is unable to start the server (missing some logs).
with the default locale-collate value ""
[root@binblog redis]# src/redis-server redis.conf --locale-collate ""
16286:C 21 Jun 2023 11:37:07.391 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
16286:C 21 Jun 2023 11:37:07.391 * Redis version=255.255.255, bits=64, commit=07c14672, modified=1, pid=16286, just started
16286:C 21 Jun 2023 11:37:07.392 * Configuration loaded
16286:M 21 Jun 2023 11:37:07.392 # Failed to configure LOCALE for invalid locale name.
and it is ok the set a another value:
[root@binblog redis]# src/redis-server redis.conf --locale-collate "C"
# is ok, in this case, using config set
127.0.0.1:6379> config get locale-collate
1) "locale-collate"
2) "C"
127.0.0.1:6379> config set locale-collate ""
(error) ERR CONFIG SET failed (possibly related to argument 'locale-collate') - Invalid locale name
Is there a better way to print errors here (i support it is somehow an OOM error),
or rather not let the server exit
Till now Redis officially supported tuning it via environment variable see redis#1074. But we had other requests to allow changing it at runtime, see redis#799, and redis#11041. Note that `strcoll()` is used as Lua comparison function and also for comparison of certain string objects in Redis, which leads to a problem that, in different regions, for some characters, the result may be different. Below is an example. ``` 127.0.0.1:6333> SORT test alpha 1) "<" 2) ">" 3) "," 4) "*" 127.0.0.1:6333> CONFIG GET locale-collate 1) "locale-collate" 2) "" 127.0.0.1:6333> CONFIG SET locale-collate 1 (error) ERR CONFIG SET failed (possibly related to argument 'locale') 127.0.0.1:6333> CONFIG SET locale-collate C OK 127.0.0.1:6333> SORT test alpha 1) "*" 2) "," 3) "<" 4) ">" ``` That will cause accidental code compatibility issues for Lua scripts and some Redis commands. This commit creates a new config parameter to control the local environment which only affects `Collate` category. Above shows how it affects `SORT` command, and below shows the influence on Lua scripts. ``` 127.0.0.1:6333> CONFIG GET locale-collate 1) " locale-collate" 2) "C" 127.0.0.1:6333> EVAL "return ',' < '*'" 0 (nil) 127.0.0.1:6333> CONFIG SET locale-collate "" OK 127.0.0.1:6333> EVAL "return ',' < '*'" 0 (integer) 1 ``` Co-authored-by: calvincjli <[email protected]> Co-authored-by: Oran Agra <[email protected]>

Till now Redis officially supported tuning it via environment variable see #1074.
But we had other requests to allow changing it at runtime, see #799, and #11041.
Note that
strcoll()is used as Lua comparison function and also for comparison of certain string objects in Redis, which leads to a problem that, in different regions, for some characters, the result may be different. Below is an example.That will cause accidental code compatibility issues for Lua scripts and some Redis commands. This commit creates a new config parameter to control the local environment which only affects
Collatecategory. Above shows how it affectsSORTcommand, and below shows the influence on Lua scripts.