Hide multi-master cache coherency issues on preferences
User preferences are held in memory in the accounts cache, but can be stale in a multi-master configuration due to writes being handled on a different server process. Paper over the lack of cache coherency by reading the preferences from the database anytime they are requested through the RPC or REST APIs. Change-Id: I2a14e1f50e908a1d5ea5628e5a05e392be2e0d42
This commit is contained in:
@@ -69,7 +69,12 @@ class AccountServiceImpl extends BaseServiceImplementation implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void myAccount(final AsyncCallback<Account> callback) {
|
public void myAccount(final AsyncCallback<Account> callback) {
|
||||||
callback.onSuccess(currentUser.get().getAccount());
|
run(callback, new Action<Account>() {
|
||||||
|
@Override
|
||||||
|
public Account run(ReviewDb db) throws OrmException {
|
||||||
|
return db.accounts().get(currentUser.get().getAccountId());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changePreferences(final AccountGeneralPreferences pref,
|
public void changePreferences(final AccountGeneralPreferences pref,
|
||||||
|
|||||||
@@ -16,28 +16,39 @@ package com.google.gerrit.server.account;
|
|||||||
|
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||||
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
|
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
|
||||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
|
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
|
||||||
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
public class GetDiffPreferences implements RestReadView<AccountResource> {
|
public class GetDiffPreferences implements RestReadView<AccountResource> {
|
||||||
|
|
||||||
private final Provider<CurrentUser> self;
|
private final Provider<CurrentUser> self;
|
||||||
|
private final Provider<ReviewDb> db;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
GetDiffPreferences(Provider<CurrentUser> self) {
|
GetDiffPreferences(Provider<CurrentUser> self, Provider<ReviewDb> db) {
|
||||||
this.self = self;
|
this.self = self;
|
||||||
|
this.db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DiffPreferencesInfo apply(AccountResource rsrc) throws AuthException {
|
public DiffPreferencesInfo apply(AccountResource rsrc)
|
||||||
|
throws AuthException, OrmException {
|
||||||
if (self.get() != rsrc.getUser()
|
if (self.get() != rsrc.getUser()
|
||||||
&& !self.get().getCapabilities().canAdministrateServer()) {
|
&& !self.get().getCapabilities().canAdministrateServer()) {
|
||||||
throw new AuthException("restricted to administrator");
|
throw new AuthException("restricted to administrator");
|
||||||
}
|
}
|
||||||
return DiffPreferencesInfo.parse(rsrc.getUser().getAccountDiffPreference());
|
|
||||||
|
Account.Id userId = rsrc.getUser().getAccountId();
|
||||||
|
AccountDiffPreference a = db.get().accountDiffPreferences().get(userId);
|
||||||
|
if (a == null) {
|
||||||
|
a = new AccountDiffPreference(userId);
|
||||||
|
}
|
||||||
|
return DiffPreferencesInfo.parse(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class DiffPreferencesInfo {
|
static class DiffPreferencesInfo {
|
||||||
|
|||||||
@@ -15,7 +15,9 @@
|
|||||||
package com.google.gerrit.server.account;
|
package com.google.gerrit.server.account;
|
||||||
|
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
|
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||||
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
|
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.ChangeScreen;
|
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.ChangeScreen;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.CommentVisibilityStrategy;
|
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.CommentVisibilityStrategy;
|
||||||
@@ -24,26 +26,34 @@ import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DiffView;
|
|||||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand;
|
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
|
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.TimeFormat;
|
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.TimeFormat;
|
||||||
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
public class GetPreferences implements RestReadView<AccountResource> {
|
public class GetPreferences implements RestReadView<AccountResource> {
|
||||||
private final Provider<CurrentUser> self;
|
private final Provider<CurrentUser> self;
|
||||||
|
private final Provider<ReviewDb> db;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
GetPreferences(Provider<CurrentUser> self) {
|
GetPreferences(Provider<CurrentUser> self, Provider<ReviewDb> db) {
|
||||||
this.self = self;
|
this.self = self;
|
||||||
|
this.db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreferenceInfo apply(AccountResource rsrc) throws AuthException {
|
public PreferenceInfo apply(AccountResource rsrc)
|
||||||
|
throws AuthException, ResourceNotFoundException, OrmException {
|
||||||
if (self.get() != rsrc.getUser()
|
if (self.get() != rsrc.getUser()
|
||||||
&& !self.get().getCapabilities().canAdministrateServer()) {
|
&& !self.get().getCapabilities().canAdministrateServer()) {
|
||||||
throw new AuthException("restricted to administrator");
|
throw new AuthException("restricted to administrator");
|
||||||
}
|
}
|
||||||
return new PreferenceInfo(rsrc.getUser().getAccount()
|
Account a = db.get().accounts().get(rsrc.getUser().getAccountId());
|
||||||
.getGeneralPreferences());
|
if (a == null) {
|
||||||
|
throw new ResourceNotFoundException();
|
||||||
|
}
|
||||||
|
return new PreferenceInfo(a.getGeneralPreferences());
|
||||||
}
|
}
|
||||||
|
|
||||||
static class PreferenceInfo {
|
static class PreferenceInfo {
|
||||||
|
|||||||
Reference in New Issue
Block a user