You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Ekaterina Dimitrova (Jira)" <ji...@apache.org> on 2019/11/26 19:37:00 UTC

[jira] [Commented] (CASSANDRA-13675) Option can be overflowed

    [ https://issues.apache.org/jira/browse/CASSANDRA-13675?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16982793#comment-16982793 ] 

Ekaterina Dimitrova commented on CASSANDRA-13675:
-------------------------------------------------

[~haozhong] , I think in the mentioned issue they try to move to fractions instead of integers ([~marcuse] correct me if I am wrong), I don't think this will help here. 

Both double and long are 64bits. BigInteger looks like the only possible option to me here.  But performance should be considered carefully.

> Option can be overflowed
> ------------------------
>
>                 Key: CASSANDRA-13675
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-13675
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Local/Compaction
>            Reporter: Hao Zhong
>            Priority: Normal
>             Fix For: 4.x
>
>
> The SizeTieredCompactionStrategyOptions_validateOptions method has the following code:
> {code}
>  public static Map<String, String> validateOptions(Map<String, String> options, Map<String, String> uncheckedOptions) throws ConfigurationException
>     {
>         String optionValue = options.get(MIN_SSTABLE_SIZE_KEY);
>         try
>         {
>             long minSSTableSize = optionValue == null ? DEFAULT_MIN_SSTABLE_SIZE : Long.parseLong(optionValue);
>             if (minSSTableSize < 0)
>             {
>                 throw new ConfigurationException(String.format("%s must be non negative: %d", MIN_SSTABLE_SIZE_KEY, minSSTableSize));
>             }
>         }
>         catch (NumberFormatException e)
>         {
>             throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", optionValue, MIN_SSTABLE_SIZE_KEY), e);
>         }
>         ...
>     }
> {code}
> Here, the optionValue can be too long and cause overflow. CASSANDRA-8406 fixed a similar bug. The buggy code is:
> {code}
> public static Map<String, String> validateOptions(Map<String, String> options, Map<String, String> uncheckedOptions) throws  ConfigurationException
>     {
>         String optionValue = options.get(TIMESTAMP_RESOLUTION_KEY);
>         try
>         {
>             if (optionValue != null)
>                 TimeUnit.valueOf(optionValue);
>         }
>         catch (IllegalArgumentException e)
>         {
>             throw new ConfigurationException(String.format("timestamp_resolution %s is not valid", optionValue));
>         }
>         optionValue = options.get(MAX_SSTABLE_AGE_KEY);
>         try
>         {
>             long maxSStableAge = optionValue == null ? DEFAULT_MAX_SSTABLE_AGE_DAYS : Long.parseLong(optionValue);
>             if (maxSStableAge < 0)
>             {
>                 throw new ConfigurationException(String.format("%s must be non-negative: %d", MAX_SSTABLE_AGE_KEY, maxSStableAge));
>             }
>         }
>         catch (NumberFormatException e)
>         {
>             throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", optionValue, MAX_SSTABLE_AGE_KEY), e);
>         }
>        ...
> }
> {code}
> The fixed code uses Double to parse the input:
> {code}
>  public static Map<String, String> validateOptions(Map<String, String> options, Map<String, String> uncheckedOptions) throws  ConfigurationException
>     {
>         String optionValue = options.get(TIMESTAMP_RESOLUTION_KEY);
>         try
>         {
>             if (optionValue != null)
>                 TimeUnit.valueOf(optionValue);
>         }
>         catch (IllegalArgumentException e)
>         {
>             throw new ConfigurationException(String.format("timestamp_resolution %s is not valid", optionValue));
>         }
>         optionValue = options.get(MAX_SSTABLE_AGE_KEY);
>         try
>         {
>             double maxSStableAge = optionValue == null ? DEFAULT_MAX_SSTABLE_AGE_DAYS : Double.parseDouble(optionValue);
>             if (maxSStableAge < 0)
>             {
>                 throw new ConfigurationException(String.format("%s must be non-negative: %.2f", MAX_SSTABLE_AGE_KEY, maxSStableAge));
>             }
>         }
>         catch (NumberFormatException e)
>         {
>             throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", optionValue, MAX_SSTABLE_AGE_KEY), e);
>         }
>      ...
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org