use of com.google.gerrit.server.config.ThreadSettingsConfig in project gerrit by GerritCodeReview.
the class MigrateAccountPatchReviewDb method run.
@Override
public int run() throws Exception {
Injector dbInjector = createDbInjector();
SitePaths sitePaths = new SitePaths(getSitePath());
ThreadSettingsConfig threadSettingsConfig = dbInjector.getInstance(ThreadSettingsConfig.class);
Config fakeCfg = new Config();
if (!Strings.isNullOrEmpty(sourceUrl)) {
fakeCfg.setString("accountPatchReviewDb", null, "url", sourceUrl);
}
JdbcAccountPatchReviewStore sourceJdbcAccountPatchReviewStore = JdbcAccountPatchReviewStore.createAccountPatchReviewStore(fakeCfg, sitePaths, threadSettingsConfig);
Config cfg = dbInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
String targetUrl = cfg.getString("accountPatchReviewDb", null, "url");
if (targetUrl == null) {
System.err.println("accountPatchReviewDb.url is null in gerrit.config");
return 1;
}
System.out.println("target Url: " + targetUrl);
JdbcAccountPatchReviewStore targetJdbcAccountPatchReviewStore = JdbcAccountPatchReviewStore.createAccountPatchReviewStore(cfg, sitePaths, threadSettingsConfig);
targetJdbcAccountPatchReviewStore.createTableIfNotExists();
if (!isTargetTableEmpty(targetJdbcAccountPatchReviewStore)) {
System.err.println("target table is not empty, cannot proceed");
return 1;
}
try (Connection sourceCon = sourceJdbcAccountPatchReviewStore.getConnection();
Connection targetCon = targetJdbcAccountPatchReviewStore.getConnection();
PreparedStatement sourceStmt = sourceCon.prepareStatement("SELECT account_id, change_id, patch_set_id, file_name " + "FROM account_patch_reviews " + "LIMIT ? " + "OFFSET ?");
PreparedStatement targetStmt = targetCon.prepareStatement("INSERT INTO account_patch_reviews " + "(account_id, change_id, patch_set_id, file_name) VALUES " + "(?, ?, ?, ?)")) {
targetCon.setAutoCommit(false);
long offset = 0;
Stopwatch sw = Stopwatch.createStarted();
List<Row> rows = selectRows(sourceStmt, offset);
while (!rows.isEmpty()) {
insertRows(targetCon, targetStmt, rows);
offset += rows.size();
System.out.printf("%8d rows migrated\n", offset);
rows = selectRows(sourceStmt, offset);
}
double t = sw.elapsed(TimeUnit.MILLISECONDS) / 1000d;
System.out.printf("Migrated %d rows in %.01fs (%.01f/s)\n", offset, t, offset / t);
}
return 0;
}
Aggregations