use of org.apache.geode.internal.cache.EvictionAttributesImpl in project geode by apache.
the class ConcurrentIndexInitOnOverflowRegionDUnitTest method testAsyncIndexInitDuringEntryDestroyAndQueryOnRR.
/**
*
*/
@Test
public void testAsyncIndexInitDuringEntryDestroyAndQueryOnRR() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
name = "PartionedPortfoliosPR";
// Create Overflow Persistent Partition Region
vm0.invoke(new CacheSerializableRunnable("Create local region with synchronous index maintenance") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region partitionRegion = null;
IndexManager.testHook = null;
try {
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
AttributesFactory attr = new AttributesFactory();
attr.setValueConstraint(PortfolioData.class);
attr.setIndexMaintenanceSynchronous(true);
EvictionAttributesImpl evicAttr = new EvictionAttributesImpl().setAction(EvictionAction.OVERFLOW_TO_DISK);
evicAttr.setAlgorithm(EvictionAlgorithm.LRU_ENTRY).setMaximum(1);
attr.setEvictionAttributes(evicAttr);
attr.setDataPolicy(DataPolicy.REPLICATE);
// attr.setPartitionAttributes(new
// PartitionAttributesFactory().setTotalNumBuckets(1).create());
attr.setDiskStoreName("disk");
RegionFactory regionFactory = cache.createRegionFactory(attr.create());
partitionRegion = regionFactory.create(name);
} catch (IllegalStateException ex) {
LogWriterUtils.getLogWriter().warning("Creation caught IllegalStateException", ex);
}
assertNotNull("Region " + name + " not in cache", cache.getRegion(name));
assertNotNull("Region ref null", partitionRegion);
assertTrue("Region ref claims to be destroyed", !partitionRegion.isDestroyed());
// Create Indexes
try {
Index index = cache.getQueryService().createIndex("statusIndex", "p.status", "/" + name + " p");
assertNotNull(index);
} catch (Exception e1) {
e1.printStackTrace();
fail("Index creation failed");
}
}
});
// Start changing the value in Region which should turn into a deadlock if
// the fix is not there
AsyncInvocation asyncInv1 = vm0.invokeAsync(new CacheSerializableRunnable("Change value in region") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
// Do a put in region.
Region r = getCache().getRegion(name);
for (int i = 0; i < 100; i++) {
r.put(i, new PortfolioData(i));
}
assertNull(IndexManager.testHook);
IndexManager.testHook = new IndexManagerTestHook();
// Destroy one of the values.
getCache().getLogger().fine("Destroying the value");
r.destroy(1);
IndexManager.testHook = null;
}
});
AsyncInvocation asyncInv2 = vm0.invokeAsync(new CacheSerializableRunnable("Run query on region") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
while (!hooked) {
Wait.pause(100);
}
// Create and hence initialize Index
try {
Index index = cache.getQueryService().createIndex("idIndex", "p.ID", "/" + name + " p");
assertNotNull(index);
} catch (Exception e1) {
e1.printStackTrace();
fail("Index creation failed");
}
}
});
// If we take more than 30 seconds then its a deadlock.
ThreadUtils.join(asyncInv2, 30 * 1000);
ThreadUtils.join(asyncInv1, 30 * 1000);
}
use of org.apache.geode.internal.cache.EvictionAttributesImpl in project geode by apache.
the class ConcurrentIndexOperationsOnOverflowRegionDUnitTest method testAsyncIndexInitDuringEntryDestroyAndQueryOnRR.
// GEODE-1828
@Category(FlakyTest.class)
@Test
public void testAsyncIndexInitDuringEntryDestroyAndQueryOnRR() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
hooked = false;
name = "PartionedPortfoliosPR";
// Create Overflow Persistent Partition Region
vm0.invoke(new CacheSerializableRunnable("Create local region with synchronous index maintenance") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region partitionRegion = null;
IndexManager.testHook = null;
try {
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
AttributesFactory attr = new AttributesFactory();
attr.setValueConstraint(PortfolioData.class);
attr.setIndexMaintenanceSynchronous(true);
EvictionAttributesImpl evicAttr = new EvictionAttributesImpl().setAction(EvictionAction.OVERFLOW_TO_DISK);
evicAttr.setAlgorithm(EvictionAlgorithm.LRU_ENTRY).setMaximum(1);
attr.setEvictionAttributes(evicAttr);
attr.setDataPolicy(DataPolicy.REPLICATE);
// attr.setPartitionAttributes(new
// PartitionAttributesFactory().setTotalNumBuckets(1).create());
attr.setDiskStoreName("disk");
RegionFactory regionFactory = cache.createRegionFactory(attr.create());
partitionRegion = regionFactory.create(name);
} catch (IllegalStateException ex) {
LogWriterUtils.getLogWriter().warning("Creation caught IllegalStateException", ex);
}
assertNotNull("Region " + name + " not in cache", cache.getRegion(name));
assertNotNull("Region ref null", partitionRegion);
assertTrue("Region ref claims to be destroyed", !partitionRegion.isDestroyed());
// Create Indexes
try {
Index index = cache.getQueryService().createIndex("statusIndex", "p.ID", "/" + name + " p");
assertNotNull(index);
} catch (Exception e1) {
e1.printStackTrace();
fail("Index creation failed");
}
}
});
// Start changing the value in Region which should turn into a deadlock if the fix is not there
AsyncInvocation asyncInv1 = vm0.invokeAsync(new CacheSerializableRunnable("Change value in region") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
// Do a put in region.
Region r = getCache().getRegion(name);
for (int i = 0; i < 100; i++) {
r.put(i, new PortfolioData(i));
}
assertNull(IndexManager.testHook);
IndexManager.testHook = new IndexManagerTestHook();
// Destroy one of the values.
getCache().getLogger().fine("Destroying the value");
r.destroy(1);
IndexManager.testHook = null;
}
});
AsyncInvocation asyncInv2 = vm0.invokeAsync(new CacheSerializableRunnable("Run query on region") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Query statusQuery = getCache().getQueryService().newQuery("select * from /" + name + " p where p.ID > -1");
while (!hooked) {
Wait.pause(100);
}
try {
getCache().getLogger().fine("Querying the region");
SelectResults results = (SelectResults) statusQuery.execute();
assertEquals(100, results.size());
} catch (Exception e) {
e.printStackTrace();
}
}
});
// If we take more than 30 seconds then its a deadlock.
ThreadUtils.join(asyncInv2, 30 * 1000);
ThreadUtils.join(asyncInv1, 30 * 1000);
}
use of org.apache.geode.internal.cache.EvictionAttributesImpl in project geode by apache.
the class CacheXmlParser method endLRUHeapPercentage.
/**
* Complete the configuration of a <code>lru-heap-percentage</code> eviction controller. Check for
* the declaration of an {@link ObjectSizer}. Assign the attributes to the enclosed
* <code>region-attributes</code>
*/
private void endLRUHeapPercentage() {
Object declCheck = stack.peek();
Declarable d = null;
if (declCheck instanceof String || declCheck instanceof Parameter) {
d = createDeclarable();
if (!(d instanceof ObjectSizer)) {
String s = "A " + d.getClass().getName() + " is not an instance of a ObjectSizer";
throw new CacheXmlException(s);
}
}
EvictionAttributesImpl eai = (EvictionAttributesImpl) stack.pop();
if (d != null) {
eai.setObjectSizer((ObjectSizer) d);
}
RegionAttributesCreation regAttrs = peekRegionAttributesContext(LRU_HEAP_PERCENTAGE);
regAttrs.setEvictionAttributes(eai);
}
use of org.apache.geode.internal.cache.EvictionAttributesImpl in project geode by apache.
the class ParallelQueueRemovalMessageJUnitTest method createQueueRegion.
private void createQueueRegion() {
// Mock queue region
this.queueRegion = mock(PartitionedRegion.class);
when(this.queueRegion.getFullPath()).thenReturn(getRegionQueueName());
when(this.queueRegion.getPrStats()).thenReturn(mock(PartitionedRegionStats.class));
when(this.queueRegion.getDataStore()).thenReturn(mock(PartitionedRegionDataStore.class));
when(this.queueRegion.getCache()).thenReturn(this.cache);
EvictionAttributesImpl ea = (EvictionAttributesImpl) EvictionAttributes.createLRUMemoryAttributes(100, null, EvictionAction.OVERFLOW_TO_DISK);
LRUAlgorithm algorithm = ea.createEvictionController(this.queueRegion, false);
algorithm.getLRUHelper().initStats(this.queueRegion, this.cache.getDistributedSystem());
when(this.queueRegion.getEvictionController()).thenReturn(algorithm);
}
use of org.apache.geode.internal.cache.EvictionAttributesImpl in project geode by apache.
the class ConcurrentIndexInitOnOverflowRegionDUnitTest method testAsyncIndexInitDuringEntryPutUsingClientOnRR.
/**
*
*/
@Test
public void testAsyncIndexInitDuringEntryPutUsingClientOnRR() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
IgnoredException.addIgnoredException("Unexpected IOException:");
IgnoredException.addIgnoredException("java.net.SocketException");
name = "PartionedPortfoliosPR";
// Create Overflow Persistent Partition Region
vm0.invoke(new CacheSerializableRunnable("Create local region with synchronous index maintenance") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region partitionRegion = null;
IndexManager.testHook = null;
try {
CacheServer bridge = cache.addCacheServer();
bridge.setPort(0);
bridge.start();
bridgeServerPort = bridge.getPort();
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
AttributesFactory attr = new AttributesFactory();
attr.setValueConstraint(PortfolioData.class);
attr.setIndexMaintenanceSynchronous(true);
EvictionAttributesImpl evicAttr = new EvictionAttributesImpl().setAction(EvictionAction.OVERFLOW_TO_DISK);
evicAttr.setAlgorithm(EvictionAlgorithm.LRU_ENTRY).setMaximum(1);
attr.setEvictionAttributes(evicAttr);
attr.setDataPolicy(DataPolicy.REPLICATE);
// attr.setPartitionAttributes(new
// PartitionAttributesFactory().setTotalNumBuckets(1).create());
attr.setDiskStoreName("disk");
RegionFactory regionFactory = cache.createRegionFactory(attr.create());
partitionRegion = regionFactory.create(name);
} catch (IllegalStateException ex) {
LogWriterUtils.getLogWriter().warning("Creation caught IllegalStateException", ex);
} catch (IOException e) {
e.printStackTrace();
}
assertNotNull("Region " + name + " not in cache", cache.getRegion(name));
assertNotNull("Region ref null", partitionRegion);
assertTrue("Region ref claims to be destroyed", !partitionRegion.isDestroyed());
// Create Indexes
try {
Index index = cache.getQueryService().createIndex("idIndex", "p.ID", "/" + name + " p");
assertNotNull(index);
} catch (Exception e1) {
e1.printStackTrace();
fail("Index creation failed");
}
}
});
final int port = vm0.invoke(() -> ConcurrentIndexInitOnOverflowRegionDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
// Start changing the value in Region which should turn into a deadlock if
// the fix is not there
vm1.invoke(new CacheSerializableRunnable("Change value in region") {
@Override
public void run2() throws CacheException {
disconnectFromDS();
ClientCache clientCache = new ClientCacheFactory().addPoolServer(host0, port).create();
// Do a put in region.
Region r = clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(name);
for (int i = 0; i < 100; i++) {
r.put(i, new PortfolioData(i));
}
}
});
vm0.invoke(new CacheSerializableRunnable("Set Test Hook") {
@Override
public void run2() throws CacheException {
// Set test hook before client operation
assertNull(IndexManager.testHook);
IndexManager.testHook = new IndexManagerTestHook();
}
});
AsyncInvocation asyncInv1 = vm1.invokeAsync(new CacheSerializableRunnable("Change value in region") {
@Override
public void run2() throws CacheException {
ClientCache clientCache = ClientCacheFactory.getAnyInstance();
// Do a put in region.
Region r = clientCache.getRegion(name);
// Destroy one of the values.
clientCache.getLogger().fine("Destroying the value");
r.destroy(1);
}
});
AsyncInvocation asyncInv2 = vm0.invokeAsync(new CacheSerializableRunnable("Run query on region") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
while (!hooked) {
Wait.pause(100);
}
// Create Indexes
try {
Index index = cache.getQueryService().createIndex("statusIndex", "p.status", "/" + name + " p");
assertNotNull(index);
} catch (Exception e1) {
e1.printStackTrace();
fail("Index creation failed");
}
}
});
// If we take more than 30 seconds then its a deadlock.
ThreadUtils.join(asyncInv2, 30 * 1000);
ThreadUtils.join(asyncInv1, 30 * 1000);
vm0.invoke(new CacheSerializableRunnable("Set Test Hook") {
@Override
public void run2() throws CacheException {
assertNotNull(IndexManager.testHook);
IndexManager.testHook = null;
}
});
}
Aggregations