Skip to content

Commit

Permalink
0001527: Add information about data gaps to the snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Jan 15, 2014
1 parent 197890a commit 25e7703
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
Expand Up @@ -24,6 +24,7 @@
import org.jumpmind.symmetric.common.TableConstants;
import org.jumpmind.symmetric.io.data.DbExport;
import org.jumpmind.symmetric.io.data.DbExport.Format;
import org.jumpmind.symmetric.model.DataGap;
import org.jumpmind.symmetric.model.Trigger;
import org.jumpmind.symmetric.model.TriggerHistory;
import org.jumpmind.symmetric.service.ITriggerRouterService;
Expand Down Expand Up @@ -196,24 +197,7 @@ public static File createSnapshot(ISymmetricEngine engine) {
IOUtils.closeQuietly(fos);
}

fos = null;
try {
fos = new FileOutputStream(new File(tmpDir, "runtime-stats.properties"));
Properties runtimeProperties = new Properties();
runtimeProperties.setProperty("unrouted.data.count",
Long.toString(engine.getRouterService().getUnroutedDataCount()));
runtimeProperties.setProperty("outgoing.errors.count",
Long.toString(engine.getOutgoingBatchService().countOutgoingBatchesInError()));
runtimeProperties.setProperty("outgoing.tosend.count",
Long.toString(engine.getOutgoingBatchService().countOutgoingBatchesUnsent()));
runtimeProperties.setProperty("incoming.errors.count",
Long.toString(engine.getIncomingBatchService().countIncomingBatchesInError()));
runtimeProperties.store(fos, "runtime-stats.properties");
} catch (IOException e) {
log.warn("Failed to export thread information", e);
} finally {
IOUtils.closeQuietly(fos);
}
writeRuntimeStats(engine, tmpDir);

fos = null;
try {
Expand All @@ -236,5 +220,38 @@ public static File createSnapshot(ISymmetricEngine engine) {
throw new IoException("Failed to package snapshot files into archive", e);
}
}

protected static void writeRuntimeStats(ISymmetricEngine engine, File tmpDir) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(new File(tmpDir, "runtime-stats.properties"));
Properties runtimeProperties = new Properties();
runtimeProperties.setProperty("unrouted.data.count",
Long.toString(engine.getRouterService().getUnroutedDataCount()));
runtimeProperties.setProperty("outgoing.errors.count",
Long.toString(engine.getOutgoingBatchService().countOutgoingBatchesInError()));
runtimeProperties.setProperty("outgoing.tosend.count",
Long.toString(engine.getOutgoingBatchService().countOutgoingBatchesUnsent()));
runtimeProperties.setProperty("incoming.errors.count",
Long.toString(engine.getIncomingBatchService().countIncomingBatchesInError()));

List<DataGap> gaps = engine.getDataService().findDataGaps();
runtimeProperties.setProperty("data.gap.count",
Long.toString(gaps.size()));
if (gaps.size() > 0) {
runtimeProperties.setProperty("data.gap.start.id",
Long.toString(gaps.get(0).getStartId()));
runtimeProperties.setProperty("data.gap.end.id",
Long.toString(gaps.get(gaps.size()-1).getStartId()));

}

runtimeProperties.store(fos, "runtime-stats.properties");
} catch (IOException e) {
log.warn("Failed to export thread information", e);
} finally {
IOUtils.closeQuietly(fos);
}
}

}
Expand Up @@ -42,6 +42,7 @@
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.io.data.DataEventType;
import org.jumpmind.symmetric.model.Data;
import org.jumpmind.symmetric.model.DataGap;
import org.jumpmind.symmetric.model.DataMetaData;
import org.jumpmind.symmetric.model.Node;
import org.jumpmind.symmetric.model.NodeChannel;
Expand Down Expand Up @@ -792,6 +793,11 @@ public long getUnroutedDataCount() {
long maxDataIdAlreadyRouted = sqlTemplate
.queryForLong(getSql("selectLastDataIdRoutedUsingDataGapSql"));
long leftToRoute = engine.getDataService().findMaxDataId() - maxDataIdAlreadyRouted;
List<DataGap> gaps = engine.getDataService().findDataGaps();
for (int i = 0; i < gaps.size()-2; i++) {
DataGap gap = gaps.get(i);
leftToRoute += (gap.getEndId() - gap.getStartId());
}
if (leftToRoute > 0) {
return leftToRoute;
} else {
Expand Down

0 comments on commit 25e7703

Please sign in to comment.