geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bogle...@apache.org
Subject geode git commit: GEODE-2947: Error message is now specific to lucene indexes
Date Wed, 31 May 2017 23:26:49 GMT
Repository: geode
Updated Branches:
  refs/heads/develop d1ec508ee -> 5f4a7a905


GEODE-2947: Error message is now specific to lucene indexes


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

Branch: refs/heads/develop
Commit: 5f4a7a905013dfa8f76f7419ea71aacae3614077
Parents: d1ec508
Author: Barry Oglesby <boglesby@pivotal.io>
Authored: Thu May 25 17:13:35 2017 -0700
Committer: Barry Oglesby <boglesby@pivotal.io>
Committed: Wed May 31 16:22:32 2017 -0700

----------------------------------------------------------------------
 .../geode/internal/cache/GemFireCacheImpl.java  |  5 ++++
 .../geode/internal/cache/InternalCache.java     |  2 ++
 .../geode/internal/cache/LocalRegion.java       |  8 ++++++
 .../geode/internal/cache/PartitionedRegion.java |  1 +
 .../geode/internal/cache/RegionService.java     | 30 ++++++++++++++++++++
 .../internal/cache/xmlcache/CacheCreation.java  |  5 ++++
 .../geode/internal/i18n/LocalizedStrings.java   |  3 ++
 .../lucene/internal/InternalLuceneService.java  |  4 +--
 .../lucene/internal/LuceneServiceImpl.java      | 22 ++++++++++++++
 .../lucene/LuceneIndexDestroyDUnitTest.java     | 18 ++++++++++--
 10 files changed, 93 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/5f4a7a90/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
index c813a80..5e35224 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
@@ -3670,6 +3670,11 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache,
Has
     return clazz.cast(this.services.get(clazz));
   }
 
