geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From upthewatersp...@apache.org
Subject incubator-geode git commit: Making File and ChunkKey DataSerializableFixedId
Date Fri, 18 Sep 2015 20:24:41 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-11 e14b2e083 -> 37bbebb92


Making File and ChunkKey DataSerializableFixedId

These classes should implement DataSerializableFixedId for efficient
serialization. As part of this change, I also added a section to
LuceneServiceImpl's constructor to register all DataSerializableFixedId
classes in the lucene service.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/37bbebb9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/37bbebb9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/37bbebb9

Branch: refs/heads/feature/GEODE-11
Commit: 37bbebb92fbb5a125eec9f3b7b17e8f566aa28c0
Parents: e14b2e0
Author: Dan Smith <upthewaterspout@apache.org>
Authored: Fri Sep 18 12:14:36 2015 -0700
Committer: Dan Smith <upthewaterspout@apache.org>
Committed: Fri Sep 18 12:21:34 2015 -0700

----------------------------------------------------------------------
 .../internal/DataSerializableFixedID.java       |  3 ++
 .../lucene/internal/LuceneServiceImpl.java      | 19 ++++++-
 .../lucene/internal/filesystem/ChunkKey.java    | 44 +++++++++++++++--
 .../cache/lucene/internal/filesystem/File.java  | 52 +++++++++++++++++++-
 .../internal/LuceneServiceImplJUnitTest.java    |  2 +-
 .../internal/filesystem/ChunkKeyJUnitTest.java  | 29 +++++++++++
 .../internal/filesystem/FileJUnitTest.java      | 34 +++++++++++++
 7 files changed, 173 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/37bbebb9/gemfire-core/src/main/java/com/gemstone/gemfire/internal/DataSerializableFixedID.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/DataSerializableFixedID.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/DataSerializableFixedID.java
