Allow to disable reindexing for account updates

At Google we need to do account updates in a context where reindex is
not possible. Hence reindexing for the AccountUpdates class must be
optional.

Change-Id: I03ae0d37da3c6550963f6be937e117da5f3cd3bc
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin 2018-01-03 12:36:09 +01:00
parent 64ae623394
commit a6339d218e
2 changed files with 71 additions and 8 deletions

View File

@ -29,6 +29,7 @@ import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.externalids.ExternalIdNotes;
import com.google.gerrit.server.account.externalids.ExternalIdNotes.ExternalIdNotesLoader;
import com.google.gerrit.server.config.AllUsersName;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import com.google.gerrit.server.git.GitRepositoryManager;
@ -159,6 +160,62 @@ public class AccountsUpdate {
}
}
/**
* Factory to create an AccountsUpdate instance for updating accounts by the Gerrit server.
*
* <p>Using this class no reindex will be performed for the affected accounts and they will also
* not be evicted from the account cache.
*
* <p>The Gerrit server identity will be used as author and committer for all commits that update
* the accounts.
*/
@Singleton
public static class ServerNoReindex {
private final GitRepositoryManager repoManager;
private final GitReferenceUpdated gitRefUpdated;
private final AllUsersName allUsersName;
private final OutgoingEmailValidator emailValidator;
private final Provider<PersonIdent> serverIdentProvider;
private final Provider<MetaDataUpdate.InternalFactory> metaDataUpdateInternalFactory;
private final RetryHelper retryHelper;
private final ExternalIdNotes.FactoryNoReindex extIdNotesFactory;
@Inject
public ServerNoReindex(
GitRepositoryManager repoManager,
GitReferenceUpdated gitRefUpdated,
AllUsersName allUsersName,
OutgoingEmailValidator emailValidator,
@GerritPersonIdent Provider<PersonIdent> serverIdentProvider,
Provider<MetaDataUpdate.InternalFactory> metaDataUpdateInternalFactory,
RetryHelper retryHelper,
ExternalIdNotes.FactoryNoReindex extIdNotesFactory) {
this.repoManager = repoManager;
this.gitRefUpdated = gitRefUpdated;
this.allUsersName = allUsersName;
this.emailValidator = emailValidator;
this.serverIdentProvider = serverIdentProvider;
this.metaDataUpdateInternalFactory = metaDataUpdateInternalFactory;
this.retryHelper = retryHelper;
this.extIdNotesFactory = extIdNotesFactory;
}
public AccountsUpdate create() {
PersonIdent serverIdent = serverIdentProvider.get();
return new AccountsUpdate(
repoManager,
gitRefUpdated,
null,
allUsersName,
emailValidator,
metaDataUpdateInternalFactory,
retryHelper,
extIdNotesFactory,
serverIdent,
serverIdent);
}
}
/**
* Factory to create an AccountsUpdate instance for updating accounts by the current user.
*
@ -228,7 +285,7 @@ public class AccountsUpdate {
private final OutgoingEmailValidator emailValidator;
private final Provider<MetaDataUpdate.InternalFactory> metaDataUpdateInternalFactory;
private final RetryHelper retryHelper;
private final ExternalIdNotes.Factory extIdNotesFactory;
private final ExternalIdNotesLoader extIdNotesLoader;
private final PersonIdent committerIdent;
private final PersonIdent authorIdent;
private final Runnable afterReadRevision;
@ -241,7 +298,7 @@ public class AccountsUpdate {
OutgoingEmailValidator emailValidator,
Provider<MetaDataUpdate.InternalFactory> metaDataUpdateInternalFactory,
RetryHelper retryHelper,
ExternalIdNotes.Factory extIdNotesFactory,
ExternalIdNotesLoader extIdNotesLoader,
PersonIdent committerIdent,
PersonIdent authorIdent) {
this(
@ -252,7 +309,7 @@ public class AccountsUpdate {
emailValidator,
metaDataUpdateInternalFactory,
retryHelper,
extIdNotesFactory,
extIdNotesLoader,
committerIdent,
authorIdent,
Runnables.doNothing());
@ -267,7 +324,7 @@ public class AccountsUpdate {
OutgoingEmailValidator emailValidator,
Provider<MetaDataUpdate.InternalFactory> metaDataUpdateInternalFactory,
RetryHelper retryHelper,
ExternalIdNotes.Factory extIdNotesFactory,
ExternalIdNotesLoader extIdNotesLoader,
PersonIdent committerIdent,
PersonIdent authorIdent,
Runnable afterReadRevision) {
@ -279,7 +336,7 @@ public class AccountsUpdate {
this.metaDataUpdateInternalFactory =
checkNotNull(metaDataUpdateInternalFactory, "metaDataUpdateInternalFactory");
this.retryHelper = checkNotNull(retryHelper, "retryHelper");
this.extIdNotesFactory = checkNotNull(extIdNotesFactory, "extIdNotesFactory");
this.extIdNotesLoader = checkNotNull(extIdNotesLoader, "extIdNotesLoader");
this.committerIdent = checkNotNull(committerIdent, "committerIdent");
this.authorIdent = checkNotNull(authorIdent, "authorIdent");
this.afterReadRevision = afterReadRevision;
@ -491,7 +548,7 @@ public class AccountsUpdate {
update.getDeletedExternalIds()),
accountId);
ExternalIdNotes extIdNotes = extIdNotesFactory.load(allUsersRepo);
ExternalIdNotes extIdNotes = extIdNotesLoader.load(allUsersRepo);
extIdNotes.replace(update.getDeletedExternalIds(), update.getCreatedExternalIds());
extIdNotes.upsert(update.getUpdatedExternalIds());
return extIdNotes;

View File

@ -78,8 +78,12 @@ public class ExternalIdNotes extends VersionedMetaData {
private static final int MAX_NOTE_SZ = 1 << 19;
public interface ExternalIdNotesLoader {
ExternalIdNotes load(Repository allUsersRepo) throws IOException, ConfigInvalidException;
}
@Singleton
public static class Factory {
public static class Factory implements ExternalIdNotesLoader {
private final ExternalIdCache externalIdCache;
private final AccountCache accountCache;
@ -89,6 +93,7 @@ public class ExternalIdNotes extends VersionedMetaData {
this.accountCache = accountCache;
}
@Override
public ExternalIdNotes load(Repository allUsersRepo)
throws IOException, ConfigInvalidException {
return new ExternalIdNotes(externalIdCache, accountCache, allUsersRepo).load();
@ -96,7 +101,7 @@ public class ExternalIdNotes extends VersionedMetaData {
}
@Singleton
public static class FactoryNoReindex {
public static class FactoryNoReindex implements ExternalIdNotesLoader {
private final ExternalIdCache externalIdCache;
@Inject
@ -104,6 +109,7 @@ public class ExternalIdNotes extends VersionedMetaData {
this.externalIdCache = externalIdCache;
}
@Override
public ExternalIdNotes load(Repository allUsersRepo)
throws IOException, ConfigInvalidException {
return new ExternalIdNotes(externalIdCache, null, allUsersRepo).load();