Search in sources :

Example 1 with StreamPlan

use of org.apache.cassandra.streaming.StreamPlan in project cassandra by apache.

the class LocalSyncTask method createStreamPlan.

@VisibleForTesting
StreamPlan createStreamPlan() {
    InetAddressAndPort remote = nodePair.peer;
    StreamPlan plan = new StreamPlan(StreamOperation.REPAIR, 1, false, pendingRepair, previewKind).listeners(this).flushBeforeTransfer(pendingRepair == null);
    if (requestRanges) {
        // see comment on RangesAtEndpoint.toDummyList for why we synthesize replicas here
        plan.requestRanges(remote, desc.keyspace, RangesAtEndpoint.toDummyList(rangesToSync), RangesAtEndpoint.toDummyList(Collections.emptyList()), desc.columnFamily);
    }
    if (transferRanges) {
        // send ranges to the remote node if we are not performing a pull repair
        // see comment on RangesAtEndpoint.toDummyList for why we synthesize replicas here
        plan.transferRanges(remote, desc.keyspace, RangesAtEndpoint.toDummyList(rangesToSync), desc.columnFamily);
    }
    return plan;
}
Also used : StreamPlan(org.apache.cassandra.streaming.StreamPlan) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with StreamPlan

use of org.apache.cassandra.streaming.StreamPlan in project cassandra by apache.

the class LegacySSTableTest method streamLegacyTable.

private void streamLegacyTable(String tablePattern, String legacyVersion) throws Exception {
    String table = String.format(tablePattern, legacyVersion);
    SSTableReader sstable = SSTableReader.open(getDescriptor(legacyVersion, table));
    IPartitioner p = sstable.getPartitioner();
    List<Range<Token>> ranges = new ArrayList<>();
    ranges.add(new Range<>(p.getMinimumToken(), p.getToken(ByteBufferUtil.bytes("100"))));
    ranges.add(new Range<>(p.getToken(ByteBufferUtil.bytes("100")), p.getMinimumToken()));
    List<OutgoingStream> streams = Lists.newArrayList(new CassandraOutgoingFile(StreamOperation.OTHER, sstable.ref(), sstable.getPositionsForRanges(ranges), ranges, sstable.estimatedKeysForRanges(ranges)));
    new StreamPlan(StreamOperation.OTHER).transferStreams(FBUtilities.getBroadcastAddressAndPort(), streams).execute().get();
}
Also used : OutgoingStream(org.apache.cassandra.streaming.OutgoingStream) CassandraOutgoingFile(org.apache.cassandra.db.streaming.CassandraOutgoingFile) StreamPlan(org.apache.cassandra.streaming.StreamPlan) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ArrayList(java.util.ArrayList) Range(org.apache.cassandra.dht.Range) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 3 with StreamPlan

use of org.apache.cassandra.streaming.StreamPlan in project cassandra by apache.

the class LocalSyncTaskTest method incrementalRepairStreamPlan.

@Test
public void incrementalRepairStreamPlan() throws Exception {
    UUID sessionID = registerSession(cfs, true, true);
    ActiveRepairService.ParentRepairSession prs = ActiveRepairService.instance.getParentRepairSession(sessionID);
    RepairJobDesc desc = new RepairJobDesc(sessionID, UUIDGen.getTimeUUID(), KEYSPACE1, CF_STANDARD, prs.getRanges());
    TreeResponse r1 = new TreeResponse(local, createInitialTree(desc, DatabaseDescriptor.getPartitioner()));
    TreeResponse r2 = new TreeResponse(PARTICIPANT2, createInitialTree(desc, DatabaseDescriptor.getPartitioner()));
    LocalSyncTask task = new LocalSyncTask(desc, r1.endpoint, r2.endpoint, MerkleTrees.difference(r1.trees, r2.trees), desc.parentSessionId, true, true, PreviewKind.NONE);
    StreamPlan plan = task.createStreamPlan();
    assertEquals(desc.parentSessionId, plan.getPendingRepair());
    assertFalse(plan.getFlushBeforeTransfer());
    assertNumInOut(plan, 1, 1);
}
Also used : StreamPlan(org.apache.cassandra.streaming.StreamPlan) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with StreamPlan

