Skip to content

Commit

Permalink
0005817: Snapshot util not returning
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed May 8, 2023
1 parent 60fd4fc commit a140689
Showing 1 changed file with 32 additions and 28 deletions.
Expand Up @@ -125,23 +125,24 @@ public static File getSnapshotDirectory(ISymmetricEngine engine) {
}

public static File createSnapshot(ISymmetricEngine engine, IProgressListener listener) {
if (listener != null) {
listener.checkpoint(engine.getEngineName(), 0, 7);
}
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
String dirName = engine.getEngineName().replaceAll(" ", "-") + "-" + dateFormat.format(new Date());
IParameterService parameterService = engine.getParameterService();
File tmpDir = new File(parameterService.getTempDirectory(), dirName);
tmpDir.mkdirs();
log.info("Creating snapshot file in " + tmpDir.getAbsolutePath());
for (ISnapshotUtilListener snapshotListener : engine.getExtensionService().getExtensionPointList(ISnapshotUtilListener.class)) {
snapshotListener.beforeSnapshot(engine, tmpDir);
checkpoint(engine, listener, 0, 7);
try {
log.info("Calling beforeSnapshot()");
for (ISnapshotUtilListener snapshotListener : engine.getExtensionService().getExtensionPointList(ISnapshotUtilListener.class)) {
snapshotListener.beforeSnapshot(engine, tmpDir);
}
} catch (Exception e) {
log.info("Call to beforeSnapshot() threw exception", e);
}
log.info("Exporting configuration");
if (listener != null) {
listener.checkpoint(engine.getEngineName(), 1, 7);
}
checkpoint(engine, listener, 1, 7);
try (FileWriter fwriter = new FileWriter(new File(tmpDir, "config-export.csv"))) {
engine.getDataExtractorService().extractConfigurationStandalone(engine.getNodeService().findIdentity(),
fwriter, TableConstants.getConfigTablesExcludedFromExport());
Expand All @@ -156,9 +157,7 @@ public static File createSnapshot(ISymmetricEngine engine, IProgressListener lis
} catch (Exception e) {
log.warn("Failed to copy " + serviceConfFile.getName() + " to the snapshot directory", e);
}
if (listener != null) {
listener.checkpoint(engine.getEngineName(), 2, 7);
}
checkpoint(engine, listener, 2, 7);
log.info("Writing table definitions");
IDatabasePlatform targetPlatform = engine.getSymmetricDialect().getTargetPlatform();
ISymmetricDialect targetDialect = engine.getTargetDialect();
Expand Down Expand Up @@ -197,9 +196,7 @@ public static File createSnapshot(ISymmetricEngine engine, IProgressListener lis
} catch (Exception e) {
log.warn("Failed to export table definitions", e);
}
if (listener != null) {
listener.checkpoint(engine.getEngineName(), 3, 7);
}
checkpoint(engine, listener, 3, 7);
log.info("Writing runtime data");
String tablePrefix = engine.getTablePrefix();
DbExport export = new DbExport(engine.getDatabasePlatform());
Expand Down Expand Up @@ -370,9 +367,7 @@ public static File createSnapshot(ISymmetricEngine engine, IProgressListener lis
extractQuery(targetPlatform.getSqlTemplate(), tmpDir + File.separator + "mysql-session-variables.csv",
"show session variables");
}
if (listener != null) {
listener.checkpoint(engine.getEngineName(), 4, 7);
}
checkpoint(engine, listener, 4, 7);
if (!engine.getParameterService().is(ParameterConstants.CLUSTER_LOCKING_ENABLED)) {
try (FileOutputStream fos = new FileOutputStream(new File(tmpDir, "sym_data_gap_cache.csv"))) {
List<DataGap> gaps = engine.getRouterService().getDataGaps();
Expand Down Expand Up @@ -434,9 +429,7 @@ public static File createSnapshot(ISymmetricEngine engine, IProgressListener lis
}
}
}
if (listener != null) {
listener.checkpoint(engine.getEngineName(), 5, 7);
}
checkpoint(engine, listener, 5, 7);
File jarFile = null;
try {
String filename = tmpDir.getName() + ".zip";
Expand All @@ -449,19 +442,30 @@ public static File createSnapshot(ISymmetricEngine engine, IProgressListener lis
} catch (Exception e) {
throw new IoException("Failed to package snapshot files into archive", e);
}
if (listener != null) {
listener.checkpoint(engine.getEngineName(), 6, 7);
}
for (ISnapshotUtilListener snapshotListener : engine.getExtensionService().getExtensionPointList(ISnapshotUtilListener.class)) {
snapshotListener.afterSnapshot(engine, tmpDir);
}
if (listener != null) {
listener.checkpoint(engine.getEngineName(), 7, 7);
checkpoint(engine, listener, 6, 7);
try {
log.info("Calling afterSnapshot()");
for (ISnapshotUtilListener snapshotListener : engine.getExtensionService().getExtensionPointList(ISnapshotUtilListener.class)) {
snapshotListener.afterSnapshot(engine, tmpDir);
}
} catch (Exception e) {
log.info("Call to afterSnapshot() threw exception", e);
}
checkpoint(engine, listener, 7, 7);
log.info("Done creating snapshot file");
return jarFile;
}

protected static void checkpoint(ISymmetricEngine engine, IProgressListener listener, int stepNumber, int totalSteps) {
try {
if (listener != null) {
listener.checkpoint(engine.getEngineName(), stepNumber, totalSteps);
}
} catch (Exception e) {
log.info("Call to checkpoint threw exception", e);
}
}

protected static void extract(DbExport export, File file, String... tables) {
extract(export, Integer.MAX_VALUE, null, file, tables);
}
Expand Down

0 comments on commit a140689

Please sign in to comment.