prms+java_Java Region.getSnapshotService方法代码示例

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");

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值