use of org.apache.cassandra.streaming.StreamPlan in project cassandra by apache.

the class LocalSyncTaskTest method transientLocalStreamPlan.

/**
 * Don't request streams if the other endpoint is a transient replica
 */
@Test
public void transientLocalStreamPlan() throws NoSuchRepairSessionException {
    UUID sessionID = registerSession(cfs, true, true);
    ActiveRepairService.ParentRepairSession prs = ActiveRepairService.instance.getParentRepairSession(sessionID);
    RepairJobDesc desc = new RepairJobDesc(sessionID, UUIDGen.getTimeUUID(), KEYSPACE1, CF_STANDARD, prs.getRanges());
    TreeResponse r1 = new TreeResponse(local, createInitialTree(desc, DatabaseDescriptor.getPartitioner()));
    TreeResponse r2 = new TreeResponse(PARTICIPANT2, createInitialTree(desc, DatabaseDescriptor.getPartitioner()));
    LocalSyncTask task = new LocalSyncTask(desc, r1.endpoint, r2.endpoint, MerkleTrees.difference(r1.trees, r2.trees), desc.parentSessionId, false, true, PreviewKind.NONE);
    StreamPlan plan = task.createStreamPlan();
    assertNumInOut(plan, 0, 1);
}
Also used : StreamPlan(org.apache.cassandra.streaming.StreamPlan) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with StreamPlan

use of org.apache.cassandra.streaming.StreamPlan in project cassandra by apache.

the class LocalSyncTask method startSync.

/**
     * Starts sending/receiving our list of differences to/from the remote endpoint: creates a callback
     * that will be called out of band once the streams complete.
     */
protected void startSync(List<Range<Token>> differences) {
    InetAddress local = FBUtilities.getBroadcastAddress();
    // We can take anyone of the node as source or destination, however if one is localhost, we put at source to avoid a forwarding
    InetAddress dst = r2.endpoint.equals(local) ? r1.endpoint : r2.endpoint;
    InetAddress preferred = SystemKeyspace.getPreferredIP(dst);
    String message = String.format("Performing streaming repair of %d ranges with %s", differences.size(), dst);
    logger.info("[repair #{}] {}", desc.sessionId, message);
    boolean isIncremental = false;
    if (desc.parentSessionId != null) {
        ActiveRepairService.ParentRepairSession prs = ActiveRepairService.instance.getParentRepairSession(desc.parentSessionId);
        isIncremental = prs.isIncremental;
    }
    Tracing.traceRepair(message);
    StreamPlan plan = new StreamPlan("Repair", repairedAt, 1, false, isIncremental, false, pendingRepair).listeners(this).flushBeforeTransfer(true).requestRanges(dst, preferred, desc.keyspace, differences, desc.columnFamily);
    if (!pullRepair) {
        // send ranges to the remote node if we are not performing a pull repair
        plan.transferRanges(dst, preferred, desc.keyspace, differences, desc.columnFamily);
    }
    plan.execute();
}
Also used : StreamPlan(org.apache.cassandra.streaming.StreamPlan) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) InetAddress(java.net.InetAddress)

Aggregations

StreamPlan (org.apache.cassandra.streaming.StreamPlan)9 ActiveRepairService (org.apache.cassandra.service.ActiveRepairService)7 UUID (java.util.UUID)6 Test (org.junit.Test)6 SyncRequest (org.apache.cassandra.repair.messages.SyncRequest)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 InetAddress (java.net.InetAddress)1 ArrayList (java.util.ArrayList)1 CassandraOutgoingFile (org.apache.cassandra.db.streaming.CassandraOutgoingFile)1 IPartitioner (org.apache.cassandra.dht.IPartitioner)1 Range (org.apache.cassandra.dht.Range)1 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)1 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)1 OutgoingStream (org.apache.cassandra.streaming.OutgoingStream)1