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

Commit

Permalink
[Part 2] | TimeLock shoots itself (#4983)
Browse files Browse the repository at this point in the history
* TimeLock corruption pingers

* Refactor

* Redesign

* Refactor

* Wire up corruption pingers through TL

* Minor refactor

* Refactor

* Rewire

* Refactor

* Minor refactor
  • Loading branch information
sudiksha27 authored Sep 15, 2020
1 parent 84670e5 commit ff2b13a
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import com.google.common.io.Closer;
import com.palantir.atlasdb.timelock.corruption.CorruptionHealthCheck;
import com.palantir.atlasdb.timelock.corruption.LocalCorruptionDetector;
import com.palantir.atlasdb.timelock.corruption.RemoteCorruptionDetector;
import com.palantir.atlasdb.timelock.paxos.NetworkClientFactories.Factory;
import com.palantir.leader.LeaderElectionService;
import com.palantir.leader.NotCurrentLeaderException;
import com.palantir.leader.proxy.AwaitingLeadershipProxy;
import com.palantir.paxos.Client;
import com.palantir.timelock.corruption.TimeLockCorruptionNotifier;
import com.palantir.timelock.paxos.HealthCheckPinger;
import com.palantir.timelock.paxos.LeaderPingHealthCheck;
import com.palantir.timelock.paxos.NamespaceTracker;
Expand All @@ -48,12 +52,15 @@ public class LeadershipComponents {

private final Factory<LeadershipContext> leadershipContextFactory;
private final LocalAndRemotes<HealthCheckPinger> healthCheckPingers;
private final List<TimeLockCorruptionNotifier> corruptionNotifiers;

LeadershipComponents(
Factory<LeadershipContext> leadershipContextFactory,
LocalAndRemotes<HealthCheckPinger> healthCheckPingers) {
LocalAndRemotes<HealthCheckPinger> healthCheckPingers,
List<TimeLockCorruptionNotifier> corruptionNotifiers) {
this.leadershipContextFactory = leadershipContextFactory;
this.healthCheckPingers = healthCheckPingers;
this.corruptionNotifiers = corruptionNotifiers;
}

public <T> T wrapInLeadershipProxy(Client client, Class<T> clazz, Supplier<T> delegateSupplier) {
Expand Down Expand Up @@ -83,6 +90,17 @@ public LeaderPingHealthCheck healthCheck(NamespaceTracker namespaceTracker) {
return new LeaderPingHealthCheck(namespaceTracker, healthCheckPingers.all());
}

public TimeLockCorruptionComponents timeLockCorruptionComponents() {
RemoteCorruptionDetector remoteCorruptionDetector = new RemoteCorruptionDetector();
CorruptionHealthCheck healthCheck = new CorruptionHealthCheck(ImmutableList.of(
LocalCorruptionDetector.create(corruptionNotifiers),
remoteCorruptionDetector));
return ImmutableTimeLockCorruptionComponents.builder()
.timeLockCorruptionHealthCheck(healthCheck)
.remoteCorruptionDetector(remoteCorruptionDetector)
.build();
}

public boolean requestHostileTakeover(Client client) {
return getOrCreateNewLeadershipContext(client).leaderElectionService().hostileTakeover();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.UUID;

import org.immutables.value.Value;
Expand All @@ -31,6 +32,7 @@
import com.palantir.paxos.Client;
import com.palantir.paxos.LeaderPinger;
import com.palantir.paxos.PaxosLearner;
import com.palantir.timelock.corruption.TimeLockCorruptionNotifier;
import com.palantir.timelock.paxos.HealthCheckPinger;

@Value.Immutable
Expand Down Expand Up @@ -106,6 +108,11 @@ public LeaderElectionHealthCheck leaderElectionHealthCheck() {
return new LeaderElectionHealthCheck(Instant::now);
}

@Value.Derived
List<TimeLockCorruptionNotifier> remoteCorruptionNotifiers() {
return remoteClients().getRemoteCorruptionNotifiers();
}

@Override
public LeadershipContext create(Client client) {
ClientAwareComponents clientAwareComponents = ImmutableClientAwareComponents.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.palantir.paxos.LeaderPingerContext;
import com.palantir.paxos.PaxosAcceptor;
import com.palantir.paxos.PaxosLearner;
import com.palantir.timelock.corruption.TimeLockCorruptionNotifier;
import com.palantir.timelock.paxos.TimelockPaxosAcceptorRpcClient;
import com.palantir.timelock.paxos.TimelockPaxosLearnerRpcClient;

Expand Down Expand Up @@ -145,6 +146,13 @@ public List<WithDedicatedExecutor<LeaderPingerContext<BatchPingableLeader>>> bat
return leaderPingerContext(BatchPingableLeader.class);
}

@Value.Derived
public List<TimeLockCorruptionNotifier> getRemoteCorruptionNotifiers() {
return createInstrumentedRemoteProxies(TimeLockCorruptionNotifier.class, true)
.values()
.collect(Collectors.toList());
}

private <T> List<WithDedicatedExecutor<LeaderPingerContext<T>>> leaderPingerContext(Class<T> clazz) {
return createInstrumentedRemoteProxies(clazz, false)
.<WithDedicatedExecutor<LeaderPingerContext<T>>>map((uri, remote) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public List<Object> resourcesForRegistration() {
public LeadershipComponents leadershipComponents() {
return new LeadershipComponents(
leadershipContextFactory(),
leadershipContextFactory().healthCheckPingers());
leadershipContextFactory().healthCheckPingers(),
leadershipContextFactory().remoteCorruptionNotifiers());
}

private static BatchPaxosResources batchResourcesFromComponents(LocalPaxosComponents components) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* (c) Copyright 2020 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.atlasdb.timelock.paxos;

import org.immutables.value.Value;

import com.palantir.atlasdb.timelock.corruption.CorruptionHealthCheck;
import com.palantir.atlasdb.timelock.corruption.RemoteCorruptionDetector;

@Value.Immutable
public interface TimeLockCorruptionComponents {
CorruptionHealthCheck timeLockCorruptionHealthCheck();
RemoteCorruptionDetector remoteCorruptionDetector();
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@
import com.palantir.atlasdb.timelock.adjudicate.FeedbackHandler;
import com.palantir.atlasdb.timelock.adjudicate.HealthStatusReport;
import com.palantir.atlasdb.timelock.adjudicate.TimeLockClientFeedbackResource;
import com.palantir.atlasdb.timelock.corruption.CorruptionNotifierResource;
import com.palantir.atlasdb.timelock.lock.LockLog;
import com.palantir.atlasdb.timelock.lock.v1.ConjureLockV1Resource;
import com.palantir.atlasdb.timelock.management.PersistentNamespaceContext;
import com.palantir.atlasdb.timelock.management.TimeLockManagementResource;
import com.palantir.atlasdb.timelock.paxos.ImmutableTimelockPaxosInstallationContext;
import com.palantir.atlasdb.timelock.paxos.PaxosResources;
import com.palantir.atlasdb.timelock.paxos.PaxosResourcesFactory;
import com.palantir.atlasdb.timelock.paxos.TimeLockCorruptionComponents;
import com.palantir.atlasdb.util.MetricsManager;
import com.palantir.common.concurrent.PTExecutors;
import com.palantir.conjure.java.api.config.service.ServicesConfigBlock;
Expand Down Expand Up @@ -200,6 +202,7 @@ private void createAndRegisterResources() {
registerPaxosResource();
registerExceptionMappers();
registerClientFeedbackService();
registerTimeLockCorruptionNotifiers();

namespaces = new TimelockNamespaces(
metricsManager,
Expand Down Expand Up @@ -241,6 +244,17 @@ private void registerClientFeedbackService() {
}
}

private void registerTimeLockCorruptionNotifiers() {
TimeLockCorruptionComponents corruptionComponents
= paxosResources.leadershipComponents().timeLockCorruptionComponents();
if (undertowRegistrar.isPresent()) {
undertowRegistrar.get().accept(
CorruptionNotifierResource.undertow(corruptionComponents.remoteCorruptionDetector()));
} else {
registrar.accept(CorruptionNotifierResource.jersey(corruptionComponents.remoteCorruptionDetector()));
}
}

private boolean isLeaderForClient(Client client) {
Map<Client, HealthCheckResponse> healthCheckResponseMap = paxosResources
.leadershipComponents()
Expand Down

0 comments on commit ff2b13a

Please sign in to comment.