Skip to content

Commit

Permalink
GEODE-7162: Remove AttributesFactory in geode-lucene (apache#4280)
Browse files Browse the repository at this point in the history
- Fixed method setPartitionAttributes to behave as the one within
  the deprecated AttributesFactory class.
- Removed references to the deprecated AttributesFactory from the
  geode-lucene module.
  • Loading branch information
jujoramos authored Nov 8, 2019
1 parent cf1aef1 commit 8525f2c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.geode.compression.Compressor;
import org.apache.geode.internal.cache.EvictionAttributesImpl;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.internal.cache.PartitionAttributesImpl;
import org.apache.geode.internal.cache.PartitionedRegionHelper;
import org.apache.geode.internal.cache.UserSpecifiedRegionAttributes;

Expand Down Expand Up @@ -1550,15 +1551,35 @@ public PartitionAttributes getPartitionAttributes() {
return this.partitionAttributes;
}

public void setPartitionAttributes(PartitionAttributes pa) {
if (pa != null) {
public void setPartitionAttributes(PartitionAttributes partitionAttr) {
if (partitionAttr != null) {
if (!hasDataPolicy()) {
this.setDataPolicy(PartitionedRegionHelper.DEFAULT_DATA_POLICY);
setDataPolicy(PartitionedRegionHelper.DEFAULT_DATA_POLICY);
setHasDataPolicy(false);
} else if (!PartitionedRegionHelper.ALLOWED_DATA_POLICIES.contains(getDataPolicy())) {
throw new IllegalStateException(
String.format(
"Data policy %s is not allowed for a partitioned region. DataPolicies other than %s are not allowed.",
this.getDataPolicy(), PartitionedRegionHelper.ALLOWED_DATA_POLICIES));
}

if (hasPartitionAttributes()
&& partitionAttributes instanceof PartitionAttributesImpl
&& partitionAttr instanceof PartitionAttributesImpl) {

// Make a copy and call merge on it to prevent bug 51616
PartitionAttributesImpl copy = ((PartitionAttributesImpl) partitionAttributes).copy();
copy.merge((PartitionAttributesImpl) partitionAttr);
this.partitionAttributes = copy;
} else {
this.partitionAttributes = partitionAttr;
}

this.partitionAttributes = pa;
setHasPartitionAttributes(true);
((PartitionAttributesImpl) partitionAttributes).setOffHeap(offHeap);
} else {
partitionAttributes = null;
setHasPartitionAttributes(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
import org.apache.lucene.document.IntPoint;
import org.apache.lucene.search.Query;

import org.apache.geode.cache.AttributesFactory;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.EntryOperation;
import org.apache.geode.cache.FixedPartitionAttributes;
import org.apache.geode.cache.FixedPartitionResolver;
import org.apache.geode.cache.PartitionAttributesFactory;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionFactory;
import org.apache.geode.cache.RegionShortcut;
import org.apache.geode.cache.asyncqueue.AsyncEventQueue;
import org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl;
import org.apache.geode.cache.lucene.LuceneIndex;
Expand Down Expand Up @@ -162,7 +163,7 @@ public static Region createFixedPartitionedRegion(final Cache cache, String regi
allPartitions.add("Q2");
}

AttributesFactory fact = new AttributesFactory();
RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);

PartitionAttributesFactory pfact = new PartitionAttributesFactory();
pfact.setTotalNumBuckets(16);
Expand All @@ -174,8 +175,8 @@ public static Region createFixedPartitionedRegion(final Cache cache, String regi
}
}
pfact.setPartitionResolver(new MyFixedPartitionResolver(allPartitions));
fact.setPartitionAttributes(pfact.create());
Region r = cache.createRegionFactory(fact.create()).create(regionName);
regionFactory.setPartitionAttributes(pfact.create());
Region r = regionFactory.create(regionName);
assertNotNull(r);
return r;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.concurrent.ExecutorService;

import org.apache.geode.CancelException;
import org.apache.geode.cache.AttributesFactory;
import org.apache.geode.cache.FixedPartitionResolver;
import org.apache.geode.cache.PartitionAttributes;
import org.apache.geode.cache.PartitionAttributesFactory;
Expand All @@ -45,6 +44,7 @@
import org.apache.geode.internal.cache.BucketRegion;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.PartitionedRegion;
import org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation;

public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
protected Region fileAndChunkRegion;
Expand Down Expand Up @@ -173,14 +173,13 @@ protected <K, V> Region<K, V> createRegion(final String regionName,
partitionAttributesFactory.setColocatedWith(colocatedWithRegionName);
configureLuceneRegionAttributesFactory(partitionAttributesFactory, partitionAttributes);

// Create AttributesFactory based on input RegionShortcut
// Create RegionAttributes based on input RegionShortcut
RegionAttributes baseAttributes = this.cache.getRegionAttributes(regionShortCut.toString());
AttributesFactory factory = new AttributesFactory(baseAttributes);
factory.setPartitionAttributes(partitionAttributesFactory.create());
RegionAttributesCreation attributes = new RegionAttributesCreation(baseAttributes, false);
attributes.setPartitionAttributes(partitionAttributesFactory.create());
if (regionAttributes.getDataPolicy().withPersistence()) {
factory.setDiskStoreName(regionAttributes.getDiskStoreName());
attributes.setDiskStoreName(regionAttributes.getDiskStoreName());
}
RegionAttributes<K, V> attributes = factory.create();

return createRegion(regionName, attributes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.logging.log4j.Logger;
import org.apache.lucene.analysis.Analyzer;

import org.apache.geode.cache.AttributesFactory;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionAttributes;
import org.apache.geode.cache.lucene.LuceneIndexDestroyedException;
Expand All @@ -29,6 +28,7 @@
import org.apache.geode.internal.cache.InternalRegionArguments;
import org.apache.geode.internal.cache.PartitionedRegion;
import org.apache.geode.internal.cache.RegionListener;
import org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation;
import org.apache.geode.logging.internal.log4j.api.LogService;

public class LuceneRegionListener implements RegionListener {
Expand Down Expand Up @@ -90,9 +90,10 @@ public RegionAttributes beforeCreate(Region parent, String regionName, RegionAtt

String aeqId = LuceneServiceImpl.getUniqueIndexName(this.indexName, this.regionPath);
if (!attrs.getAsyncEventQueueIds().contains(aeqId)) {
AttributesFactory af = new AttributesFactory(attrs);
af.addAsyncEventQueueId(aeqId);
updatedRA = af.create();
RegionAttributesCreation regionAttributesCreation =
new RegionAttributesCreation(attrs, false);
regionAttributesCreation.addAsyncEventQueueId(aeqId);
updatedRA = regionAttributesCreation;
}

// Add index creation profile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;

import org.apache.geode.cache.AttributesFactory;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheListener;
import org.apache.geode.cache.DataPolicy;
Expand All @@ -56,6 +55,7 @@
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.PartitionedRegion;
import org.apache.geode.internal.cache.extension.ExtensionPoint;
import org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation;
import org.apache.geode.test.fake.Fakes;
import org.apache.geode.test.junit.categories.LuceneTest;

Expand Down Expand Up @@ -222,15 +222,15 @@ private Region initializeScenario(final boolean withPersistence, final String re

private RegionAttributes createRegionAttributes(final boolean withPersistence,
PartitionAttributes partitionAttributes) {
AttributesFactory factory = new AttributesFactory();
RegionAttributesCreation regionAttributes = new RegionAttributesCreation();
if (withPersistence) {
factory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
regionAttributes.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
} else {
factory.setDataPolicy(DataPolicy.PARTITION);
regionAttributes.setDataPolicy(DataPolicy.PARTITION);
}
factory.setPartitionAttributes(partitionAttributes);
RegionAttributes ra = factory.create();
return ra;

regionAttributes.setPartitionAttributes(partitionAttributes);
return regionAttributes;
}

private Region initializeScenario(final boolean withPersistence, final String regionPath,
Expand All @@ -254,6 +254,7 @@ private Region initializeScenario(final boolean withPersistence, final String re
private PartitionAttributes initializeAttributes(final Cache cache) {
PartitionAttributes partitionAttributes = mock(PartitionAttributes.class);
RegionAttributes attributes = mock(RegionAttributes.class);
when(attributes.getDataPolicy()).thenReturn(DataPolicy.PARTITION);
when(attributes.getCacheListeners()).thenReturn(new CacheListener[0]);
when(attributes.getRegionTimeToLive()).thenReturn(ExpirationAttributes.DEFAULT);
when(attributes.getRegionIdleTimeout()).thenReturn(ExpirationAttributes.DEFAULT);
Expand Down

0 comments on commit 8525f2c

Please sign in to comment.