public class AccountsUpdate
extends java.lang.Object
This class should be used for all account updates. It supports updating account properties, external IDs, preferences (general, diff and edit preferences) and project watches.
Updates to one account are always atomic. Batch updating several accounts within one transaction is not supported.
For any account update the caller must provide a commit message, the account ID and an AccountsUpdate.AccountUpdater
. The account updater allows to read the current AccountState
and to
prepare updates to the account by calling setters on the provided InternalAccountUpdate.Builder
. If the current account state is of no interest the caller may
also provide a Consumer
for InternalAccountUpdate.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.
For creating a new account a new account ID can be retrieved from Sequences.nextAccountId()
.
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, 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 Preferences
) 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 ReindexAfterRefUpdate
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 ReindexAfterRefUpdate
.
Reindexing and flushing accounts from the account cache can be disabled by
GitReferenceUpdated.DISABLED
and
ExternalIdNotes.FactoryNoReindex
factory as
parameter of AccountsUpdate.Factory.create(IdentifiedUser,
ExternalIdNotes.ExternalIdNotesLoader)
If there are concurrent account updates 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
.
Modifier and Type | Class and Description |
---|---|
static interface |
AccountsUpdate.AccountUpdater
Updater for an account.
|
static interface |
AccountsUpdate.Factory |
Constructor and Description |
---|
AccountsUpdate(GitRepositoryManager repoManager,
GitReferenceUpdated gitRefUpdated,
java.util.Optional<IdentifiedUser> currentUser,
AllUsersName allUsersName,
ExternalIds externalIds,
com.google.inject.Provider<MetaDataUpdate.InternalFactory> metaDataUpdateInternalFactory,
RetryHelper retryHelper,
ExternalIdNotes.ExternalIdNotesLoader extIdNotesLoader,
org.eclipse.jgit.lib.PersonIdent committerIdent,
org.eclipse.jgit.lib.PersonIdent authorIdent,
java.lang.Runnable afterReadRevision,
java.lang.Runnable beforeCommit) |
Modifier and Type | Method and Description |
---|---|
AccountState |
insert(java.lang.String message,
Account.Id accountId,
AccountsUpdate.AccountUpdater updater)
Inserts a new account.
|
AccountState |
insert(java.lang.String message,
Account.Id accountId,
java.util.function.Consumer<InternalAccountUpdate.Builder> init)
Inserts a new account.
|
java.util.Optional<AccountState> |
update(java.lang.String message,
Account.Id accountId,
AccountsUpdate.AccountUpdater updater)
Gets the account and updates it atomically.
|
java.util.Optional<AccountState> |
update(java.lang.String message,
Account.Id accountId,
java.util.function.Consumer<InternalAccountUpdate.Builder> update)
Gets the account and updates it atomically.
|
public AccountsUpdate(GitRepositoryManager repoManager, GitReferenceUpdated gitRefUpdated, java.util.Optional<IdentifiedUser> currentUser, AllUsersName allUsersName, ExternalIds externalIds, com.google.inject.Provider<MetaDataUpdate.InternalFactory> metaDataUpdateInternalFactory, RetryHelper retryHelper, ExternalIdNotes.ExternalIdNotesLoader extIdNotesLoader, org.eclipse.jgit.lib.PersonIdent committerIdent, org.eclipse.jgit.lib.PersonIdent authorIdent, java.lang.Runnable afterReadRevision, java.lang.Runnable beforeCommit)
public AccountState insert(java.lang.String message, Account.Id accountId, java.util.function.Consumer<InternalAccountUpdate.Builder> init) throws java.io.IOException, org.eclipse.jgit.errors.ConfigInvalidException
message
- commit message for the account creation, must not be null or empty
accountId
- ID of the new accountinit
- consumer to populate the new accountcom.google.gerrit.exceptions.DuplicateKeyException
- if the account already existsjava.io.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 valuepublic AccountState insert(java.lang.String message, Account.Id accountId, AccountsUpdate.AccountUpdater updater) throws java.io.IOException, org.eclipse.jgit.errors.ConfigInvalidException
message
- commit message for the account creation, must not be null or empty
accountId
- ID of the new accountupdater
- updater to populate the new accountcom.google.gerrit.exceptions.DuplicateKeyException
- if the account already existsjava.io.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 valuepublic java.util.Optional<AccountState> update(java.lang.String message, Account.Id accountId, java.util.function.Consumer<InternalAccountUpdate.Builder> update) throws com.google.gerrit.git.LockFailureException, java.io.IOException, org.eclipse.jgit.errors.ConfigInvalidException
Changing the registration date of an account is not supported.
message
- commit message for the account update, must not be null or empty
accountId
- ID of the accountupdate
- consumer to update the account, only invoked if the account existsOptional.empty()
if the account doesn't existjava.io.IOException
- if updating the user branch fails due to an IO errorcom.google.gerrit.git.LockFailureException
- if updating the user branch still fails due to concurrent updates
after the retry timeout exceededorg.eclipse.jgit.errors.ConfigInvalidException
- if any of the account fields has an invalid valuepublic java.util.Optional<AccountState> update(java.lang.String message, Account.Id accountId, AccountsUpdate.AccountUpdater updater) throws com.google.gerrit.git.LockFailureException, java.io.IOException, org.eclipse.jgit.errors.ConfigInvalidException
Changing the registration date of an account is not supported.
message
- commit message for the account update, must not be null or empty
accountId
- ID of the accountupdater
- updater to update the account, only invoked if the account existsOptional.empty()
if the account doesn't existjava.io.IOException
- if updating the user branch fails due to an IO errorcom.google.gerrit.git.LockFailureException
- if updating the user branch still fails due to concurrent updates
after the retry timeout exceededorg.eclipse.jgit.errors.ConfigInvalidException
- if any of the account fields has an invalid value