+  @Override
+  public Collection<CacheService> getServices() {
+    return Collections.unmodifiableCollection(this.services.values());
+  }
+
   /**
    * Creates the single instance of the Transaction Manager for this cache. Returns the existing
one
    * upon request.

http://git-wip-us.apache.org/repos/asf/geode/blob/5f4a7a90/geode-core/src/main/java/org/apache/geode/internal/cache/InternalCache.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/InternalCache.java b/geode-core/src/main/java/org/apache/geode/internal/cache/InternalCache.java
index 5533ed1..d9a34e1 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/InternalCache.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/InternalCache.java
@@ -84,6 +84,8 @@ public interface InternalCache extends Cache, Extensible<Cache>, CacheTime
{
 
   <T extends CacheService> T getService(Class<T> clazz);
 
+  Collection<CacheService> getServices();
+
   SystemTimer getCCPTimer();
 
   void cleanupForClient(CacheClientNotifier ccn, ClientProxyMembershipID client);

http://git-wip-us.apache.org/repos/asf/geode/blob/5f4a7a90/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
index f581856..e1fe6c7 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
@@ -1139,6 +1139,14 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
     basicDestroyRegion(event, true);
   }
 
+  protected void invokeBeforeRegionDestroyInServices() {
+    for (CacheService service : this.cache.getServices()) {
+      if (service instanceof RegionService) {
+        ((RegionService) service).beforeRegionDestroyed(this);
+      }
+    }
+  }
+
   public InternalDataView getDataView() {
     final TXStateInterface tx = getTXState();
     if (tx == null) {

http://git-wip-us.apache.org/repos/asf/geode/blob/5f4a7a90/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
index 02d04b3..288f4a9 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
@@ -7057,6 +7057,7 @@ public class PartitionedRegion extends LocalRegion
   @Override
   public void destroyRegion(Object aCallbackArgument)
       throws CacheWriterException, TimeoutException {
+    invokeBeforeRegionDestroyInServices();
     checkForColocatedChildren();
     getDataView().checkSupportsRegionDestroy();
     checkForLimitedOrNoAccess();

http://git-wip-us.apache.org/repos/asf/geode/blob/5f4a7a90/geode-core/src/main/java/org/apache/geode/internal/cache/RegionService.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/RegionService.java b/geode-core/src/main/java/org/apache/geode/internal/cache/RegionService.java
new file mode 100644
index 0000000..3d6488d
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/RegionService.java
@@ -0,0 +1,30 @@
+/*
+ * 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 org.apache.geode.internal.cache;
+
+import org.apache.geode.cache.Region;
+
+/**
+ * Interface for a service that is linked to a region.
+ */
+public interface RegionService extends CacheService {
+
+  /**
+   * Called before a region is destroyed.
+   *
+   * @param region The region being destroyed
+   */
+  public void beforeRegionDestroyed(Region region);
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/5f4a7a90/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheCreation.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheCreation.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheCreation.java
index 7f623c7..f99f9db 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheCreation.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheCreation.java
@@ -1959,6 +1959,11 @@ public class CacheCreation implements InternalCache {
   }
 
   @Override
+  public Collection<CacheService> getServices() {
+    throw new UnsupportedOperationException(LocalizedStrings.SHOULDNT_INVOKE.toLocalizedString());
+  }
+
+  @Override
   public SystemTimer getCCPTimer() {
     throw new UnsupportedOperationException(LocalizedStrings.SHOULDNT_INVOKE.toLocalizedString());
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/5f4a7a90/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
b/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
index f19c4e7..67867fb 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
@@ -7695,6 +7695,9 @@ public class LocalizedStrings {
   public static final StringId StringQueryProvider_PARSING_QUERY_0_FAILED_DUE_TO_1 =
       new StringId(6659, "Parsing query {0} failed due to: {1}");
 
+  public static final StringId LuceneServiceImpl_REGION_0_CANNOT_BE_DESTROYED = new StringId(6660,
+      "Region {0} cannot be destroyed because it defines Lucene index(es) [{1}]. Destroy
all Lucene indexes before destroying the region.");
+
   /** Testing strings, messageId 90000-99999 **/
 
   /**

http://git-wip-us.apache.org/repos/asf/geode/blob/5f4a7a90/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/InternalLuceneService.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/InternalLuceneService.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/InternalLuceneService.java
index 9e1e244..3c27d80 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/InternalLuceneService.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/InternalLuceneService.java
@@ -17,9 +17,9 @@ package org.apache.geode.cache.lucene.internal;
 
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.lucene.LuceneService;
-import org.apache.geode.internal.cache.CacheService;
+import org.apache.geode.internal.cache.RegionService;
 import org.apache.geode.internal.cache.extension.Extension;
 
-public interface InternalLuceneService extends LuceneService, Extension<Cache>, CacheService
{
+public interface InternalLuceneService extends LuceneService, Extension<Cache>, RegionService
{
 
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/5f4a7a90/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
index 23b6925..c263884 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
@@ -19,6 +19,7 @@ import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 
 import org.apache.geode.cache.lucene.LuceneIndexExistsException;
 import org.apache.geode.cache.lucene.internal.distributed.LuceneQueryFunction;
@@ -115,6 +116,17 @@ public class LuceneServiceImpl implements InternalLuceneService {
     return InternalLuceneService.class;
   }
 
+  @Override
+  public void beforeRegionDestroyed(Region region) {
+    List<LuceneIndex> indexes = getIndexes(region.getFullPath());
+    if (!indexes.isEmpty()) {
+      String indexNames = indexes.stream().map(i -> i.getName()).collect(Collectors.joining(","));
+      throw new IllegalStateException(
+          LocalizedStrings.LuceneServiceImpl_REGION_0_CANNOT_BE_DESTROYED
+              .toLocalizedString(region.getFullPath(), indexNames));
+    }
+  }
+
   public static String getUniqueIndexName(String indexName, String regionPath) {
     if (!regionPath.startsWith("/")) {
       regionPath = "/" + regionPath;
@@ -252,6 +264,16 @@ public class LuceneServiceImpl implements InternalLuceneService {
     return indexMap.values();
   }
 
+  public List<LuceneIndex> getIndexes(String regionPath) {
+    List<LuceneIndex> indexes = new ArrayList();
+    for (LuceneIndex index : getAllIndexes()) {
+      if (index.getRegionPath().equals(regionPath)) {
+        indexes.add(index);
+      }
+    }
+    return Collections.unmodifiableList(indexes);
+  }
+
   @Override
   public void destroyIndex(String indexName, String regionPath) {
     destroyIndex(indexName, regionPath, true);

http://git-wip-us.apache.org/repos/asf/geode/blob/5f4a7a90/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java
index b34d998..a93a4e7 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java
@@ -24,6 +24,7 @@ import org.apache.geode.cache.lucene.test.TestObject;
 import org.apache.geode.cache.snapshot.RegionSnapshotService;
 import org.apache.geode.cache.snapshot.SnapshotOptions;
 import org.apache.geode.internal.cache.LocalRegion;
+import org.apache.geode.internal.i18n.LocalizedStrings;
 import org.apache.geode.test.dunit.AsyncInvocation;
 import org.apache.geode.test.dunit.Host;
 import org.apache.geode.test.dunit.IgnoredException;
@@ -92,7 +93,7 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
 
     // Attempt to destroy data region (should fail)
     if (destroyDataRegion) {
-      dataStore1.invoke(() -> destroyDataRegion(false));
+      dataStore1.invoke(() -> destroyDataRegion(false, INDEX_NAME));
     }
 
     // Destroy index (only needs to be done on one member)
@@ -121,7 +122,7 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
 
     // Attempt to destroy data region (should fail)
     if (destroyDataRegion) {
-      dataStore1.invoke(() -> destroyDataRegion(false));
+      dataStore1.invoke(() -> destroyDataRegion(false, INDEX1_NAME, INDEX2_NAME));
     }
 
     // Destroy indexes (only needs to be done on one member)
@@ -602,7 +603,7 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
     assertEquals(expectedResultsSize, results.size());
   }
 
-  private void destroyDataRegion(boolean shouldSucceed) {
+  private void destroyDataRegion(boolean shouldSucceed, String... indexNames) {
     Region region = getCache().getRegion(REGION_NAME);
     assertNotNull(region);
     try {
@@ -613,6 +614,17 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
     } catch (IllegalStateException e) {
       if (shouldSucceed) {
         fail(e);
+      } else {
+        // Verify the correct exception is thrown
+        StringBuilder builder = new StringBuilder();
+        for (int i = 0; i < indexNames.length; i++) {
+          builder.append(indexNames[i]);
+          if (i + 1 != indexNames.length) {
+            builder.append(',');
+          }
+        }
+        assertEquals(LocalizedStrings.LuceneServiceImpl_REGION_0_CANNOT_BE_DESTROYED
+            .toLocalizedString(region.getFullPath(), builder.toString()), e.getLocalizedMessage());
       }
     }
   }


Mime
View raw message