Establish bootstrap stream sessions sequentially

patch by Paulo Motta; reviewed by yukim for CASSANDRA-6992
This commit is contained in:
Paulo Motta 2015-11-18 16:00:36 -08:00 committed by Yuki Morishita
parent 07c6a36cc3
commit a018bcb7d7
11 changed files with 80 additions and 18 deletions

View File

@ -1,4 +1,5 @@
3.2
* Establish bootstrap stream sessions sequentially (CASSANDRA-6992)
* Sort compactionhistory output by timestamp (CASSANDRA-10464)
* More efficient BTree removal (CASSANDRA-9991)
* Make tablehistograms accept the same syntax as tablestats (CASSANDRA-10149)

View File

@ -74,7 +74,8 @@ public class BootStrapper extends ProgressEventNotifierSupport
"Bootstrap",
useStrictConsistency,
DatabaseDescriptor.getEndpointSnitch(),
stateStore);
stateStore,
true);
streamer.addSourceFilter(new RangeStreamer.FailureDetectorSourceFilter(FailureDetector.instance));
for (String keyspaceName : Schema.instance.getNonSystemKeyspaces())

View File

@ -117,13 +117,14 @@ public class RangeStreamer
String description,
boolean useStrictConsistency,
IEndpointSnitch snitch,
StreamStateStore stateStore)
StreamStateStore stateStore,
boolean connectSequentially)
{
this.metadata = metadata;
this.tokens = tokens;
this.address = address;
this.description = description;
this.streamPlan = new StreamPlan(description, true);
this.streamPlan = new StreamPlan(description, true, connectSequentially);
this.useStrictConsistency = useStrictConsistency;
this.snitch = snitch;
this.stateStore = stateStore;

View File

@ -159,7 +159,7 @@ public class SSTableLoader implements StreamEventHandler
client.init(keyspace);
outputHandler.output("Established connection to initial hosts");
StreamPlan plan = new StreamPlan("Bulk Load", 0, connectionsPerHost, false, false).connectionFactory(client.getConnectionFactory());
StreamPlan plan = new StreamPlan("Bulk Load", 0, connectionsPerHost, false, false, false).connectionFactory(client.getConnectionFactory());
Map<InetAddress, Collection<Range<Token>>> endpointToRanges = client.getEndpointToRangesMap();
openSSTables(endpointToRanges);

View File

@ -73,7 +73,7 @@ public class LocalSyncTask extends SyncTask implements StreamEventHandler
isIncremental = prs.isIncremental;
}
Tracing.traceRepair(message);
new StreamPlan("Repair", repairedAt, 1, false, isIncremental).listeners(this)
new StreamPlan("Repair", repairedAt, 1, false, isIncremental, false).listeners(this)
.flushBeforeTransfer(true)
// request ranges from the remote node
.requestRanges(dst, preferred, desc.keyspace, differences, desc.columnFamily)

View File

@ -62,7 +62,7 @@ public class StreamingRepairTask implements Runnable, StreamEventHandler
ActiveRepairService.ParentRepairSession prs = ActiveRepairService.instance.getParentRepairSession(desc.parentSessionId);
isIncremental = prs.isIncremental;
}
new StreamPlan("Repair", repairedAt, 1, false, isIncremental).listeners(this)
new StreamPlan("Repair", repairedAt, 1, false, isIncremental, false).listeners(this)
.flushBeforeTransfer(true)
// request ranges from the remote node
.requestRanges(dest, preferred, desc.keyspace, request.ranges, desc.columnFamily)

View File

@ -1106,7 +1106,8 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
"Rebuild",
!replacing && useStrictConsistency,
DatabaseDescriptor.getEndpointSnitch(),
streamStateStore);
streamStateStore,
false);
streamer.addSourceFilter(new RangeStreamer.FailureDetectorSourceFilter(FailureDetector.instance));
if (sourceDc != null)
streamer.addSourceFilter(new RangeStreamer.SingleDatacenterFilter(DatabaseDescriptor.getEndpointSnitch(), sourceDc));

View File

