Make SiteIndexer.Result an AutoValue
Change-Id: I64699cb04cb382350360470cbabbf5f7322c4f4d
This commit is contained in:
committed by
Edwin Kempin
parent
b5ef9bf951
commit
08b7525bbd
@@ -17,6 +17,7 @@ package com.google.gerrit.index;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
@@ -36,33 +37,23 @@ public abstract class SiteIndexer<K, V, I extends Index<K, V>> {
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
/** Result of an operation to index a subset or all of the entities of a given type. */
|
||||
public static class Result {
|
||||
private final long elapsedNanos;
|
||||
private final boolean success;
|
||||
private final int done;
|
||||
private final int failed;
|
||||
@AutoValue
|
||||
public abstract static class Result {
|
||||
public abstract long elapsedNanos();
|
||||
|
||||
public Result(Stopwatch sw, boolean success, int done, int failed) {
|
||||
this.elapsedNanos = sw.elapsed(TimeUnit.NANOSECONDS);
|
||||
this.success = success;
|
||||
this.done = done;
|
||||
this.failed = failed;
|
||||
}
|
||||
public abstract boolean success();
|
||||
|
||||
public boolean success() {
|
||||
return success;
|
||||
}
|
||||
public abstract int doneCount();
|
||||
|
||||
public int doneCount() {
|
||||
return done;
|
||||
}
|
||||
public abstract int failedCount();
|
||||
|
||||
public int failedCount() {
|
||||
return failed;
|
||||
public static Result create(Stopwatch sw, boolean success, int done, int failed) {
|
||||
return new AutoValue_SiteIndexer_Result(
|
||||
sw.elapsed(TimeUnit.NANOSECONDS), success, done, failed);
|
||||
}
|
||||
|
||||
public long elapsed(TimeUnit timeUnit) {
|
||||
return timeUnit.convert(elapsedNanos, TimeUnit.NANOSECONDS);
|
||||
return timeUnit.convert(elapsedNanos(), TimeUnit.NANOSECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public class AllAccountsIndexer extends SiteIndexer<Account.Id, AccountState, Ac
|
||||
ids = collectAccounts(progress);
|
||||
} catch (IOException e) {
|
||||
logger.atSevere().withCause(e).log("Error collecting accounts");
|
||||
return new SiteIndexer.Result(sw, false, 0, 0);
|
||||
return SiteIndexer.Result.create(sw, false, 0, 0);
|
||||
}
|
||||
return reindexAccounts(index, ids, progress);
|
||||
}
|
||||
@@ -113,11 +113,11 @@ public class AllAccountsIndexer extends SiteIndexer<Account.Id, AccountState, Ac
|
||||
Futures.successfulAsList(futures).get();
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
logger.atSevere().withCause(e).log("Error waiting on account futures");
|
||||
return new SiteIndexer.Result(sw, false, 0, 0);
|
||||
return SiteIndexer.Result.create(sw, false, 0, 0);
|
||||
}
|
||||
|
||||
progress.endTask();
|
||||
return new SiteIndexer.Result(sw, ok.get(), done.get(), failed.get());
|
||||
return SiteIndexer.Result.create(sw, ok.get(), done.get(), failed.get());
|
||||
}
|
||||
|
||||
private List<Account.Id> collectAccounts(ProgressMonitor progress) throws IOException {
|
||||
|
||||
@@ -123,7 +123,7 @@ public class AllChangesIndexer extends SiteIndexer<Change.Id, ChangeData, Change
|
||||
projectsFailed++;
|
||||
if (projectsFailed > projects.size() / 2) {
|
||||
logger.atSevere().log("Over 50%% of the projects could not be collected: aborted");
|
||||
return new Result(sw, false, 0, 0);
|
||||
return Result.create(sw, false, 0, 0);
|
||||
}
|
||||
}
|
||||
pm.update(1);
|
||||
@@ -192,7 +192,7 @@ public class AllChangesIndexer extends SiteIndexer<Change.Id, ChangeData, Change
|
||||
nFailed, nTotal, Math.round(pctFailed));
|
||||
ok.set(false);
|
||||
}
|
||||
return new Result(sw, ok.get(), nDone, nFailed);
|
||||
return Result.create(sw, ok.get(), nDone, nFailed);
|
||||
}
|
||||
|
||||
public Callable<Void> reindexProject(
|
||||
|
||||
@@ -75,7 +75,7 @@ public class AllGroupsIndexer extends SiteIndexer<AccountGroup.UUID, InternalGro
|
||||
uuids = collectGroups(progress);
|
||||
} catch (IOException | ConfigInvalidException e) {
|
||||
logger.atSevere().withCause(e).log("Error collecting groups");
|
||||
return new SiteIndexer.Result(sw, false, 0, 0);
|
||||
return SiteIndexer.Result.create(sw, false, 0, 0);
|
||||
}
|
||||
return reindexGroups(index, uuids, progress);
|
||||
}
|
||||
@@ -121,11 +121,11 @@ public class AllGroupsIndexer extends SiteIndexer<AccountGroup.UUID, InternalGro
|
||||
Futures.successfulAsList(futures).get();
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
logger.atSevere().withCause(e).log("Error waiting on group futures");
|
||||
return new SiteIndexer.Result(sw, false, 0, 0);
|
||||
return SiteIndexer.Result.create(sw, false, 0, 0);
|
||||
}
|
||||
|
||||
progress.endTask();
|
||||
return new SiteIndexer.Result(sw, ok.get(), done.get(), failed.get());
|
||||
return SiteIndexer.Result.create(sw, ok.get(), done.get(), failed.get());
|
||||
}
|
||||
|
||||
private List<AccountGroup.UUID> collectGroups(ProgressMonitor progress)
|
||||
|
||||
@@ -95,11 +95,11 @@ public class AllProjectsIndexer extends SiteIndexer<Project.NameKey, ProjectData
|
||||
Futures.successfulAsList(futures).get();
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
logger.atSevere().withCause(e).log("Error waiting on project futures");
|
||||
return new SiteIndexer.Result(sw, false, 0, 0);
|
||||
return SiteIndexer.Result.create(sw, false, 0, 0);
|
||||
}
|
||||
|
||||
progress.endTask();
|
||||
return new SiteIndexer.Result(sw, ok.get(), done.get(), failed.get());
|
||||
return SiteIndexer.Result.create(sw, ok.get(), done.get(), failed.get());
|
||||
}
|
||||
|
||||
private List<Project.NameKey> collectProjects(ProgressMonitor progress) {
|
||||
|
||||
Reference in New Issue
Block a user