Search in sources :

Example 1 with ManagedTimestampService

use of com.palantir.timestamp.ManagedTimestampService in project atlasdb by palantir.

the class DefaultLockAndTimestampServiceFactory method createRawLeaderServices.

private static LockAndTimestampServices createRawLeaderServices(MetricsManager metricsManager, LeaderConfig leaderConfig, Consumer<Object> env, Supplier<LockService> lock, Supplier<ManagedTimestampService> time, UserAgent userAgent) {
    // Create local services, that may or may not end up being registered in an Consumer<Object>.
    LocalPaxosServices localPaxosServices = Leaders.createAndRegisterLocalServices(metricsManager, env, leaderConfig, userAgent);
    LeadershipCoordinator leadershipCoordinator = localPaxosServices.leadershipCoordinator();
    LockService localLock = AwaitingLeadershipProxy.newProxyInstance(LockService.class, lock, leadershipCoordinator);
    ManagedTimestampService managedTimestampProxy = AwaitingLeadershipProxy.newProxyInstance(ManagedTimestampService.class, time, leadershipCoordinator);
    // These facades are necessary because of the semantics of the JAX-RS algorithm (in particular, accepting
    // just the managed timestamp service will *not* work).
    TimestampService localTime = getTimestampFacade(managedTimestampProxy);
    TimestampManagementService localManagement = getTimestampManagementFacade(managedTimestampProxy);
    env.accept(localLock);
    env.accept(localTime);
    env.accept(localManagement);
    // Create remote services, that may end up calling our own local services.
    ImmutableServerListConfig serverListConfig = ImmutableServerListConfig.builder().servers(leaderConfig.leaders()).sslConfiguration(leaderConfig.sslConfiguration()).build();
    ServiceCreator creator = ServiceCreator.noPayloadLimiter(metricsManager, Refreshable.only(serverListConfig), userAgent, () -> RemotingClientConfigs.DEFAULT);
    LockService remoteLock = new RemoteLockServiceAdapter(creator.createService(NamespaceAgnosticLockRpcClient.class));
    TimestampService remoteTime = creator.createService(TimestampService.class);
    TimestampManagementService remoteManagement = creator.createService(TimestampManagementService.class);
    if (leaderConfig.leaders().size() == 1) {
        // Attempting to connect to ourself while processing a request can lead to deadlock if incoming request
        // volume is high, as all Jetty threads end up waiting for the timestamp server, and no threads remain to
        // actually handle the timestamp server requests. If we are the only single leader, we can avoid the
        // deadlock entirely; so use PingableLeader's getUUID() to detect this situation and eliminate the redundant
        // call.
        PingableLeader localPingableLeader = localPaxosServices.localPingableLeader();
        String localServerId = localPingableLeader.getUUID();
        PingableLeader remotePingableLeader = AtlasDbHttpClients.createProxy(ServiceCreator.createTrustContext(leaderConfig.sslConfiguration()), Iterables.getOnlyElement(leaderConfig.leaders()), PingableLeader.class, AuxiliaryRemotingParameters.builder().userAgent(userAgent).shouldRetry(true).shouldLimitPayload(true).shouldUseExtendedTimeout(false).build());
        // Determine asynchronously whether the remote services are talking to our local services.
        CompletableFuture<Boolean> useLocalServicesFuture = new CompletableFuture<>();
        TransactionManagers.runAsync.accept(() -> {
            int attemptsLeftBeforeLog = ATTEMPTS_BEFORE_LOGGING_FAILURE_TO_READ_REMOTE_TIMESTAMP_SERVER_ID;
            while (true) {
                try {
                    String remoteServerId = remotePingableLeader.getUUID();
                    useLocalServicesFuture.complete(localServerId.equals(remoteServerId));
                    return;
                } catch (ClientErrorException e) {
                    useLocalServicesFuture.complete(false);
                    return;
                } catch (UnknownRemoteException e) {
                    // manifest as ClientErrorExceptions.
                    if (400 <= e.getStatus() && e.getStatus() <= 499) {
                        useLocalServicesFuture.complete(false);
                        return;
                    }
                    attemptsLeftBeforeLog = logFailureToReadRemoteTimestampServerId(attemptsLeftBeforeLog, e);
                } catch (Throwable e) {
                    attemptsLeftBeforeLog = logFailureToReadRemoteTimestampServerId(attemptsLeftBeforeLog, e);
                }
                Uninterruptibles.sleepUninterruptibly(Duration.ofSeconds(1));
            }
        });
        // Create dynamic service proxies, that switch to talking directly to our local services if it turns out our
        // remote services are pointed at them anyway.
        LockService dynamicLockService = LocalOrRemoteProxy.newProxyInstance(LockService.class, localLock, remoteLock, useLocalServicesFuture);
        // Use managedTimestampProxy here to avoid local calls going through indirection.
        TimestampService dynamicTimeService = LocalOrRemoteProxy.newProxyInstance(TimestampService.class, managedTimestampProxy, remoteTime, useLocalServicesFuture);
        TimestampManagementService dynamicManagementService = LocalOrRemoteProxy.newProxyInstance(TimestampManagementService.class, managedTimestampProxy, remoteManagement, useLocalServicesFuture);
        return ImmutableLockAndTimestampServices.builder().lock(dynamicLockService).timestamp(dynamicTimeService).timestampManagement(dynamicManagementService).timelock(new LegacyTimelockService(dynamicTimeService, dynamicLockService, TransactionManagers.LOCK_CLIENT)).build();
    } else {
        return ImmutableLockAndTimestampServices.builder().lock(remoteLock).timestamp(remoteTime).timestampManagement(remoteManagement).timelock(new LegacyTimelockService(remoteTime, remoteLock, TransactionManagers.LOCK_CLIENT)).build();
    }
}
Also used : LegacyTimelockService(com.palantir.lock.impl.LegacyTimelockService) ImmutableServerListConfig(com.palantir.atlasdb.config.ImmutableServerListConfig) RemoteLockServiceAdapter(com.palantir.lock.client.RemoteLockServiceAdapter) LockRefreshingLockService(com.palantir.lock.client.LockRefreshingLockService) LockService(com.palantir.lock.LockService) ManagedTimestampService(com.palantir.timestamp.ManagedTimestampService) UnknownRemoteException(com.palantir.conjure.java.api.errors.UnknownRemoteException) LeadershipCoordinator(com.palantir.leader.proxy.LeadershipCoordinator) LocalPaxosServices(com.palantir.atlasdb.factory.Leaders.LocalPaxosServices) TimestampManagementService(com.palantir.timestamp.TimestampManagementService) CompletableFuture(java.util.concurrent.CompletableFuture) NamespaceAgnosticLockRpcClient(com.palantir.lock.NamespaceAgnosticLockRpcClient) PingableLeader(com.palantir.leader.PingableLeader) ClientErrorException(javax.ws.rs.ClientErrorException) TimestampService(com.palantir.timestamp.TimestampService) ManagedTimestampService(com.palantir.timestamp.ManagedTimestampService)

