Use BatchRefUpdate to update accounts

In future we want to update accounts and external IDs atomically. Since
the account properties and external IDs are stored in different refs
(user branch and refs/meta/external-ids) we need to use a BatchRefUpdate
to update the refs atomically. At the moment we still only update the
user branch, but this change is a preparation for being able to update
refs/meta/external-ids branch in the same transaction.

When we start to do updates in multiple branches we also should now
always use the server identity as committer. The calling user is still
set as author if the User factory is used.

With this change we now also open the All-Users repository only once for
reading and writing.

Change-Id: I134bb9ba7f73733a006bd6a5d39486a042f2dc4a
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2017-12-11 17:35:42 +01:00
parent 173e5877ff
commit 84d9297298
2 changed files with 102 additions and 66 deletions

View File

@@ -95,6 +95,7 @@ import com.google.gerrit.server.account.externalids.ExternalIds;
import com.google.gerrit.server.account.externalids.ExternalIdsUpdate;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import com.google.gerrit.server.git.LockFailureException;
import com.google.gerrit.server.git.MetaDataUpdate;
import com.google.gerrit.server.git.ProjectConfig;
import com.google.gerrit.server.index.account.AccountIndexer;
import com.google.gerrit.server.index.account.StalenessChecker;
@@ -195,6 +196,8 @@ public class AccountIT extends AbstractDaemonTest {
@Inject private RetryHelper.Metrics retryMetrics;
@Inject private Provider<MetaDataUpdate.InternalFactory> metaDataUpdateInternalFactory;
@Inject
@Named("accounts")
private LoadingCache<Account.Id, Optional<AccountState>> accountsCache;
@@ -1899,6 +1902,7 @@ public class AccountIT extends AbstractDaemonTest {
String status = "happy";
String fullName = "Foo";
AtomicBoolean doneBgUpdate = new AtomicBoolean(false);
PersonIdent ident = serverIdent.get();
AccountsUpdate update =
new AccountsUpdate(
repoManager,
@@ -1906,8 +1910,7 @@ public class AccountIT extends AbstractDaemonTest {
null,
allUsers,
emailValidator,
serverIdent.get(),
() -> metaDataUpdateFactory.create(allUsers),
metaDataUpdateInternalFactory,
new RetryHelper(
cfg,
retryMetrics,
@@ -1915,6 +1918,8 @@ public class AccountIT extends AbstractDaemonTest {
null,
null,
r -> r.withBlockStrategy(noSleepBlockStrategy)),
ident,
ident,
() -> {
if (!doneBgUpdate.getAndSet(true)) {
try {
@@ -1945,6 +1950,7 @@ public class AccountIT extends AbstractDaemonTest {
List<String> status = ImmutableList.of("foo", "bar", "baz");
String fullName = "Foo";
AtomicInteger bgCounter = new AtomicInteger(0);
PersonIdent ident = serverIdent.get();
AccountsUpdate update =
new AccountsUpdate(
repoManager,
@@ -1952,8 +1958,7 @@ public class AccountIT extends AbstractDaemonTest {
null,
allUsers,
emailValidator,
serverIdent.get(),
() -> metaDataUpdateFactory.create(allUsers),
metaDataUpdateInternalFactory,
new RetryHelper(
cfg,
retryMetrics,
@@ -1963,6 +1968,8 @@ public class AccountIT extends AbstractDaemonTest {
r ->
r.withStopStrategy(StopStrategies.stopAfterAttempt(status.size()))
.withBlockStrategy(noSleepBlockStrategy)),
ident,
ident,
() -> {
try {
accountsUpdate