forked from Ericsson/ecchronos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for parallel vnode repair
- Iterates through all token ranges in the replica repair group - Adds each range to the combinedRanges set - Create one vnode repair task for all combinedRanges - Create one repair session per range in collection and start each session
- Loading branch information
sajid riaz
committed
Dec 17, 2024
1 parent
267d72c
commit e81faf9
Showing
5 changed files
with
351 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
230 changes: 230 additions & 0 deletions
230
...java/com/ericsson/bss/cassandra/ecchronos/core/impl/repair/vnode/TestVnodeRepairTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
/* | ||
* Copyright 2024 Telefonaktiebolaget LM Ericsson | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.ericsson.bss.cassandra.ecchronos.core.impl.repair.vnode; | ||
|
||
import com.datastax.oss.driver.api.core.metadata.Node; | ||
import com.ericsson.bss.cassandra.ecchronos.core.jmx.DistributedJmxProxy; | ||
import com.ericsson.bss.cassandra.ecchronos.core.jmx.DistributedJmxProxyFactory; | ||
import com.ericsson.bss.cassandra.ecchronos.core.metadata.DriverNode; | ||
import com.ericsson.bss.cassandra.ecchronos.core.repair.config.RepairConfiguration; | ||
import com.ericsson.bss.cassandra.ecchronos.core.state.LongTokenRange; | ||
import com.ericsson.bss.cassandra.ecchronos.core.state.RepairHistory; | ||
import com.ericsson.bss.cassandra.ecchronos.core.table.TableReference; | ||
import com.ericsson.bss.cassandra.ecchronos.core.table.TableRepairMetrics; | ||
import com.ericsson.bss.cassandra.ecchronos.data.repairhistory.RepairHistoryService; | ||
import com.ericsson.bss.cassandra.ecchronos.utils.enums.repair.RepairStatus; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
import static org.mockito.Mockito.*; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class TestVnodeRepairTask { | ||
@Mock | ||
private Node mockNode; | ||
|
||
@Mock | ||
private DistributedJmxProxyFactory mockJmxProxyFactory; | ||
|
||
@Mock | ||
private TableReference mockTableReference; | ||
|
||
@Mock | ||
private RepairConfiguration mockRepairConfiguration; | ||
|
||
@Mock | ||
private TableRepairMetrics mockTableRepairMetrics; | ||
|
||
@Mock | ||
private RepairHistory mockRepairHistory; | ||
|
||
@Mock | ||
private DistributedJmxProxy mockJmxProxy; | ||
|
||
@Mock | ||
private RepairHistoryService.RepairSession mockRepairSession; | ||
|
||
private Set<LongTokenRange> tokenRanges; | ||
private Set<DriverNode> replicas; | ||
private UUID jobId; | ||
private VnodeRepairTask vnodeRepairTask; | ||
|
||
@Before | ||
public void setup() { | ||
UUID nodeId = UUID.randomUUID(); | ||
jobId = UUID.randomUUID(); | ||
tokenRanges = new HashSet<>(); | ||
replicas = new HashSet<>(); | ||
|
||
when(mockNode.getHostId()).thenReturn(nodeId); | ||
when(mockRepairHistory.newSession(eq(mockNode), eq(mockTableReference), eq(jobId), any(), any())) | ||
.thenReturn(mockRepairSession); | ||
} | ||
|
||
@Test | ||
public void testParallelVnodeRepairExecution() { | ||
// Setup | ||
LongTokenRange range1 = new LongTokenRange(0, 100); | ||
LongTokenRange range2 = new LongTokenRange(100, 200); | ||
tokenRanges.add(range1); | ||
tokenRanges.add(range2); | ||
|
||
when(mockRepairConfiguration.getRepairType()).thenReturn(RepairType.PARALLEL_VNODE); | ||
when(mockJmxProxyFactory.create(any())).thenReturn(mockJmxProxy); | ||
|
||
RepairHistoryService.RepairSession mockSession1 = mock(RepairHistoryService.RepairSession.class); | ||
RepairHistoryService.RepairSession mockSession2 = mock(RepairHistoryService.RepairSession.class); | ||
|
||
when(mockRepairHistory.newSession(eq(mockNode), eq(mockTableReference), eq(jobId), eq(range1), eq(replicas))) | ||
.thenReturn(mockSession1); | ||
when(mockRepairHistory.newSession(eq(mockNode), eq(mockTableReference), eq(jobId), eq(range2), eq(replicas))) | ||
.thenReturn(mockSession2); | ||
|
||
// Create task | ||
vnodeRepairTask = new VnodeRepairTask(mockNode, mockJmxProxyFactory, mockTableReference, | ||
mockRepairConfiguration, mockTableRepairMetrics, mockRepairHistory, | ||
tokenRanges, replicas, jobId); | ||
|
||
// Execute repair | ||
vnodeRepairTask.execute(); | ||
|
||
// Verify both sessions were started in parallel | ||
verify(mockSession1, timeout(1000)).start(); | ||
verify(mockSession2, timeout(1000)).start(); | ||
|
||
// Verify sessions are properly finished | ||
vnodeRepairTask.onFinish(RepairStatus.SUCCESS); | ||
|
||
verify(mockSession1).finish(RepairStatus.SUCCESS); | ||
verify(mockSession2).finish(RepairStatus.SUCCESS); | ||
} | ||
|
||
@Test | ||
public void testParallelVnodeRepairWithFailure() { | ||
// Setup | ||
LongTokenRange range1 = new LongTokenRange(0, 100); | ||
LongTokenRange range2 = new LongTokenRange(100, 200); | ||
LongTokenRange range3 = new LongTokenRange(200, 300); | ||
tokenRanges.add(range1); | ||
tokenRanges.add(range2); | ||
tokenRanges.add(range3); | ||
|
||
when(mockRepairConfiguration.getRepairType()).thenReturn(RepairType.PARALLEL_VNODE); | ||
when(mockJmxProxyFactory.create(any())).thenReturn(mockJmxProxy); | ||
|
||
RepairHistoryService.RepairSession mockSession1 = mock(RepairHistoryService.RepairSession.class); | ||
RepairHistoryService.RepairSession mockSession2 = mock(RepairHistoryService.RepairSession.class); | ||
RepairHistoryService.RepairSession mockSession3 = mock(RepairHistoryService.RepairSession.class); | ||
|
||
when(mockRepairHistory.newSession(eq(mockNode), eq(mockTableReference), eq(jobId), eq(range1), eq(replicas))) | ||
.thenReturn(mockSession1); | ||
when(mockRepairHistory.newSession(eq(mockNode), eq(mockTableReference), eq(jobId), eq(range2), eq(replicas))) | ||
.thenReturn(mockSession2); | ||
when(mockRepairHistory.newSession(eq(mockNode), eq(mockTableReference), eq(jobId), eq(range3), eq(replicas))) | ||
.thenReturn(mockSession3); | ||
|
||
// Simulate session2 failing during start | ||
doThrow(new RuntimeException("Simulated repair failure")).when(mockSession2).start(); | ||
|
||
// Create task | ||
vnodeRepairTask = new VnodeRepairTask(mockNode, mockJmxProxyFactory, mockTableReference, | ||
mockRepairConfiguration, mockTableRepairMetrics, mockRepairHistory, | ||
tokenRanges, replicas, jobId); | ||
|
||
// Execute repair | ||
vnodeRepairTask.execute(); | ||
|
||
// Verify all sessions were attempted to start | ||
verify(mockSession1, timeout(1000)).start(); | ||
verify(mockSession2, timeout(1000)).start(); | ||
verify(mockSession3, timeout(1000)).start(); | ||
|
||
// Verify session2 was marked as failed | ||
verify(mockSession2, timeout(1000)).finish(RepairStatus.FAILED); | ||
|
||
// Finish the repair task with failure status due to partial failure | ||
vnodeRepairTask.onFinish(RepairStatus.FAILED); | ||
|
||
// Verify all sessions are properly finished | ||
verify(mockSession1).finish(RepairStatus.FAILED); | ||
verify(mockSession3).finish(RepairStatus.FAILED); | ||
|
||
// Verify the failed ranges are tracked | ||
Set<LongTokenRange> failedRanges = vnodeRepairTask.getUnknownRanges(); | ||
assert failedRanges != null && failedRanges.contains(range2); | ||
} | ||
|
||
@Test | ||
public void testParallelVnodeRepairProgress() { | ||
// Setup | ||
LongTokenRange range1 = new LongTokenRange(0, 100); | ||
LongTokenRange range2 = new LongTokenRange(100, 200); | ||
LongTokenRange range3 = new LongTokenRange(200, 300); | ||
tokenRanges.add(range1); | ||
tokenRanges.add(range2); | ||
tokenRanges.add(range3); | ||
|
||
when(mockRepairConfiguration.getRepairType()).thenReturn(RepairType.PARALLEL_VNODE); | ||
when(mockJmxProxyFactory.create(any())).thenReturn(mockJmxProxy); | ||
|
||
RepairHistoryService.RepairSession mockSession1 = mock(RepairHistoryService.RepairSession.class); | ||
RepairHistoryService.RepairSession mockSession2 = mock(RepairHistoryService.RepairSession.class); | ||
RepairHistoryService.RepairSession mockSession3 = mock(RepairHistoryService.RepairSession.class); | ||
|
||
when(mockRepairHistory.newSession(eq(mockNode), eq(mockTableReference), eq(jobId), eq(range1), eq(replicas))) | ||
.thenReturn(mockSession1); | ||
when(mockRepairHistory.newSession(eq(mockNode), eq(mockTableReference), eq(jobId), eq(range2), eq(replicas))) | ||
.thenReturn(mockSession2); | ||
when(mockRepairHistory.newSession(eq(mockNode), eq(mockTableReference), eq(jobId), eq(range3), eq(replicas))) | ||
.thenReturn(mockSession3); | ||
|
||
// Create task | ||
vnodeRepairTask = new VnodeRepairTask(mockNode, mockJmxProxyFactory, mockTableReference, | ||
mockRepairConfiguration, mockTableRepairMetrics, mockRepairHistory, | ||
tokenRanges, replicas, jobId); | ||
|
||
// Execute repair | ||
vnodeRepairTask.execute(); | ||
|
||
// Verify all sessions are started | ||
verify(mockSession1, timeout(1000)).start(); | ||
verify(mockSession2, timeout(1000)).start(); | ||
verify(mockSession3, timeout(1000)).start(); | ||
|
||
// Simulate progress by completing repairs one by one | ||
vnodeRepairTask.onRangeFinished(range1, RepairStatus.SUCCESS); | ||
assertEquals("Progress should be ~33% after first range", 0.33d, vnodeRepairTask.getProgress(), 0.01d); | ||
|
||
vnodeRepairTask.onRangeFinished(range2, RepairStatus.SUCCESS); | ||
assertEquals("Progress should be ~66% after second range", 0.66d, vnodeRepairTask.getProgress(), 0.01d); | ||
|
||
vnodeRepairTask.onRangeFinished(range3, RepairStatus.SUCCESS); | ||
assertEquals("Progress should be 100% after all ranges", 1.0d, vnodeRepairTask.getProgress(), 0.01d); | ||
|
||
// Verify final state | ||
vnodeRepairTask.onFinish(RepairStatus.SUCCESS); | ||
verify(mockSession1).finish(RepairStatus.SUCCESS); | ||
verify(mockSession2).finish(RepairStatus.SUCCESS); | ||
verify(mockSession3).finish(RepairStatus.SUCCESS); | ||
} | ||
} |
Oops, something went wrong.