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

Commit

Permalink
timelock-server (#6883)
Browse files Browse the repository at this point in the history
  • Loading branch information
barisoyoruk authored Dec 4, 2023
1 parent 05ba227 commit 62069ed
Show file tree
Hide file tree
Showing 41 changed files with 181 additions and 1,516 deletions.
17 changes: 0 additions & 17 deletions timelock-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,11 @@ dependencies {
testCommonImplementation 'com.github.tomakehurst:wiremock-standalone'
testCommonImplementation 'com.palantir.conjure.java.runtime:client-config'
testCommonImplementation 'com.palantir.docker.compose:docker-compose-rule-core'
testCommonImplementation 'com.palantir.docker.compose:docker-compose-rule-junit4'
testCommonImplementation 'com.palantir.docker.compose:docker-compose-junit-jupiter'
testCommonImplementation 'com.ea.agentloader:ea-agent-loader'
testCommonImplementation 'com.fasterxml.jackson.core:jackson-core'
testCommonImplementation 'com.fasterxml.jackson.core:jackson-databind'
testCommonImplementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'
testCommonImplementation 'com.github.peterwippermann.junit4:parameterized-suite'
testCommonImplementation 'com.google.errorprone:error_prone_annotations'
testCommonImplementation 'com.google.guava:guava'
testCommonImplementation 'com.palantir.common:streams'
Expand Down Expand Up @@ -144,12 +142,8 @@ dependencies {
testCommonImplementation (project(':atlasdb-tests-shared')) {
exclude group: 'com.fasterxml.jackson.jaxrs'
}
testCommonRuntimeOnly("org.junit.vintage:junit-vintage-engine") {
because 'allows JUnit 3 and JUnit 4 tests to run'
}

testCommonApi 'io.dropwizard:dropwizard-testing'
testCommonApi 'com.github.peterwippermann.junit4:parameterized-suite'

testCommonAnnotationProcessor 'org.immutables:value'
testCommonCompileOnly 'org.immutables:value::annotations'
Expand Down Expand Up @@ -177,13 +171,6 @@ dependencies {

stressTestImplementation project(':timelock-api:timelock-api-jersey')

stressTestRuntimeOnly("org.junit.vintage:junit-vintage-engine") {
because 'allows JUnit 3 and JUnit 4 tests to run'
}
integ2TestRuntimeOnly("org.junit.vintage:junit-vintage-engine") {
because 'allows JUnit 3 and JUnit 4 tests to run'
}

integTestImplementation 'com.fasterxml.jackson.core:jackson-core'
integTestImplementation 'com.fasterxml.jackson.core:jackson-databind'
integTestImplementation 'com.google.guava:guava'
Expand All @@ -209,8 +196,4 @@ dependencies {
integTestImplementation project(':timelock-api:timelock-api-objects')
integTestImplementation project(':timelock-impl')
integTestImplementation project(':timestamp-api')

integTestRuntimeOnly("org.junit.vintage:junit-vintage-engine") {
because 'allows JUnit 3 and JUnit 4 tests to run'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@

public abstract class AbstractMultiNodePaxosTimeLockServerIntegrationTest {

private final TestableTimelockClusterV2 cluster;
private final TestableTimelockCluster cluster;

public AbstractMultiNodePaxosTimeLockServerIntegrationTest(TestableTimelockClusterV2 cluster) {
public AbstractMultiNodePaxosTimeLockServerIntegrationTest(TestableTimelockCluster cluster) {
this.cluster = cluster;
}

Expand All @@ -100,7 +100,7 @@ public AbstractMultiNodePaxosTimeLockServerIntegrationTest(TestableTimelockClust
.toMillis());
private static final AuthHeader AUTH_HEADER = AuthHeader.valueOf("Bearer omitted");

private NamespacedClientsV2 client;
private NamespacedClients client;

@BeforeEach
public void bringAllNodesOnline() {
Expand Down Expand Up @@ -130,7 +130,7 @@ public void nonLeadersReturn503_conjure() {

@Test
public void leaderRespondsToRequests() {
NamespacedClientsV2 currentLeader =
NamespacedClients currentLeader =
cluster.currentLeaderFor(client.namespace()).client(client.namespace());
currentLeader.getFreshTimestamp();

Expand All @@ -154,8 +154,7 @@ public void canUseNamespaceStartingWithTlOnLegacyEndpoints() {

@Test
public void leaderLosesLeadershipIfQuorumIsNotAlive() throws ExecutionException {
NamespacedClientsV2 leader =
cluster.currentLeaderFor(client.namespace()).client(client.namespace());
NamespacedClients leader = cluster.currentLeaderFor(client.namespace()).client(client.namespace());
cluster.killAndAwaitTermination(cluster.nonLeaders(client.namespace()).values());

assertThatThrownBy(leader::getFreshTimestamp)
Expand All @@ -164,18 +163,18 @@ public void leaderLosesLeadershipIfQuorumIsNotAlive() throws ExecutionException

@Test
public void someoneBecomesLeaderAgainAfterQuorumIsRestored() throws ExecutionException {
Set<TestableTimelockServerV2> nonLeaders =
Set<TestableTimelockServer> nonLeaders =
ImmutableSet.copyOf(cluster.nonLeaders(client.namespace()).values());
cluster.killAndAwaitTermination(nonLeaders);

nonLeaders.forEach(TestableTimelockServerV2::start);
nonLeaders.forEach(TestableTimelockServer::start);
client.getFreshTimestamp();
}

@Test
public void canHostilelyTakeOverNamespace() {
TestableTimelockServerV2 currentLeader = cluster.currentLeaderFor(client.namespace());
TestableTimelockServerV2 nonLeader =
TestableTimelockServer currentLeader = cluster.currentLeaderFor(client.namespace());
TestableTimelockServer nonLeader =
Iterables.get(cluster.nonLeaders(client.namespace()).get(client.namespace()), 0);

assertThatThrownBy(nonLeader.client(client.namespace())::getFreshTimestamp)
Expand All @@ -198,7 +197,7 @@ public void canHostilelyTakeOverNamespace() {
@Test
public void canPerformRollingRestart() {
bringAllNodesOnline();
for (TestableTimelockServerV2 server : cluster.servers()) {
for (TestableTimelockServer server : cluster.servers()) {
server.killSync();
cluster.waitUntilAllServersOnlineAndReadyToServeNamespaces(ImmutableList.of(client.namespace()));
client.getFreshTimestamp();
Expand Down Expand Up @@ -251,7 +250,7 @@ public void locksAreInvalidatedAcrossFailovers() {
@Test
public void canCreateNewClientsDynamically() {
for (int i = 0; i < 5; i++) {
NamespacedClientsV2 randomNamespace =
NamespacedClients randomNamespace =
cluster.clientForRandomNamespace().throughWireMockProxy();

randomNamespace.getFreshTimestamp();
Expand Down Expand Up @@ -327,7 +326,7 @@ public void canGetAllNamespaces() {
Set<String> activeNamespaces = getActiveNamespaces();
assertThat(activeNamespaces).contains(randomNamespace);

for (TestableTimelockServerV2 server : cluster.servers()) {
for (TestableTimelockServer server : cluster.servers()) {
server.killSync();
server.start();
}
Expand All @@ -346,15 +345,15 @@ public void canGetAllNamespaces() {

private Set<String> getKnownNamespaces() {
return cluster.servers().stream()
.map(TestableTimelockServerV2::timeLockManagementService)
.map(TestableTimelockServer::timeLockManagementService)
.map(resource -> resource.getNamespaces(AuthHeader.valueOf("Bearer omitted")))
.flatMap(Set::stream)
.collect(Collectors.toSet());
}

private Set<String> getActiveNamespaces() {
return cluster.servers().stream()
.map(TestableTimelockServerV2::timeLockManagementService)
.map(TestableTimelockServer::timeLockManagementService)
.map(resource -> resource.getActiveNamespaces(AuthHeader.valueOf("Bearer omitted")))
.flatMap(Set::stream)
.collect(Collectors.toSet());
Expand Down Expand Up @@ -448,7 +447,7 @@ public void fastForwardsDoNotHaveCrossNamespaceImpact() {
long freshTimestamp = client.getFreshTimestamp();

long fastForwardTimestamp = freshTimestamp + 100_000_000;
NamespacedClientsV2 other = cluster.clientForRandomNamespace().throughWireMockProxy();
NamespacedClients other = cluster.clientForRandomNamespace().throughWireMockProxy();
other.timestampManagementService().fastForwardTimestamp(fastForwardTimestamp);

cluster.failoverToNewLeader(client.namespace());
Expand All @@ -458,7 +457,7 @@ public void fastForwardsDoNotHaveCrossNamespaceImpact() {

@Test
public void sanityCheckMultiClientLeaderTime() {
TestableTimelockServerV2 leader = cluster.currentLeaderFor(client.namespace());
TestableTimelockServer leader = cluster.currentLeaderFor(client.namespace());
// Multi client batched TimeLock endpoints do not support multi-leader mode on TimeLock
Assumptions.assumeFalse(leader.isMultiLeader());

Expand All @@ -475,7 +474,7 @@ public void sanityCheckMultiClientLeaderTime() {

@Test
public void sanityCheckMultiClientLeaderTimeAgainstConjureTimelockService() {
TestableTimelockServerV2 leader = cluster.currentLeaderFor(client.namespace());
TestableTimelockServer leader = cluster.currentLeaderFor(client.namespace());
// Multi client batched TimeLock endpoints do not support multi-leader mode on TimeLock
Assumptions.assumeFalse(leader.isMultiLeader());

Expand All @@ -494,7 +493,7 @@ public void sanityCheckMultiClientLeaderTimeAgainstConjureTimelockService() {

@Test
public void sanityCheckMultiClientStartTransactions() {
TestableTimelockServerV2 leader = cluster.currentLeaderFor(client.namespace());
TestableTimelockServer leader = cluster.currentLeaderFor(client.namespace());
// Multi client batched TimeLock endpoints do not support multi-leader mode on TimeLock
Assumptions.assumeFalse(leader.isMultiLeader());

Expand All @@ -512,7 +511,7 @@ public void sanityCheckMultiClientStartTransactions() {

@Test
public void sanityCheckMultiClientStartTransactionsAgainstConjureTimelockService() {
TestableTimelockServerV2 leader = cluster.currentLeaderFor(client.namespace());
TestableTimelockServer leader = cluster.currentLeaderFor(client.namespace());
// Multi client batched TimeLock endpoints do not support multi-leader mode on TimeLock
Assumptions.assumeFalse(leader.isMultiLeader());

Expand Down Expand Up @@ -543,15 +542,15 @@ public void sanityCheckMultiClientStartTransactionsAgainstConjureTimelockService

@Test
public void multiClientStartTransactionsReturnsCorrectStartTimestamps() {
TestableTimelockServerV2 leader = cluster.currentLeaderFor(client.namespace());
TestableTimelockServer leader = cluster.currentLeaderFor(client.namespace());
// Multi client batched TimeLock endpoints do not support multi-leader mode on TimeLock
Assumptions.assumeFalse(leader.isMultiLeader());

Namespace delta = Namespace.of("delta");
Namespace gamma = Namespace.of("gamma");

NamespacedClientsV2 deltaClient = leader.client(delta.get()).throughWireMockProxy();
NamespacedClientsV2 gammaClient = leader.client(gamma.get()).throughWireMockProxy();
NamespacedClients deltaClient = leader.client(delta.get()).throughWireMockProxy();
NamespacedClients gammaClient = leader.client(gamma.get()).throughWireMockProxy();
List<String> expectedNamespaces = ImmutableList.of(delta.get(), gamma.get());

int deltaFastForwardedTimestamp = 155_200_000;
Expand All @@ -572,7 +571,7 @@ public void multiClientStartTransactionsReturnsCorrectStartTimestamps() {

@Test
public void sanityCheckMultiClientGetCommitTimestamps() {
TestableTimelockServerV2 leader = cluster.currentLeaderFor(client.namespace());
TestableTimelockServer leader = cluster.currentLeaderFor(client.namespace());
// Multi client batched TimeLock endpoints do not support multi-leader mode on TimeLock
Assumptions.assumeFalse(leader.isMultiLeader());

Expand All @@ -593,7 +592,7 @@ public void sanityCheckMultiClientGetCommitTimestamps() {

@Test
public void sanityCheckMultiClientGetCommitTimestampsAgainstConjureTimelockService() {
TestableTimelockServerV2 leader = cluster.currentLeaderFor(client.namespace());
TestableTimelockServer leader = cluster.currentLeaderFor(client.namespace());
// Multi client batched TimeLock endpoints do not support multi-leader mode on TimeLock
Assumptions.assumeFalse(leader.isMultiLeader());

Expand Down Expand Up @@ -783,7 +782,7 @@ private GetCommitTimestampsRequest defaultCommitTimestampRequest() {
}

private Map<Namespace, ConjureStartTransactionsResponse> assertSanityAndStartTransactions(
TestableTimelockServerV2 leader, List<String> expectedNamespaces) {
TestableTimelockServer leader, List<String> expectedNamespaces) {
MultiClientConjureTimelockService multiClientConjureTimelockService = leader.multiClientService();
int numTransactions = 5;

Expand Down Expand Up @@ -819,7 +818,7 @@ private Map<Namespace, ConjureStartTransactionsRequest> defaultStartTransactions
}

private LeaderTimes assertSanityAndGetLeaderTimes(
TestableTimelockServerV2 leader, Set<Namespace> expectedNamespaces) {
TestableTimelockServer leader, Set<Namespace> expectedNamespaces) {
MultiClientConjureTimelockService multiClientConjureTimelockService = leader.multiClientService();

LeaderTimes leaderTimes = multiClientConjureTimelockService.leaderTimes(AUTH_HEADER, expectedNamespaces);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.palantir.atlasdb.timelock.paxos.BatchPaxosAcceptorRpcClient;
import com.palantir.atlasdb.timelock.paxos.PaxosRemoteClients;
import com.palantir.atlasdb.timelock.util.ExceptionMatchers;
import com.palantir.atlasdb.timelock.util.TestProxiesV2;
import com.palantir.atlasdb.timelock.util.TestProxies;
import com.palantir.paxos.Client;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -38,11 +38,11 @@
public abstract class AbstractSingleLeaderMultiNodePaxosTimeLockIntegrationTest {
private static final ImmutableSet<Client> CLIENT_SET = ImmutableSet.of(PSEUDO_LEADERSHIP_CLIENT);

private final TestableTimelockClusterV2 cluster;
private final TestableTimelockCluster cluster;

private NamespacedClientsV2 namespace;
private NamespacedClients namespace;

public AbstractSingleLeaderMultiNodePaxosTimeLockIntegrationTest(TestableTimelockClusterV2 cluster) {
public AbstractSingleLeaderMultiNodePaxosTimeLockIntegrationTest(TestableTimelockCluster cluster) {
this.cluster = cluster;
}

Expand Down Expand Up @@ -86,12 +86,12 @@ public void noConflictIfLeaderAndNonLeadersSeparatelyInitializeClient() {

@Test
public void migrationToBatchedSingleLeaderHasConsistentSequenceNumbers() {
NamespacedClientsV2 client = cluster.clientForRandomNamespace().throughWireMockProxy();
NamespacedClients client = cluster.clientForRandomNamespace().throughWireMockProxy();
cluster.waitUntilAllServersOnlineAndReadyToServeNamespaces(ImmutableList.of(client.namespace()));

List<Long> sequenceNumbers = new ArrayList<>();

for (TestableTimelockServerV2 server : cluster.servers()) {
for (TestableTimelockServer server : cluster.servers()) {
server.startUsingBatchedSingleLeader();
if (cluster.currentLeaderFor(client.namespace()) == server) {
// if we are the leader failover twice to ensure we see the new sequence
Expand All @@ -110,12 +110,12 @@ public void migrationToBatchedSingleLeaderHasConsistentSequenceNumbers() {

@Test
public void reverseMigrationFromBatchedSingleLeaderHasConsistentSequenceNumbers() {
NamespacedClientsV2 client = cluster.clientForRandomNamespace().throughWireMockProxy();
NamespacedClients client = cluster.clientForRandomNamespace().throughWireMockProxy();
cluster.waitUntilAllServersOnlineAndReadyToServeNamespaces(ImmutableList.of(client.namespace()));
cluster.servers().forEach(TestableTimelockServerV2::startUsingBatchedSingleLeader);
cluster.servers().forEach(TestableTimelockServer::startUsingBatchedSingleLeader);
List<Long> sequenceNumbers = new ArrayList<>();

for (TestableTimelockServerV2 server : cluster.servers()) {
for (TestableTimelockServer server : cluster.servers()) {
server.stopUsingBatchedSingleLeader();
cluster.failoverToNewLeader(client.namespace());
long sequenceForBatchedEndpoint = getSequenceForServerUsingBatchedEndpoint(server);
Expand All @@ -128,21 +128,21 @@ public void reverseMigrationFromBatchedSingleLeaderHasConsistentSequenceNumbers(
assertThat(ImmutableSet.copyOf(sequenceNumbers)).hasSameSizeAs(sequenceNumbers);
}

private static long getSequenceForServerUsingBatchedEndpoint(TestableTimelockServerV2 server) {
private static long getSequenceForServerUsingBatchedEndpoint(TestableTimelockServer server) {
BatchPaxosAcceptorRpcClient acceptor = server.client(LEADER_PAXOS_NAMESPACE)
.proxyFactory()
.createProxy(BatchPaxosAcceptorRpcClient.class, TestProxiesV2.ProxyModeV2.DIRECT);
.createProxy(BatchPaxosAcceptorRpcClient.class, TestProxies.ProxyMode.DIRECT);
return acceptor.latestSequencesPreparedOrAccepted(LEADER_FOR_ALL_CLIENTS, null, CLIENT_SET)
.updates()
.get(PSEUDO_LEADERSHIP_CLIENT);
}

private static long getSequenceForServerUsingOldEndpoint(TestableTimelockServerV2 server) {
private static long getSequenceForServerUsingOldEndpoint(TestableTimelockServer server) {
PaxosRemoteClients.TimelockSingleLeaderPaxosAcceptorRpcClient acceptor = server.client(LEADER_PAXOS_NAMESPACE)
.proxyFactory()
.createProxy(
PaxosRemoteClients.TimelockSingleLeaderPaxosAcceptorRpcClient.class,
TestProxiesV2.ProxyModeV2.DIRECT);
TestProxies.ProxyMode.DIRECT);
return acceptor.getLatestSequencePreparedOrAccepted();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class BatchedSingleLeaderMultiNodePaxosTimeLockIntegrationTest
extends AbstractSingleLeaderMultiNodePaxosTimeLockIntegrationTest {

@RegisterExtension
public static final TestableTimelockClusterV2 BATCHED_PAXOS = new TestableTimelockClusterV2(
public static final TestableTimelockCluster BATCHED_PAXOS = new TestableTimelockCluster(
"batched single leader",
"paxosMultiServer.ftl",
generateThreeNodeTimelockCluster(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class BatchedSingleLeaderMultiNodePaxosTimeLockServerIntegrationTest
extends AbstractMultiNodePaxosTimeLockServerIntegrationTest {

@RegisterExtension
public static final TestableTimelockClusterV2 BATCHED_PAXOS = new TestableTimelockClusterV2(
public static final TestableTimelockCluster BATCHED_PAXOS = new TestableTimelockCluster(
"batched single leader",
"paxosMultiServer.ftl",
generateThreeNodeTimelockCluster(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class BatchedTimestampSingleLeaderMultiNodePaxosTimeLockIntegrationTest
extends AbstractSingleLeaderMultiNodePaxosTimeLockIntegrationTest {

@RegisterExtension
public static final TestableTimelockClusterV2 BATCHED_TIMESTAMP_PAXOS = new TestableTimelockClusterV2(
public static final TestableTimelockCluster BATCHED_TIMESTAMP_PAXOS = new TestableTimelockCluster(
"batched timestamp paxos single leader",
"paxosMultiServer.ftl",
generateThreeNodeTimelockCluster(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class BatchedTimestampSingleLeaderMultiNodePaxosTimeLockServerIntegration
extends AbstractMultiNodePaxosTimeLockServerIntegrationTest {

@RegisterExtension
public static final TestableTimelockClusterV2 BATCHED_TIMESTAMP_PAXOS = new TestableTimelockClusterV2(
public static final TestableTimelockCluster BATCHED_TIMESTAMP_PAXOS = new TestableTimelockCluster(
"batched timestamp paxos single leader",
"paxosMultiServer.ftl",
generateThreeNodeTimelockCluster(
Expand Down
Loading

0 comments on commit 62069ed

Please sign in to comment.