import com.gemstone.gemfire.cache.Region; //导入方法依赖的package包/类
/** Invoke export, right now just use a simple file name ... one per snapshot
*
*/
private void doExportStep() {
// obtain a snapshot (for each region separately)
for (Region aRegion: testInstance.allRegions) {
// create some entries to filter out later (regardless of whether filtering is on import or export)
if (useSnapshotFilter) {
int numToCreate = SnapshotPrms.numFilterObjects();
for (int i=1; i <=numToCreate; i++) {
String key = "FilterObject_" + i;
String value = "object to be filtered via snapshot.save() or snapshot.load(): this should never be a value in the cache once snapshot restored";
aRegion.put(key, value);
}
Log.getLogWriter().info("Wrote " + numToCreate + " FilterObject entries to " + aRegion.getFullPath());
}
RegionSnapshotService snapshotService = aRegion.getSnapshotService();
String currDirName = System.getProperty("user.dir");
String snapshotDirName = snapshotDirPrefix + "_" + RemoteTestModule.getMyVmid();
snapshotDirName = currDirName + File.separator + snapshotDirName;
FileUtil.mkdir(snapshotDirName);
String filename = "snapshot-vm_" + RemoteTestModule.getMyVmid() + "_" + RemoteTestModule.getMyClientName() + aRegion.getFullPath().replace('/', '-')
+ ".gfd";
File snapshotFile = new File(snapshotDirName, filename);
long startTime = System.currentTimeMillis();
if (exportStrategy.equalsIgnoreCase(SnapshotPrms.exportUsingCmdLineTool)) {
// export the snapshot, every region in the cache will be exported from the offline persistence files
// do nothing (this is done directly in the snapshotController code)
} else if (exportStrategy.equalsIgnoreCase(SnapshotPrms.exportUsingApiFromAllVms)) {
throw new TestException("Parallel snapshot option not supported in GemFire 7.0");
/*
SnapshotOptions options = snapshotService.createOptions();
options.setParallelMode(true);
try {
snapshotService.save(snapshotFile, SnapshotFormat.GEMFIRE, options);
} catch (IOException ioe) {
throw new TestException("Caught " + ioe + " while exporting region snapshot to " + snapshotFile.getAbsoluteFile() + " " + TestHelper.getStackTrace(ioe));
}
*/
} else {
// exportUsingApiFromOneVm or exportUsingCli
Log.getLogWriter().info("Starting export of " + aRegion.getFullPath() + " containing " + aRegion.size() + " entries to " + snapshotFile.getAbsoluteFile());
SnapshotOptions options = snapshotService.createOptions();
if (useFilterOnExport) {
options.setFilter(getSnapshotFilter());
}
try {
if (exportStrategy.equalsIgnoreCase(SnapshotPrms.exportUsingCli)) {
String command = "export data --region=" + aRegion.getFullPath() + " --file=" +
snapshotFile.getAbsolutePath() + " --member=" + DistributedSystemHelper.getDistributedSystem().getDistributedMember().getName();
CliHelper.execCommandOnRemoteCli(command, true);
} else {
Log.getLogWriter().info("Calling snapshotService.save(...)");
snapshotService.save(snapshotFile, SnapshotOptions.SnapshotFormat.GEMFIRE, options);
}
} catch (IOException ioe) {
String errStr = ioe.toString();
boolean memberDepartedEvent = (errStr.indexOf("memberDeparted event") >=0);
if (memberDepartedEvent) { // retry
Log.getLogWriter().info("Caught " + ioe + ", retrying export");
try {
snapshotService.save(snapshotFile, SnapshotOptions.SnapshotFormat.GEMFIRE, options);
} catch (IOException e) {
throw new TestException("Caught " + e + " on retry of export region snapshot to " + snapshotFile.getAbsoluteFile() + " " + TestHelper.getStackTrace(ioe));
}
} else {
throw new TestException("Caught " + ioe + " while exporting region snapshot to " + snapshotFile.getAbsoluteFile() + " " + TestHelper.getStackTrace(ioe));
}
}
}
long endTime = System.currentTimeMillis();
Log.getLogWriter().info("Export of " + aRegion.getFullPath() + " containing " + aRegion.size() + " entries to " + snapshotFile.getAbsoluteFile() + " took " + (endTime - startTime) + " ms");
}
}