Skip to content

Commit 2e87fa8

Browse files
jasonstackmichaelsembwever
authored andcommitted
CNDB-15565: CNDB-15160: add counter to track num of skipped compaction aggregates due to insufficient disk space (#1962)
count num of skipped compaction aggregates due to insufficient disk space
1 parent c02813d commit 2e87fa8

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

src/java/org/apache/cassandra/db/compaction/AbstractCompactionStrategy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ protected BackgroundCompactions getBackgroundCompactions()
358358
return backgroundCompactions;
359359
}
360360

361+
public long getSkippedAggregatesDueToDiskSpace()
362+
{
363+
return backgroundCompactions.getSkippedAggregatesDueToDiskSpace();
364+
}
365+
361366
public static Map<String, String> validateOptions(Map<String, String> options) throws ConfigurationException
362367
{
363368
return CompactionStrategyOptions.validateOptions(options);

src/java/org/apache/cassandra/db/compaction/BackgroundCompactions.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.List;
2424
import java.util.TreeMap;
2525
import java.util.concurrent.ConcurrentHashMap;
26+
import java.util.concurrent.atomic.AtomicLong;
2627

2728
import com.google.common.collect.ImmutableList;
2829
import org.slf4j.Logger;
@@ -73,6 +74,11 @@ public class BackgroundCompactions
7374
*/
7475
MovingAverage compactionRate = ExpMovingAverage.decayBy1000();
7576

77+
/**
78+
* Track num of skipped compaction aggregates due to insufficient disk space
79+
*/
80+
private final AtomicLong skippedAggregatesDueToDiskSpace = new AtomicLong(0);
81+
7682
BackgroundCompactions(CompactionRealm realm)
7783
{
7884
this.metadata = realm.metadata();
@@ -283,6 +289,16 @@ private void updateCompactionRate(CompactionProgress progress)
283289
}
284290
}
285291

