use of org.apache.cassandra.utils.progress.ProgressListener 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.ProgressListener in project cassandra by apache.
the class RepairRunnable method complete.
private void complete(String msg) {
long durationMillis = currentTimeMillis() - creationTimeMillis;
if (msg == null) {
String duration = DurationFormatUtils.formatDurationWords(durationMillis, true, true);
msg = String.format("Repair command #%d finished in %s", cmd, duration);
}
fireProgressEvent(new ProgressEvent(ProgressEventType.COMPLETE, progressCounter.get(), totalProgress, msg));
logger.info(options.getPreviewKind().logPrefix(parentSession) + msg);
ActiveRepairService.instance.removeParentRepairSession(parentSession);
TraceState localState = traceState;
if (options.isTraced() && localState != null) {
for (ProgressListener listener : listeners) localState.removeProgressListener(listener);
// Because ExecutorPlus#afterExecute and this callback
// run in a nondeterministic order (within the same thread), the
// TraceState may have been nulled out at this point. The TraceState
// should be traceState, so just set it without bothering to check if it
// actually was nulled out.
Tracing.instance.set(localState);
Tracing.traceRepair(msg);
Tracing.instance.stopSession();
}
Keyspace.open(keyspace).metric.repairTime.update(durationMillis, TimeUnit.MILLISECONDS);
}
use of org.apache.cassandra.utils.progress.ProgressListener in project cassandra by apache.
the class TracingTest method test_progress_listener.
@Test
public void test_progress_listener() {
List<String> traces = new ArrayList<>();
Tracing tracing = new TracingImpl(traces);
tracing.newSession(Tracing.TraceType.REPAIR);
tracing.begin("test-request", Collections.<String, String>emptyMap());
tracing.get().enableActivityNotification("test-tag");
tracing.get().addProgressListener(new ProgressListener() {
public void progress(String tag, ProgressEvent pe) {
assert "test-tag".equals(tag);
assert "test-trace".equals(pe.getMessage());
}
});
tracing.get().trace("test-trace");
tracing.stopSession();
assert null == tracing.get();
}
use of org.apache.cassandra.utils.progress.ProgressListener in project cassandra by apache.
the class RepairRunnable method maybeCreateTraceState.
private TraceState maybeCreateTraceState(Iterable<ColumnFamilyStore> columnFamilyStores) {
if (!options.isTraced())
return null;
StringBuilder cfsb = new StringBuilder();
for (ColumnFamilyStore cfs : columnFamilyStores) cfsb.append(", ").append(cfs.keyspace.getName()).append(".").append(cfs.name);
UUID sessionId = Tracing.instance.newSession(Tracing.TraceType.REPAIR);
TraceState traceState = Tracing.instance.begin("repair", ImmutableMap.of("keyspace", keyspace, "columnFamilies", cfsb.substring(2)));
traceState.enableActivityNotification(tag);
for (ProgressListener listener : listeners) traceState.addProgressListener(listener);
Thread queryThread = createQueryThread(sessionId);
queryThread.setName("RepairTracePolling");
return traceState;
}
use of org.apache.cassandra.utils.progress.ProgressListener in project cassandra by apache.
the class StorageService method createRepairTask.
private FutureTask<Object> createRepairTask(final int cmd, final String keyspace, final RepairOption options, List<ProgressListener> listeners) {
if (!options.getDataCenters().isEmpty() && !options.getDataCenters().contains(DatabaseDescriptor.getLocalDataCenter())) {
throw new IllegalArgumentException("the local data center must be part of the repair");
}
RepairRunnable task = new RepairRunnable(this, cmd, options, keyspace);
task.addProgressListener(progressSupport);
for (ProgressListener listener : listeners) task.addProgressListener(listener);
if (options.isTraced())
return new FutureTaskWithResources<>(() -> ExecutorLocals::clear, task);
return new FutureTask<>(task);
}
Aggregations