Example usage for org.apache.cassandra.repair RepairParallelism PARALLEL

List of usage examples for org.apache.cassandra.repair RepairParallelism PARALLEL

Introduction

In this page you can find the example usage for org.apache.cassandra.repair RepairParallelism PARALLEL.

Prototype

RepairParallelism PARALLEL

To view the source code for org.apache.cassandra.repair RepairParallelism PARALLEL.

Click Source Link

Document

All nodes at the same time

Usage

From source file:io.cassandrareaper.service.RepairRunnerTest.java

License:Apache License

@Test
public void testResumeRepair() throws InterruptedException, ReaperException {
    final String CLUSTER_NAME = "reaper";
    final String KS_NAME = "reaper";
    final Set<String> CF_NAMES = Sets.newHashSet("reaper");
    final boolean INCREMENTAL_REPAIR = false;
    final Set<String> NODES = Sets.newHashSet("127.0.0.1");
    final Set<String> DATACENTERS = Collections.emptySet();
    final Set<String> BLACKLISTED_TABLES = Collections.emptySet();
    final long TIME_RUN = 41L;
    final double INTENSITY = 0.5f;
    final int REPAIR_THREAD_COUNT = 1;

    final IStorage storage = new MemoryStorage();
    AppContext context = new AppContext();
    context.storage = storage;/*from w  w  w.  ja  v  a  2 s.c  o  m*/
    context.config = new ReaperApplicationConfiguration();
    context.repairManager = RepairManager.create(context);

    storage.addCluster(new Cluster(CLUSTER_NAME, null, Collections.<String>singleton("127.0.0.1")));
    UUID cf = storage.addRepairUnit(new RepairUnit.Builder(CLUSTER_NAME, KS_NAME, CF_NAMES, INCREMENTAL_REPAIR,
            NODES, DATACENTERS, BLACKLISTED_TABLES, REPAIR_THREAD_COUNT)).getId();
    DateTimeUtils.setCurrentMillisFixed(TIME_RUN);

    RepairRun run = storage
            .addRepairRun(
                    new RepairRun.Builder(CLUSTER_NAME, cf, DateTime
                            .now(), INTENSITY, 1, RepairParallelism.PARALLEL),
                    Lists.newArrayList(
                            RepairSegment
                                    .builder(Segment.builder()
                                            .withTokenRange(new RingRange(BigInteger.ZERO, BigInteger.ONE))
                                            .build(), cf)
                                    .withState(RepairSegment.State.RUNNING).withStartTime(DateTime.now())
                                    .withCoordinatorHost("reaper"),
                            RepairSegment.builder(Segment.builder()
                                    .withTokenRange(new RingRange(BigInteger.ONE, BigInteger.ZERO)).build(),
                                    cf)));

    final UUID RUN_ID = run.getId();
    final UUID SEGMENT_ID = storage.getNextFreeSegmentInRange(run.getId(), Optional.absent()).get().getId();

    context.repairManager.initializeThreadPool(1, 500, TimeUnit.MILLISECONDS, 1, TimeUnit.MILLISECONDS);

    assertEquals(storage.getRepairSegment(RUN_ID, SEGMENT_ID).get().getState(),
            RepairSegment.State.NOT_STARTED);
    context.jmxConnectionFactory = new JmxConnectionFactory() {
        @Override
        protected JmxProxy connect(final Optional<RepairStatusHandler> handler, Node host,
                int connectionTimeout) throws ReaperException {

            final JmxProxy jmx = mock(JmxProxy.class);
            when(jmx.getClusterName()).thenReturn(CLUSTER_NAME);
            when(jmx.isConnectionAlive()).thenReturn(true);
            when(jmx.tokenRangeToEndpoint(anyString(), any(Segment.class))).thenReturn(Lists.newArrayList(""));
            when(jmx.getRangeToEndpointMap(anyString())).thenReturn(RepairRunnerTest.sixNodeCluster());
            when(jmx.getDataCenter()).thenReturn("dc1");
            when(jmx.getDataCenter(anyString())).thenReturn("dc1");

            when(jmx.triggerRepair(any(BigInteger.class), any(BigInteger.class), any(),
                    any(RepairParallelism.class), any(), anyBoolean(), any(), any(), any(), any(Integer.class)))
                            .then((invocation) -> {
                                assertEquals(RepairSegment.State.NOT_STARTED,
                                        storage.getRepairSegment(RUN_ID, SEGMENT_ID).get().getState());

                                new Thread() {
                                    @Override
                                    public void run() {
                                        handler.get().handle(1, Optional.of(ActiveRepairService.Status.STARTED),
                                                Optional.absent(), null, jmx);

                                        handler.get().handle(1,
                                                Optional.of(ActiveRepairService.Status.SESSION_SUCCESS),
                                                Optional.absent(), null, jmx);

                                        handler.get().handle(1,
                                                Optional.of(ActiveRepairService.Status.FINISHED),
                                                Optional.absent(), null, jmx);
                                    }
                                }.start();
                                return 1;
                            });
            return jmx;
        }
    };

    assertEquals(RepairRun.RunState.NOT_STARTED, storage.getRepairRun(RUN_ID).get().getRunState());
    context.repairManager.resumeRunningRepairRuns();
    assertEquals(RepairRun.RunState.NOT_STARTED, storage.getRepairRun(RUN_ID).get().getRunState());
    storage.updateRepairRun(run.with().runState(RepairRun.RunState.RUNNING).build(RUN_ID));
    context.repairManager.resumeRunningRepairRuns();
    Thread.sleep(1000);
    assertEquals(RepairRun.RunState.DONE, storage.getRepairRun(RUN_ID).get().getRunState());
}

