You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by nn...@apache.org on 2018/08/06 23:35:33 UTC
[geode] branch develop updated: GEODE-5197: Synchronized update
cache service profiles (#2270)
This is an automated email from the ASF dual-hosted git repository.
nnag pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 2c139a5 GEODE-5197: Synchronized update cache service profiles (#2270)
2c139a5 is described below
commit 2c139a563b3d8931c26664ed9c54ac202579a438
Author: Nabarun Nag <na...@users.noreply.github.com>
AuthorDate: Mon Aug 6 16:35:28 2018 -0700
GEODE-5197: Synchronized update cache service profiles (#2270)
* new lock created for updating the region's cache service profile
* synchronized the addition / validation / removal of LuceneIndexCreationProfile in the data region.
---
.../apache/geode/internal/cache/LocalRegion.java | 40 ++++++++++++++++++++--
.../cache/lucene/internal/LuceneServiceImpl.java | 29 ++++++++++------
2 files changed, 56 insertions(+), 13 deletions(-)
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 1642a8a..5e2a491 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
@@ -499,6 +499,20 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
private final Lock clientMetaDataLock = new ReentrantLock();
/**
+ * Lock for updating the cache service profile for the region.
+ */
+ private final Lock cacheServiceProfileUpdateLock = new ReentrantLock();
+
+ public void executeSynchronizedOperationOnCacheProfiles(Runnable operation) {
+ cacheServiceProfileUpdateLock.lock();
+ try {
+ operation.run();
+ } finally {
+ cacheServiceProfileUpdateLock.unlock();
+ }
+ }
+
+ /**
* There seem to be cases where a region can be created and yet the distributed system is not yet
* in place...
*/
@@ -660,7 +674,7 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
internalRegionArgs.isUsedForParallelGatewaySenderQueue();
this.serialGatewaySender = internalRegionArgs.getSerialGatewaySender();
if (internalRegionArgs.getCacheServiceProfiles() != null) {
- this.cacheServiceProfiles.putAll(internalRegionArgs.getCacheServiceProfiles());
+ addCacheServiceProfiles(internalRegionArgs);
}
if (!isUsedForMetaRegion && !isUsedForPartitionedRegionAdmin
@@ -685,6 +699,15 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
versionVector = createRegionVersionVector();
}
+ private void addCacheServiceProfiles(InternalRegionArguments internalRegionArgs) {
+ cacheServiceProfileUpdateLock.lock();
+ try {
+ this.cacheServiceProfiles.putAll(internalRegionArgs.getCacheServiceProfiles());
+ } finally {
+ cacheServiceProfileUpdateLock.unlock();
+ }
+ }
+
protected EventTracker createEventTracker() {
return NonDistributedEventTracker.getInstance();
}
@@ -10433,7 +10456,13 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
}
public void removeCacheServiceProfile(String profileID) {
- this.cacheServiceProfiles.remove(profileID);
+ cacheServiceProfileUpdateLock.lock();
+ try {
+ this.cacheServiceProfiles.remove(profileID);
+ } finally {
+ cacheServiceProfileUpdateLock.unlock();
+ }
+
}
public AbstractGatewaySender getSerialGatewaySender() {
@@ -10495,7 +10524,12 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
}
public void addCacheServiceProfile(CacheServiceProfile profile) {
- this.cacheServiceProfiles.put(profile.getId(), profile);
+ cacheServiceProfileUpdateLock.lock();
+ try {
+ this.cacheServiceProfiles.put(profile.getId(), profile);
+ } finally {
+ cacheServiceProfileUpdateLock.unlock();
+ }
}
@Override
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 f60b667..48d475b 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
@@ -252,17 +252,10 @@ public class LuceneServiceImpl implements InternalLuceneService {
LuceneIndexCreationProfile luceneIndexCreationProfile = new LuceneIndexCreationProfile(
indexName, regionPath, fields, analyzer, fieldAnalyzers, serializer);
- region.addCacheServiceProfile(luceneIndexCreationProfile);
+ Runnable validateIndexProfile =
+ getIndexValidationRunnable(region, indexName, luceneIndexCreationProfile);
+ region.executeSynchronizedOperationOnCacheProfiles(validateIndexProfile);
- try {
- validateLuceneIndexProfile(region);
- } catch (IllegalStateException e) {
- region.removeCacheServiceProfile(luceneIndexCreationProfile.getId());
- throw new UnsupportedOperationException(
- LocalizedStrings.LuceneIndexCreation_INDEX_CANNOT_BE_CREATED_DUE_TO_PROFILE_VIOLATION
- .toString(indexName),
- e);
- }
String aeqId = LuceneServiceImpl.getUniqueIndexName(indexName, regionPath);
region.updatePRConfigWithNewGatewaySender(aeqId);
LuceneIndexImpl luceneIndex = beforeDataRegionCreated(indexName, regionPath,
@@ -279,6 +272,22 @@ public class LuceneServiceImpl implements InternalLuceneService {
createLuceneIndexOnDataRegion(region, luceneIndex);
}
+ private Runnable getIndexValidationRunnable(PartitionedRegion region, String indexName,
+ LuceneIndexCreationProfile luceneIndexCreationProfile) {
+ return () -> {
+ region.addCacheServiceProfile(luceneIndexCreationProfile);
+ try {
+ validateLuceneIndexProfile(region);
+ } catch (IllegalStateException e) {
+ region.removeCacheServiceProfile(luceneIndexCreationProfile.getId());
+ throw new UnsupportedOperationException(
+ LocalizedStrings.LuceneIndexCreation_INDEX_CANNOT_BE_CREATED_DUE_TO_PROFILE_VIOLATION
+ .toString(indexName),
+ e);
+ }
+ };
+ }
+
protected void validateLuceneIndexProfile(PartitionedRegion region) {
new CreateRegionProcessorForLucene(region).initializeRegion();
}