Search in sources :

Example 1 with Client

use of com.palantir.paxos.Client in project atlasdb by palantir.

the class TimeLockCorruptionTestSetup method createLogComponentsForServer.

private static StateLogComponents createLogComponentsForServer(DataSource dataSource, NamespaceAndUseCase namespaceAndUseCase) {
    Client client = namespaceAndUseCase.namespace();
    String paxosUseCase = namespaceAndUseCase.useCase();
    PaxosStateLog<PaxosValue> learnerLog = SqlitePaxosStateLog.create(ImmutableNamespaceAndUseCase.of(client, LearnerUseCase.createLearnerUseCase(paxosUseCase).value()), dataSource);
    PaxosStateLog<PaxosAcceptorState> acceptorLog = SqlitePaxosStateLog.create(ImmutableNamespaceAndUseCase.of(client, AcceptorUseCase.createAcceptorUseCase(paxosUseCase).value()), dataSource);
    return StateLogComponents.builder().dataSource(dataSource).learnerLog(learnerLog).acceptorLog(acceptorLog).build();
}
Also used : Client(com.palantir.paxos.Client) PaxosAcceptorState(com.palantir.paxos.PaxosAcceptorState) PaxosValue(com.palantir.paxos.PaxosValue)

Example 2 with Client

use of com.palantir.paxos.Client in project atlasdb by palantir.

the class CumulativeLeaderPinger method runOneIteration.

@Override
protected void runOneIteration() {
    try {
        Set<Client> clientsToCheck = ImmutableSet.copyOf(hasProcessedFirstRequest.keySet());
        Instant before = Instant.now();
        Set<Client> clientsThisNodeIsTheLeaderFor = remoteClient.pinger().ping(clientsToCheck);
        Instant after = Instant.now();
        Duration pingDuration = Duration.between(before, after);
        if (pingDuration.compareTo(leaderPingResponseWait) >= 0) {
            log.info("Ping took more than ping response wait, any waiters will report that ping timed out", SafeArg.of("pingDuration", pingDuration), SafeArg.of("leaderPingResponseWait", leaderPingResponseWait));
        }
        LastSuccessfulResult newResult = ImmutableLastSuccessfulResult.of(after, clientsThisNodeIsTheLeaderFor);
        this.lastSuccessfulResult.set(newResult);
        histogram.update(clientsToCheck.size());
        clientsToCheck.forEach(clientJustProcessed -> hasProcessedFirstRequest.get(clientJustProcessed).set(null));
    } catch (Exception e) {
        log.warn("Failed to ping node, trying again in the next round", e);
    }
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration) Client(com.palantir.paxos.Client)

Example 3 with Client

use of com.palantir.paxos.Client in project atlasdb by palantir.

the class LocalPaxosComponents method createWithAsyncMigration.

public static LocalPaxosComponents createWithAsyncMigration(TimelockPaxosMetrics metrics, PaxosUseCase paxosUseCase, Path legacyLogDirectory, DataSource sqliteDataSource, UUID leaderUuid, boolean canCreateNewClients, OrderableSlsVersion timeLockVersion, boolean skipConsistencyCheckAndTruncateOldPaxosLog, ExecutorService sqliteAsyncExecutor) {
    LocalPaxosComponents components = new LocalPaxosComponents(metrics, paxosUseCase, legacyLogDirectory, sqliteDataSource, leaderUuid, canCreateNewClients, timeLockVersion, skipConsistencyCheckAndTruncateOldPaxosLog);
    Path legacyClientDir = paxosUseCase.logDirectoryRelativeToDataDirectory(legacyLogDirectory);
    PersistentNamespaceLoader namespaceLoader = new DiskNamespaceLoader(legacyClientDir);
    Set<Client> namespaces = namespaceLoader.getAllPersistedNamespaces();
    sqliteAsyncExecutor.execute(() -> migrate(components, namespaces));
    return components;
}
Also used : Path(java.nio.file.Path) DiskNamespaceLoader(com.palantir.atlasdb.timelock.management.DiskNamespaceLoader) Client(com.palantir.paxos.Client) PersistentNamespaceLoader(com.palantir.atlasdb.timelock.management.PersistentNamespaceLoader)

Example 4 with Client

use of com.palantir.paxos.Client in project atlasdb by palantir.

the class AcceptorCacheImpl method updateSequenceNumbers.

