|
14 | 14 | import org.apache.lucene.index.MergePolicy; |
15 | 15 | import org.apache.lucene.index.NoMergePolicy; |
16 | 16 | import org.apache.lucene.index.TieredMergePolicy; |
| 17 | +import org.elasticsearch.ElasticsearchParseException; |
17 | 18 | import org.elasticsearch.common.settings.Setting; |
18 | 19 | import org.elasticsearch.common.settings.Setting.Property; |
19 | 20 | import org.elasticsearch.common.unit.ByteSizeUnit; |
@@ -398,26 +399,32 @@ private static CompoundFileThreshold parseCompoundFormat(String noCFSRatio) { |
398 | 399 | return new CompoundFileThreshold(1.0d); |
399 | 400 | } else if (noCFSRatio.equalsIgnoreCase("false")) { |
400 | 401 | return new CompoundFileThreshold(0.0d); |
401 | | - } else { |
| 402 | + } |
| 403 | + NumberFormatException suppressedNfe = null; |
| 404 | + if (noCFSRatio.endsWith("b") == false) { |
| 405 | + // If the value ends with a `b`, it implies it is probably a byte size value, so do not try to parse as a ratio at all. |
| 406 | + // The main motivation is to make parsing faster. Using exception throwing and catching when trying to parse |
| 407 | + // as a ratio as a means of identifying that a string is not a ratio can be quite slow. |
402 | 408 | try { |
403 | | - try { |
404 | | - return new CompoundFileThreshold(Double.parseDouble(noCFSRatio)); |
405 | | - } catch (NumberFormatException ex) { |
406 | | - throw new IllegalArgumentException( |
407 | | - "index.compound_format must be a boolean, a non-negative byte size or a ratio in the interval [0..1] but was: [" |
408 | | - + noCFSRatio |
409 | | - + "]", |
410 | | - ex |
411 | | - ); |
412 | | - } |
413 | | - } catch (IllegalArgumentException e) { |
414 | | - try { |
415 | | - return new CompoundFileThreshold(ByteSizeValue.parseBytesSizeValue(noCFSRatio, INDEX_COMPOUND_FORMAT_SETTING_KEY)); |
416 | | - } catch (RuntimeException e2) { |
417 | | - e.addSuppressed(e2); |
418 | | - } |
419 | | - throw e; |
| 409 | + return new CompoundFileThreshold(Double.parseDouble(noCFSRatio)); |
| 410 | + } catch (NumberFormatException e) { |
| 411 | + // ignore for now, see if it parses as bytes |
| 412 | + suppressedNfe = e; |
| 413 | + } |
| 414 | + } |
| 415 | + try { |
| 416 | + return new CompoundFileThreshold(ByteSizeValue.parseBytesSizeValue(noCFSRatio, INDEX_COMPOUND_FORMAT_SETTING_KEY)); |
| 417 | + } catch (ElasticsearchParseException ex) { |
| 418 | + final var illegalArgumentException = new IllegalArgumentException( |
| 419 | + "index.compound_format must be a boolean, a non-negative byte size or a ratio in the interval [0..1] but was: [" |
| 420 | + + noCFSRatio |
| 421 | + + "]", |
| 422 | + ex |
| 423 | + ); |
| 424 | + if (suppressedNfe != null) { |
| 425 | + illegalArgumentException.addSuppressed(suppressedNfe); |
420 | 426 | } |
| 427 | + throw illegalArgumentException; |
421 | 428 | } |
422 | 429 | } |
423 | 430 |
|
|
0 commit comments