You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2018/01/11 02:08:00 UTC
[geode] branch feature/GEODE-3583-storage updated: GEODE-4206:
remove getInstance calls in GFSnapshot
This is an automated email from the ASF dual-hosted git repository.
dschneider pushed a commit to branch feature/GEODE-3583-storage
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/feature/GEODE-3583-storage by this push:
new 0d33da8 GEODE-4206: remove getInstance calls in GFSnapshot
0d33da8 is described below
commit 0d33da8120b5223db3eac045088bc7d4eecadb0e
Author: Darrel Schneider <ds...@pivotal.io>
AuthorDate: Wed Jan 10 18:05:40 2018 -0800
GEODE-4206: remove getInstance calls in GFSnapshot
GFSnapshot was calling getInstance so it could get the pdx type registry.
Now a TypeRegistry is passed in to the constructor.
Note that this change required that the external class SnapshotReader
by changed to call CacheFactory.getAnyInstance().
---
.../geode/cache/snapshot/SnapshotReader.java | 16 ++++++++++++-
.../cache/snapshot/CacheSnapshotServiceImpl.java | 2 +-
.../geode/internal/cache/snapshot/GFSnapshot.java | 27 ++++++++--------------
.../cache/snapshot/RegionSnapshotServiceImpl.java | 2 +-
.../snapshot/GFSnapshotJUnitPerformanceTest.java | 4 ++--
5 files changed, 28 insertions(+), 23 deletions(-)
diff --git a/geode-core/src/main/java/org/apache/geode/cache/snapshot/SnapshotReader.java b/geode-core/src/main/java/org/apache/geode/cache/snapshot/SnapshotReader.java
index be92716..dd0ad37 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/snapshot/SnapshotReader.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/snapshot/SnapshotReader.java
@@ -17,10 +17,15 @@ package org.apache.geode.cache.snapshot;
import java.io.File;
import java.io.IOException;
+import org.apache.geode.CancelException;
import org.apache.geode.DataSerializer;
import org.apache.geode.Instantiator;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.snapshot.GFSnapshot;
import org.apache.geode.pdx.PdxSerializer;
+import org.apache.geode.pdx.internal.TypeRegistry;
/**
* Provides utilities for reading cache data.
@@ -47,6 +52,15 @@ public class SnapshotReader {
*/
public static <K, V> SnapshotIterator<K, V> read(File snapshot)
throws IOException, ClassNotFoundException {
- return GFSnapshot.read(snapshot);
+ TypeRegistry typeRegistry = null;
+ try {
+ Cache cache = CacheFactory.getAnyInstance();
+ if (cache != null) {
+ typeRegistry = ((InternalCache) cache).getPdxRegistry();
+ }
+ } catch (CancelException ignore) {
+ // proceed with no type registry
+ }
+ return GFSnapshot.read(snapshot, typeRegistry);
}
}
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/snapshot/CacheSnapshotServiceImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/snapshot/CacheSnapshotServiceImpl.java
index b3c920c..bb37198 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/snapshot/CacheSnapshotServiceImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/snapshot/CacheSnapshotServiceImpl.java
@@ -101,7 +101,7 @@ public class CacheSnapshotServiceImpl implements CacheSnapshotService {
SnapshotOptions<Object, Object> options) throws IOException, ClassNotFoundException {
for (File file : snapshotFiles) {
- GFSnapshotImporter in = new GFSnapshotImporter(file);
+ GFSnapshotImporter in = new GFSnapshotImporter(file, cache.getPdxRegistry());
try {
byte version = in.getVersion();
if (version == GFSnapshot.SNAP_VER_1) {
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/snapshot/GFSnapshot.java b/geode-core/src/main/java/org/apache/geode/internal/cache/snapshot/GFSnapshot.java
index 9c714a6..587cede 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/snapshot/GFSnapshot.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/snapshot/GFSnapshot.java
@@ -79,7 +79,7 @@ public class GFSnapshot {
ExitCode.FATAL.doSystemExit();
}
- GFSnapshotImporter imp = new GFSnapshotImporter(new File(args[0]));
+ GFSnapshotImporter imp = new GFSnapshotImporter(new File(args[0]), null);
try {
System.out.println("Snapshot format is version " + imp.getVersion());
System.out.println("Snapshot region is " + imp.getRegionName());
@@ -141,10 +141,10 @@ public class GFSnapshot {
* @throws IOException error reading the snapshot file
* @throws ClassNotFoundException unable to deserialize entry
*/
- public static <K, V> SnapshotIterator<K, V> read(final File snapshot)
+ public static <K, V> SnapshotIterator<K, V> read(final File snapshot, TypeRegistry typeRegistry)
throws IOException, ClassNotFoundException {
return new SnapshotIterator<K, V>() {
- GFSnapshotImporter in = new GFSnapshotImporter(snapshot);
+ GFSnapshotImporter in = new GFSnapshotImporter(snapshot, typeRegistry);
private boolean foundNext;
private Entry<K, V> next;
@@ -290,7 +290,8 @@ public class GFSnapshot {
/** the input stream */
private final DataInputStream dis;
- public GFSnapshotImporter(File in) throws IOException, ClassNotFoundException {
+ public GFSnapshotImporter(File in, TypeRegistry typeRegistry)
+ throws IOException, ClassNotFoundException {
pdx = new ExportedRegistry();
// read header and pdx registry
@@ -340,8 +341,8 @@ public class GFSnapshot {
// check compatibility with the existing pdx types so we don't have to
// do any translation...preexisting types or concurrent put ops may cause
// this check to fail
- checkPdxTypeCompatibility();
- checkPdxEnumCompatibility();
+ checkPdxTypeCompatibility(typeRegistry);
+ checkPdxEnumCompatibility(typeRegistry);
// open new stream with buffering for reading entries
dis = new DataInputStream(new BufferedInputStream(new FileInputStream(in)));
@@ -396,16 +397,7 @@ public class GFSnapshot {
dis.close();
}
- private TypeRegistry getRegistry() {
- InternalCache gfc = GemFireCacheImpl.getInstance();
- if (gfc != null) {
- return gfc.getPdxRegistry();
- }
- return null;
- }
-
- private void checkPdxTypeCompatibility() {
- TypeRegistry tr = getRegistry();
+ private void checkPdxTypeCompatibility(TypeRegistry tr) {
if (tr == null) {
return;
}
@@ -415,8 +407,7 @@ public class GFSnapshot {
}
}
- private void checkPdxEnumCompatibility() {
- TypeRegistry tr = getRegistry();
+ private void checkPdxEnumCompatibility(TypeRegistry tr) {
if (tr == null) {
return;
}
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/snapshot/RegionSnapshotServiceImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/snapshot/RegionSnapshotServiceImpl.java
index 49e1e58..aa24047 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/snapshot/RegionSnapshotServiceImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/snapshot/RegionSnapshotServiceImpl.java
@@ -237,7 +237,7 @@ public class RegionSnapshotServiceImpl<K, V> implements RegionSnapshotService<K,
// Would be interesting to use a PriorityQueue ordered on isDone()
// but this is probably close enough in practice.
LinkedList<Future<?>> puts = new LinkedList<>();
- GFSnapshotImporter in = new GFSnapshotImporter(snapshot);
+ GFSnapshotImporter in = new GFSnapshotImporter(snapshot, local.getCache().getPdxRegistry());
try {
int bufferSize = 0;
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/snapshot/GFSnapshotJUnitPerformanceTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/snapshot/GFSnapshotJUnitPerformanceTest.java
index d0151dd..36000b2 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/snapshot/GFSnapshotJUnitPerformanceTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/snapshot/GFSnapshotJUnitPerformanceTest.java
@@ -101,7 +101,7 @@ public class GFSnapshotJUnitPerformanceTest {
long start = System.currentTimeMillis();
int count = 0;
- GFSnapshotImporter in = new GFSnapshotImporter(f);
+ GFSnapshotImporter in = new GFSnapshotImporter(f, null);
SnapshotRecord entry;
while ((entry = in.readSnapshotRecord()) != null) {
@@ -128,7 +128,7 @@ public class GFSnapshotJUnitPerformanceTest {
final SnapshotWriter writer = GFSnapshot.create(tmp, "test");
long start = System.currentTimeMillis();
- SnapshotIterator<Integer, String> iter = GFSnapshot.read(f);
+ SnapshotIterator<Integer, String> iter = GFSnapshot.read(f, null);
try {
while (iter.hasNext()) {
Entry<Integer, String> entry = iter.next();
--
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].