Merge "Write debug log that shows up in trace when meta data file is read/saved"

This commit is contained in:
Edwin Kempin
2018-08-27 07:01:09 +00:00
committed by Gerrit Code Review
49 changed files with 346 additions and 193 deletions

View File

@@ -38,6 +38,7 @@ import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gerrit.reviewdb.client.AccountGroupByIdAud;
import com.google.gerrit.reviewdb.client.AccountGroupMember;
import com.google.gerrit.reviewdb.client.AccountGroupMemberAudit;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.reviewdb.server.ReviewDbWrapper;
import com.google.gerrit.server.group.InternalGroup;
@@ -118,9 +119,10 @@ abstract class GroupBundle {
this.auditLogReader = auditLogReader;
}
public GroupBundle fromNoteDb(Repository repo, AccountGroup.UUID uuid)
public GroupBundle fromNoteDb(
Project.NameKey projectName, Repository repo, AccountGroup.UUID uuid)
throws ConfigInvalidException, IOException {
GroupConfig groupConfig = GroupConfig.loadForGroup(repo, uuid);
GroupConfig groupConfig = GroupConfig.loadForGroup(projectName, repo, uuid);
InternalGroup internalGroup = groupConfig.getLoadedGroup().get();
AccountGroup.Id groupId = internalGroup.getId();

View File

@@ -81,7 +81,7 @@ class GroupRebuilder {
.setNameKey(group.getNameKey())
.setGroupUUID(group.getGroupUUID())
.build();
GroupConfig groupConfig = GroupConfig.createForNewGroup(allUsersRepo, groupCreation);
GroupConfig groupConfig = GroupConfig.createForNewGroup(allUsers, allUsersRepo, groupCreation);
groupConfig.setAllowSaveEmptyName();
InternalGroupUpdate.Builder updateBuilder =

View File

@@ -214,12 +214,14 @@ public class SchemaCreator {
AuditLogFormatter auditLogFormatter =
AuditLogFormatter.createBackedBy(ImmutableSet.of(), ImmutableSet.of(), serverId);
GroupConfig groupConfig = GroupConfig.createForNewGroup(allUsersRepo, groupCreation);
GroupConfig groupConfig =
GroupConfig.createForNewGroup(allUsersName, allUsersRepo, groupCreation);
groupConfig.setGroupUpdate(groupUpdate, auditLogFormatter);
AccountGroup.NameKey groupName = groupUpdate.getName().orElseGet(groupCreation::getNameKey);
GroupNameNotes groupNameNotes =
GroupNameNotes.forNewGroup(allUsersRepo, groupCreation.getGroupUUID(), groupName);
GroupNameNotes.forNewGroup(
allUsersName, allUsersRepo, groupCreation.getGroupUUID(), groupName);
commit(allUsersRepo, groupConfig, groupNameNotes);

View File

@@ -148,7 +148,7 @@ public class Schema_139 extends SchemaVersion {
md.getCommitBuilder().setCommitter(serverUser);
md.setMessage(MSG);
AccountConfig accountConfig = new AccountConfig(e.getKey(), git);
AccountConfig accountConfig = new AccountConfig(e.getKey(), allUsersName, git);
accountConfig.load(md);
accountConfig.setAccountUpdate(
InternalAccountUpdate.builder()

View File

@@ -80,7 +80,7 @@ public class Schema_144 extends SchemaVersion {
try {
try (Repository repo = repoManager.openRepository(allUsersName)) {
ExternalIdNotes extIdNotes = ExternalIdNotes.loadNoCacheUpdate(repo);
ExternalIdNotes extIdNotes = ExternalIdNotes.loadNoCacheUpdate(allUsersName, repo);
extIdNotes.upsert(toAdd);
try (MetaDataUpdate metaDataUpdate =
new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, repo)) {

View File

@@ -55,7 +55,7 @@ public class Schema_148 extends SchemaVersion {
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
try (Repository repo = repoManager.openRepository(allUsersName)) {
ExternalIdNotes extIdNotes = ExternalIdNotes.loadNoCacheUpdate(repo);
ExternalIdNotes extIdNotes = ExternalIdNotes.loadNoCacheUpdate(allUsersName, repo);
for (ExternalId extId : extIdNotes.all()) {
if (needsUpdate(extId)) {
extIdNotes.upsert(extId);

View File

@@ -139,7 +139,10 @@ public class Schema_154 extends SchemaVersion {
PersonIdent ident = serverIdent.get();
md.getCommitBuilder().setAuthor(ident);
md.getCommitBuilder().setCommitter(ident);
new AccountConfig(account.getId(), allUsersRepo).load().setAccount(account).commit(md);
new AccountConfig(account.getId(), allUsersName, allUsersRepo)
.load()
.setAccount(account)
.commit(md);
}
@FunctionalInterface

View File

@@ -110,7 +110,7 @@ public class Schema_160 extends SchemaVersion {
md.getCommitBuilder().setAuthor(ident);
md.getCommitBuilder().setCommitter(ident);
Prefs prefs = new Prefs(ref);
prefs.load(repo);
prefs.load(allUsersName, repo);
prefs.removeMyDrafts();
prefs.commit(md);
if (prefs.dirty()) {

View File

@@ -150,7 +150,8 @@ public class Schema_167 extends SchemaVersion {
ReviewDb db, Repository allUsersRepo, Config gerritConfig, SitePaths sitePaths)
throws IOException, ConfigInvalidException {
String serverId = new GerritServerIdProvider(gerritConfig, sitePaths).get();
SimpleInMemoryAccountCache accountCache = new SimpleInMemoryAccountCache(allUsersRepo);
SimpleInMemoryAccountCache accountCache =
new SimpleInMemoryAccountCache(allUsersName, allUsersRepo);
SimpleInMemoryGroupCache groupCache = new SimpleInMemoryGroupCache(db);
return AuditLogFormatter.create(
accountCache::get,
@@ -178,10 +179,12 @@ public class Schema_167 extends SchemaVersion {
// The regular account cache isn't available during init. -> Use a simple replacement which tries
// to load every account only once from disk.
private static class SimpleInMemoryAccountCache {
private final AllUsersName allUsersName;
private final Repository allUsersRepo;
private Map<Account.Id, Optional<Account>> accounts = new HashMap<>();
public SimpleInMemoryAccountCache(Repository allUsersRepo) {
public SimpleInMemoryAccountCache(AllUsersName allUsersName, Repository allUsersRepo) {
this.allUsersName = allUsersName;
this.allUsersRepo = allUsersRepo;
}
@@ -192,7 +195,8 @@ public class Schema_167 extends SchemaVersion {
private Optional<Account> load(Account.Id accountId) {
try {
AccountConfig accountConfig = new AccountConfig(accountId, allUsersRepo).load();
AccountConfig accountConfig =
new AccountConfig(accountId, allUsersName, allUsersRepo).load();
return accountConfig.getLoadedAccount();
} catch (IOException | ConfigInvalidException ignored) {
logger.atWarning().withCause(ignored).log(