diff --git a/appjar/src/main/java/com/google/gerrit/server/GroupCache.java b/appjar/src/main/java/com/google/gerrit/server/GroupCache.java index 44b814ced0..6afaabb119 100644 --- a/appjar/src/main/java/com/google/gerrit/server/GroupCache.java +++ b/appjar/src/main/java/com/google/gerrit/server/GroupCache.java @@ -193,4 +193,11 @@ public class GroupCache { } return m; } + + /** Force the entire group cache to flush from memory and recompute. */ + public void flush() { + synchronized (byAccount) { + byAccount.clear(); + } + } } diff --git a/appjar/src/main/java/com/google/gerrit/server/ssh/AdminFlushGroupCache.java b/appjar/src/main/java/com/google/gerrit/server/ssh/AdminFlushGroupCache.java new file mode 100644 index 0000000000..6d8d112cd0 --- /dev/null +++ b/appjar/src/main/java/com/google/gerrit/server/ssh/AdminFlushGroupCache.java @@ -0,0 +1,30 @@ +// Copyright 2008 Google Inc. +// +// 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.google.gerrit.server.ssh; + +import com.google.gerrit.server.GroupCache; + +/** Causes the {@link GroupCache} to purge all entries and reload. */ +class AdminFlushGroupCache extends AbstractCommand { + @Override + protected void run(String[] args) throws Failure { + final GroupCache gc = getGerritServer().getGroupCache(); + if (gc.isAdministrator(getAccountId())) { + gc.flush(); + } else { + throw new Failure(1, "fatal: Not a Gerrit administrator"); + } + } +} diff --git a/appjar/src/main/java/com/google/gerrit/server/ssh/GerritCommandFactory.java b/appjar/src/main/java/com/google/gerrit/server/ssh/GerritCommandFactory.java index fbef552900..10d3d37d2d 100644 --- a/appjar/src/main/java/com/google/gerrit/server/ssh/GerritCommandFactory.java +++ b/appjar/src/main/java/com/google/gerrit/server/ssh/GerritCommandFactory.java @@ -55,6 +55,10 @@ class GerritCommandFactory implements CommandFactory { return new Receive(); } + if ("gerrit-flush-group-cache".equals(cmd)) { + return new AdminFlushGroupCache(); + } + return new AbstractCommand() { @Override protected void run(final String[] argv) throws Failure {