Define an SSH command to force the group cache to flush and reload

This may be necessary if the admin has modified the group records in
the database directly, without going through the Gerrit APIs.  This
isn't a common case, but forcing a flush and reload of the groups
may be necessary.

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-01-03 12:07:14 -08:00
parent a76796b3c6
commit e8cfbb6a4b
3 changed files with 41 additions and 0 deletions

View File

@@ -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();
}
}
}

View File

@@ -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");
}
}
}

View File

@@ -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 {