use of com.palantir.logsafe.exceptions.SafeRuntimeException in project atlasdb by palantir.
the class PaxosConsensusTestUtils method setup.
public static PaxosTestState setup(int numLeaders, int quorumSize) {
List<LeaderElectionService> leaders = new ArrayList<>();
List<PaxosAcceptor> acceptors = new ArrayList<>();
List<PaxosLearner> learners = new ArrayList<>();
List<AtomicBoolean> failureToggles = new ArrayList<>();
ExecutorService executor = PTExecutors.newCachedThreadPool();
DataSource sqliteDataSource = SqliteConnections.getDefaultConfiguredPooledDataSource(getSqlitePath());
RuntimeException exception = new SafeRuntimeException("mock server failure");
SplittingPaxosStateLog.LegacyOperationMarkers noop = ImmutableLegacyOperationMarkers.builder().markLegacyRead(() -> {
}).markLegacyWrite(() -> {
}).build();
for (int i = 0; i < numLeaders; i++) {
failureToggles.add(new AtomicBoolean(false));
PaxosLearner learner = PaxosLearnerImpl.newSplittingLearner(getLearnerStorageParameters(i, sqliteDataSource), noop, PaxosKnowledgeEventRecorder.NO_OP);
learners.add(ToggleableExceptionProxy.newProxyInstance(PaxosLearner.class, learner, failureToggles.get(i), exception));
PaxosAcceptor acceptor = PaxosAcceptorImpl.newSplittingAcceptor(getAcceptorStorageParameters(i, sqliteDataSource), noop, Optional.empty());
acceptors.add(ToggleableExceptionProxy.newProxyInstance(PaxosAcceptor.class, acceptor, failureToggles.get(i), exception));
}
PaxosAcceptorNetworkClient acceptorNetworkClient = SingleLeaderAcceptorNetworkClient.createLegacy(acceptors, quorumSize, Maps.toMap(acceptors, $ -> executor), PaxosConstants.CANCEL_REMAINING_CALLS);
for (int i = 0; i < numLeaders; i++) {
UUID leaderUuid = UUID.randomUUID();
PaxosLearner ourLearner = learners.get(i);
List<PaxosLearner> remoteLearners = learners.stream().filter(learner -> !learner.equals(ourLearner)).collect(ImmutableList.toImmutableList());
PaxosLearnerNetworkClient learnerNetworkClient = SingleLeaderLearnerNetworkClient.createLegacy(ourLearner, remoteLearners, quorumSize, Maps.toMap(learners, $ -> executor), PaxosConstants.CANCEL_REMAINING_CALLS);
LeaderElectionService leader = new LeaderElectionServiceBuilder().leaderUuid(leaderUuid).pingRate(Duration.ZERO).randomWaitBeforeProposingLeadership(Duration.ZERO).leaderAddressCacheTtl(Duration.ZERO).knowledge(ourLearner).acceptorClient(acceptorNetworkClient).learnerClient(learnerNetworkClient).leaderPinger(SingleLeaderPinger.createForTests(ImmutableMap.of(), Duration.ZERO, leaderUuid, true, Optional.empty())).build();
leaders.add(SimulatingFailingServerProxy.newProxyInstance(LeaderElectionService.class, leader, SERVER_DELAY_TIME_MS, failureToggles.get(i)));
}
return new PaxosTestState(leaders, learners, failureToggles, executor);
}
use of com.palantir.logsafe.exceptions.SafeRuntimeException in project atlasdb by palantir.
the class PaxosQuorumChecker method collectResponses.
private static <SERVICE, RESPONSE extends PaxosResponse> PaxosResponsesWithRemote<SERVICE, RESPONSE> collectResponses(ImmutableList<SERVICE> remotes, Function<SERVICE, RESPONSE> request, int quorumSize, Duration remoteRequestTimeout, Predicate<InProgressResponseState<SERVICE, RESPONSE>> shouldSkipNextRequest, boolean cancelRemainingCalls, MultiplexingCompletionService<SERVICE, RESPONSE> responseCompletionService) {
PaxosResponseAccumulator<SERVICE, RESPONSE> receivedResponses = PaxosResponseAccumulator.newResponse(remotes.size(), quorumSize, shouldSkipNextRequest);
// kick off all the requests
List<Future<Map.Entry<SERVICE, RESPONSE>>> allFutures = new ArrayList<>();
for (SERVICE remote : remotes) {
try {
allFutures.add(responseCompletionService.submit(remote, () -> request.apply(remote)));
} catch (CheckedRejectedExecutionException e) {
requestExecutionRejection.mark();
receivedResponses.markFailure();
if (shouldLogDiagnosticInformation()) {
log.info("Quorum checker executor rejected task", e);
log.info("Rate of execution rejections: {}", SafeArg.of("rate1m", requestExecutionRejection.getOneMinuteRate()));
}
}
}
List<Throwable> encounteredErrors = new ArrayList<>();
boolean interrupted = false;
try {
long deadline = System.nanoTime() + remoteRequestTimeout.toNanos();
while (receivedResponses.hasMoreRequests() && receivedResponses.shouldProcessNextRequest()) {
try {
Future<Map.Entry<SERVICE, RESPONSE>> responseFuture = responseCompletionService.poll(deadline - System.nanoTime(), TimeUnit.NANOSECONDS);
if (timedOut(responseFuture)) {
break;
}
receivedResponses.add(responseFuture.get().getKey(), responseFuture.get().getValue());
} catch (ExecutionException e) {
receivedResponses.markFailure();
encounteredErrors.add(e.getCause());
}
}
} catch (InterruptedException e) {
log.warn("paxos request interrupted", e);
interrupted = true;
} finally {
if (cancelRemainingCalls) {
cancelOutstandingRequestsAfterTimeout(allFutures);
}
if (interrupted) {
Thread.currentThread().interrupt();
}
if (!receivedResponses.hasQuorum()) {
RuntimeException exceptionForSuppression = new SafeRuntimeException("exception for suppresion");
encounteredErrors.forEach(throwable -> {
throwable.addSuppressed(exceptionForSuppression);
log.warn(PAXOS_MESSAGE_ERROR, throwable);
});
}
}
return receivedResponses.collect();
}
use of com.palantir.logsafe.exceptions.SafeRuntimeException in project atlasdb by palantir.
the class TimestampCorroboratingTimelockService method clocksWentBackwards.
private static RuntimeException clocksWentBackwards(TimestampBounds bounds, TimestampBoundsRecord currentBoundsRecord) {
RuntimeException runtimeException = new SafeRuntimeException(CLOCKS_WENT_BACKWARDS_MESSAGE);
log.error(CLOCKS_WENT_BACKWARDS_MESSAGE + ": bounds were {}, operation {}, fresh timestamp of {}.", SafeArg.of("persistedBounds", bounds), SafeArg.of("boundsRecordForCurrentRequest", currentBoundsRecord), runtimeException);
throw runtimeException;
}
use of com.palantir.logsafe.exceptions.SafeRuntimeException in project atlasdb by palantir.
the class ForkedJsonFormat method printToString.
/**
* Like {@code print()}, but writes directly to a {@code String} and returns it.
*/
public static String printToString(UnknownFieldSet fields) {
try {
StringBuilder text = new StringBuilder();
print(fields, text);
return text.toString();
} catch (IOException e) {
throw new SafeRuntimeException("Writing to a StringBuilder threw an IOException (should never happen).", e);
}
}
use of com.palantir.logsafe.exceptions.SafeRuntimeException in project conjure by palantir.
the class ConjureParser method parseAnnotated.
/**
* Parse all files & imports (breadth-first).
*/
public static Map<String, AnnotatedConjureSourceFile> parseAnnotated(Collection<File> files) {
CachingParser parser = new CachingParser();
Map<String, AnnotatedConjureSourceFile> parsed = new HashMap<>();
Queue<FileWithProvenance> toProcess = new ArrayDeque<>(files.stream().map(FileWithProvenance::of).collect(Collectors.toList()));
while (!toProcess.isEmpty()) {
FileWithProvenance nextFileWithProvenance = toProcess.poll();
File nextFile;
try {
nextFile = nextFileWithProvenance.file().getCanonicalFile();
} catch (IOException e) {
throw new SafeRuntimeException("Couldn't canonicalize file path", e);
}
String key = nextFile.getAbsolutePath();
if (!parsed.containsKey(key)) {
AnnotatedConjureSourceFile annotatedConjureSourceFile = parseSingleFile(parser, nextFile, nextFileWithProvenance.importedFrom());
parsed.put(key, annotatedConjureSourceFile);
// Add all imports as files to be parsed
annotatedConjureSourceFile.importProviders().values().stream().map(File::new).forEach(file -> toProcess.add(FileWithProvenance.of(file, nextFile)));
}
}
return parsed;
}
Aggregations