From f1ffb501f05ed7b385a9970e5be166b255d73d52 Mon Sep 17 00:00:00 2001 From: Felipe Mendes Date: Sun, 11 Sep 2022 16:11:56 -0300 Subject: [PATCH] time_window_compaction_strategy: reject invalid window_sizes Scylla mistakenly allows an user to configure an invalid TWCS window_size <= 0, which effectively breaks the notion of compaction windows. Interestingly enough, a <= 0 window size should be considered an undefined behavior as either we would create a new window every 0 duration (?) or the table would behave as STCS, the reader is encouraged to figure out which one of these is true. :-) Cassandra, on the other hand, will properly throw a ConfigurationException when receiving such invalid window sizes and we now match the behavior to the same as Cassandra's. Refs: #2336 --- compaction/time_window_compaction_strategy.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compaction/time_window_compaction_strategy.cc b/compaction/time_window_compaction_strategy.cc index f477c07ab2..a6c7c1c543 100644 --- a/compaction/time_window_compaction_strategy.cc +++ b/compaction/time_window_compaction_strategy.cc @@ -43,6 +43,10 @@ time_window_compaction_strategy_options::time_window_compaction_strategy_options } } + if (window_size <= 0) { + throw exceptions::configuration_exception(fmt::format("{} must be greater than 1 for compaction_window_size", window_size)); + } + sstable_window_size = window_size * window_unit; it = options.find(EXPIRED_SSTABLE_CHECK_FREQUENCY_SECONDS_KEY);