Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
[Named min timestamp leases] Wiring it all except legacy (#7398)
Browse files Browse the repository at this point in the history
  • Loading branch information
ergo14 authored Oct 25, 2024
1 parent 90862c4 commit ccfe5ae
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.palantir.atlasdb.keyvalue.api.watch.LockWatchManagerInternal;
import com.palantir.atlasdb.table.description.Schema;
import com.palantir.atlasdb.timelock.api.ConjureTimelockService;
import com.palantir.atlasdb.timelock.api.Namespace;
import com.palantir.atlasdb.transaction.impl.InstrumentedTimelockService;
import com.palantir.atlasdb.transaction.impl.TimelockTimestampServiceAdapter;
import com.palantir.atlasdb.util.MetricsManager;
Expand All @@ -45,6 +46,7 @@
import com.palantir.lock.client.LeaderTimeGetter;
import com.palantir.lock.client.LegacyLeaderTimeGetter;
import com.palantir.lock.client.LegacyLockTokenUnlocker;
import com.palantir.lock.client.LockLeaseService;
import com.palantir.lock.client.LockTokenUnlocker;
import com.palantir.lock.client.MultiClientTimeLockUnlocker;
import com.palantir.lock.client.NamespacedCoalescingLeaderTimeGetter;
Expand All @@ -60,6 +62,12 @@
import com.palantir.lock.client.TimeLockClient;
import com.palantir.lock.client.TimestampCorroboratingTimelockService;
import com.palantir.lock.client.metrics.TimeLockFeedbackBackgroundTask;
import com.palantir.lock.client.timestampleases.MinLeasedTimestampGetter;
import com.palantir.lock.client.timestampleases.MinLeasedTimestampGetterImpl;
import com.palantir.lock.client.timestampleases.NamespacedTimestampLeaseService;
import com.palantir.lock.client.timestampleases.NamespacedTimestampLeaseServiceImpl;
import com.palantir.lock.client.timestampleases.TimestampLeaseAcquirer;
import com.palantir.lock.client.timestampleases.TimestampLeaseAcquirerImpl;
import com.palantir.lock.impl.LegacyTimelockService;
import com.palantir.lock.v2.DefaultNamespacedTimelockRpcClient;
import com.palantir.lock.v2.NamespacedTimelockRpcClient;
Expand Down Expand Up @@ -355,20 +363,14 @@ private static LockAndTimestampServices getLockAndTimestampServices(
lockWatchDiagnosticsService);
LockWatchManagerInternal lockWatchManager = timeLockHelperServices.lockWatchManager();

RemoteTimelockServiceAdapter remoteTimelockServiceAdapter = RemoteTimelockServiceAdapter.create(
namespacedTimelockRpcClient,
RemoteTimelockServiceAdapter remoteTimelockServiceAdapter = createRemoteTimelockServiceAdapter(
timelockNamespace,
timelockRequestBatcherProviders,
namespacedConjureTimelockService,
getLeaderTimeGetter(
timelockNamespace,
timelockRequestBatcherProviders,
namespacedConjureTimelockService,
multiClientTimelockServiceSupplier),
timeLockHelperServices.requestBatchersFactory(),
getTimeLockUnlocker(
timelockNamespace,
timelockRequestBatcherProviders,
namespacedConjureTimelockService,
multiClientTimelockServiceSupplier));
multiClientTimelockServiceSupplier,
namespacedTimelockRpcClient,
timeLockHelperServices.requestBatchersFactory());

TimestampManagementService timestampManagementService = new RemoteTimestampManagementAdapter(
serviceProvider.getTimestampManagementRpcClient(), timelockNamespace);

Expand All @@ -383,6 +385,45 @@ private static LockAndTimestampServices getLockAndTimestampServices(
.build();
}

private static RemoteTimelockServiceAdapter createRemoteTimelockServiceAdapter(
String timelockNamespace,
Optional<TimeLockRequestBatcherProviders> timelockRequestBatcherProviders,
NamespacedConjureTimelockService namespacedConjureTimelockService,
Supplier<InternalMultiClientConjureTimelockService> multiClientTimelockServiceSupplier,
NamespacedTimelockRpcClient namespacedTimelockRpcClient,
RequestBatchersFactory batchersFactory) {
LockTokenUnlocker unlocker = getTimeLockUnlocker(
timelockNamespace,
timelockRequestBatcherProviders,
namespacedConjureTimelockService,
multiClientTimelockServiceSupplier);

NamespacedTimestampLeaseService timestampLeaseService = new NamespacedTimestampLeaseServiceImpl(
Namespace.of(timelockNamespace), multiClientTimelockServiceSupplier.get());

TimestampLeaseAcquirer timestampLeaseAcquirer =
TimestampLeaseAcquirerImpl.create(timestampLeaseService, unlocker);

MinLeasedTimestampGetter minLeasedTimestampGetter = new MinLeasedTimestampGetterImpl(timestampLeaseService);

LockLeaseService lockLeaseService = LockLeaseService.create(
namespacedConjureTimelockService,
getLeaderTimeGetter(
timelockNamespace,
timelockRequestBatcherProviders,
namespacedConjureTimelockService,
multiClientTimelockServiceSupplier),
unlocker);

return RemoteTimelockServiceAdapter.create(
namespacedTimelockRpcClient,
namespacedConjureTimelockService,
batchersFactory,
lockLeaseService,
timestampLeaseAcquirer,
minLeasedTimestampGetter);
}

// Note: There is some duplication in the following two methods, but extracting a common method requires a fairly
// large amount of nontrivial state. Consider extracting a common method if this needs to be implemented again.
private static LockTokenUnlocker getTimeLockUnlocker(
Expand Down
4 changes: 3 additions & 1 deletion atlasdb-tests-shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
implementation 'com.palantir.refreshable:refreshable'
implementation 'com.palantir.safe-logging:safe-logging'
implementation 'com.palantir.sls.versions:sls-versions'
implementation 'com.palantir.tokens:auth-tokens'
implementation 'com.palantir.tritium:tritium-registry'
implementation 'io.dropwizard.metrics:metrics-core'
implementation 'org.apache.commons:commons-lang3'
Expand All @@ -32,7 +33,6 @@ dependencies {
implementation 'org.rocksdb:rocksdbjni'
implementation 'com.palantir.safe-logging:preconditions-assertj'


implementation project(':atlasdb-api')
implementation project(':atlasdb-client')
implementation project(':atlasdb-client-protobufs')
Expand All @@ -45,7 +45,9 @@ dependencies {
implementation project(':lock-api-objects')
implementation project(':lock-impl')
implementation project(':timelock-agent')
implementation project(':timelock-api')
implementation project(':timelock-api:timelock-api-jersey')
implementation project(':timelock-api:timelock-api-objects')
implementation project(":timelock-impl")
implementation project(':timestamp-api')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import com.palantir.atlasdb.timelock.ConjureTimelockResource;
import com.palantir.atlasdb.timelock.TimeLockServices;
import com.palantir.atlasdb.timelock.api.ConjureTimelockService;
import com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService;
import com.palantir.atlasdb.timelock.api.Namespace;
import com.palantir.atlasdb.timelock.batch.MultiClientConjureTimelockResource;
import com.palantir.atlasdb.timelock.lock.LockLog;
import com.palantir.atlasdb.util.MetricsManager;
import com.palantir.atlasdb.util.MetricsManagers;
Expand All @@ -36,10 +39,15 @@
import com.palantir.lock.client.LegacyLeaderTimeGetter;
import com.palantir.lock.client.LegacyLockTokenUnlocker;
import com.palantir.lock.client.LockLeaseService;
import com.palantir.lock.client.LockTokenUnlocker;
import com.palantir.lock.client.NamespacedConjureTimelockServiceImpl;
import com.palantir.lock.client.RemoteTimelockServiceAdapter;
import com.palantir.lock.client.RequestBatchersFactory;
import com.palantir.lock.client.TransactionStarter;
import com.palantir.lock.client.timestampleases.MinLeasedTimestampGetterImpl;
import com.palantir.lock.client.timestampleases.NamespacedTimestampLeaseService;
import com.palantir.lock.client.timestampleases.NamespacedTimestampLeaseServiceImpl;
import com.palantir.lock.client.timestampleases.TimestampLeaseAcquirerImpl;
import com.palantir.lock.v2.NamespacedTimelockRpcClient;
import com.palantir.lock.v2.TimelockService;
import com.palantir.logsafe.exceptions.SafeRuntimeException;
Expand Down Expand Up @@ -80,6 +88,8 @@ public abstract class AbstractInMemoryTimelockExtension implements TimeLockServi

private LockLeaseService lockLeaseService;
private NamespacedConjureTimelockServiceImpl namespacedConjureTimelockService;
private NamespacedTimestampLeaseService timestampLeaseService;
private LockTokenUnlocker unlocker;

public AbstractInMemoryTimelockExtension() {
this("client");
Expand Down Expand Up @@ -159,11 +169,19 @@ private void createHelperServices(MetricsManager metricsManager) {
RedirectRetryTargeter redirectRetryTargeter = timeLockAgent.redirectRetryTargeter();
ConjureTimelockService conjureTimelockService = ConjureTimelockResource.jersey(
redirectRetryTargeter, (_namespace, _context) -> delegate.getTimelockService());
MultiClientConjureTimelockService multiClientConjureTimelockService = MultiClientConjureTimelockResource.jersey(
redirectRetryTargeter, (_namespace, _context) -> delegate.getTimelockService());

namespacedConjureTimelockService = new NamespacedConjureTimelockServiceImpl(conjureTimelockService, client);
timestampLeaseService = new NamespacedTimestampLeaseServiceImpl(
Namespace.of(client),
new InMemoryInternalMultiClientConjureTimelockService(multiClientConjureTimelockService));

unlocker = new LegacyLockTokenUnlocker(namespacedConjureTimelockService);
lockLeaseService = LockLeaseService.create(
namespacedConjureTimelockService,
new LegacyLeaderTimeGetter(namespacedConjureTimelockService),
new LegacyLockTokenUnlocker(namespacedConjureTimelockService));
unlocker);
}

public void tearDown() {
Expand Down Expand Up @@ -229,7 +247,9 @@ public TimelockService getLegacyTimelockService() {
namespacedConjureTimelockService,
lockLeaseService,
transactionStarter,
commitTimestampGetter);
commitTimestampGetter,
TimestampLeaseAcquirerImpl.create(timestampLeaseService, unlocker),
new MinLeasedTimestampGetterImpl(timestampLeaseService));
}

public LockLeaseService getLockLeaseService() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.timelock.paxos;

import com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest;
import com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse;
import com.palantir.atlasdb.timelock.api.ConjureUnlockRequestV2;
import com.palantir.atlasdb.timelock.api.ConjureUnlockResponseV2;
import com.palantir.atlasdb.timelock.api.GetCommitTimestampsRequest;
import com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse;
import com.palantir.atlasdb.timelock.api.GetMinLeasedTimestampRequests;
import com.palantir.atlasdb.timelock.api.GetMinLeasedTimestampResponses;
import com.palantir.atlasdb.timelock.api.LeaderTimes;
import com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService;
import com.palantir.atlasdb.timelock.api.MultiClientGetMinLeasedTimestampRequest;
import com.palantir.atlasdb.timelock.api.MultiClientTimestampLeaseRequest;
import com.palantir.atlasdb.timelock.api.Namespace;
import com.palantir.atlasdb.timelock.api.NamespaceTimestampLeaseRequest;
import com.palantir.atlasdb.timelock.api.NamespaceTimestampLeaseResponse;
import com.palantir.lock.client.InternalMultiClientConjureTimelockService;
import com.palantir.tokens.auth.AuthHeader;
import java.util.Map;
import java.util.Set;

final class InMemoryInternalMultiClientConjureTimelockService implements InternalMultiClientConjureTimelockService {
private static final AuthHeader AUTH_HEADER = AuthHeader.valueOf("Bearer omitted");

private final MultiClientConjureTimelockService delegate;

InMemoryInternalMultiClientConjureTimelockService(MultiClientConjureTimelockService delegate) {
this.delegate = delegate;
}

@Override
public LeaderTimes leaderTimes(Set<Namespace> namespaces) {
return delegate.leaderTimes(AUTH_HEADER, namespaces);
}

@Override
public Map<Namespace, GetCommitTimestampsResponse> getCommitTimestamps(
Map<Namespace, GetCommitTimestampsRequest> requests) {
return delegate.getCommitTimestampsForClients(AUTH_HEADER, requests);
}

@Override
public Map<Namespace, ConjureStartTransactionsResponse> startTransactions(
Map<Namespace, ConjureStartTransactionsRequest> requests) {
return delegate.startTransactions(AUTH_HEADER, requests);
}

@Override
public Map<Namespace, ConjureUnlockResponseV2> unlock(Map<Namespace, ConjureUnlockRequestV2> requests) {
return delegate.unlock(AUTH_HEADER, requests);
}

@Override
public Map<Namespace, NamespaceTimestampLeaseResponse> acquireTimestampLeases(
Map<Namespace, NamespaceTimestampLeaseRequest> requests) {
return delegate.acquireTimestampLease(AUTH_HEADER, MultiClientTimestampLeaseRequest.of(requests))
.get();
}

@Override
public Map<Namespace, GetMinLeasedTimestampResponses> getMinLeasedTimestamps(
Map<Namespace, GetMinLeasedTimestampRequests> requests) {
return delegate.getMinLeasedTimestamp(AUTH_HEADER, MultiClientGetMinLeasedTimestampRequest.of(requests))
.get();
}
}
Loading

0 comments on commit ccfe5ae

Please sign in to comment.