From source file:io.cassandrareaper.service.SegmentRunnerTest.java

License:Apache License

@Test
public void timeoutTest() throws InterruptedException, ReaperException, ExecutionException {
    final AppContext context = new AppContext();
    context.config = Mockito.mock(ReaperApplicationConfiguration.class);
    when(context.config.getJmxConnectionTimeoutInSeconds()).thenReturn(30);
    when(context.config.getDatacenterAvailability()).thenReturn(DatacenterAvailability.ALL);
    context.storage = new MemoryStorage();
    RepairUnit cf = context.storage/* w  w w .  j av  a  2 s  .c  o m*/
            .addRepairUnit(new RepairUnit.Builder("reaper", "reaper", Sets.newHashSet("reaper"), false,
                    Sets.newHashSet("127.0.0.1"), Collections.emptySet(), Collections.emptySet(), 1));
    RepairRun run = context.storage.addRepairRun(
            new RepairRun.Builder("reaper", cf.getId(), DateTime.now(), 0.5, 1, RepairParallelism.PARALLEL),
            Collections.singleton(RepairSegment.builder(
                    Segment.builder().withTokenRange(new RingRange(BigInteger.ONE, BigInteger.ZERO)).build(),
                    cf.getId())));

    final UUID runId = run.getId();
    final UUID segmentId = context.storage.getNextFreeSegmentInRange(run.getId(), Optional.absent()).get()
            .getId();

    final ExecutorService executor = Executors.newSingleThreadExecutor();
    final MutableObject<Future<?>> future = new MutableObject<>();

    context.jmxConnectionFactory = new JmxConnectionFactory() {
        @Override
        public JmxProxy connect(final Optional<RepairStatusHandler> handler, Node host, int connectionTimeout)
                throws ReaperException {

            JmxProxy jmx = mock(JmxProxy.class);
            when(jmx.getClusterName()).thenReturn("reaper");
            when(jmx.isConnectionAlive()).thenReturn(true);
            when(jmx.tokenRangeToEndpoint(anyString(), any(Segment.class))).thenReturn(Lists.newArrayList(""));
            when(jmx.getDataCenter()).thenReturn("dc1");
            when(jmx.getDataCenter(anyString())).thenReturn("dc1");

            when(jmx.triggerRepair(any(BigInteger.class), any(BigInteger.class), any(),
                    any(RepairParallelism.class), any(), anyBoolean(), any(), any(), any(), any(Integer.class)))
                            .then((invocation) -> {
                                assertEquals(RepairSegment.State.NOT_STARTED,
                                        context.storage.getRepairSegment(runId, segmentId).get().getState());

                                future.setValue(executor.submit(new Thread() {
                                    @Override
                                    public void run() {
                                        handler.get().handle(1, Optional.of(ActiveRepairService.Status.STARTED),
                                                Optional.absent(), "Repair command 1 has started", jmx);

                                        assertEquals(RepairSegment.State.RUNNING, context.storage
                                                .getRepairSegment(runId, segmentId).get().getState());
                                    }
                                }));
                                return 1;
                            });

            return jmx;
        }
    };
    RepairRunner rr = mock(RepairRunner.class);
    RepairUnit ru = mock(RepairUnit.class);

    SegmentRunner sr = new SegmentRunner(context, segmentId, Collections.singleton(""), 100, 0.5,
            RepairParallelism.PARALLEL, "reaper", ru, rr);

    sr.run();

    future.getValue().get();
    executor.shutdown();

    assertEquals(RepairSegment.State.NOT_STARTED,
            context.storage.getRepairSegment(runId, segmentId).get().getState());
    assertEquals(1, context.storage.getRepairSegment(runId, segmentId).get().getFailCount());
}

