Class AccountsUpdateNoteDbImpl
Batch updates of multiple different accounts can be performed atomically, see AccountsUpdate.updateBatch(List)
. Batch creation is not supported.
For any account update the caller must provide a commit message, the account ID and an AccountsUpdate.ConfigureDeltaFromState
. The account updater
reads the current AccountState
and prepares updates to the account by calling setters on
the provided AccountDelta.Builder
. If the current
account state is of no interest the caller may also provide a Consumer
for AccountDelta.Builder
instead of the account updater.
The provided commit message is used for the update of the user branch. Using a precise and unique commit message allows to identify the code from which an update was made when looking at a commit in the user branch, and thus help debugging.
The account updates are written to NoteDb. In NoteDb accounts are represented as user branches
in the All-Users
repository. Optionally a user branch can contain a 'account.config' file
that stores account properties, such as full name, display name, preferred email, status and the
active flag. The timestamp of the first commit on a user branch denotes the registration date.
The initial commit on the user branch may be empty (since having an 'account.config' is
optional). See AccountConfig
for details of the 'account.config' file format. In addition
the user branch can contain a 'preferences.config' config file to store preferences (see StoredPreferences
) and a 'watch.config' config file to store project watches (see ProjectWatches
). External IDs are stored separately in the refs/meta/external-ids
notes
branch (see ExternalIdNotes
).
On updating an account the account is evicted from the account cache and reindexed. The
eviction from the account cache and the reindexing is done by the ReindexAccountsAfterRefUpdate
class which receives the event about updating the user branch that
is triggered by this class.
If external IDs are updated, the ExternalIdCache is automatically updated by ExternalIdNotes
. In addition ExternalIdNotes
takes care about evicting and reindexing
corresponding accounts. This is needed because external ID updates don't touch the user branches.
Hence, in this case the accounts are not evicted and reindexed via ReindexAccountsAfterRefUpdate
.
Reindexing and flushing accounts from the account cache can be disabled by-
- using
AccountsUpdateNoteDbImpl.FactoryNoReindex
and - binding
GitReferenceUpdated.DISABLED
, or avoid bindingReindexAccountsAfterRefUpdate
.
If there are concurrent account updates which updating the user branch in NoteDb may fail with
LockFailureException
. In this case the account update is automatically retried and the
account updater is invoked once more with the updated account state. This means the whole
read-modify-write sequence is atomic. Retrying is limited by a timeout. If the timeout is
exceeded the account update can still fail with LockFailureException
.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
Nested classes/interfaces inherited from class com.google.gerrit.server.account.AccountsUpdate
AccountsUpdate.AccountsUpdateLoader, AccountsUpdate.ConfigureDeltaFromState, AccountsUpdate.UpdateArguments
-
Field Summary
Fields inherited from class com.google.gerrit.server.account.AccountsUpdate
authorIdent, committerIdent, currentUser
-
Constructor Summary
ConstructorsConstructorDescriptionAccountsUpdateNoteDbImpl
(GitRepositoryManager repoManager, GitReferenceUpdated gitRefUpdated, Optional<IdentifiedUser> currentUser, AllUsersName allUsersName, ExternalIdsNoteDbImpl externalIds, ExternalIdNotes.ExternalIdNotesLoader extIdNotesFactory, com.google.inject.Provider<MetaDataUpdate.InternalFactory> metaDataUpdateInternalFactory, RetryHelper retryHelper, org.eclipse.jgit.lib.PersonIdent committerIdent, Runnable afterReadRevision, Runnable beforeCommit) -
Method Summary
Modifier and TypeMethodDescriptionvoid
delete
(String message, Account.Id accountId) Deletes all the account state data.protected com.google.common.collect.ImmutableList<Optional<AccountState>>
executeUpdates
(List<AccountsUpdate.UpdateArguments> updates) insert
(String message, Account.Id accountId, AccountsUpdate.ConfigureDeltaFromState init) Inserts a new account.Methods inherited from class com.google.gerrit.server.account.AccountsUpdate
insert, joinConsumers, update, update, updateBatch
-
Constructor Details
-
AccountsUpdateNoteDbImpl
public AccountsUpdateNoteDbImpl(GitRepositoryManager repoManager, GitReferenceUpdated gitRefUpdated, Optional<IdentifiedUser> currentUser, AllUsersName allUsersName, ExternalIdsNoteDbImpl externalIds, ExternalIdNotes.ExternalIdNotesLoader extIdNotesFactory, com.google.inject.Provider<MetaDataUpdate.InternalFactory> metaDataUpdateInternalFactory, RetryHelper retryHelper, org.eclipse.jgit.lib.PersonIdent committerIdent, Runnable afterReadRevision, Runnable beforeCommit)
-
-
Method Details
-
insert
public AccountState insert(String message, Account.Id accountId, AccountsUpdate.ConfigureDeltaFromState init) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException Description copied from class:AccountsUpdate
Inserts a new account.- Specified by:
insert
in classAccountsUpdate
- Parameters:
message
- commit message for the account creation, must not benull or empty
accountId
- ID of the new accountinit
- to populate the new account- Returns:
- the newly created account
- Throws:
IOException
- if creating the user branch fails due to an IO errororg.eclipse.jgit.errors.ConfigInvalidException
- if any of the account fields has an invalid value
-
delete
public void delete(String message, Account.Id accountId) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException Description copied from class:AccountsUpdate
Deletes all the account state data.- Specified by:
delete
in classAccountsUpdate
- Parameters:
message
- commit message for the account update, must not benull or empty
accountId
- ID of the account- Throws:
IOException
- if updating the user branch fails due to an IO errororg.eclipse.jgit.errors.ConfigInvalidException
- if any of the account fields has an invalid value
-
executeUpdates
protected com.google.common.collect.ImmutableList<Optional<AccountState>> executeUpdates(List<AccountsUpdate.UpdateArguments> updates) throws org.eclipse.jgit.errors.ConfigInvalidException, IOException - Specified by:
executeUpdates
in classAccountsUpdate
- Throws:
org.eclipse.jgit.errors.ConfigInvalidException
IOException
-