Example 2 with ManagedTimestampService

use of com.palantir.timestamp.ManagedTimestampService in project atlasdb by palantir.

the class DefaultLockAndTimestampServiceFactory method createRawEmbeddedServices.

private static LockAndTimestampServices createRawEmbeddedServices(MetricsManager metricsManager, Consumer<Object> env, Supplier<LockService> lock, Supplier<ManagedTimestampService> managedTimestampServiceSupplier) {
    LockService lockService = ServiceCreator.instrumentService(metricsManager.getRegistry(), lock.get(), LockService.class);
    ManagedTimestampService managedTimestampService = managedTimestampServiceSupplier.get();
    TimestampService timeService = ServiceCreator.instrumentService(metricsManager.getRegistry(), managedTimestampService, TimestampService.class);
    TimestampManagementService timestampManagementService = ServiceCreator.instrumentService(metricsManager.getRegistry(), managedTimestampService, TimestampManagementService.class);
    env.accept(lockService);
    env.accept(timeService);
    env.accept(timestampManagementService);
    return ImmutableLockAndTimestampServices.builder().lock(lockService).timestamp(timeService).timestampManagement(timestampManagementService).timelock(new LegacyTimelockService(timeService, lockService, TransactionManagers.LOCK_CLIENT)).build();
}
Also used : LegacyTimelockService(com.palantir.lock.impl.LegacyTimelockService) TimestampManagementService(com.palantir.timestamp.TimestampManagementService) LockRefreshingLockService(com.palantir.lock.client.LockRefreshingLockService) LockService(com.palantir.lock.LockService) ManagedTimestampService(com.palantir.timestamp.ManagedTimestampService) TimestampService(com.palantir.timestamp.TimestampService) ManagedTimestampService(com.palantir.timestamp.ManagedTimestampService)

Example 3 with ManagedTimestampService

use of com.palantir.timestamp.ManagedTimestampService in project atlasdb by palantir.

the class LockAndTimestampModule method provideLockAndTimestampServices.

@Provides
@Singleton
public LockAndTimestampServices provideLockAndTimestampServices(MetricsManager metricsManager, ServicesConfig config) {
    ServiceDiscoveringAtlasSupplier atlasSupplier = config.atlasDbSupplier(metricsManager);
    Supplier<ManagedTimestampService> managedTimestampService = atlasSupplier::getManagedTimestampService;
    return TransactionManagers.createLockAndTimestampServicesForCli(metricsManager, config.atlasDbConfig(), Refreshable.only(config.atlasDbRuntimeConfig()), resource -> {
    }, LockServiceImpl::create, managedTimestampService, config.atlasDbSupplier(metricsManager).getTimestampStoreInvalidator(), "cli");
}
Also used : ServiceDiscoveringAtlasSupplier(com.palantir.atlasdb.factory.ServiceDiscoveringAtlasSupplier) ManagedTimestampService(com.palantir.timestamp.ManagedTimestampService) LockServiceImpl(com.palantir.lock.impl.LockServiceImpl) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 4 with ManagedTimestampService