@Override
public void updateSequenceNumbers(Set<WithSeq<Client>> clientsAndSeqs) {
    if (clientsAndSeqs.isEmpty()) {
        return;
    }
    lock.writeLock().lock();
    try {
        long nextTimestamp = latestTimestampedAcceptorCacheKey.timestamp() + 1;
        AtomicBoolean updated = new AtomicBoolean(false);
        clientsAndSeqs.forEach(clientAndSeq -> {
            Client client = clientAndSeq.value();
            long incomingSequenceNumber = clientAndSeq.seq();
            WithSeq<Long> clientLatestWithTs = clientToTimeAndSeq.get(client);
            if (clientLatestWithTs == null) {
                clientToTimeAndSeq.put(client, WithSeq.of(nextTimestamp, incomingSequenceNumber));
                clientsByLatestTimestamp.put(nextTimestamp, clientAndSeq);
                updated.set(true);
            } else if (incomingSequenceNumber > clientLatestWithTs.seq()) {
                clientToTimeAndSeq.put(client, WithSeq.of(nextTimestamp, incomingSequenceNumber));
                clientsByLatestTimestamp.put(nextTimestamp, clientAndSeq);
                clientsByLatestTimestamp.remove(clientLatestWithTs.value(), WithSeq.of(client, clientLatestWithTs.seq()));
                updated.set(true);
            }
        });
        if (!updated.get()) {
            return;
        }
        AcceptorCacheKey nextCacheKey = AcceptorCacheKey.newCacheKey();
        TimestampedAcceptorCacheKey newTimestampedCacheKey = TimestampedAcceptorCacheKey.of(nextCacheKey, nextTimestamp);
        cacheKeyToTimestamp.put(nextCacheKey, newTimestampedCacheKey);
        latestTimestampedAcceptorCacheKey = newTimestampedCacheKey;
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Client(com.palantir.paxos.Client)

Example 5 with Client

use of com.palantir.paxos.Client in project atlasdb by palantir.

the class LearnedValuesSinceCoalescingFunctionTests method batchesAndReturnsPreciselyValuesLearnedSinceSeq.

@Test
public void batchesAndReturnsPreciselyValuesLearnedSinceSeq() {
    PaxosValue paxosValue1 = paxosValue(10);
    PaxosValue paxosValue2 = paxosValue(12);
    PaxosValue paxosValue3 = paxosValue(20);
    PaxosValue paxosValue4 = paxosValue(25);
    Set<WithSeq<Client>> request = ImmutableSet.of(WithSeq.of(CLIENT_1, 10), WithSeq.of(CLIENT_1, 12), WithSeq.of(CLIENT_1, 14), WithSeq.of(CLIENT_2, 15), WithSeq.of(CLIENT_2, 23), WithSeq.of(CLIENT_3, 1));
    // we pick the lowest sequence number from the set per client
    Map<Client, Long> minimumRequest = ImmutableMap.<Client, Long>builder().put(CLIENT_1, 10L).put(CLIENT_2, 15L).put(CLIENT_3, 1L).build();
    SetMultimap<Client, PaxosValue> remoteResponse = ImmutableSetMultimap.<Client, PaxosValue>builder().putAll(CLIENT_1, paxosValue1, paxosValue2, paxosValue4).putAll(CLIENT_2, paxosValue3, paxosValue4).build();
    when(remote.getLearnedValuesSince(minimumRequest)).thenReturn(remoteResponse);
    LearnedValuesSinceCoalescingFunction function = new LearnedValuesSinceCoalescingFunction(remote);
    SetMultimap<WithSeq<Client>, PaxosValue> asMultimap = KeyedStream.stream(function.apply(request)).map(PaxosUpdate::getValues).flatMap(Collection::stream).collectToSetMultimap();
    SetMultimap<WithSeq<Client>, PaxosValue> expectedResult = ImmutableSetMultimap.<WithSeq<Client>, PaxosValue>builder().putAll(WithSeq.of(CLIENT_1, 10), paxosValue1, paxosValue2, paxosValue4).putAll(WithSeq.of(CLIENT_1, 12), paxosValue2, paxosValue4).putAll(WithSeq.of(CLIENT_1, 14), paxosValue4).putAll(WithSeq.of(CLIENT_2, 15), paxosValue3, paxosValue4).putAll(WithSeq.of(CLIENT_2, 23), paxosValue4).build();
    assertThat(asMultimap).isEqualTo(expectedResult);
    assertThat(asMultimap.keySet()).as("despite requesting learnt values for client-3, we still learn nothing, if remote server hasn't " + "learnt anything for that client").doesNotContain(WithSeq.of(CLIENT_3, 1));
}
Also used : PaxosUpdate(com.palantir.paxos.PaxosUpdate) Client(com.palantir.paxos.Client) PaxosValue(com.palantir.paxos.PaxosValue) Test(org.junit.Test)

Aggregations

Client (com.palantir.paxos.Client)19 Test (org.junit.Test)14 PaxosValue (com.palantir.paxos.PaxosValue)8 PaxosLearner (com.palantir.paxos.PaxosLearner)2 PaxosProposal (com.palantir.paxos.PaxosProposal)2 PaxosProposer (com.palantir.paxos.PaxosProposer)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ImmutableList (com.google.common.collect.ImmutableList)1 Maps (com.google.common.collect.Maps)1 Closer (com.google.common.io.Closer)1 ImmutableLeaderConfig (com.palantir.atlasdb.config.ImmutableLeaderConfig)1 LeaderConfig (com.palantir.atlasdb.config.LeaderConfig)1 DiskNamespaceLoader (com.palantir.atlasdb.timelock.management.DiskNamespaceLoader)1 PersistentNamespaceLoader (com.palantir.atlasdb.timelock.management.PersistentNamespaceLoader)1 PaxosContainer (com.palantir.atlasdb.timelock.paxos.PaxosQuorumCheckingCoalescingFunction.PaxosContainer)1 MetricsManagers (com.palantir.atlasdb.util.MetricsManagers)1 CheckedRejectionExecutorService (com.palantir.common.concurrent.CheckedRejectionExecutorService)1 PTExecutors (com.palantir.common.concurrent.PTExecutors)1 ServiceNotAvailableException (com.palantir.common.remoting.ServiceNotAvailableException)1 KeyedStream (com.palantir.common.streams.KeyedStream)1