Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache project metadata and tokens #1099

Merged
merged 9 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from 8 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
209 changes: 0 additions & 209 deletions it/server/src/test/java/com/linecorp/centraldogma/it/CacheTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.awaitility.Awaitility.await;

import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -64,8 +65,8 @@ void updateWriteQuota() throws Exception {
CompletableFutures.allAsList(futures).join();

/// update write quota to 2qps
QuotaConfig writeQuota = new QuotaConfig(2, 1);
QuotaConfig updated = updateWriteQuota(webClient(), repositoryName, writeQuota);
final QuotaConfig writeQuota = new QuotaConfig(2, 1);
final QuotaConfig updated = updateWriteQuota(webClient(), repositoryName, writeQuota);
assertThat(updated).isEqualTo(writeQuota);

// Wait for releasing previously acquired locks
Expand All @@ -86,9 +87,9 @@ void updateWriteQuota() throws Exception {
Thread.sleep(1000);

// Increase write quota
writeQuota = new QuotaConfig(5, 1);
updated = updateWriteQuota(webClient(), repositoryName, writeQuota);
assertThat(updated).isEqualTo(writeQuota);
final QuotaConfig writeQuota1 = new QuotaConfig(5, 1);
await().untilAsserted(() -> assertThat(updateWriteQuota(webClient(), repositoryName, writeQuota1))
.isEqualTo(writeQuota1));

final List<CompletableFuture<PushResult>> futures4 = parallelPush(dogmaClient(), repositoryName, 4);
assertThat(CompletableFutures.allAsList(futures4).join()).hasSize(8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,8 @@ private Server startServer(ProjectManager pm, CommandExecutor executor,
cfg.gracefulShutdownTimeout().ifPresent(
t -> sb.gracefulShutdownTimeoutMillis(t.quietPeriodMillis(), t.timeoutMillis()));

final MetadataService mds = new MetadataService(pm, executor);
final MetadataService mds = new MetadataService(pm, executor, projectInitializer);
executor.setRepositoryMetadataSupplier(mds::getRepo);
final WatchService watchService = new WatchService(meterRegistry);
final AuthProvider authProvider = createAuthProvider(executor, sessionManager, mds);
final ProjectApiManager projectApiManager = new ProjectApiManager(pm, executor, mds);
Expand Down Expand Up @@ -796,7 +797,7 @@ private CommandExecutor newZooKeeperCommandExecutor(
new StandaloneCommandExecutor(pm, repositoryWorker, serverStatusManager, sessionManager,
/* onTakeLeadership */ null, /* onReleaseLeadership */ null,
/* onTakeZoneLeadership */ null, /* onReleaseZoneLeadership */ null),
meterRegistry, pm, config().writeQuotaPerRepository(), zone,
meterRegistry, config().writeQuotaPerRepository(), zone,
onTakeLeadership, onReleaseLeadership,
onTakeZoneLeadership, onReleaseZoneLeadership);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiFunction;
import java.util.function.Consumer;

import javax.annotation.Nullable;
Expand All @@ -34,6 +35,7 @@
import com.linecorp.armeria.common.util.Exceptions;
import com.linecorp.armeria.common.util.StartStopSupport;
import com.linecorp.centraldogma.common.ReadOnlyException;
import com.linecorp.centraldogma.server.metadata.RepositoryMetadata;

/**
* Helps to implement a concrete {@link CommandExecutor}.
Expand All @@ -57,6 +59,9 @@ public abstract class AbstractCommandExecutor implements CommandExecutor {
private final AtomicInteger numPendingStopRequests = new AtomicInteger();
private final CommandExecutorStatusManager statusManager;

@Nullable
private BiFunction<String, String, CompletableFuture<RepositoryMetadata>> repositoryMetadataSupplier;

/**
* Creates a new instance.
*
Expand Down Expand Up @@ -120,6 +125,23 @@ public final void setWritable(boolean writable) {
this.writable = writable;
}

@Override
public void setRepositoryMetadataSupplier(
BiFunction<String, String, CompletableFuture<RepositoryMetadata>> supplier) {
repositoryMetadataSupplier = requireNonNull(supplier, "supplier");
}

/**
* Returns the {@link RepositoryMetadata} of the specified repository.
*/
@Nullable
protected CompletableFuture<RepositoryMetadata> repositoryMetadata(String projectName, String repoName) {
if (repositoryMetadataSupplier == null) {
return null;
}
return repositoryMetadataSupplier.apply(projectName, repoName);
}

@Override
public final <T> CompletableFuture<T> execute(Command<T> command) {
requireNonNull(command, "command");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
package com.linecorp.centraldogma.server.command;

import java.util.concurrent.CompletableFuture;
import java.util.function.BiFunction;

import javax.annotation.Nullable;

import com.linecorp.centraldogma.server.QuotaConfig;
import com.linecorp.centraldogma.server.metadata.RepositoryMetadata;

/**
* An executor interface which executes {@link Command}s.
Expand Down Expand Up @@ -66,6 +68,12 @@ public interface CommandExecutor {
*/
void setWriteQuota(String projectName, String repoName, @Nullable QuotaConfig writeQuota);

/**
* Sets the {@link RepositoryMetadata} supplier.
*/
void setRepositoryMetadataSupplier(
BiFunction<String, String, CompletableFuture<RepositoryMetadata>> supplier);

/**
* Executes the specified {@link Command}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import static java.util.Objects.requireNonNull;

import java.util.concurrent.CompletableFuture;
import java.util.function.BiFunction;

import com.linecorp.centraldogma.internal.Util;
import com.linecorp.centraldogma.server.QuotaConfig;
import com.linecorp.centraldogma.server.metadata.RepositoryMetadata;

/**
* A {@link CommandExecutor} which forwards all its method calls to another {@link CommandExecutor}.
Expand Down Expand Up @@ -73,6 +75,12 @@ public void setWriteQuota(String projectName, String repoName, QuotaConfig write
delegate().setWriteQuota(projectName, repoName, writeQuota);
}

@Override
public void setRepositoryMetadataSupplier(
BiFunction<String, String, CompletableFuture<RepositoryMetadata>> supplier) {
delegate().setRepositoryMetadataSupplier(supplier);
}

@Override
public <T> CompletableFuture<T> execute(Command<T> command) {
return delegate().execute(command);
Expand Down
Loading
Loading