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

[Named min timestamp leases] Metrics #7400

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -59,7 +61,14 @@
import com.palantir.lock.client.RequestBatchersFactory;
import com.palantir.lock.client.TimeLockClient;
import com.palantir.lock.client.TimestampCorroboratingTimelockService;
import com.palantir.lock.client.TimestampLeaseMetrics;
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 +364,15 @@ 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),
multiClientTimelockServiceSupplier,
namespacedTimelockRpcClient,
timeLockHelperServices.requestBatchersFactory(),
getTimeLockUnlocker(
timelockNamespace,
timelockRequestBatcherProviders,
namespacedConjureTimelockService,
multiClientTimelockServiceSupplier));
metricsManager);

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

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

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

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

TimestampLeaseAcquirer timestampLeaseAcquirer = TimestampLeaseAcquirerImpl.create(
timestampLeaseService, unlocker, TimestampLeaseMetrics.of(metricsManager.getTaggedRegistry()));

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,16 @@
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.TimestampLeaseMetrics;
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 +89,9 @@ public abstract class AbstractInMemoryTimelockExtension implements TimeLockServi

private LockLeaseService lockLeaseService;
private NamespacedConjureTimelockServiceImpl namespacedConjureTimelockService;
private NamespacedTimestampLeaseService timestampLeaseService;
private LockTokenUnlocker unlocker;
private final MetricsManager metricsManager = MetricsManagers.createForTests();

public AbstractInMemoryTimelockExtension() {
this("client");
Expand Down Expand Up @@ -119,8 +131,6 @@ public void setup() {
.clusterSnapshot(clusterConfig)
.build();

MetricsManager metricsManager = MetricsManagers.createForTests();

timeLockAgent = TimeLockAgent.create(
metricsManager,
install,
Expand All @@ -136,7 +146,7 @@ public void setup() {
() -> System.exit(0));

delegate = timeLockAgent.createInvalidatingTimeLockServices(client);
createHelperServices(metricsManager);
createHelperServices();

// Wait for leadership
Awaitility.await()
Expand All @@ -146,7 +156,7 @@ public void setup() {
.until(() -> delegate.getTimestampService().getFreshTimestamp() > 0);
}

private void createHelperServices(MetricsManager metricsManager) {
private void createHelperServices() {
helperServices = TimeLockHelperServices.create(
client,
metricsManager,
Expand All @@ -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,10 @@ public TimelockService getLegacyTimelockService() {
namespacedConjureTimelockService,
lockLeaseService,
transactionStarter,
commitTimestampGetter);
commitTimestampGetter,
TimestampLeaseAcquirerImpl.create(
timestampLeaseService, unlocker, TimestampLeaseMetrics.of(metricsManager.getTaggedRegistry())),
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();
}
}
1 change: 1 addition & 0 deletions lock-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ apply plugin: 'com.palantir.metric-schema'
license {
exclude '**/TimestampCorrectnessMetrics.java'
exclude '**/TopologyMetrics.java'
exclude '**/TimestampLeaseMetrics.java'
}

libsDirName = file('build/artifacts')
Expand Down
Loading