You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by up...@apache.org on 2016/06/01 22:03:03 UTC

incubator-geode git commit: GEODE-11: Adding a method to LuceneIndexImpl to dump indexes

Repository: incubator-geode
Updated Branches:
  refs/heads/develop 6ef7d4754 -> 1e97dbb68


GEODE-11: Adding a method to LuceneIndexImpl to dump indexes

Adding a method to LuceneIndexImpl to invoke the DumpDirectoryFiles
function and dump all of the index files to disk.


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

Branch: refs/heads/develop
Commit: 1e97dbb6848fa76663a56900ed8a869d749ba9db
Parents: 6ef7d47
Author: Dan Smith <up...@apache.org>
Authored: Wed Jun 1 11:12:17 2016 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Wed Jun 1 15:00:09 2016 -0700

----------------------------------------------------------------------
 .../lucene/internal/InternalLuceneIndex.java    |  5 ++
 .../LuceneIndexForPartitionedRegion.java        | 18 ++++++-
 .../LuceneIndexForReplicatedRegion.java         | 49 --------------------
 .../internal/directory/DumpDirectoryFiles.java  |  5 ++
 .../LuceneIndexForPartitionedRegionTest.java    | 21 +++++++++
 .../DumpDirectoryFilesIntegrationTest.java      | 17 ++-----
 6 files changed, 50 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1e97dbb6/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/InternalLuceneIndex.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/InternalLuceneIndex.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/InternalLuceneIndex.java
