From a6339d218e66717e2597542cf5c88919effb37d7 Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Wed, 3 Jan 2018 12:36:09 +0100 Subject: [PATCH] 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 --- .../gerrit/server/account/AccountsUpdate.java | 69 +++++++++++++++++-- .../account/externalids/ExternalIdNotes.java | 10 ++- 2 files changed, 71 insertions(+), 8 deletions(-) diff --git a/java/com/google/gerrit/server/account/AccountsUpdate.java b/java/com/google/gerrit/server/account/AccountsUpdate.java index f88f7e25cd..85550aa4af 100644 --- a/java/com/google/gerrit/server/account/AccountsUpdate.java +++ b/java/com/google/gerrit/server/account/AccountsUpdate.java @@ -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. + * + *

Using this class no reindex will be performed for the affected accounts and they will also + * not be evicted from the account cache. + * + *

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 serverIdentProvider; + private final Provider metaDataUpdateInternalFactory; + private final RetryHelper retryHelper; + private final ExternalIdNotes.FactoryNoReindex extIdNotesFactory; + + @Inject + public ServerNoReindex( + GitRepositoryManager repoManager, + GitReferenceUpdated gitRefUpdated, + AllUsersName allUsersName, + OutgoingEmailValidator emailValidator, + @GerritPersonIdent Provider serverIdentProvider, + Provider 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 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 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 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; diff --git a/java/com/google/gerrit/server/account/externalids/ExternalIdNotes.java b/java/com/google/gerrit/server/account/externalids/ExternalIdNotes.java index f6ded07138..f663247e4c 100644 --- a/java/com/google/gerrit/server/account/externalids/ExternalIdNotes.java +++ b/java/com/google/gerrit/server/account/externalids/ExternalIdNotes.java @@ -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();