use of org.apache.geode.internal.cache.snapshot.GFSnapshot.SnapshotWriter in project geode by apache.
the class DiskStoreImpl method exportSnapshot.
private void exportSnapshot(String name, File out) throws IOException {
// Since we are recovering a disk store, the cast from DiskRegionView -->
// PlaceHolderDiskRegion
// and from RegionEntry --> DiskEntry should be ok.
// coelesce disk regions so that partitioned buckets from a member end up in
// the same file
Map<String, SnapshotWriter> regions = new HashMap<String, SnapshotWriter>();
try {
for (DiskRegionView drv : getKnown()) {
PlaceHolderDiskRegion ph = (PlaceHolderDiskRegion) drv;
String regionName = (drv.isBucket() ? ph.getPrName() : drv.getName());
SnapshotWriter writer = regions.get(regionName);
if (writer == null) {
String fname = regionName.substring(1).replace('/', '-');
File f = new File(out, "snapshot-" + name + "-" + fname + ".gfd");
writer = GFSnapshot.create(f, regionName);
regions.put(regionName, writer);
}
// Add a mapping from the bucket name to the writer for the PR
// if this is a bucket.
regions.put(drv.getName(), writer);
}
// explicitly.
for (DiskRegionView drv : getKnown()) {
final SnapshotWriter writer = regions.get(drv.getName());
scheduleForRecovery(new ExportDiskRegion(this, drv, new ExportWriter() {
@Override
public void writeBatch(Map<Object, RecoveredEntry> entries) throws IOException {
for (Map.Entry<Object, RecoveredEntry> re : entries.entrySet()) {
Object key = re.getKey();
// TODO:KIRK:OK Rusty's code was value = de.getValueWithContext(drv);
Object value = re.getValue().getValue();
writer.snapshotEntry(new SnapshotRecord(key, value));
}
}
}));
}
recoverRegionsThatAreReady();
} finally {
// Some writers are in the map multiple times because of multiple buckets
// get a the unique set of writers and close each writer once.
Set<SnapshotWriter> uniqueWriters = new HashSet(regions.values());
for (SnapshotWriter writer : uniqueWriters) {
writer.snapshotComplete();
}
}
}
use of org.apache.geode.internal.cache.snapshot.GFSnapshot.SnapshotWriter in project geode by apache.
the class RegionSnapshotServiceImpl method exportOnMember.
private void exportOnMember(File snapshot, SnapshotFormat format, SnapshotOptions<K, V> options) throws IOException {
LocalRegion local = getLocalRegion(region);
Exporter<K, V> exp = createExporter(region, options);
if (getLoggerI18n().fineEnabled()) {
getLoggerI18n().fine("Writing to snapshot " + snapshot.getAbsolutePath());
}
long count = 0;
long start = CachePerfStats.getStatTime();
SnapshotWriter writer = GFSnapshot.create(snapshot, region.getFullPath());
try {
if (getLoggerI18n().infoEnabled())
getLoggerI18n().info(LocalizedStrings.Snapshot_EXPORT_BEGIN_0, region.getName());
SnapshotWriterSink sink = new SnapshotWriterSink(writer);
count = exp.export(region, sink, options);
if (getLoggerI18n().infoEnabled()) {
getLoggerI18n().info(LocalizedStrings.Snapshot_EXPORT_END_0_1_2_3, new Object[] { count, sink.getBytesWritten(), region.getName(), snapshot });
}
} finally {
writer.snapshotComplete();
local.getCachePerfStats().endExport(count, start);
}
}
use of org.apache.geode.internal.cache.snapshot.GFSnapshot.SnapshotWriter in project geode by apache.
the class GFSnapshotJUnitPerformanceTest method testCopyPerformance.
@Test
public void testCopyPerformance() throws IOException, ClassNotFoundException {
int count = 100000;
for (int i = 0; i < 10; i++) {
writeFile(count, val);
File tmp = File.createTempFile("snapshot-copy", null);
tmp.deleteOnExit();
final SnapshotWriter writer = GFSnapshot.create(tmp, "test");
long start = System.currentTimeMillis();
SnapshotIterator<Integer, String> iter = GFSnapshot.read(f);
try {
while (iter.hasNext()) {
Entry<Integer, String> entry = iter.next();
writer.snapshotEntry(new SnapshotRecord(null, entry));
}
writer.snapshotComplete();
long elapsed = System.currentTimeMillis() - start;
double rate = 1.0 * count / elapsed;
System.out.println("rate = " + rate + " entries / ms");
} finally {
iter.close();
}
}
}
use of org.apache.geode.internal.cache.snapshot.GFSnapshot.SnapshotWriter in project geode by apache.
the class GFSnapshotJUnitPerformanceTest method testWritePerformance.
@Test
public void testWritePerformance() throws IOException {
int j = 0;
while (j++ < 10) {
long start = System.currentTimeMillis();
int count = 100000;
String s = val;
SnapshotWriter ss = GFSnapshot.create(f, "test");
try {
for (int i = 0; i < count; i++) {
ss.snapshotEntry(new SnapshotRecord(i, s));
}
} finally {
ss.snapshotComplete();
}
long elapsed = System.currentTimeMillis() - start;
double rate = 1000.0 * count / elapsed;
System.out.println(rate + " write operations / sec");
}
}
Aggregations