Fix data race in MultiProgressMonitor
This is work related to [1] and [2]. Synchronizing on different objects (Task vs Monitor) doesn't have much sense as it results (sooner or later) in deadlocks. This is an attempt to synchronize on monitor object only (note that Task.getCount() is called from outside the monitor when processing is basically done). [1] https://gerrit-review.googlesource.com/#/c/87442/ [2] https://gerrit-review.googlesource.com/#/c/91132/ Change-Id: I99b5da03d5d9ecc9a2fa0d6ca022d6e026d45aba
This commit is contained in:
@@ -81,7 +81,7 @@ public class MultiProgressMonitor {
|
||||
@Override
|
||||
public void update(final int completed) {
|
||||
boolean w = false;
|
||||
synchronized (this) {
|
||||
synchronized (MultiProgressMonitor.this) {
|
||||
count += completed;
|
||||
if (total != UNKNOWN) {
|
||||
int percent = count * 100 / total;
|
||||
@@ -124,10 +124,12 @@ public class MultiProgressMonitor {
|
||||
return false;
|
||||
}
|
||||
|
||||
public synchronized int getCount() {
|
||||
public int getCount() {
|
||||
synchronized(MultiProgressMonitor.this) {
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final OutputStream out;
|
||||
private final String taskName;
|
||||
|
||||
@@ -199,14 +199,15 @@ public class AllChangesIndexer
|
||||
// trust the results. This is not an exact percentage since we bump the same
|
||||
// failure counter if a project can't be read, but close enough.
|
||||
int nFailed = failedTask.getCount();
|
||||
int nTotal = nFailed + doneTask.getCount();
|
||||
int nDone = doneTask.getCount();
|
||||
int nTotal = nFailed + nDone;
|
||||
double pctFailed = ((double) nFailed) / nTotal * 100;
|
||||
if (pctFailed > 10) {
|
||||
log.error("Failed {}/{} changes ({}%); not marking new index as ready",
|
||||
nFailed, nTotal, Math.round(pctFailed));
|
||||
ok.set(false);
|
||||
}
|
||||
return new Result(sw, ok.get(), doneTask.getCount(), failedTask.getCount());
|
||||
return new Result(sw, ok.get(), nDone, nFailed);
|
||||
}
|
||||
|
||||
private Callable<Void> reindexProject(final ChangeIndexer indexer,
|
||||
|
||||
Reference in New Issue
Block a user