index 951b0f9..27b4820 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/InternalLuceneIndex.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/InternalLuceneIndex.java
@@ -26,4 +26,9 @@ public interface InternalLuceneIndex extends LuceneIndex {
   
   public RepositoryManager getRepositoryManager();
 
+  /**
+   * Dump the files for this index to the given directory.
+   */
+  public void dumpFiles(String directory);
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1e97dbb6/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
index 3def888..8fe5fac 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
@@ -29,6 +29,9 @@ import com.gemstone.gemfire.cache.RegionAttributes;
 import com.gemstone.gemfire.cache.RegionShortcut;
 import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
 import com.gemstone.gemfire.cache.asyncqueue.internal.AsyncEventQueueFactoryImpl;
+import com.gemstone.gemfire.cache.execute.FunctionService;
+import com.gemstone.gemfire.cache.execute.ResultCollector;
+import com.gemstone.gemfire.cache.lucene.internal.directory.DumpDirectoryFiles;
 import com.gemstone.gemfire.cache.lucene.internal.filesystem.ChunkKey;
 import com.gemstone.gemfire.cache.lucene.internal.filesystem.File;
 import com.gemstone.gemfire.cache.lucene.internal.filesystem.FileSystemStats;
@@ -49,7 +52,7 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
   public void initialize() {
     if (!hasInitialized) {
       /* create index region */
-      PartitionedRegion dataRegion = (PartitionedRegion) cache.getRegion(regionPath);
+      PartitionedRegion dataRegion = getDataRegion();
       //assert dataRegion != null;
       RegionAttributes ra = dataRegion.getAttributes();
       DataPolicy dp = ra.getDataPolicy();
@@ -99,6 +102,10 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
     }
   }
 
+  private PartitionedRegion getDataRegion() {
+    return (PartitionedRegion) cache.getRegion(regionPath);
+  }
+
   private AsyncEventQueueFactoryImpl createAEQFactory(final Region dataRegion) {
     AsyncEventQueueFactoryImpl factory = (AsyncEventQueueFactoryImpl) cache.createAsyncEventQueueFactory();
     factory.setParallel(true); // parallel AEQ for PR
@@ -176,5 +183,12 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
     // TODO Auto-generated method stub
     
   }
-  
+
+  @Override
+  public void dumpFiles(final String directory) {
+    ResultCollector results = FunctionService.onRegion(getDataRegion())
+      .withArgs(new String[] {directory, indexName})
+      .execute(DumpDirectoryFiles.ID);
+    results.getResult();
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1e97dbb6/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForReplicatedRegion.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForReplicatedRegion.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForReplicatedRegion.java
deleted file mode 100644
index c24cb9d..0000000
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForReplicatedRegion.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * 
- *   http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package com.gemstone.gemfire.cache.lucene.internal;
-
-import java.util.Map;
-
-import org.apache.lucene.analysis.Analyzer;
-
-import com.gemstone.gemfire.cache.Cache;
-
-/* wrapper of IndexWriter */
-public class LuceneIndexForReplicatedRegion extends LuceneIndexImpl {
-
-  public LuceneIndexForReplicatedRegion(String indexName, String regionPath, Cache cache) {
-    super(indexName, regionPath, cache);
-    throw new UnsupportedOperationException("Lucene indexes on replicated regions is not yet implemented");
-  }
-
-  public void initialize() {
-    throw new UnsupportedOperationException("Lucene indexes on replicated regions is not yet implemented");
-  }
-
-  public void close() {
-    throw new UnsupportedOperationException("Lucene indexes on replicated regions is not yet implemented");
-  }
-
-  @Override
-  public Map<String, Analyzer> getFieldAnalyzers() {
-    throw new UnsupportedOperationException("Lucene indexes on replicated regions is not yet implemented");
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1e97dbb6/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/directory/DumpDirectoryFiles.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/directory/DumpDirectoryFiles.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/directory/DumpDirectoryFiles.java
index 0d7b859..0d18144 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/directory/DumpDirectoryFiles.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/directory/DumpDirectoryFiles.java
@@ -59,6 +59,7 @@ public class DumpDirectoryFiles implements Function, InternalEntity {
   private static final long serialVersionUID = 1L;
 
   private static final Logger logger = LogService.getLogger();
+  public static final String ID = DumpDirectoryFiles.class.getSimpleName();
 
   @Override
   public void execute(FunctionContext context) {
@@ -104,6 +105,10 @@ public class DumpDirectoryFiles implements Function, InternalEntity {
     }
   }
 
+  @Override public String getId() {
+    return ID;
+  }
+
   @Override
   public boolean optimizeForWrite() {
     return true;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1e97dbb6/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegionTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegionTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegionTest.java
index 4ae1efe..394a2bf 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegionTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegionTest.java
@@ -36,6 +36,9 @@ import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionAttributes;
 import com.gemstone.gemfire.cache.RegionShortcut;
 import com.gemstone.gemfire.cache.asyncqueue.internal.AsyncEventQueueFactoryImpl;
+import com.gemstone.gemfire.cache.execute.FunctionService;
+import com.gemstone.gemfire.cache.execute.ResultCollector;
+import com.gemstone.gemfire.cache.lucene.internal.directory.DumpDirectoryFiles;
 import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
 import com.gemstone.gemfire.internal.cache.PartitionedRegion;
 import com.gemstone.gemfire.internal.cache.extension.ExtensionPoint;
@@ -344,4 +347,22 @@ public class LuceneIndexForPartitionedRegionTest {
     verify(spy).createFileRegion(eq(RegionShortcut.PARTITION_PERSISTENT), eq(index.createFileRegionName()), any());
   }
 
+  @Test
+  public void dumpFilesShouldInvokeDumpFunction() {
+    boolean withPersistence = false;
+    String name = "indexName";
+    String regionPath = "regionName";
+    Cache cache = Fakes.cache();
+    initializeScenario(withPersistence, regionPath, cache);
+
+    DumpDirectoryFiles function = new DumpDirectoryFiles();
+    FunctionService.registerFunction(function);
+    LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath, cache);
+    PartitionedRegion region = (PartitionedRegion) cache.getRegion(regionPath);
+    ResultCollector collector = mock(ResultCollector.class);
+    when(region.executeFunction(eq(function), any(), any(), anyBoolean())).thenReturn(collector);
+    index.dumpFiles("directory");
+    verify(region).executeFunction(eq(function), any(), any(), anyBoolean());
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1e97dbb6/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/directory/DumpDirectoryFilesIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/directory/DumpDirectoryFilesIntegrationTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/directory/DumpDirectoryFilesIntegrationTest.java
index 9f02f2b..5d3105c 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/directory/DumpDirectoryFilesIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/directory/DumpDirectoryFilesIntegrationTest.java
@@ -22,18 +22,11 @@ import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.*;
 import static org.junit.Assert.*;
 
 import java.io.File;
-import java.nio.file.Files;
-import java.nio.file.Paths;
 
-import com.gemstone.gemfire.cache.PartitionAttributes;
-import com.gemstone.gemfire.cache.PartitionAttributesFactory;
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionShortcut;
-import com.gemstone.gemfire.cache.execute.FunctionService;
-import com.gemstone.gemfire.cache.execute.ResultCollector;
-import com.gemstone.gemfire.cache.lucene.LuceneIndex;
 import com.gemstone.gemfire.cache.lucene.LuceneIntegrationTest;
-import com.gemstone.gemfire.cache.lucene.LuceneQuery;
+import com.gemstone.gemfire.cache.lucene.internal.InternalLuceneIndex;
 import com.gemstone.gemfire.cache.lucene.test.TestObject;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
 import com.gemstone.gemfire.test.junit.rules.DiskDirRule;
@@ -63,15 +56,11 @@ public class DumpDirectoryFilesIntegrationTest extends LuceneIntegrationTest {
     region.put(2 * 113, new TestObject("title 3", "hello world"));
     region.put(3 * 113, new TestObject("hello world", "hello world"));
 
-    LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
+    InternalLuceneIndex index = (InternalLuceneIndex) luceneService.getIndex(INDEX_NAME, REGION_NAME);
 
     index.waitUntilFlushed(60000);
 
-    ResultCollector resultCollector= FunctionService
-      .onRegion(region)
-      .withArgs(new String[] {diskDirRule.get().getAbsolutePath(), INDEX_NAME})
-      .execute(new DumpDirectoryFiles().getId());
-    resultCollector.getResult();
+    index.dumpFiles(diskDirRule.get().getAbsolutePath());
 
     //Find the directory for the first bucket
     File bucket0 = diskDirRule.get().listFiles(file -> file.getName().endsWith("_0"))[0];