LocalUsernamesToLowerCase: Reindex accounts after updating external IDs

LocalUsernamesToLowerCase is changing the case of external IDs in the
"gerrit" scheme. Since the external IDs are stored as fields in the
account index the corresponding accounts must be reindexed.

LocalUsernamesToLowerCase as a site program doesn't have the account
index available and hence can't do the reindexing itself (at least not
without blowing up the Guice injector stack). Instead invoke the reindex
program to reindex the accounts. This is the same approach that was
taken for the MigrateToNoteDb program which was added in master. This
will reindex all accounts and also means that the
LocalUsernamesToLowerCase program cannot run in parallel to the Gerrit
server. This should be okay since running LocalUsernamesToLowerCase is a
one time effort when you want to configure case-insensitive login for
Gerrit.

Change-Id: I6f2804ece996b22ec834aaebf209dac3b5b89415
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin 2017-07-04 11:46:19 +02:00 committed by David Pursehouse
parent 87938bfb47
commit 8803103ebe
3 changed files with 25 additions and 5 deletions

View File

@ -28,9 +28,11 @@ The program will produce errors if there are accounts that have the
same local username, but with different case. In this case the local
username for these accounts is not converted to lower case.
This task can run in the background concurrently to the server if the
database is MySQL or PostgreSQL. If the database is H2, this task
must be run by itself.
After all usernames have been migrated, the link:pgm-reindex.html[
reindex] program is automatically invoked to reindex all accounts.
This task cannot run in the background concurrently to the server;
it must be run by itself.
== OPTIONS

View File

@ -22,12 +22,14 @@ import com.google.gerrit.pgm.util.SiteProgram;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.account.ExternalId;
import com.google.gerrit.server.account.ExternalIdsBatchUpdate;
import com.google.gerrit.server.index.account.AccountSchemaDefinitions;
import com.google.gerrit.server.schema.SchemaVersionCheck;
import com.google.gwtorm.server.SchemaFactory;
import com.google.inject.Inject;
import com.google.inject.Injector;
import java.util.Collection;
import java.util.Locale;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.TextProgressMonitor;
/** Converts the local username for all accounts to lower case */
@ -58,8 +60,10 @@ public class LocalUsernamesToLowerCase extends SiteProgram {
externalIdsBatchUpdate.commit(db, "Convert local usernames to lower case");
}
monitor.endTask();
int exitCode = reindexAccounts();
manager.stop();
return 0;
return exitCode;
}
private void convertLocalUserToLowerCase(ExternalId extId) {
@ -78,4 +82,17 @@ public class LocalUsernamesToLowerCase extends SiteProgram {
}
}
}
private int reindexAccounts() throws Exception {
monitor.beginTask("Reindex accounts", ProgressMonitor.UNKNOWN);
String[] reindexArgs = {
"--site-path", getSitePath().toString(), "--index", AccountSchemaDefinitions.NAME
};
System.out.println("Migration complete, reindexing accounts with:");
System.out.println(" reindex " + String.join(" ", reindexArgs));
Reindex reindexPgm = new Reindex();
int exitCode = reindexPgm.main(reindexArgs);
monitor.endTask();
return exitCode;
}
}

View File

@ -38,9 +38,10 @@ public class AccountSchemaDefinitions extends SchemaDefinitions<AccountState> {
static final Schema<AccountState> V4 = schema(V3);
public static final String NAME = "accounts";
public static final AccountSchemaDefinitions INSTANCE = new AccountSchemaDefinitions();
private AccountSchemaDefinitions() {
super("accounts", AccountState.class);
super(NAME, AccountState.class);
}
}