Repository: cassandra Updated Branches: refs/heads/trunk b6350ca7a -> f9d4044f1
Make it possible to set DTCS max_sstable_age in fractional days Patch by marcuse; reviewed by jshook for CASSANDRA-8406 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/93769b3b Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/93769b3b Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/93769b3b Branch: refs/heads/trunk Commit: 93769b3b90a16cccea6dee2b2d224d4ed90993c1 Parents: 782b0b6 Author: Marcus Eriksson <marc...@apache.org> Authored: Tue Feb 17 10:26:55 2015 +0100 Committer: Marcus Eriksson <marc...@apache.org> Committed: Tue Feb 17 10:26:55 2015 +0100 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../DateTieredCompactionStrategyOptions.java | 11 +++---- .../DateTieredCompactionStrategyTest.java | 31 ++++++++++++++++++++ 3 files changed, 38 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/93769b3b/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 3d7bf12..2052f70 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 2.0.13: + * Make it possible to set max_sstable_age to fractional days (CASSANDRA-8406) * Fix memory leak in SSTableSimple*Writer and SSTableReader.validate() (CASSANDRA-8748) * Fix some multi-column relations with indexes on some clustering columns (CASSANDRA-8275) http://git-wip-us.apache.org/repos/asf/cassandra/blob/93769b3b/src/java/org/apache/cassandra/db/compaction/DateTieredCompactionStrategyOptions.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/compaction/DateTieredCompactionStrategyOptions.java b/src/java/org/apache/cassandra/db/compaction/DateTieredCompactionStrategyOptions.java index ddc8dc7..f54c020 100644 --- a/src/java/org/apache/cassandra/db/compaction/DateTieredCompactionStrategyOptions.java +++ b/src/java/org/apache/cassandra/db/compaction/DateTieredCompactionStrategyOptions.java @@ -25,7 +25,7 @@ import org.apache.cassandra.exceptions.ConfigurationException; public final class DateTieredCompactionStrategyOptions { protected static final TimeUnit DEFAULT_TIMESTAMP_RESOLUTION = TimeUnit.MICROSECONDS; - protected static final long DEFAULT_MAX_SSTABLE_AGE_DAYS = 365; + protected static final double DEFAULT_MAX_SSTABLE_AGE_DAYS = 365; protected static final long DEFAULT_BASE_TIME_SECONDS = 60; protected static final String TIMESTAMP_RESOLUTION_KEY = "timestamp_resolution"; protected static final String MAX_SSTABLE_AGE_KEY = "max_sstable_age_days"; @@ -39,14 +39,15 @@ public final class DateTieredCompactionStrategyOptions String optionValue = options.get(TIMESTAMP_RESOLUTION_KEY); TimeUnit timestampResolution = optionValue == null ? DEFAULT_TIMESTAMP_RESOLUTION : TimeUnit.valueOf(optionValue); optionValue = options.get(MAX_SSTABLE_AGE_KEY); - maxSSTableAge = timestampResolution.convert(optionValue == null ? DEFAULT_MAX_SSTABLE_AGE_DAYS : Long.parseLong(optionValue), TimeUnit.DAYS); + double fractionalDays = optionValue == null ? DEFAULT_MAX_SSTABLE_AGE_DAYS : Double.parseDouble(optionValue); + maxSSTableAge = Math.round(fractionalDays * timestampResolution.convert(1, TimeUnit.DAYS)); optionValue = options.get(BASE_TIME_KEY); baseTime = timestampResolution.convert(optionValue == null ? DEFAULT_BASE_TIME_SECONDS : Long.parseLong(optionValue), TimeUnit.SECONDS); } public DateTieredCompactionStrategyOptions() { - maxSSTableAge = DEFAULT_TIMESTAMP_RESOLUTION.convert(DEFAULT_MAX_SSTABLE_AGE_DAYS, TimeUnit.DAYS); + maxSSTableAge = Math.round(DEFAULT_MAX_SSTABLE_AGE_DAYS * DEFAULT_TIMESTAMP_RESOLUTION.convert(1, TimeUnit.DAYS)); baseTime = DEFAULT_TIMESTAMP_RESOLUTION.convert(DEFAULT_BASE_TIME_SECONDS, TimeUnit.SECONDS); } @@ -66,10 +67,10 @@ public final class DateTieredCompactionStrategyOptions optionValue = options.get(MAX_SSTABLE_AGE_KEY); try { - long maxSStableAge = optionValue == null ? DEFAULT_MAX_SSTABLE_AGE_DAYS : Long.parseLong(optionValue); + 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: %d", MAX_SSTABLE_AGE_KEY, maxSStableAge)); + throw new ConfigurationException(String.format("%s must be non-negative: %.2f", MAX_SSTABLE_AGE_KEY, maxSStableAge)); } } catch (NumberFormatException e) http://git-wip-us.apache.org/repos/asf/cassandra/blob/93769b3b/test/unit/org/apache/cassandra/db/compaction/DateTieredCompactionStrategyTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/compaction/DateTieredCompactionStrategyTest.java b/test/unit/org/apache/cassandra/db/compaction/DateTieredCompactionStrategyTest.java index 84230da..7d48575 100644 --- a/test/unit/org/apache/cassandra/db/compaction/DateTieredCompactionStrategyTest.java +++ b/test/unit/org/apache/cassandra/db/compaction/DateTieredCompactionStrategyTest.java @@ -19,6 +19,7 @@ package org.apache.cassandra.db.compaction; import java.nio.ByteBuffer; import java.util.*; +import java.util.concurrent.TimeUnit; import org.junit.Test; @@ -94,6 +95,36 @@ public class DateTieredCompactionStrategyTest extends SchemaLoader } @Test + public void testTimeConversions() + { + Map<String, String> options = new HashMap<>(); + options.put(DateTieredCompactionStrategyOptions.BASE_TIME_KEY, "30"); + options.put(DateTieredCompactionStrategyOptions.TIMESTAMP_RESOLUTION_KEY, "SECONDS"); + + DateTieredCompactionStrategyOptions opts = new DateTieredCompactionStrategyOptions(options); + assertEquals(opts.maxSSTableAge, TimeUnit.SECONDS.convert(365, TimeUnit.DAYS)); + + options.put(DateTieredCompactionStrategyOptions.TIMESTAMP_RESOLUTION_KEY, "MILLISECONDS"); + opts = new DateTieredCompactionStrategyOptions(options); + assertEquals(opts.maxSSTableAge, TimeUnit.MILLISECONDS.convert(365, TimeUnit.DAYS)); + + options.put(DateTieredCompactionStrategyOptions.TIMESTAMP_RESOLUTION_KEY, "MICROSECONDS"); + options.put(DateTieredCompactionStrategyOptions.MAX_SSTABLE_AGE_KEY, "10"); + opts = new DateTieredCompactionStrategyOptions(options); + assertEquals(opts.maxSSTableAge, TimeUnit.MICROSECONDS.convert(10, TimeUnit.DAYS)); + + options.put(DateTieredCompactionStrategyOptions.MAX_SSTABLE_AGE_KEY, "0.5"); + opts = new DateTieredCompactionStrategyOptions(options); + assertEquals(opts.maxSSTableAge, TimeUnit.MICROSECONDS.convert(1, TimeUnit.DAYS) / 2); + + options.put(DateTieredCompactionStrategyOptions.TIMESTAMP_RESOLUTION_KEY, "HOURS"); + options.put(DateTieredCompactionStrategyOptions.MAX_SSTABLE_AGE_KEY, "0.5"); + opts = new DateTieredCompactionStrategyOptions(options); + assertEquals(opts.maxSSTableAge, 12); + + } + + @Test public void testGetBuckets() { List<Pair<String, Long>> pairs = Lists.newArrayList(