use of com.palantir.timestamp.ManagedTimestampService in project atlasdb by palantir.

the class ServiceDiscoveringAtlasSupplierTest method delegateToFactoriesAnnotatedWithAutoService.

@Test
public void delegateToFactoriesAnnotatedWithAutoService() {
    ServiceDiscoveringAtlasSupplier atlasSupplier = createAtlasSupplier(kvsConfig);
    assertThat(atlasSupplier.getKeyValueService()).as("delegates createRawKeyValueService").isEqualTo(delegate.createRawKeyValueService(metrics, kvsConfig, Refreshable.only(Optional.empty()), leaderConfig, Optional.empty(), AtlasDbFactory.THROWING_FRESH_TIMESTAMP_SOURCE, AtlasDbFactory.DEFAULT_INITIALIZE_ASYNC));
    ManagedTimestampService timestampService = mock(ManagedTimestampService.class);
    AutoServiceAnnotatedAtlasDbFactory.nextTimestampServiceToReturn(timestampService);
    assertThat(atlasSupplier.getManagedTimestampService()).as("delegates getManagedTimestampService").isEqualTo(timestampService);
}
Also used : ManagedTimestampService(com.palantir.timestamp.ManagedTimestampService) Test(org.junit.Test)

Example 5 with ManagedTimestampService

use of com.palantir.timestamp.ManagedTimestampService in project atlasdb by palantir.

the class KeyValueServiceMigratorsTest method createMock.

private static AtlasDbServices createMock(KeyValueService kvs, InMemoryTimeLockRule timeLock) {
    ManagedTimestampService timestampService = timeLock.getManagedTimestampService();
    TransactionTables.createTables(kvs);
    TransactionService transactionService = spy(TransactionServices.createRaw(kvs, timestampService, false));
    AtlasDbServices mockServices = mock(AtlasDbServices.class);
    when(mockServices.getManagedTimestampService()).thenReturn(timestampService);
    when(mockServices.getTransactionService()).thenReturn(transactionService);
    when(mockServices.getKeyValueService()).thenReturn(kvs);
    TargetedSweeper sweeper = TargetedSweeper.createUninitializedForTest(() -> 1);
    SerializableTransactionManager txManager = SerializableTransactionManager.createForTest(MetricsManagers.createForTests(), kvs, timeLock.getLegacyTimelockService(), timestampService, timeLock.getLockService(), timeLock.getLockWatchManager(), transactionService, () -> AtlasDbConstraintCheckingMode.NO_CONSTRAINT_CHECKING, ConflictDetectionManagers.createWithoutWarmingCache(kvs), SweepStrategyManagers.createDefault(kvs), new NoOpCleaner(), 16, 4, sweeper);
    sweeper.initialize(txManager);
    when(mockServices.getTransactionManager()).thenReturn(txManager);
    return mockServices;
}
Also used : TransactionService(com.palantir.atlasdb.transaction.service.TransactionService) NoOpCleaner(com.palantir.atlasdb.cleaner.NoOpCleaner) ManagedTimestampService(com.palantir.timestamp.ManagedTimestampService) SerializableTransactionManager(com.palantir.atlasdb.transaction.impl.SerializableTransactionManager) AtlasDbServices(com.palantir.atlasdb.services.AtlasDbServices) TargetedSweeper(com.palantir.atlasdb.sweep.queue.TargetedSweeper)

Aggregations

ManagedTimestampService (com.palantir.timestamp.ManagedTimestampService)8 LockService (com.palantir.lock.LockService)3 LockRefreshingLockService (com.palantir.lock.client.LockRefreshingLockService)2 LegacyTimelockService (com.palantir.lock.impl.LegacyTimelockService)2 TimestampManagementService (com.palantir.timestamp.TimestampManagementService)2 TimestampService (com.palantir.timestamp.TimestampService)2 Test (org.junit.Test)2 NoOpCleaner (com.palantir.atlasdb.cleaner.NoOpCleaner)1 ImmutableLeaderConfig (com.palantir.atlasdb.config.ImmutableLeaderConfig)1 ImmutableServerListConfig (com.palantir.atlasdb.config.ImmutableServerListConfig)1 LeaderConfig (com.palantir.atlasdb.config.LeaderConfig)1 LocalPaxosServices (com.palantir.atlasdb.factory.Leaders.LocalPaxosServices)1 ServiceDiscoveringAtlasSupplier (com.palantir.atlasdb.factory.ServiceDiscoveringAtlasSupplier)1 AtlasDbServices (com.palantir.atlasdb.services.AtlasDbServices)1 TargetedSweeper (com.palantir.atlasdb.sweep.queue.TargetedSweeper)1 AsyncLockService (com.palantir.atlasdb.timelock.lock.AsyncLockService)1 LockLog (com.palantir.atlasdb.timelock.lock.LockLog)1 SerializableTransactionManager (com.palantir.atlasdb.transaction.impl.SerializableTransactionManager)1 TransactionService (com.palantir.atlasdb.transaction.service.TransactionService)1 UnknownRemoteException (com.palantir.conjure.java.api.errors.UnknownRemoteException)1