Search in sources :

Example 1 with SnapshotWriter

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();
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SnapshotRecord(org.apache.geode.internal.cache.snapshot.SnapshotPacket.SnapshotRecord) ExportWriter(org.apache.geode.internal.cache.ExportDiskRegion.ExportWriter) DiskRegionView(org.apache.geode.internal.cache.persistence.DiskRegionView) SnapshotWriter(org.apache.geode.internal.cache.snapshot.GFSnapshot.SnapshotWriter) File(java.io.File) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) RecoveredEntry(org.apache.geode.internal.cache.DiskEntry.RecoveredEntry) ConcurrentHashSet(org.apache.geode.internal.concurrent.ConcurrentHashSet) IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) HashSet(java.util.HashSet) LongOpenHashSet(it.unimi.dsi.fastutil.longs.LongOpenHashSet)

Example 2 with SnapshotWriter

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);
    }
}
Also used : SnapshotWriter(org.apache.geode.internal.cache.snapshot.GFSnapshot.SnapshotWriter)

Example 3 with SnapshotWriter

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();
        }
    }
}
Also used : SnapshotWriter(org.apache.geode.internal.cache.snapshot.GFSnapshot.SnapshotWriter) SnapshotRecord(org.apache.geode.internal.cache.snapshot.SnapshotPacket.SnapshotRecord) File(java.io.File) Test(org.junit.Test) PerformanceTest(org.apache.geode.test.junit.categories.PerformanceTest)

Example 4 with SnapshotWriter

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");
    }
}
Also used : SnapshotWriter(org.apache.geode.internal.cache.snapshot.GFSnapshot.SnapshotWriter) SnapshotRecord(org.apache.geode.internal.cache.snapshot.SnapshotPacket.SnapshotRecord) Test(org.junit.Test) PerformanceTest(org.apache.geode.test.junit.categories.PerformanceTest)

Aggregations

SnapshotWriter (org.apache.geode.internal.cache.snapshot.GFSnapshot.SnapshotWriter)4 SnapshotRecord (org.apache.geode.internal.cache.snapshot.SnapshotPacket.SnapshotRecord)3 File (java.io.File)2 PerformanceTest (org.apache.geode.test.junit.categories.PerformanceTest)2 Test (org.junit.Test)2 IntOpenHashSet (it.unimi.dsi.fastutil.ints.IntOpenHashSet)1 LongOpenHashSet (it.unimi.dsi.fastutil.longs.LongOpenHashSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 RecoveredEntry (org.apache.geode.internal.cache.DiskEntry.RecoveredEntry)1 ExportWriter (org.apache.geode.internal.cache.ExportDiskRegion.ExportWriter)1 DiskRegionView (org.apache.geode.internal.cache.persistence.DiskRegionView)1 ConcurrentHashSet (org.apache.geode.internal.concurrent.ConcurrentHashSet)1