Search in sources :

Example 1 with CheckedRejectionExecutorService

use of com.palantir.common.concurrent.CheckedRejectionExecutorService in project atlasdb by palantir.

the class AllNodesDisabledNamespacesUpdaterTest method setUp.

@Before
public void setUp() {
    when(remote1.ping(AUTH_HEADER)).thenReturn(true);
    when(remote2.ping(AUTH_HEADER)).thenReturn(true);
    ImmutableList<DisabledNamespacesUpdaterService> remotes = ImmutableList.of(remote1, remote2);
    Map<DisabledNamespacesUpdaterService, CheckedRejectionExecutorService> executors = ImmutableMap.of(remote1, new CheckedRejectionExecutorService(Executors.newSingleThreadExecutor()), remote2, new CheckedRejectionExecutorService(Executors.newSingleThreadExecutor()));
    when(remote1.reenable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(remote2.reenable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(localUpdater.reEnable(any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    updater = new AllNodesDisabledNamespacesUpdater(remotes, executors, localUpdater);
}
Also used : DisabledNamespacesUpdaterService(com.palantir.atlasdb.timelock.api.DisabledNamespacesUpdaterService) CheckedRejectionExecutorService(com.palantir.common.concurrent.CheckedRejectionExecutorService) Before(org.junit.Before)

Example 2 with CheckedRejectionExecutorService

use of com.palantir.common.concurrent.CheckedRejectionExecutorService in project atlasdb by palantir.

the class GetSuspectedLeaderWithUuidTests method functionForRemotes.

private GetSuspectedLeaderWithUuid functionForRemotes(ClientAwareLeaderPinger... remotes) {
    Set<ClientAwareLeaderPinger> clientAwareLeaders = ImmutableSet.copyOf(remotes);
    Set<LeaderPingerContext<BatchPingableLeader>> rpcClients = clientAwareLeaders.stream().map(ClientAwareLeaderPinger::underlyingRpcClient).collect(Collectors.toSet());
    Map<LeaderPingerContext<BatchPingableLeader>, CheckedRejectionExecutorService> executors = Maps.toMap(ImmutableList.copyOf(rpcClients), $ -> new CheckedRejectionExecutorService(executorService));
    return new GetSuspectedLeaderWithUuid(executors, clientAwareLeaders, LOCAL_UUID, Duration.ofSeconds(1));
}
Also used : LeaderPingerContext(com.palantir.paxos.LeaderPingerContext) CheckedRejectionExecutorService(com.palantir.common.concurrent.CheckedRejectionExecutorService)

Example 3 with CheckedRejectionExecutorService

use of com.palantir.common.concurrent.CheckedRejectionExecutorService in project atlasdb by palantir.

the class TestableTimelockCluster method currentLeaders.

SetMultimap<String, TestableTimelockServer> currentLeaders(Iterable<String> namespaces) {
    Set<String> namespacesIterable = ImmutableSet.copyOf(namespaces);
    KeyedStream<TestableTimelockServer, PaxosContainer<Set<String>>> responses = PaxosQuorumChecker.collectUntil(ImmutableList.copyOf(servers), server -> PaxosContainer.of(server.pinger().ping(namespaces)), Maps.toMap(servers, unused -> new CheckedRejectionExecutorService(executorService)), Duration.ofSeconds(2), untilAllNamespacesAreSeen(namespacesIterable), true).stream();
    return responses.filter(PaxosContainer::isSuccessful).map(PaxosContainer::get).flatMap(Collection::stream).mapEntries((server, namespace) -> Maps.immutableEntry(namespace, server)).collectToSetMultimap();
}
Also used : Statement(org.junit.runners.model.Statement) Iterables(com.google.common.collect.Iterables) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TestRule(org.junit.rules.TestRule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PaxosContainer(com.palantir.atlasdb.timelock.paxos.PaxosQuorumCheckingCoalescingFunction.PaxosContainer) Hashing(com.google.common.hash.Hashing) Random(java.util.Random) Multimap(com.google.common.collect.Multimap) ProxyMode(com.palantir.atlasdb.timelock.util.TestProxies.ProxyMode) ImmutableList(com.google.common.collect.ImmutableList) Duration(java.time.Duration) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) PaxosQuorumChecker(com.palantir.paxos.PaxosQuorumChecker) NoSuchElementException(java.util.NoSuchElementException) ExecutorService(java.util.concurrent.ExecutorService) ImmutableSet(com.google.common.collect.ImmutableSet) KeyedStream(com.palantir.common.streams.KeyedStream) Predicate(java.util.function.Predicate) CheckedRejectionExecutorService(com.palantir.common.concurrent.CheckedRejectionExecutorService) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TestProxies(com.palantir.atlasdb.timelock.util.TestProxies) Set(java.util.Set) Description(org.junit.runner.Description) UUID(java.util.UUID) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) SetMultimap(com.google.common.collect.SetMultimap) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) InProgressResponseState(com.palantir.paxos.InProgressResponseState) ExecutionException(java.util.concurrent.ExecutionException) RuleChain(org.junit.rules.RuleChain) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Awaitility(org.awaitility.Awaitility) TemporaryFolder(org.junit.rules.TemporaryFolder) PaxosContainer(com.palantir.atlasdb.timelock.paxos.PaxosQuorumCheckingCoalescingFunction.PaxosContainer) CheckedRejectionExecutorService(com.palantir.common.concurrent.CheckedRejectionExecutorService) Collection(java.util.Collection)

Example 4 with CheckedRejectionExecutorService

use of com.palantir.common.concurrent.CheckedRejectionExecutorService in project atlasdb by palantir.

the class AllNodesDisabledNamespacesUpdaterFactory method create.

public AllNodesDisabledNamespacesUpdater create(TimelockNamespaces localNamespaces) {
    PaxosRemoteClients remoteClients = ImmutablePaxosRemoteClients.of(install, metricsManager);
    List<WithDedicatedExecutor<DisabledNamespacesUpdaterService>> remoteUpdaters = remoteClients.updaters();
    Map<DisabledNamespacesUpdaterService, CheckedRejectionExecutorService> remoteExecutors = ImmutableMap.<DisabledNamespacesUpdaterService, CheckedRejectionExecutorService>builder().putAll(KeyedStream.of(remoteUpdaters).mapKeys(WithDedicatedExecutor::service).map(WithDedicatedExecutor::executor).collectToMap()).build();
    ImmutableList<DisabledNamespacesUpdaterService> remoteServices = ImmutableList.copyOf(remoteUpdaters.stream().map(WithDedicatedExecutor::service).collect(Collectors.toList()));
    return AllNodesDisabledNamespacesUpdater.create(remoteServices, remoteExecutors, localNamespaces);
}
Also used : WithDedicatedExecutor(com.palantir.atlasdb.timelock.paxos.WithDedicatedExecutor) DisabledNamespacesUpdaterService(com.palantir.atlasdb.timelock.api.DisabledNamespacesUpdaterService) CheckedRejectionExecutorService(com.palantir.common.concurrent.CheckedRejectionExecutorService) PaxosRemoteClients(com.palantir.atlasdb.timelock.paxos.PaxosRemoteClients) ImmutablePaxosRemoteClients(com.palantir.atlasdb.timelock.paxos.ImmutablePaxosRemoteClients)

Example 5 with CheckedRejectionExecutorService

use of com.palantir.common.concurrent.CheckedRejectionExecutorService in project atlasdb by palantir.

the class TimeLockPaxosExecutors method createBoundedExecutors.

/**
 * Creates a mapping of services to {@link ExecutorService}s indicating that tasks oriented towards the relevant
 * node should be run on the associated executor.
 *
 * It is assumed that tasks run on the local node will return quickly (hence the use of the direct executor).
 */
static <T> Map<T, CheckedRejectionExecutorService> createBoundedExecutors(int poolSize, LocalAndRemotes<T> localAndRemotes, String useCase) {
    int numRemotes = localAndRemotes.remotes().size();
    ImmutableMap.Builder<T, CheckedRejectionExecutorService> remoteExecutors = ImmutableMap.builderWithExpectedSize(numRemotes);
    for (int index = 0; index < numRemotes; index++) {
        T remote = localAndRemotes.remotes().get(index);
        remoteExecutors.put(remote, createBoundedExecutor(poolSize, useCase, index));
    }
    remoteExecutors.put(localAndRemotes.local(), new CheckedRejectionExecutorService(MoreExecutors.newDirectExecutorService()));
    return remoteExecutors.build();
}
Also used : CheckedRejectionExecutorService(com.palantir.common.concurrent.CheckedRejectionExecutorService) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

CheckedRejectionExecutorService (com.palantir.common.concurrent.CheckedRejectionExecutorService)6 ImmutableList (com.google.common.collect.ImmutableList)2 Maps (com.google.common.collect.Maps)2 DisabledNamespacesUpdaterService (com.palantir.atlasdb.timelock.api.DisabledNamespacesUpdaterService)2 KeyedStream (com.palantir.common.streams.KeyedStream)2 List (java.util.List)2 UUID (java.util.UUID)2 ExecutorService (java.util.concurrent.ExecutorService)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 TemporaryFolder (org.junit.rules.TemporaryFolder)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Multimap (com.google.common.collect.Multimap)1 SetMultimap (com.google.common.collect.SetMultimap)1 Sets (com.google.common.collect.Sets)1 Hashing (com.google.common.hash.Hashing)1 Closer (com.google.common.io.Closer)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1