From source file:io.cassandrareaper.service.SegmentRunnerTest.java

License:Apache License

@Test
public void successTest() throws InterruptedException, ReaperException, ExecutionException {
    final IStorage storage = new MemoryStorage();
    RepairUnit cf = storage.addRepairUnit(new RepairUnit.Builder("reaper", "reaper", Sets.newHashSet("reaper"),
            false, Sets.newHashSet("127.0.0.1"), Collections.emptySet(), Collections.emptySet(), 1));
    RepairRun run = storage.addRepairRun(
            new RepairRun.Builder("reaper", cf.getId(), DateTime.now(), 0.5, 1, RepairParallelism.PARALLEL),
            Collections.singleton(RepairSegment.builder(
                    Segment.builder().withTokenRange(new RingRange(BigInteger.ONE, BigInteger.ZERO)).build(),
                    cf.getId())));/* w  w  w. ja v a  2s  . c o m*/
    final UUID runId = run.getId();
    final UUID segmentId = storage.getNextFreeSegmentInRange(run.getId(), Optional.absent()).get().getId();

    final ExecutorService executor = Executors.newSingleThreadExecutor();
    final MutableObject<Future<?>> future = new MutableObject<>();

    AppContext context = new AppContext();
    context.storage = storage;
    context.config = Mockito.mock(ReaperApplicationConfiguration.class);
    when(context.config.getJmxConnectionTimeoutInSeconds()).thenReturn(30);
    when(context.config.getDatacenterAvailability()).thenReturn(DatacenterAvailability.ALL);

    context.jmxConnectionFactory = new JmxConnectionFactory() {
        @Override
        protected JmxProxy connect(final Optional<RepairStatusHandler> handler, Node host,
                int connectionTimeout) throws ReaperException {

            JmxProxy jmx = mock(JmxProxy.class);
            when(jmx.getClusterName()).thenReturn("reaper");
            when(jmx.isConnectionAlive()).thenReturn(true);
            when(jmx.tokenRangeToEndpoint(anyString(), any(Segment.class))).thenReturn(Lists.newArrayList(""));
            when(jmx.getDataCenter()).thenReturn("dc1");
            when(jmx.getDataCenter(anyString())).thenReturn("dc1");

            when(jmx.triggerRepair(any(BigInteger.class), any(BigInteger.class), any(),
                    any(RepairParallelism.class), any(), anyBoolean(), any(), any(), any(), any(Integer.class)))
                            .then(invocation -> {
                                assertEquals(RepairSegment.State.NOT_STARTED,
                                        storage.getRepairSegment(runId, segmentId).get().getState());

                                future.setValue(executor.submit(() -> {
                                    handler.get().handle(1, Optional.of(ActiveRepairService.Status.STARTED),
                                            Optional.absent(), "Repair command 1 has started", jmx);

                                    assertEquals(RepairSegment.State.RUNNING,
                                            storage.getRepairSegment(runId, segmentId).get().getState());
                                    // report about an unrelated repair. Shouldn't affect anything.
                                    handler.get().handle(2,
                                            Optional.of(ActiveRepairService.Status.SESSION_FAILED),
                                            Optional.absent(), "Repair command 2 has failed", jmx);

                                    handler.get().handle(1,
                                            Optional.of(ActiveRepairService.Status.SESSION_SUCCESS),
                                            Optional.absent(), "Repair session succeeded in command 1", jmx);

                                    assertEquals(RepairSegment.State.DONE,
                                            storage.getRepairSegment(runId, segmentId).get().getState());

                                    handler.get().handle(1, Optional.of(ActiveRepairService.Status.FINISHED),
                                            Optional.absent(), "Repair command 1 has finished", jmx);

                                    assertEquals(RepairSegment.State.DONE,
                                            storage.getRepairSegment(runId, segmentId).get().getState());
                                }));
                                return 1;
                            });

            return jmx;
        }
    };

    RepairRunner rr = mock(RepairRunner.class);
    RepairUnit ru = mock(RepairUnit.class);

    SegmentRunner sr = new SegmentRunner(context, segmentId, Collections.singleton(""), 5000, 0.5,
            RepairParallelism.PARALLEL, "reaper", ru, rr);

    sr.run();

    future.getValue().get();
    executor.shutdown();

    assertEquals(RepairSegment.State.DONE, storage.getRepairSegment(runId, segmentId).get().getState());
    assertEquals(0, storage.getRepairSegment(runId, segmentId).get().getFailCount());
}