index a8a1715..98efb3e 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/DataSerializableFixedID.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/DataSerializableFixedID.java
@@ -809,6 +809,9 @@ public interface DataSerializableFixedID extends SerializationVersions
{
   public static final short DIST_TX_PRE_COMMIT_RESPONSE = 2167;
   public static final short DIST_TX_THIN_ENTRY_STATE = 2168;
   
+  public static final short LUCENE_CHUNK_KEY = 2169;
+  public static final short LUCENE_FILE = 2170;
+  
   // NOTE, codes > 65535 will take 4 bytes to serialize
   
   /**

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/37bbebb9/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java
b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java
index 245287c..cee9dc9 100644
--- a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java
+++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java
@@ -7,13 +7,16 @@ import java.util.Map;
 import org.apache.lucene.analysis.Analyzer;
 
 import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.execute.FunctionService;
-import com.gemstone.gemfire.cache.GemFireCache;
 import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.execute.FunctionService;
 import com.gemstone.gemfire.cache.lucene.LuceneIndex;
 import com.gemstone.gemfire.cache.lucene.LuceneQueryFactory;
 import com.gemstone.gemfire.cache.lucene.LuceneService;
 import com.gemstone.gemfire.cache.lucene.internal.distributed.LuceneFunction;
+import com.gemstone.gemfire.cache.lucene.internal.filesystem.ChunkKey;
+import com.gemstone.gemfire.cache.lucene.internal.filesystem.File;
+import com.gemstone.gemfire.internal.DSFIDFactory;
+import com.gemstone.gemfire.internal.DataSerializableFixedID;
 import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
 import com.gemstone.gemfire.internal.cache.PartitionedRegion;
 import com.gemstone.gemfire.internal.cache.extension.Extensible;
@@ -43,6 +46,7 @@ public class LuceneServiceImpl implements LuceneService, Extension<Cache>
{
     this.cache = gfc;
 
     FunctionService.registerFunction(new LuceneFunction());
+    registerDataSerializables();
 
     // Initialize the Map which maintains indexes
     this.indexMap = new HashMap<String, LuceneIndex>();
@@ -128,4 +132,15 @@ public class LuceneServiceImpl implements LuceneService, Extension<Cache>
{
     if( indexMap.containsKey( region )) indexMap.remove( region );
   }
 
+  /**Public for test purposes */
+  public static void registerDataSerializables() {
+    DSFIDFactory.registerDSFID(
+        DataSerializableFixedID.LUCENE_CHUNK_KEY,
+        ChunkKey.class);
+    
+    DSFIDFactory.registerDSFID(
+        DataSerializableFixedID.LUCENE_FILE,
+        File.class);
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/37bbebb9/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/ChunkKey.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/ChunkKey.java
b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/ChunkKey.java
index ada0382..d13f3f5 100644
--- a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/ChunkKey.java
+++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/ChunkKey.java
@@ -1,17 +1,25 @@
 package com.gemstone.gemfire.cache.lucene.internal.filesystem;
 
-import java.io.Serializable;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
 import java.util.UUID;
 
+import com.gemstone.gemfire.internal.DataSerializableFixedID;
+import com.gemstone.gemfire.internal.Version;
+
 /**
  * The key for a single chunk on a file stored within a region.
  */
-public class ChunkKey implements Serializable {
-
-  private static final long serialVersionUID = 1L;
-
+public class ChunkKey implements DataSerializableFixedID {
   UUID fileId;
   int chunkId;
+  
+  /**
+   * Constructor used for serialization only.
+   */
+  public ChunkKey() {
+  }
 
   ChunkKey(UUID fileName, int chunkId) {
     this.fileId = fileName;
@@ -66,5 +74,31 @@ public class ChunkKey implements Serializable {
     return true;
   }
 
+  @Override
+  public Version[] getSerializationVersions() {
+    return null;
+  }
+
+  @Override
+  public int getDSFID() {
+    return LUCENE_CHUNK_KEY;
+  }
+
+  @Override
+  public void toData(DataOutput out) throws IOException {
+    out.writeInt(chunkId);
+    out.writeLong(fileId.getMostSignificantBits());
+    out.writeLong(fileId.getLeastSignificantBits());
+  }
+
+  @Override
+  public void fromData(DataInput in)
+      throws IOException, ClassNotFoundException {
+    chunkId = in.readInt();
+    long high = in.readLong();
+    long low = in.readLong();
+    fileId = new UUID(high, low);
+  }
+
   
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/37bbebb9/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/File.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/File.java
b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/File.java
index 894ef4c..1ad0808 100644
--- a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/File.java
+++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/File.java
@@ -1,15 +1,21 @@
 package com.gemstone.gemfire.cache.lucene.internal.filesystem;
 
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Serializable;
 import java.util.UUID;
 
+import com.gemstone.gemfire.DataSerializer;
+import com.gemstone.gemfire.internal.DataSerializableFixedID;
+import com.gemstone.gemfire.internal.Version;
+
 /**
  * A file that is stored in a gemfire region.
  */
-public class File implements Serializable {
-  private static final long serialVersionUID = 1L;
+public class File implements DataSerializableFixedID {
   
   private transient FileSystem fileSystem;
   private transient int chunkSize;
@@ -20,6 +26,12 @@ public class File implements Serializable {
   long created = System.currentTimeMillis();
   long modified = created;
   UUID id = UUID.randomUUID();
+  
+  /**
+   * Constructor for serialization only
+   */
+  public File() {
+  }
 
   File(final FileSystem fileSystem, final String name) {
     setFileSystem(fileSystem);
@@ -85,4 +97,40 @@ public class File implements Serializable {
   public FileSystem getFileSystem() {
     return fileSystem;
   }
+
+  @Override
+  public Version[] getSerializationVersions() {
+    return null;
+  }
+
+  @Override
+  public int getDSFID() {
+    return LUCENE_FILE;
+  }
+
+  @Override
+  public void toData(DataOutput out) throws IOException {
+    DataSerializer.writeString(name, out);
+    out.writeLong(length);
+    out.writeInt(chunks);
+    out.writeLong(created);
+    out.writeLong(modified);
+    out.writeLong(id.getMostSignificantBits());
+    out.writeLong(id.getLeastSignificantBits());
+  }
+
+  @Override
+  public void fromData(DataInput in)
+      throws IOException, ClassNotFoundException {
+    name = DataSerializer.readString(in);
+    length = in.readLong();
+    chunks = in.readInt();
+    created = in.readLong();
+    modified = in.readLong();
+    long high = in.readLong();
+    long low = in.readLong();
+    id = new UUID(high, low);
+  }
+  
+  
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/37bbebb9/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java
b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java
index 14929b5..2b890db 100644
--- a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java
+++ b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java
@@ -31,7 +31,7 @@ public class LuceneServiceImplJUnitTest {
     function = FunctionService.getFunction(LuceneFunction.ID);
     assertNotNull(function);
   }
-
+  
   private GemFireCacheImpl createBasicCache() {
     return (GemFireCacheImpl) new CacheFactory().set("mcast-port", "0").create();
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/37bbebb9/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/ChunkKeyJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/ChunkKeyJUnitTest.java
b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/ChunkKeyJUnitTest.java
new file mode 100644
index 0000000..90cfca0
--- /dev/null
+++ b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/ChunkKeyJUnitTest.java
@@ -0,0 +1,29 @@
+package com.gemstone.gemfire.cache.lucene.internal.filesystem;
+
+import static org.junit.Assert.*;
+
+import java.util.UUID;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.CopyHelper;
+import com.gemstone.gemfire.cache.lucene.internal.LuceneServiceImpl;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class ChunkKeyJUnitTest {
+
+  @Test
+  public void testSerialization() {
+    LuceneServiceImpl.registerDataSerializables();
+    ChunkKey key = new ChunkKey(UUID.randomUUID(), 5);
+    ChunkKey copy = CopyHelper.deepCopy(key);
+    
+    assertEquals(key, copy);
+    assertEquals(key.hashCode(), copy.hashCode());
+    assertEquals(key.getFileId(), copy.getFileId());
+    assertEquals(key.getChunkId(), copy.getChunkId());
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/37bbebb9/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/FileJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/FileJUnitTest.java
b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/FileJUnitTest.java
new file mode 100644
index 0000000..a30e69b
--- /dev/null
+++ b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/FileJUnitTest.java
@@ -0,0 +1,34 @@
+package com.gemstone.gemfire.cache.lucene.internal.filesystem;
+
+import static org.junit.Assert.*;
+
+import java.util.UUID;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.CopyHelper;
+import com.gemstone.gemfire.cache.lucene.internal.LuceneServiceImpl;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class FileJUnitTest {
+
+  @Test
+  public void testSerialization() {
+    LuceneServiceImpl.registerDataSerializables();
+    File file = new File(null, "fileName");
+    file.modified = -10;
+    file.length = 5;
+    file.chunks = 7;
+    File copy = CopyHelper.deepCopy(file);
+    
+    assertEquals(file.chunks, copy.chunks);
+    assertEquals(file.created, copy.created);
+    assertEquals(file.modified, copy.modified);
+    assertEquals(file.getName(), copy.getName());
+    assertEquals(file.length, copy.length);
+    assertEquals(file.id, copy.id);
+  }
+
+}


Mime
View raw message