@ -41,19 +41,23 @@ public class StreamCoordinator
// streaming is handled directly by the ConnectionHandler's incoming and outgoing threads.
private static final DebuggableThreadPoolExecutor streamExecutor = DebuggableThreadPoolExecutor.createWithFixedPoolSize("StreamConnectionEstablisher",
FBUtilities.getAvailableProcessors());
private final boolean connectSequentially;
private Map<InetAddress, HostStreamingData> peerSessions = new HashMap<>();
private final int connectionsPerHost;
private StreamConnectionFactory factory;
private final boolean keepSSTableLevel;
private final boolean isIncremental;
private Iterator<StreamSession> sessionsToConnect = null;
public StreamCoordinator(int connectionsPerHost, boolean keepSSTableLevel, boolean isIncremental, StreamConnectionFactory factory)
public StreamCoordinator(int connectionsPerHost, boolean keepSSTableLevel, boolean isIncremental,
StreamConnectionFactory factory, boolean connectSequentially)
{
this.connectionsPerHost = connectionsPerHost;
this.factory = factory;
this.keepSSTableLevel = keepSSTableLevel;
this.isIncremental = isIncremental;
this.connectSequentially = connectSequentially;
}
public void setConnectionFactory(StreamConnectionFactory factory)
@ -89,12 +93,61 @@ public class StreamCoordinator
return connectionsPerHost == 0;
}
public void connectAllStreamSessions()
public void connect(StreamResultFuture future)
{
if (this.connectSequentially)
connectSequentially(future);
else
connectAllStreamSessions();
}
private void connectAllStreamSessions()
{
for (HostStreamingData data : peerSessions.values())
data.connectAllStreamSessions();
}
private void connectSequentially(StreamResultFuture future)
{
sessionsToConnect = getAllStreamSessions().iterator();
future.addEventListener(new StreamEventHandler()
{
public void handleStreamEvent(StreamEvent event)
{
if (event.eventType == StreamEvent.Type.STREAM_PREPARED)
{
connectNext();
}
}
public void onSuccess(StreamState result)
{
}
public void onFailure(Throwable t)
{
}
});
connectNext();
}
private void connectNext()
{
if (sessionsToConnect == null)
return;
if (sessionsToConnect.hasNext())
{
StreamSession next = sessionsToConnect.next();
logger.debug("Connecting next session {} with {}.", next.planId(), next.peer.getHostAddress());
streamExecutor.execute(new StreamSessionConnector(next));
}
else
logger.debug("Finished connecting all sessions");
}
public synchronized Set<InetAddress> getPeers()
{
return new HashSet<>(peerSessions.keySet());

View File

@ -47,19 +47,21 @@ public class StreamPlan
*/
public StreamPlan(String description)
{
this(description, ActiveRepairService.UNREPAIRED_SSTABLE, 1, false, false);
this(description, ActiveRepairService.UNREPAIRED_SSTABLE, 1, false, false, false);
}
public StreamPlan(String description, boolean keepSSTableLevels)
public StreamPlan(String description, boolean keepSSTableLevels, boolean connectSequentially)
{
this(description, ActiveRepairService.UNREPAIRED_SSTABLE, 1, keepSSTableLevels, false);
this(description, ActiveRepairService.UNREPAIRED_SSTABLE, 1, keepSSTableLevels, false, connectSequentially);
}
public StreamPlan(String description, long repairedAt, int connectionsPerHost, boolean keepSSTableLevels, boolean isIncremental)
public StreamPlan(String description, long repairedAt, int connectionsPerHost, boolean keepSSTableLevels,
boolean isIncremental, boolean connectSequentially)
{
this.description = description;
this.repairedAt = repairedAt;
this.coordinator = new StreamCoordinator(connectionsPerHost, keepSSTableLevels, isIncremental, new DefaultConnectionFactory());
this.coordinator = new StreamCoordinator(connectionsPerHost, keepSSTableLevels, isIncremental, new DefaultConnectionFactory(),
connectSequentially);
}
/**

View File

@ -71,10 +71,12 @@ public final class StreamResultFuture extends AbstractFuture<StreamState>
private StreamResultFuture(UUID planId, String description, boolean keepSSTableLevels, boolean isIncremental)
{
this(planId, description, new StreamCoordinator(0, keepSSTableLevels, isIncremental, new DefaultConnectionFactory()));
this(planId, description, new StreamCoordinator(0, keepSSTableLevels, isIncremental,
new DefaultConnectionFactory(), false));
}
static StreamResultFuture init(UUID planId, String description, Collection<StreamEventHandler> listeners, StreamCoordinator coordinator)
static StreamResultFuture init(UUID planId, String description, Collection<StreamEventHandler> listeners,
StreamCoordinator coordinator)
{
StreamResultFuture future = createAndRegister(planId, description, coordinator);
if (listeners != null)
@ -90,7 +92,8 @@ public final class StreamResultFuture extends AbstractFuture<StreamState>
{
session.init(future);
}
coordinator.connectAllStreamSessions();
coordinator.connect(future);
return future;
}

View File

@ -93,7 +93,7 @@ public class BootStrapperTest
InetAddress myEndpoint = InetAddress.getByName("127.0.0.1");
assertEquals(numOldNodes, tmd.sortedTokens().size());
RangeStreamer s = new RangeStreamer(tmd, null, myEndpoint, "Bootstrap", true, DatabaseDescriptor.getEndpointSnitch(), new StreamStateStore());
RangeStreamer s = new RangeStreamer(tmd, null, myEndpoint, "Bootstrap", true, DatabaseDescriptor.getEndpointSnitch(), new StreamStateStore(), false);
IFailureDetector mockFailureDetector = new IFailureDetector()
{
public boolean isAlive(InetAddress ep)