Add a separate queue for non-interactive users

A new internal user group, "Non-Interactive Users" is added. members
of this group are not expected to perform interactive operations on
the gerrit web frontend.

However, sometimes such a user may need a separate thread pool in
order to prevent it from grabbing threads from the interactive users.

This change introduces a second thread pool, which separates
operations from the non-interactive users from the interactive ones.
This ensures that the interactive users can keep working when
resources are tight.

Change-Id: I16334dd84ec50e1a6ca894e635c8beea9bd42115
This commit is contained in:
Nico Sallembien
2010-05-18 16:40:10 -07:00
parent 8ef3b69f35
commit fc53f7fd7a
12 changed files with 224 additions and 37 deletions

View File

@@ -59,6 +59,11 @@ public abstract class CurrentUser {
/** Set of changes starred by this user. */
public abstract Set<Change.Id> getStarredChanges();
/** Is the user a non-interactive user? */
public boolean isBatchUser() {
return getEffectiveGroups().contains(authConfig.getBatchUsersGroup());
}
@Deprecated
public final boolean isAdministrator() {
return getEffectiveGroups().contains(authConfig.getAdministratorsGroup());

View File

@@ -46,6 +46,7 @@ public class AuthConfig {
private final AccountGroup.Id administratorGroup;
private final Set<AccountGroup.Id> anonymousGroups;
private final Set<AccountGroup.Id> registeredGroups;
private final AccountGroup.Id batchUsersGroup;
private final boolean allowGoogleAccountUpgrade;
@@ -65,6 +66,7 @@ public class AuthConfig {
registeredGroups = Collections.unmodifiableSet(r);
anonymousGroups = Collections.singleton(s.anonymousGroupId);
administratorGroup = s.adminGroupId;
batchUsersGroup = s.batchUsersGroupId;
if (authType == AuthType.OPENID) {
allowGoogleAccountUpgrade =
@@ -117,6 +119,11 @@ public class AuthConfig {
return administratorGroup;
}
/** Identity of the group whose service is degraded to lower priority. */
public AccountGroup.Id getBatchUsersGroup() {
return batchUsersGroup;
}
/** Groups that all users, including anonymous users, belong to. */
public Set<AccountGroup.Id> getAnonymousGroups() {
return anonymousGroups;

View File

@@ -140,11 +140,22 @@ public class SchemaCreator {
c.accountGroupNames().insert(
Collections.singleton(new AccountGroupName(registered)));
final AccountGroup batchUsers =
new AccountGroup(new AccountGroup.NameKey("Non-Interactive Users"),
new AccountGroup.Id(c.nextAccountGroupId()));
batchUsers.setDescription("Users who perform batch actions on Gerrit");
batchUsers.setOwnerGroupId(admin.getId());
batchUsers.setType(AccountGroup.Type.INTERNAL);
c.accountGroups().insert(Collections.singleton(batchUsers));
c.accountGroupNames().insert(
Collections.singleton(new AccountGroupName(batchUsers)));
final SystemConfig s = SystemConfig.create();
s.registerEmailPrivateKey = SignedToken.generateRandomKey();
s.adminGroupId = admin.getId();
s.anonymousGroupId = anonymous.getId();
s.registeredGroupId = registered.getId();
s.batchUsersGroupId = batchUsers.getId();
s.wildProjectName = DEFAULT_WILD_NAME;
try {
s.sitePath = site_path.getCanonicalPath();

View File

@@ -32,7 +32,7 @@ import java.util.List;
/** A version of the database schema. */
public abstract class SchemaVersion {
/** The current schema version. */
private static final Class<? extends SchemaVersion> C = Schema_32.class;
private static final Class<? extends SchemaVersion> C = Schema_33.class;
public static class Module extends AbstractModule {
@Override

View File

@@ -0,0 +1,49 @@
// Copyright (C) 2010 The Android Open Source Project
//
// 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.schema;
import com.google.gerrit.reviewdb.AccountGroup;
import com.google.gerrit.reviewdb.AccountGroupName;
import com.google.gerrit.reviewdb.ReviewDb;
import com.google.gerrit.reviewdb.SystemConfig;
import com.google.gwtorm.client.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.util.Collections;
public class Schema_33 extends SchemaVersion {
@Inject
Schema_33(Provider<Schema_32> prior) {
super(prior);
}
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
SystemConfig config = db.systemConfig().all().toList().get(0);
final AccountGroup batchUsers =
new AccountGroup(new AccountGroup.NameKey("Non-Interactive Users"),
new AccountGroup.Id(db.nextAccountGroupId()));
batchUsers.setDescription("Users who perform batch actions on Gerrit");
batchUsers.setOwnerGroupId(config.adminGroupId);
batchUsers.setType(AccountGroup.Type.INTERNAL);
db.accountGroups().insert(Collections.singleton(batchUsers));
db.accountGroupNames().insert(
Collections.singleton(new AccountGroupName(batchUsers)));
config.batchUsersGroupId = batchUsers.getId();
db.systemConfig().update(Collections.singleton(config));
}
}