Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions usage/src/main/java/com/cloud/usage/UsageManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import com.cloud.network.Network;
import com.cloud.usage.dao.UsageNetworksDao;
Expand Down Expand Up @@ -192,6 +193,7 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
private final List<UsageVmDiskVO> usageVmDisks = new ArrayList<UsageVmDiskVO>();

private final ScheduledExecutorService _executor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Usage-Job"));
private final AtomicBoolean isParsingJobRunning = new AtomicBoolean(false);
private final ScheduledExecutorService _heartbeatExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Usage-HB"));
private final ScheduledExecutorService _sanityExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Usage-Sanity"));
private Future _scheduledFuture = null;
Expand Down Expand Up @@ -367,7 +369,12 @@ public void run() {
(new ManagedContextRunnable() {
@Override
protected void runInContext() {
runInContextInternal();
isParsingJobRunning.set(true);
try {
runInContextInternal();
} finally {
isParsingJobRunning.set(false);
}
}
}).run();
}
Expand Down Expand Up @@ -2269,7 +2276,9 @@ protected void runInContext() {
if (timeToJob > (aggregationDurationMillis / 2)) {
logger.debug("it's been {} ms since last usage job and {} ms until next job, scheduling an immediate job to catch up (aggregation duration is {} minutes)"
, timeSinceLastSuccessJob, timeToJob, _aggregationDuration);
scheduleParse();
if (!isParsingJobRunning.get()) {
scheduleParse();
}
}
}

Expand Down
Loading