use of org.apache.cassandra.utils.progress.ProgressEventType in project cassandra by apache.
the class BootStrapper method bootstrap.
public ListenableFuture<StreamState> bootstrap(StreamStateStore stateStore, boolean useStrictConsistency) {
logger.trace("Beginning bootstrap process");
RangeStreamer streamer = new RangeStreamer(tokenMetadata, tokens, address, "Bootstrap", useStrictConsistency, DatabaseDescriptor.getEndpointSnitch(), stateStore, true, DatabaseDescriptor.getStreamingConnectionsPerHost());
streamer.addSourceFilter(new RangeStreamer.FailureDetectorSourceFilter(FailureDetector.instance));
streamer.addSourceFilter(new RangeStreamer.ExcludeLocalNodeFilter());
for (String keyspaceName : Schema.instance.getNonLocalStrategyKeyspaces()) {
AbstractReplicationStrategy strategy = Keyspace.open(keyspaceName).getReplicationStrategy();
streamer.addRanges(keyspaceName, strategy.getPendingAddressRanges(tokenMetadata, tokens, address));
}
StreamResultFuture bootstrapStreamResult = streamer.fetchAsync();
bootstrapStreamResult.addEventListener(new StreamEventHandler() {
private final AtomicInteger receivedFiles = new AtomicInteger();
private final AtomicInteger totalFilesToReceive = new AtomicInteger();
@Override
public void handleStreamEvent(StreamEvent event) {
switch(event.eventType) {
case STREAM_PREPARED:
StreamEvent.SessionPreparedEvent prepared = (StreamEvent.SessionPreparedEvent) event;
int currentTotal = totalFilesToReceive.addAndGet((int) prepared.session.getTotalFilesToReceive());
ProgressEvent prepareProgress = new ProgressEvent(ProgressEventType.PROGRESS, receivedFiles.get(), currentTotal, "prepare with " + prepared.session.peer + " complete");
fireProgressEvent("bootstrap", prepareProgress);
break;
case FILE_PROGRESS:
StreamEvent.ProgressEvent progress = (StreamEvent.ProgressEvent) event;
if (progress.progress.isCompleted()) {
int received = receivedFiles.incrementAndGet();
ProgressEvent currentProgress = new ProgressEvent(ProgressEventType.PROGRESS, received, totalFilesToReceive.get(), "received file " + progress.progress.fileName);
fireProgressEvent("bootstrap", currentProgress);
}
break;
case STREAM_COMPLETE:
StreamEvent.SessionCompleteEvent completeEvent = (StreamEvent.SessionCompleteEvent) event;
ProgressEvent completeProgress = new ProgressEvent(ProgressEventType.PROGRESS, receivedFiles.get(), totalFilesToReceive.get(), "session with " + completeEvent.peer + " complete");
fireProgressEvent("bootstrap", completeProgress);
break;
}
}
@Override
public void onSuccess(StreamState streamState) {
ProgressEventType type;
String message;
if (streamState.hasFailedSession()) {
type = ProgressEventType.ERROR;
message = "Some bootstrap stream failed";
} else {
type = ProgressEventType.SUCCESS;
message = "Bootstrap streaming success";
}
ProgressEvent currentProgress = new ProgressEvent(type, receivedFiles.get(), totalFilesToReceive.get(), message);
fireProgressEvent("bootstrap", currentProgress);
}
@Override
public void onFailure(Throwable throwable) {
ProgressEvent currentProgress = new ProgressEvent(ProgressEventType.ERROR, receivedFiles.get(), totalFilesToReceive.get(), throwable.getMessage());
fireProgressEvent("bootstrap", currentProgress);
}
});
return bootstrapStreamResult;
}
use of org.apache.cassandra.utils.progress.ProgressEventType in project cassandra by apache.
the class RepairRunner method progress.
@Override
public void progress(String tag, ProgressEvent event) {
ProgressEventType type = event.getType();
String message = String.format("[%s] %s", format.format(System.currentTimeMillis()), event.getMessage());
if (type == ProgressEventType.PROGRESS) {
message = message + " (progress: " + (int) event.getProgressPercentage() + "%)";
}
out.println(message);
if (type == ProgressEventType.ERROR) {
error = new RuntimeException("Repair job has failed with the error message: " + message);
}
if (type == ProgressEventType.COMPLETE) {
condition.signalAll();
}
}
use of org.apache.cassandra.utils.progress.ProgressEventType in project cassandra by apache.
the class BootstrapMonitor method progress.
@Override
public void progress(String tag, ProgressEvent event) {
ProgressEventType type = event.getType();
String message = String.format("[%s] %s", format.format(System.currentTimeMillis()), event.getMessage());
if (type == ProgressEventType.PROGRESS) {
message = message + " (progress: " + (int) event.getProgressPercentage() + "%)";
}
out.println(message);
if (type == ProgressEventType.COMPLETE) {
condition.signalAll();
}
}
Aggregations