use of org.apache.cassandra.utils.progress.ProgressEvent 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.ProgressEvent in project cassandra by apache.
the class RepairRunnable method runMayThrow.
protected void runMayThrow() throws Exception {
final TraceState traceState;
final UUID parentSession = UUIDGen.getTimeUUID();
final String tag = "repair:" + cmd;
final AtomicInteger progress = new AtomicInteger();
// get valid column families, calculate neighbors, validation, prepare for repair + number of ranges to repair
final int totalProgress = 4 + options.getRanges().size();
String[] columnFamilies = options.getColumnFamilies().toArray(new String[options.getColumnFamilies().size()]);
Iterable<ColumnFamilyStore> validColumnFamilies;
try {
validColumnFamilies = storageService.getValidColumnFamilies(false, false, keyspace, columnFamilies);
progress.incrementAndGet();
} catch (IllegalArgumentException e) {
logger.error("Repair failed:", e);
fireErrorAndComplete(tag, progress.get(), totalProgress, e.getMessage());
return;
}
final long startTime = System.currentTimeMillis();
String message = String.format("Starting repair command #%d (%s), repairing keyspace %s with %s", cmd, parentSession, keyspace, options);
logger.info(message);
if (options.isTraced()) {
StringBuilder cfsb = new StringBuilder();
for (ColumnFamilyStore cfs : validColumnFamilies) cfsb.append(", ").append(cfs.keyspace.getName()).append(".").append(cfs.name);
UUID sessionId = Tracing.instance.newSession(Tracing.TraceType.REPAIR);
traceState = Tracing.instance.begin("repair", ImmutableMap.of("keyspace", keyspace, "columnFamilies", cfsb.substring(2)));
message = message + " tracing with " + sessionId;
fireProgressEvent(tag, new ProgressEvent(ProgressEventType.START, 0, 100, message));
Tracing.traceRepair(message);
traceState.enableActivityNotification(tag);
for (ProgressListener listener : listeners) traceState.addProgressListener(listener);
Thread queryThread = createQueryThread(cmd, sessionId);
queryThread.setName("RepairTracePolling");
queryThread.start();
} else {
fireProgressEvent(tag, new ProgressEvent(ProgressEventType.START, 0, 100, message));
traceState = null;
}
final Set<InetAddress> allNeighbors = new HashSet<>();
List<Pair<Set<InetAddress>, ? extends Collection<Range<Token>>>> commonRanges = new ArrayList<>();
//pre-calculate output of getLocalRanges and pass it to getNeighbors to increase performance and prevent
//calculation multiple times
Collection<Range<Token>> keyspaceLocalRanges = storageService.getLocalRanges(keyspace);
try {
for (Range<Token> range : options.getRanges()) {
Set<InetAddress> neighbors = ActiveRepairService.getNeighbors(keyspace, keyspaceLocalRanges, range, options.getDataCenters(), options.getHosts());
addRangeToNeighbors(commonRanges, range, neighbors);
allNeighbors.addAll(neighbors);
}
progress.incrementAndGet();
} catch (IllegalArgumentException e) {
logger.error("Repair failed:", e);
fireErrorAndComplete(tag, progress.get(), totalProgress, e.getMessage());
return;
}
// Validate columnfamilies
List<ColumnFamilyStore> columnFamilyStores = new ArrayList<>();
try {
Iterables.addAll(columnFamilyStores, validColumnFamilies);
progress.incrementAndGet();
} catch (IllegalArgumentException e) {
fireErrorAndComplete(tag, progress.get(), totalProgress, e.getMessage());
return;
}
String[] cfnames = new String[columnFamilyStores.size()];
for (int i = 0; i < columnFamilyStores.size(); i++) {
cfnames[i] = columnFamilyStores.get(i).name;
}
SystemDistributedKeyspace.startParentRepair(parentSession, keyspace, cfnames, options);
long repairedAt;
try {
ActiveRepairService.instance.prepareForRepair(parentSession, FBUtilities.getBroadcastAddress(), allNeighbors, options, columnFamilyStores);
repairedAt = ActiveRepairService.instance.getParentRepairSession(parentSession).getRepairedAt();
progress.incrementAndGet();
} catch (Throwable t) {
SystemDistributedKeyspace.failParentRepair(parentSession, t);
fireErrorAndComplete(tag, progress.get(), totalProgress, t.getMessage());
return;
}
if (options.isIncremental()) {
consistentRepair(parentSession, repairedAt, startTime, traceState, allNeighbors, commonRanges, cfnames);
} else {
normalRepair(parentSession, startTime, traceState, allNeighbors, commonRanges, cfnames);
}
}
use of org.apache.cassandra.utils.progress.ProgressEvent in project cassandra by apache.
the class RepairRunnable method fireErrorAndComplete.
protected void fireErrorAndComplete(String tag, int progressCount, int totalProgress, String message) {
fireProgressEvent(tag, new ProgressEvent(ProgressEventType.ERROR, progressCount, totalProgress, message));
fireProgressEvent(tag, new ProgressEvent(ProgressEventType.COMPLETE, progressCount, totalProgress, String.format("Repair command #%d finished with error", cmd)));
}
use of org.apache.cassandra.utils.progress.ProgressEvent in project cassandra by apache.
the class LegacyJMXProgressSupportTest method testSessionSuccess.
@Test
public void testSessionSuccess() {
int cmd = 321;
String message = String.format("Repair session %s for range %s finished", UUID.randomUUID(), new Range<Token>(new Murmur3Partitioner.LongToken(3), new Murmur3Partitioner.LongToken(4)));
Optional<int[]> result = LegacyJMXProgressSupport.getLegacyUserdata(String.format("repair:%d", cmd), new ProgressEvent(ProgressEventType.PROGRESS, 2, 10, message));
assertTrue(result.isPresent());
assertArrayEquals(new int[] { cmd, ActiveRepairService.Status.SESSION_SUCCESS.ordinal() }, result.get());
}
use of org.apache.cassandra.utils.progress.ProgressEvent in project cassandra by apache.
the class LegacyJMXProgressSupportTest method testNone.
/*
States not mapped to the legacy notification
*/
@Test
public void testNone() {
int cmd = 33;
Optional<int[]> result = LegacyJMXProgressSupport.getLegacyUserdata(String.format("repair:%d", cmd), new ProgressEvent(ProgressEventType.ERROR, 2, 10, "bla"));
assertFalse(result.isPresent());
cmd = 33;
result = LegacyJMXProgressSupport.getLegacyUserdata(String.format("repair:%d", cmd), new ProgressEvent(ProgressEventType.SUCCESS, 2, 10, "bla"));
assertFalse(result.isPresent());
cmd = 43;
result = LegacyJMXProgressSupport.getLegacyUserdata(String.format("repair:%d", cmd), new ProgressEvent(ProgressEventType.PROGRESS, 2, 10, "bla"));
assertFalse(result.isPresent());
cmd = 1;
result = LegacyJMXProgressSupport.getLegacyUserdata(String.format("repair:%d", cmd), new ProgressEvent(ProgressEventType.ABORT, 2, 10, "bla"));
assertFalse(result.isPresent());
cmd = 9;
result = LegacyJMXProgressSupport.getLegacyUserdata(String.format("repair:%d", cmd), new ProgressEvent(ProgressEventType.NOTIFICATION, 2, 10, "bla"));
assertFalse(result.isPresent());
}
Aggregations