Use the standard 'C' locale to handle option conversions correctly in the JNI context. Fixes #13841 #13940
+7
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
RocksDB heavily relies on the default 'C' locale when storing to and reading options from the OPTIONS file.
For example, filter_policy option for bloomfilter has a parameter bits_per_key of double type. When this options is written to the OPTIONS file the value returned by BloomLikeFilterPolicy::GetId() is used. To compose the value, decimal dot is explicitly used:
rocksdb/table/block_based/filter_policy.cc
Lines 1568 to 1584 in d87e598
To read the option parameter the standard C++ std::stod() function is used:
rocksdb/util/string_util.cc
Lines 398 to 404 in d87e598
std::stod() is a locale dependent and for some locales (de_DE.UTF-8, fr_FR.UTF-8, ru_RU.UTF-8, etc) decimal comma is expected and because of this fractional part is not read. Whereas C/C++ code of RocksDB seems to never change the default locale and it's guaranteed to be 'C' by the standard, Java sets locale (for JNI code) according to the system environment.
This bug leads to failures or exceptions in java tests (for example OptionsUtilTest.loadLatestTableFormatOptions) if the said locales are set in the user system.
I suggest to enforce default 'C' locale when JNI library is loaded defining JNI_OnLoad() function from jni.h.
This PR fixes #13841.