DATAGEODE-35 - Add missing configuration support for critical-off-heap-percentage and eviction-off-heap-percentage.

This commit is contained in:
John Blum
2017-08-08 00:18:52 -04:00
parent a23afdb7e3
commit 9530287e05
7 changed files with 241 additions and 48 deletions

View File

@@ -126,7 +126,9 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
private DynamicRegionSupport dynamicRegionSupport;
private Float criticalHeapPercentage;
private Float criticalOffHeapPercentage;
private Float evictionHeapPercentage;
private Float evictionOffHeapPercentage;
private GatewayConflictResolver gatewayConflictResolver;
@@ -260,7 +262,7 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
setCache(postProcess(resolveCache()));
Optional.ofNullable(this.<GemFireCache>getCache()).ifPresent(cache -> {
Optional.<GemFireCache>ofNullable(this.getCache()).ifPresent(cache -> {
Optional.ofNullable(cache.getDistributedSystem()).map(DistributedSystem::getDistributedMember)
.ifPresent(member ->
@@ -470,35 +472,59 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
}
configureHeapPercentages(cache);
configureOffHeapPercentages(cache);
registerJndiDataSources();
registerTransactionListeners(cache);
registerTransactionWriter(cache);
registerJndiDataSources();
return cache;
}
/* (non-Javadoc) */
private boolean isHeapPercentageValid(Float heapPercentage) {
return (heapPercentage > 0.0f && heapPercentage <= 100.0f);
return (heapPercentage >= 0.0f && heapPercentage <= 100.0f);
}
/* (non-Javadoc) */
private void configureHeapPercentages(GemFireCache cache) {
Optional.ofNullable(getCriticalHeapPercentage()).ifPresent(criticalHeapPercentage -> {
Assert.isTrue(isHeapPercentageValid(criticalHeapPercentage), String.format(
"criticalHeapPercentage [%s] is not valid; must be > 0.0 and <= 100.0", criticalHeapPercentage));
"criticalHeapPercentage [%s] is not valid; must be >= 0.0 and <= 100.0", criticalHeapPercentage));
cache.getResourceManager().setCriticalHeapPercentage(criticalHeapPercentage);
});
Optional.ofNullable(getEvictionHeapPercentage()).ifPresent(evictionHeapPercentage -> {
Assert.isTrue(isHeapPercentageValid(evictionHeapPercentage), String.format(
"evictionHeapPercentage [%s] is not valid; must be > 0.0 and <= 100.0", evictionHeapPercentage));
"evictionHeapPercentage [%s] is not valid; must be >= 0.0 and <= 100.0", evictionHeapPercentage));
cache.getResourceManager().setEvictionHeapPercentage(evictionHeapPercentage);
});
}
/* (non-Javadoc) */
private void configureOffHeapPercentages(GemFireCache cache) {
Optional.ofNullable(getCriticalOffHeapPercentage()).ifPresent(criticalOffHeapPercentage -> {
Assert.isTrue(isHeapPercentageValid(criticalOffHeapPercentage), String.format(
"criticalOffHeapPercentage [%s] is not valid; must be >= 0.0 and <= 100.0", criticalOffHeapPercentage));
cache.getResourceManager().setCriticalOffHeapPercentage(criticalOffHeapPercentage);
});
Optional.ofNullable(getEvictionOffHeapPercentage()).ifPresent(evictionOffHeapPercentage -> {
Assert.isTrue(isHeapPercentageValid(evictionOffHeapPercentage), String.format(
"evictionOffHeapPercentage [%s] is not valid; must be >= 0.0 and <= 100.0", evictionOffHeapPercentage));
cache.getResourceManager().setEvictionOffHeapPercentage(evictionOffHeapPercentage);
});
}
/* (non-Javadoc) */
private void registerJndiDataSources() {
@@ -865,6 +891,22 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
return criticalHeapPercentage;
}
/**
* Set the cache's critical off-heap percentage property.
*
* @param criticalOffHeapPercentage floating point value indicating the critical off-heap percentage.
*/
public void setCriticalOffHeapPercentage(Float criticalOffHeapPercentage) {
this.criticalOffHeapPercentage = criticalOffHeapPercentage;
}
/**
* @return the criticalOffHeapPercentage
*/
public Float getCriticalOffHeapPercentage() {
return this.criticalOffHeapPercentage;
}
/**
* Sets an instance of the DynamicRegionSupport to support Dynamic Regions in this GemFire Cache.
*
@@ -917,6 +959,22 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
return evictionHeapPercentage;
}
/**
* Set the cache's eviction off-heap percentage property.
*
* @param evictionOffHeapPercentage float-point value indicating the percentage of off-heap use triggering eviction.
*/
public void setEvictionOffHeapPercentage(Float evictionOffHeapPercentage) {
this.evictionOffHeapPercentage = evictionOffHeapPercentage;
}
/**
* @return the evictionOffHeapPercentage
*/
public Float getEvictionOffHeapPercentage() {
return this.evictionOffHeapPercentage;
}
/**
* Requires GemFire 7.0 or higher
* @param gatewayConflictResolver defined as Object in the signature for backward

View File

@@ -64,6 +64,7 @@ class CacheParser extends AbstractSingleBeanDefinitionParser {
*/
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
super.doParse(element, builder);
registerGemFireBeanFactoryPostProcessors(getRegistry(parserContext));
@@ -74,7 +75,9 @@ class CacheParser extends AbstractSingleBeanDefinitionParser {
ParsingUtils.setPropertyValue(element, builder, "close");
ParsingUtils.setPropertyValue(element, builder, "copy-on-read");
ParsingUtils.setPropertyValue(element, builder, "critical-heap-percentage");
ParsingUtils.setPropertyValue(element, builder, "critical-off-heap-percentage");
ParsingUtils.setPropertyValue(element, builder, "eviction-heap-percentage");
ParsingUtils.setPropertyValue(element, builder, "eviction-off-heap-percentage");
ParsingUtils.setPropertyValue(element, builder, "enable-auto-reconnect");
ParsingUtils.setPropertyValue(element, builder, "lock-lease");
ParsingUtils.setPropertyValue(element, builder, "lock-timeout");
@@ -127,15 +130,18 @@ class CacheParser extends AbstractSingleBeanDefinitionParser {
/* (non-Javadoc) */
void registerGemFireBeanFactoryPostProcessors(BeanDefinitionRegistry registry) {
BeanDefinitionReaderUtils.registerWithGeneratedName(BeanDefinitionBuilder.genericBeanDefinition(
CustomEditorBeanFactoryPostProcessor.class).getBeanDefinition(), registry);
BeanDefinitionReaderUtils.registerWithGeneratedName(
BeanDefinitionBuilder.genericBeanDefinition(CustomEditorBeanFactoryPostProcessor.class)
.getBeanDefinition(), registry);
}
/* (non-Javadoc) */
private void parsePdxDiskStore(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
ParsingUtils.setPropertyValue(element, builder, "pdx-disk-store", "pdxDiskStoreName");
final String pdxDiskStoreName = element.getAttribute("pdx-disk-store");
String pdxDiskStoreName = element.getAttribute("pdx-disk-store");
if (!StringUtils.isEmpty(pdxDiskStoreName)) {
registerPdxDiskStoreAwareBeanFactoryPostProcessor(getRegistry(parserContext), pdxDiskStoreName);
@@ -144,20 +150,25 @@ class CacheParser extends AbstractSingleBeanDefinitionParser {
/* (non-Javadoc) */
void registerPdxDiskStoreAwareBeanFactoryPostProcessor(BeanDefinitionRegistry registry, String pdxDiskStoreName) {
BeanDefinitionReaderUtils.registerWithGeneratedName(
createPdxDiskStoreAwareBeanFactoryPostProcessorBeanDefinition(pdxDiskStoreName), registry);
}
/* (non-Javadoc) */
private AbstractBeanDefinition createPdxDiskStoreAwareBeanFactoryPostProcessorBeanDefinition(String pdxDiskStoreName) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
PdxDiskStoreAwareBeanFactoryPostProcessor.class);
BeanDefinitionBuilder builder =
BeanDefinitionBuilder.genericBeanDefinition(PdxDiskStoreAwareBeanFactoryPostProcessor.class);
builder.addConstructorArgValue(pdxDiskStoreName);
return builder.getBeanDefinition();
}
/* (non-Javadoc) */
private void parseDynamicRegionFactory(Element element, BeanDefinitionBuilder builder) {
Element dynamicRegionFactory = DomUtils.getChildElementByTagName(element, "dynamic-region-factory");
if (dynamicRegionFactory != null) {
@@ -169,7 +180,9 @@ class CacheParser extends AbstractSingleBeanDefinitionParser {
/* (non-Javadoc) */
private BeanDefinitionBuilder buildDynamicRegionSupport(Element dynamicRegionFactory) {
if (dynamicRegionFactory != null) {
BeanDefinitionBuilder dynamicRegionSupport = BeanDefinitionBuilder.genericBeanDefinition(
CacheFactoryBean.DynamicRegionSupport.class);
@@ -205,17 +218,21 @@ class CacheParser extends AbstractSingleBeanDefinitionParser {
/* (non-Javadoc) */
private void parseJndiBindings(Element element, BeanDefinitionBuilder builder) {
List<Element> jndiBindings = DomUtils.getChildElementsByTagName(element, "jndi-binding");
if (!CollectionUtils.isEmpty(jndiBindings)) {
ManagedList<Object> jndiDataSources = new ManagedList<Object>(jndiBindings.size());
for (Element jndiBinding : jndiBindings) {
BeanDefinitionBuilder jndiDataSource = BeanDefinitionBuilder.genericBeanDefinition(
CacheFactoryBean.JndiDataSource.class);
// NOTE 'jndi-name' and 'type' are required by the XSD so we should have at least 2 attributes.
NamedNodeMap attributes = jndiBinding.getAttributes();
ManagedMap<String, String> jndiAttributes = new ManagedMap<String, String>(attributes.getLength());
for (int index = 0, length = attributes.getLength(); index < length; index++) {
@@ -260,6 +277,7 @@ class CacheParser extends AbstractSingleBeanDefinitionParser {
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {
String name = super.resolveId(element, definition, parserContext);
if (!StringUtils.hasText(name)) {

View File

@@ -187,6 +187,17 @@ Set the percentage of heap at or above which the cache is considered in danger o
due to garbage collection pauses or out of memory exceptions. Changing this value can cause a LowMemoryException to
be thrown during certain cache operation. This feature requires additional VM flags to perform properly (see the
JavaDocs for org.apache.geode.cache.control.ResourceManager for more information).
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="critical-off-heap-percentage">
<xsd:annotation>
<xsd:documentation
source="org.apache.geode.cache.control.ResourceManager"><![CDATA[
Set the percentage of off-heap at or above which the cache is considered in danger of becoming inoperable
due to out of memory errors. Changing this value can cause LowMemoryException to be thrown. Only one change
to this attribute or the eviction off-heap percentage will be allowed at any given time and its effect will be
fully realized before the next change is allowed.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
@@ -197,6 +208,16 @@ JavaDocs for org.apache.geode.cache.control.ResourceManager for more information
Set the percentage of heap at or above which the eviction should begin on Regions configured for HeapLRU eviction.
This feature requires additional VM flags to perform properly (see the
JavaDocs for org.apache.geode.cache.control.ResourceManager for more information).
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="eviction-off-heap-percentage">
<xsd:annotation>
<xsd:documentation
source="org.apache.geode.cache.control.ResourceManager"><![CDATA[
Set the percentage of off-heap at or above which the eviction should begin on Regions configured for HeapLRU eviction.
Changing this value may cause eviction to begin immediately. Only one change to this attribute or critical off-heap
percentage will be allowed at any given time and its effect will be fully realized before the next change is allowed.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>