292+
public void incrementSkippedAggregatesDueToDiskSpace()
293+
{
294+
skippedAggregatesDueToDiskSpace.incrementAndGet();
295+
}
296+
297+
public long getSkippedAggregatesDueToDiskSpace()
298+
{
299+
return skippedAggregatesDueToDiskSpace.get();
300+
}
301+
286302
public Collection<CompactionAggregate> getAggregates()
287303
{
288304
return aggregates;

src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,10 @@ List<CompactionAggregate> getSelection(List<CompactionAggregate.UnifiedAggregate
10891089
++proposed;
10901090
long overheadSizeInBytes = pick.totalOverheadInBytes();
10911091
if (overheadSizeInBytes > spaceAvailable)
1092+
{
1093+
getBackgroundCompactions().incrementSkippedAggregatesDueToDiskSpace();
10921094
continue; // compaction is too large for current cycle
1095+
}
10931096

10941097
int currentLevel = levelOf(pick);
10951098
boolean isAdaptive = controller.isRecentAdaptive(pick);

test/unit/org/apache/cassandra/db/compaction/UnifiedCompactionStrategyGetSelectionTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ public void testGetSelection(List<CompactionAggregate.UnifiedAggregate> compacti
190190
when(strategy.getController()).thenReturn(controller);
191191
when(strategy.getShardingStats(any())).thenReturn(stats);
192192
when(strategy.getSelection(any(), anyInt(), any(), anyLong(), anyInt())).thenCallRealMethod();
193+
when(strategy.getBackgroundCompactions()).thenReturn(Mockito.mock(BackgroundCompactions.class));
193194

194195
int[] perLevel = new int[levelCount];
195196
int maxReservations = totalCount / levelCount;

test/unit/org/apache/cassandra/db/compaction/UnifiedCompactionStrategyTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.ArrayList;
2323
import java.util.Arrays;
2424
import java.util.Collection;
25+
import java.util.Collections;
2526
import java.util.Comparator;
2627
import java.util.HashMap;
2728
import java.util.HashSet;
@@ -42,6 +43,7 @@
4243
import com.google.common.collect.ImmutableSet;
4344
import com.google.common.collect.Iterables;
4445
import com.google.common.collect.Sets;
46+
4547
import org.junit.Assert;
4648
import org.junit.After;
4749
import org.junit.Before;
@@ -72,13 +74,15 @@
7274
import org.mockito.Mockito;
7375

7476
import static org.assertj.core.api.Assertions.assertThat;
77+
7578
import static org.junit.Assert.assertEquals;
7679
import static org.junit.Assert.assertFalse;
7780
import static org.junit.Assert.assertNotEquals;
7881
import static org.junit.Assert.assertNotNull;
7982
import static org.junit.Assert.assertNull;
8083
import static org.junit.Assert.assertSame;
8184
import static org.junit.Assert.assertTrue;
85+
8286
import static org.mockito.ArgumentMatchers.any;
8387
import static org.mockito.ArgumentMatchers.anyDouble;
8488
import static org.mockito.ArgumentMatchers.anyInt;
@@ -2209,4 +2213,47 @@ public void testGetLevel()
22092213
assertEquals(0.25d, level.min, 0);
22102214
assertEquals(0.5d, level.max, 0);
22112215
}
2216+
2217+
@Test
2218+
public void testSkippedAggregatesOnInsufficientDiskSpace()
2219+
{
2220+
long overheadSizeInBytes = 1000L;
2221+
long insufficientSpaceAvailable = 500L;
2222+
2223+
BackgroundCompactions backgroundCompactions = Mockito.mock(BackgroundCompactions.class);
2224+
Controller controller = Mockito.mock(Controller.class, Mockito.withSettings().stubOnly());
2225+
2226+
when(controller.prioritize(anyList())).thenCallRealMethod();
2227+
when(controller.getReservedThreads()).thenReturn(0);
2228+
when(controller.getReservationsType()).thenReturn(Reservations.Type.PER_LEVEL);
2229+
when(controller.getOverheadSizeInBytes(any(), anyLong())).thenReturn(overheadSizeInBytes);
2230+
when(controller.isRecentAdaptive(any())).thenReturn(false);
2231+
when(controller.overlapInclusionMethod()).thenReturn(Overlaps.InclusionMethod.TRANSITIVE);
2232+
when(controller.parallelizeOutputShards()).thenReturn(false);
2233+
2234+
CompactionSSTable mockSSTable = Mockito.mock(CompactionSSTable.class);
2235+
CompactionPick pick = CompactionPick.create(TimeUUID.Generator.nextTimeUUID(),
2236+
0,
2237+
ImmutableList.of(mockSSTable),
2238+
Collections.emptySet(),
2239+
1,
2240+
overheadSizeInBytes,
2241+
overheadSizeInBytes,
2242+
overheadSizeInBytes);
2243+
2244+
CompactionAggregate.UnifiedAggregate aggregate = Mockito.mock(CompactionAggregate.UnifiedAggregate.class, Mockito.withSettings().stubOnly());
2245+
when(aggregate.getSelected()).thenReturn(pick);
2246+
when(aggregate.maxOverlap()).thenReturn(0);
2247+
2248+
UnifiedCompactionStrategy strategy = new UnifiedCompactionStrategy(strategyFactory, backgroundCompactions, controller);
2249+
List<CompactionAggregate.UnifiedAggregate> pending = Arrays.asList(aggregate);
2250+
int[] perLevel = new int[1];
2251+
2252+
List<CompactionAggregate> result = strategy.getSelection(pending, 1, perLevel, insufficientSpaceAvailable, 0);
2253+
assertEquals("No compactions should be selected when insufficient disk space", 0, result.size());
2254+
Mockito.verify(backgroundCompactions, Mockito.times(1)).incrementSkippedAggregatesDueToDiskSpace();
2255+
2256+
Mockito.when(backgroundCompactions.getSkippedAggregatesDueToDiskSpace()).thenReturn(1L);
2257+
assertThat(strategy.getSkippedAggregatesDueToDiskSpace()).isEqualTo(1);
2258+
}
22122259
}

0 commit comments

Comments
 (0)