use of com.palantir.atlasdb.autobatch.BatchElement in project atlasdb by palantir.
the class GetSuspectedLeaderWithUuid method accept.
@Override
public void accept(List<BatchElement<UUID, Optional<ClientAwareLeaderPinger>>> batchElements) {
Multimap<UUID, DisruptorFuture<Optional<ClientAwareLeaderPinger>>> uuidsToRequests = batchElements.stream().collect(ImmutableListMultimap.toImmutableListMultimap(BatchElement::argument, BatchElement::result));
KeyedStream.of(uuidsToRequests.keySet()).filterKeys(cache::containsKey).map(cache::get).forEach((cachedUuid, pingable) -> completeRequest(uuidsToRequests.get(cachedUuid), Optional.of(clientAwareLeaders.get(pingable))));
Set<UUID> uncachedUuids = uuidsToRequests.keySet().stream().filter(uuid -> !cache.containsKey(uuid)).collect(toSet());
if (uncachedUuids.isEmpty()) {
return;
}
PaxosResponsesWithRemote<LeaderPingerContext<BatchPingableLeader>, PaxosContainer<UUID>> results = PaxosQuorumChecker.collectUntil(ImmutableList.copyOf(executors.keySet()), pingable -> PaxosContainer.of(pingable.pinger().uuid()), executors, leaderPingResponseWait, state -> state.responses().values().stream().map(PaxosContainer::get).collect(toSet()).containsAll(uncachedUuids), PaxosConstants.CANCEL_REMAINING_CALLS);
for (Map.Entry<LeaderPingerContext<BatchPingableLeader>, PaxosContainer<UUID>> resultEntries : results.responses().entrySet()) {
LeaderPingerContext<BatchPingableLeader> pingable = resultEntries.getKey();
UUID uuid = resultEntries.getValue().get();
LeaderPingerContext<BatchPingableLeader> oldCachedEntry = cache.putIfAbsent(uuid, pingable);
throwIfInvalidSetup(oldCachedEntry, pingable, uuid);
completeRequest(uuidsToRequests.get(uuid), Optional.of(clientAwareLeaders.get(pingable)));
}
Set<UUID> missingUuids = Sets.difference(uncachedUuids, results.withoutRemotes().stream().map(PaxosContainer::get).collect(toSet()));
missingUuids.forEach(missingUuid -> completeRequest(uuidsToRequests.get(missingUuid), Optional.empty()));
}
use of com.palantir.atlasdb.autobatch.BatchElement in project atlasdb by palantir.
the class WriteBatchingTransactionServiceTest method repeatedProcessBatchOnlyMakesOneCallWithDuplicatesIfFailedAndKnownFailed.
@Test
public void repeatedProcessBatchOnlyMakesOneCallWithDuplicatesIfFailedAndKnownFailed() {
KeyAlreadyExistsException exception = new KeyAlreadyExistsException("boo", ImmutableList.of(ENCODING_STRATEGY.encodeStartTimestampAsCell(5L)));
doThrow(exception).when(mockTransactionService).putUnlessExistsMultiple(anyMap());
int numRequests = 100;
List<BatchElement<WriteBatchingTransactionService.TimestampPair, Void>> batchedRequest = IntStream.range(0, numRequests).mapToObj(unused -> TestTransactionBatchElement.of(5L, 9L)).collect(Collectors.toList());
WriteBatchingTransactionService.processBatch(mockTransactionService, batchedRequest);
AtomicInteger successCount = new AtomicInteger();
AtomicInteger failureCount = new AtomicInteger();
getResultsTrackingOutcomes(batchedRequest, successCount, failureCount);
verify(mockTransactionService, times(1)).putUnlessExistsMultiple(anyMap());
verify(mockTransactionService, atLeastOnce()).getCellEncodingStrategy();
// XXX Technically invalid, but valid for a mock transaction service.
assertThat(successCount).hasValue(0);
assertThat(failureCount).hasValue(numRequests);
}
use of com.palantir.atlasdb.autobatch.BatchElement in project atlasdb by palantir.
the class WriteBatchingTransactionServiceTest method repeatedProcessBatchFiltersOutPartialSuccesses.
@Test
public void repeatedProcessBatchFiltersOutPartialSuccesses() {
KeyAlreadyExistsException exception = new KeyAlreadyExistsException("boo", ImmutableList.of(ENCODING_STRATEGY.encodeStartTimestampAsCell(5L)), ImmutableList.of(ENCODING_STRATEGY.encodeStartTimestampAsCell(6L)));
doThrow(exception).when(mockTransactionService).putUnlessExistsMultiple(anyMap());
int numFailingRequests = 100;
List<BatchElement<WriteBatchingTransactionService.TimestampPair, Void>> batchedRequest = IntStream.range(0, numFailingRequests).mapToObj(unused -> TestTransactionBatchElement.of(6L, 9L)).collect(Collectors.toList());
batchedRequest.add(TestTransactionBatchElement.of(5L, 888L));
WriteBatchingTransactionService.processBatch(mockTransactionService, batchedRequest);
AtomicInteger successCount = new AtomicInteger();
AtomicInteger failureCount = new AtomicInteger();
getResultsTrackingOutcomes(batchedRequest, successCount, failureCount);
verify(mockTransactionService, times(1)).putUnlessExistsMultiple(anyMap());
verify(mockTransactionService, atLeastOnce()).getCellEncodingStrategy();
// XXX Technically invalid, but valid for a mock transaction service.
assertThat(successCount).hasValue(1);
assertThat(failureCount).hasValue(numFailingRequests);
}
use of com.palantir.atlasdb.autobatch.BatchElement in project atlasdb by palantir.
the class MultiClientCommitTimestampGetterTest method updatesCacheWhileProcessingResponse.
@Test
public void updatesCacheWhileProcessingResponse() {
Namespace client = Namespace.of("Kitty");
List<BatchElement<NamespacedRequest, Long>> batchElements = IntStream.range(0, COMMIT_TS_LIMIT_PER_REQUEST * 2).mapToObj(ind -> batchElementForNamespace(client)).collect(toList());
setupServiceAndAssertSanityOfResponse(batchElements);
LockWatchCache cache = lockWatchCacheMap.get(client);
verify(cache, times(2)).processCommitTimestampsUpdate(any(), any());
}
use of com.palantir.atlasdb.autobatch.BatchElement in project atlasdb by palantir.
the class MultiClientCommitTimestampGetterTest method doesNotUpdateCacheIfClientNotServed.
@Test
public void doesNotUpdateCacheIfClientNotServed() {
Namespace alpha = Namespace.of("alpha" + UUID.randomUUID());
Namespace beta = Namespace.of("beta" + UUID.randomUUID());
BatchElement<NamespacedRequest, Long> requestForAlpha = batchElementForNamespace(alpha);
BatchElement<NamespacedRequest, Long> requestForBeta = batchElementForNamespace(beta);
List<BatchElement<NamespacedRequest, Long>> allRequests = ImmutableList.of(requestForAlpha, requestForBeta);
List<BatchElement<NamespacedRequest, Long>> alphaRequestList = ImmutableList.of(requestForAlpha);
Map<Namespace, GetCommitTimestampsResponse> responseMap = getCommitTimestamps(alphaRequestList);
when(timelockService.getCommitTimestamps(any())).thenReturn(responseMap).thenThrow(EXCEPTION);
assertThatThrownBy(() -> consumer.accept(allRequests)).isEqualTo(EXCEPTION);
// assert requests made by client alpha are served
assertSanityOfResponse(alphaRequestList, ImmutableMap.of(alpha, ImmutableList.of(responseMap.get(alpha))));
LockWatchCache alphaCache = lockWatchCacheMap.get(alpha);
verify(alphaCache).processCommitTimestampsUpdate(any(), any());
assertThat(requestForBeta.result().isDone()).as("No requests made by client - beta were successful").isFalse();
LockWatchCache betaCache = lockWatchCacheMap.get(beta);
verify(betaCache, never()).processCommitTimestampsUpdate(any(), any());
}
Aggregations