Use `ProjectCache.onCreateProject` after project creation Change I05243b1065d consolidateid all logic about project cache by adding negative caching invalidation to `ProjectCacheImpl`. This means that explicit project cache eviction is not needed anymore. Use only `ProjectCache.onCreateProject` after project creation. Bug: Issue 308448333 Change-Id: I3de9b7503a0284ccf96f31696421284c6f82f05a
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectInitializationAction.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectInitializationAction.java index 9f48441..9afae71 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectInitializationAction.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectInitializationAction.java
@@ -140,7 +140,7 @@ } public boolean initProject(String gitRepositoryName) - throws AuthException, PermissionBackendException { + throws AuthException, PermissionBackendException, IOException { if (initProject(gitRepositoryName, true)) { repLog.info("Init project API from {}", gitRepositoryName); return true; @@ -166,9 +166,6 @@ input.getRevisionsData(), input.getLabel(), input.getEventCreatedOn()); - // XXX: The cache eviction is needed temporarily until Issue 308448333 won't be fixed. - // Once the fix will be in place, `onCreateProject` will take care of evicting the cache. - projectCache.evict(Project.nameKey(projectName)); projectCache.onCreateProject(Project.nameKey(projectName)); repLog.info( "Init project API from {} for {}:{} - {}", @@ -180,7 +177,7 @@ } private boolean initProject(String gitRepositoryName, boolean needsProjectReindexing) - throws AuthException, PermissionBackendException { + throws AuthException, PermissionBackendException, IOException { // When triggered internally(for example by consuming stream events) user is not provided // and internal user is returned. Project creation should be always allowed for internal user. if (!userProvider.get().isInternalUser()) { @@ -195,7 +192,7 @@ Project.NameKey projectNameKey = Project.NameKey.parse(gitRepositoryName); if (localFS.createProject(projectNameKey, RefNames.HEAD)) { if (needsProjectReindexing) { - projectCache.evictAndReindex(projectNameKey); + projectCache.onCreateProject(projectNameKey); } return true; }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/event/EventsBrokerMessageConsumer.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/event/EventsBrokerMessageConsumer.java index a9b0a5e..a9b4945 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/event/EventsBrokerMessageConsumer.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/event/EventsBrokerMessageConsumer.java
@@ -28,6 +28,7 @@ import com.google.inject.Inject; import com.google.inject.name.Named; import com.googlesource.gerrit.plugins.replication.pull.ShutdownState; +import java.io.IOException; import java.util.function.Consumer; public class EventsBrokerMessageConsumer implements Consumer<Event>, LifecycleListener { @@ -57,7 +58,7 @@ try { eventListener.fetchRefsForEvent(event); if (shutdownState.isShuttingDown()) stop(); - } catch (AuthException | PermissionBackendException e) { + } catch (AuthException | PermissionBackendException | IOException e) { throw new EventRejectedException(event, e); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/event/StreamEventListener.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/event/StreamEventListener.java index b14d4a1..4c621ac 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/event/StreamEventListener.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/event/StreamEventListener.java
@@ -95,7 +95,7 @@ public void onEvent(Event event) { try { fetchRefsForEvent(event); - } catch (AuthException | PermissionBackendException e) { + } catch (AuthException | PermissionBackendException | IOException e) { logger.atSevere().withCause(e).log( "This is the event handler of Gerrit's event-bus. It isn't" + "supposed to throw any exception, otherwise the other handlers " @@ -103,7 +103,8 @@ } } - public void fetchRefsForEvent(Event event) throws AuthException, PermissionBackendException { + public void fetchRefsForEvent(Event event) + throws AuthException, PermissionBackendException, IOException { if (instanceId.equals(event.instanceId) || !shouldReplicateProject(event)) { return; } @@ -153,7 +154,7 @@ projectCreatedEvent.instanceId, projectCreatedEvent.getProjectNameKey(), metrics); - } catch (AuthException | PermissionBackendException e) { + } catch (AuthException | PermissionBackendException | IOException e) { logger.atSevere().withCause(e).log( "Cannot initialise project:%s", projectCreatedEvent.projectName); throw e;