Java Code Examples for com.gemstone.gemfire.cache.Region#getSnapshotService()
The following examples show how to use
com.gemstone.gemfire.cache.Region#getSnapshotService() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImportDataFunction.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void execute(FunctionContext context) { final String [] args = (String [])context.getArguments(); final String regionName = args[0]; final String importFileName = args[1]; try { final Cache cache = CacheFactory.getAnyInstance(); final Region<?,?> region = cache.getRegion(regionName); final String hostName = cache.getDistributedSystem().getDistributedMember().getHost(); if (region != null) { RegionSnapshotService<?, ?> snapshotService = region.getSnapshotService(); File importFile = new File(importFileName); snapshotService.load(new File(importFileName), SnapshotFormat.GEMFIRE); String successMessage = CliStrings.format(CliStrings.IMPORT_DATA__SUCCESS__MESSAGE, importFile.getCanonicalPath(), hostName, regionName); context.getResultSender().lastResult(successMessage); } else { throw new IllegalArgumentException(CliStrings.format(CliStrings.REGION_NOT_FOUND, regionName)); } } catch (Exception e) { context.getResultSender().sendException(e); } }
Example 2
Source File: ParallelSnapshotDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private void doImport(boolean explode) throws ClassNotFoundException, IOException { Region region = getCache().getRegion("test"); RegionSnapshotService rss = region.getSnapshotService(); final TestSnapshotFileMapper mapper = new TestSnapshotFileMapper(); mapper.explode = explode; SnapshotOptionsImpl opt = (SnapshotOptionsImpl) rss.createOptions(); opt.setParallelMode(true); opt.setMapper(mapper); final File f = new File("mysnap"); for (int i = 0; i < 1000; i++) { region.put(i, eeee); } rss.load(f, SnapshotFormat.GEMFIRE, opt); for (int i = 0; i < 1000; i++) { assertTrue(Arrays.equals(ffff, (byte[]) region.get(i))); } }
Example 3
Source File: ImportDataFunction.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void execute(FunctionContext context) { final String [] args = (String [])context.getArguments(); final String regionName = args[0]; final String importFileName = args[1]; try { final Cache cache = CacheFactory.getAnyInstance(); final Region<?,?> region = cache.getRegion(regionName); final String hostName = cache.getDistributedSystem().getDistributedMember().getHost(); if (region != null) { RegionSnapshotService<?, ?> snapshotService = region.getSnapshotService(); File importFile = new File(importFileName); snapshotService.load(new File(importFileName), SnapshotFormat.GEMFIRE); String successMessage = CliStrings.format(CliStrings.IMPORT_DATA__SUCCESS__MESSAGE, importFile.getCanonicalPath(), hostName, regionName); context.getResultSender().lastResult(successMessage); } else { throw new IllegalArgumentException(CliStrings.format(CliStrings.REGION_NOT_FOUND, regionName)); } } catch (Exception e) { context.getResultSender().sendException(e); } }
Example 4
Source File: ExportDataFunction.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void execute(FunctionContext context) { final String [] args = (String [])context.getArguments(); final String regionName = args[0]; final String fileName = args[1]; try { Cache cache = CacheFactory.getAnyInstance(); Region<?,?> region = cache.getRegion(regionName); String hostName = cache.getDistributedSystem().getDistributedMember().getHost(); if (region != null) { RegionSnapshotService<?, ?> snapshotService = region.getSnapshotService(); final File exportFile = new File(fileName); snapshotService.save(exportFile, SnapshotFormat.GEMFIRE); String successMessage = CliStrings.format(CliStrings.EXPORT_DATA__SUCCESS__MESSAGE, regionName, exportFile.getCanonicalPath(), hostName); context.getResultSender().lastResult(successMessage); } else { throw new IllegalArgumentException(CliStrings.format(CliStrings.REGION_NOT_FOUND, regionName)); } } catch (Exception e) { context.getResultSender().sendException(e); } }
Example 5
Source File: ParallelSnapshotDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private void doImport(boolean explode) throws ClassNotFoundException, IOException { Region region = getCache().getRegion("test"); RegionSnapshotService rss = region.getSnapshotService(); final TestSnapshotFileMapper mapper = new TestSnapshotFileMapper(); mapper.explode = explode; SnapshotOptionsImpl opt = (SnapshotOptionsImpl) rss.createOptions(); opt.setParallelMode(true); opt.setMapper(mapper); final File f = new File("mysnap"); for (int i = 0; i < 1000; i++) { region.put(i, eeee); } rss.load(f, SnapshotFormat.GEMFIRE, opt); for (int i = 0; i < 1000; i++) { assertTrue(Arrays.equals(ffff, (byte[]) region.get(i))); } }
Example 6
Source File: ExportDataFunction.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void execute(FunctionContext context) { final String [] args = (String [])context.getArguments(); final String regionName = args[0]; final String fileName = args[1]; try { Cache cache = CacheFactory.getAnyInstance(); Region<?,?> region = cache.getRegion(regionName); String hostName = cache.getDistributedSystem().getDistributedMember().getHost(); if (region != null) { RegionSnapshotService<?, ?> snapshotService = region.getSnapshotService(); final File exportFile = new File(fileName); snapshotService.save(exportFile, SnapshotFormat.GEMFIRE); String successMessage = CliStrings.format(CliStrings.EXPORT_DATA__SUCCESS__MESSAGE, regionName, exportFile.getCanonicalPath(), hostName); context.getResultSender().lastResult(successMessage); } else { throw new IllegalArgumentException(CliStrings.format(CliStrings.REGION_NOT_FOUND, regionName)); } } catch (Exception e) { context.getResultSender().sendException(e); } }
Example 7
Source File: RegionSnapshotJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void testFilterImportException() throws Exception { SnapshotFilter<Integer, MyObject> oops = new SnapshotFilter<Integer, MyObject>() { @Override public boolean accept(Entry<Integer, MyObject> entry) { throw new RuntimeException(); } }; for (final RegionType rt : RegionType.values()) { for (final SerializationType st : SerializationType.values()) { String name = "test-" + rt.name() + "-" + st.name(); Region<Integer, MyObject> region = rgen.createRegion(cache, ds.getName(), rt, name); final Map<Integer, MyObject> expected = createExpected(st); region.putAll(expected); RegionSnapshotService<Integer, MyObject> rss = region.getSnapshotService(); rss.save(f, SnapshotFormat.GEMFIRE); region.destroyRegion(); region = rgen.createRegion(cache, ds.getName(), rt, name); rss = region.getSnapshotService(); SnapshotOptions<Integer, MyObject> options = rss.createOptions().setFilter(oops); boolean caughtException = false; try { rss.load(f, SnapshotFormat.GEMFIRE, options); } catch (RuntimeException e) { caughtException = true; } assertTrue(caughtException); assertEquals("Comparison failure for " + rt.name() + "/" + st.name(), 0, region.size()); } } }
Example 8
Source File: ParallelSnapshotDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private void doExport(boolean explode) throws Exception { Region region = getCache().getRegion("test"); for (int i = 0; i < 1000; i++) { region.put(i, ffff); } RegionSnapshotService rss = region.getSnapshotService(); final TestSnapshotFileMapper mapper = new TestSnapshotFileMapper(); mapper.explode = explode; SnapshotOptionsImpl opt = (SnapshotOptionsImpl) rss.createOptions(); opt.setParallelMode(true); opt.setMapper(mapper); final File f = new File("mysnap"); rss.save(f, SnapshotFormat.GEMFIRE, opt); mapper.explode = false; SerializableCallable check = new SerializableCallable() { @Override public Object call() throws Exception { getCache().getDistributedSystem().getDistributedMember(); File snap = mapper.mapExportPath( getCache().getDistributedSystem().getDistributedMember(), f); assertTrue("Could not find snapshot: " + snap, snap.exists()); return null; } }; forEachVm(check, true); }
Example 9
Source File: RegionSnapshotJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void testFilterExportException() throws Exception { SnapshotFilter<Integer, MyObject> oops = new SnapshotFilter<Integer, MyObject>() { @Override public boolean accept(Entry<Integer, MyObject> entry) { throw new RuntimeException(); } }; for (final RegionType rt : RegionType.values()) { for (final SerializationType st : SerializationType.values()) { String name = "test-" + rt.name() + "-" + st.name(); Region<Integer, MyObject> region = rgen.createRegion(cache, ds.getName(), rt, name); final Map<Integer, MyObject> expected = createExpected(st); region.putAll(expected); RegionSnapshotService<Integer, MyObject> rss = region.getSnapshotService(); SnapshotOptions<Integer, MyObject> options = rss.createOptions().setFilter(oops); boolean caughtException = false; try { rss.save(f, SnapshotFormat.GEMFIRE, options); } catch (RuntimeException e) { caughtException = true; } assertTrue(caughtException); region.destroyRegion(); region = rgen.createRegion(cache, ds.getName(), rt, name); rss = region.getSnapshotService(); rss.load(f, SnapshotFormat.GEMFIRE, options); assertEquals("Comparison failure for " + rt.name() + "/" + st.name(), 0, region.size()); } } }
Example 10
Source File: CacheSnapshotServiceImpl.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) private void saveRegion(Region<?, ?> region, File dir, SnapshotFormat format, SnapshotOptions options) throws IOException { RegionSnapshotService<?, ?> rs = region.getSnapshotService(); String name = "snapshot" + region.getFullPath().replace('/', '-'); File f = new File(dir, name); rs.save(f, format, options); }
Example 11
Source File: CacheSnapshotServiceImpl.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
@Override public void load(File[] snapshots, SnapshotFormat format, SnapshotOptions<Object, Object> options) throws IOException, ClassNotFoundException { for (File f : snapshots) { GFSnapshotImporter in = new GFSnapshotImporter(f); try { byte version = in.getVersion(); if (version == GFSnapshot.SNAP_VER_1) { throw new IOException(LocalizedStrings.Snapshot_UNSUPPORTED_SNAPSHOT_VERSION_0.toLocalizedString(version)); } String regionName = in.getRegionName(); Region<Object, Object> region = cache.getRegion(regionName); if (region == null) { throw new RegionNotFoundException(LocalizedStrings.Snapshot_COULD_NOT_FIND_REGION_0_1.toLocalizedString(regionName, f)); } RegionSnapshotService<Object, Object> rs = region.getSnapshotService(); rs.load(f, format, options); } finally { in.close(); } } }
Example 12
Source File: CacheSnapshotServiceImpl.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
@Override public void load(File[] snapshots, SnapshotFormat format, SnapshotOptions<Object, Object> options) throws IOException, ClassNotFoundException { for (File f : snapshots) { GFSnapshotImporter in = new GFSnapshotImporter(f); try { byte version = in.getVersion(); if (version == GFSnapshot.SNAP_VER_1) { throw new IOException(LocalizedStrings.Snapshot_UNSUPPORTED_SNAPSHOT_VERSION_0.toLocalizedString(version)); } String regionName = in.getRegionName(); Region<Object, Object> region = cache.getRegion(regionName); if (region == null) { throw new RegionNotFoundException(LocalizedStrings.Snapshot_COULD_NOT_FIND_REGION_0_1.toLocalizedString(regionName, f)); } RegionSnapshotService<Object, Object> rs = region.getSnapshotService(); rs.load(f, format, options); } finally { in.close(); } } }
Example 13
Source File: CacheSnapshotServiceImpl.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) private void saveRegion(Region<?, ?> region, File dir, SnapshotFormat format, SnapshotOptions options) throws IOException { RegionSnapshotService<?, ?> rs = region.getSnapshotService(); String name = "snapshot" + region.getFullPath().replace('/', '-'); File f = new File(dir, name); rs.save(f, format, options); }
Example 14
Source File: RegionSnapshotJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void testFilterExportException() throws Exception { SnapshotFilter<Integer, MyObject> oops = new SnapshotFilter<Integer, MyObject>() { @Override public boolean accept(Entry<Integer, MyObject> entry) { throw new RuntimeException(); } }; for (final RegionType rt : RegionType.values()) { for (final SerializationType st : SerializationType.values()) { String name = "test-" + rt.name() + "-" + st.name(); Region<Integer, MyObject> region = rgen.createRegion(cache, ds.getName(), rt, name); final Map<Integer, MyObject> expected = createExpected(st); region.putAll(expected); RegionSnapshotService<Integer, MyObject> rss = region.getSnapshotService(); SnapshotOptions<Integer, MyObject> options = rss.createOptions().setFilter(oops); boolean caughtException = false; try { rss.save(f, SnapshotFormat.GEMFIRE, options); } catch (RuntimeException e) { caughtException = true; } assertTrue(caughtException); region.destroyRegion(); region = rgen.createRegion(cache, ds.getName(), rt, name); rss = region.getSnapshotService(); rss.load(f, SnapshotFormat.GEMFIRE, options); assertEquals("Comparison failure for " + rt.name() + "/" + st.name(), 0, region.size()); } } }
Example 15
Source File: RegionSnapshotJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void testFilterImportException() throws Exception { SnapshotFilter<Integer, MyObject> oops = new SnapshotFilter<Integer, MyObject>() { @Override public boolean accept(Entry<Integer, MyObject> entry) { throw new RuntimeException(); } }; for (final RegionType rt : RegionType.values()) { for (final SerializationType st : SerializationType.values()) { String name = "test-" + rt.name() + "-" + st.name(); Region<Integer, MyObject> region = rgen.createRegion(cache, ds.getName(), rt, name); final Map<Integer, MyObject> expected = createExpected(st); region.putAll(expected); RegionSnapshotService<Integer, MyObject> rss = region.getSnapshotService(); rss.save(f, SnapshotFormat.GEMFIRE); region.destroyRegion(); region = rgen.createRegion(cache, ds.getName(), rt, name); rss = region.getSnapshotService(); SnapshotOptions<Integer, MyObject> options = rss.createOptions().setFilter(oops); boolean caughtException = false; try { rss.load(f, SnapshotFormat.GEMFIRE, options); } catch (RuntimeException e) { caughtException = true; } assertTrue(caughtException); assertEquals("Comparison failure for " + rt.name() + "/" + st.name(), 0, region.size()); } } }
Example 16
Source File: ParallelSnapshotDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private void doExport(boolean explode) throws Exception { Region region = getCache().getRegion("test"); for (int i = 0; i < 1000; i++) { region.put(i, ffff); } RegionSnapshotService rss = region.getSnapshotService(); final TestSnapshotFileMapper mapper = new TestSnapshotFileMapper(); mapper.explode = explode; SnapshotOptionsImpl opt = (SnapshotOptionsImpl) rss.createOptions(); opt.setParallelMode(true); opt.setMapper(mapper); final File f = new File("mysnap"); rss.save(f, SnapshotFormat.GEMFIRE, opt); mapper.explode = false; SerializableCallable check = new SerializableCallable() { @Override public Object call() throws Exception { getCache().getDistributedSystem().getDistributedMember(); File snap = mapper.mapExportPath( getCache().getDistributedSystem().getDistributedMember(), f); assertTrue("Could not find snapshot: " + snap, snap.exists()); return null; } }; forEachVm(check, true); }
Example 17
Source File: SnapshotTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** 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"); } }
Example 18
Source File: SnapshotTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** 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"); } }