From source file:io.cassandrareaper.service.SegmentRunnerTest.java

License:Apache License

@Test
public void failureTest() throws InterruptedException, ReaperException, ExecutionException {
    final IStorage storage = new MemoryStorage();
    RepairUnit cf = storage.addRepairUnit(new RepairUnit.Builder("reaper", "reaper", Sets.newHashSet("reaper"),
            false, Sets.newHashSet("127.0.0.1"), Collections.emptySet(), Collections.emptySet(), 1));
    RepairRun run = storage.addRepairRun(
            new RepairRun.Builder("reaper", cf.getId(), DateTime.now(), 0.5, 1, RepairParallelism.PARALLEL),
            Collections.singleton(RepairSegment.builder(
                    Segment.builder().withTokenRange(new RingRange(BigInteger.ONE, BigInteger.ZERO)).build(),
                    cf.getId())));//from  w  w  w.  j av a  2s. c o  m
    final UUID runId = run.getId();
    final UUID segmentId = storage.getNextFreeSegmentInRange(run.getId(), Optional.absent()).get().getId();

    final ExecutorService executor = Executors.newSingleThreadExecutor();
    final MutableObject<Future<?>> future = new MutableObject<>();

    AppContext context = new AppContext();
    context.storage = storage;
    context.config = Mockito.mock(ReaperApplicationConfiguration.class);
    when(context.config.getJmxConnectionTimeoutInSeconds()).thenReturn(30);
    when(context.config.getDatacenterAvailability()).thenReturn(DatacenterAvailability.ALL);

    context.jmxConnectionFactory = new JmxConnectionFactory() {
        @Override
        protected JmxProxy connect(final Optional<RepairStatusHandler> handler, Node host,
                int connectionTimeout) throws ReaperException {

            JmxProxy jmx = mock(JmxProxy.class);
            when(jmx.getClusterName()).thenReturn("reaper");
            when(jmx.isConnectionAlive()).thenReturn(true);
            when(jmx.tokenRangeToEndpoint(anyString(), any(Segment.class))).thenReturn(Lists.newArrayList(""));
            when(jmx.getDataCenter()).thenReturn("dc1");
            when(jmx.getDataCenter(anyString())).thenReturn("dc1");

            when(jmx.triggerRepair(any(BigInteger.class), any(BigInteger.class), any(),
                    any(RepairParallelism.class), any(), anyBoolean(), any(), any(), any(), any(Integer.class)))
                            .then((invocation) -> {
                                assertEquals(RepairSegment.State.NOT_STARTED,
                                        storage.getRepairSegment(runId, segmentId).get().getState());

                                future.setValue(executor.submit(() -> {
                                    handler.get().handle(1, Optional.of(ActiveRepairService.Status.STARTED),
                                            Optional.absent(), "Repair command 1 has started", jmx);

                                    assertEquals(RepairSegment.State.RUNNING,
                                            storage.getRepairSegment(runId, segmentId).get().getState());

                                    handler.get().handle(1,
                                            Optional.of(ActiveRepairService.Status.SESSION_FAILED),
                                            Optional.absent(), "Repair command 1 has failed", jmx);

                                    assertEquals(RepairSegment.State.NOT_STARTED,
                                            storage.getRepairSegment(runId, segmentId).get().getState());

                                    handler.get().handle(1, Optional.of(ActiveRepairService.Status.FINISHED),
                                            Optional.absent(), "Repair command 1 has finished", jmx);

                                    assertEquals(RepairSegment.State.NOT_STARTED,
                                            storage.getRepairSegment(runId, segmentId).get().getState());
                                }));

                                return 1;
                            });

            return jmx;
        }
    };

    RepairRunner rr = mock(RepairRunner.class);
    RepairUnit ru = mock(RepairUnit.class);

    SegmentRunner sr = new SegmentRunner(context, segmentId, Collections.singleton(""), 5000, 0.5,
            RepairParallelism.PARALLEL, "reaper", ru, rr);

    sr.run();

    future.getValue().get();
    executor.shutdown();

    assertEquals(RepairSegment.State.NOT_STARTED, storage.getRepairSegment(runId, segmentId).get().getState());
    assertEquals(2, storage.getRepairSegment(runId, segmentId).get().getFailCount());
}