use of org.apache.geode.cache.EvictionAction in project geode by apache.
the class CacheXmlGenerator method generate.
private void generate(EvictionAttributes ea) throws SAXException {
EvictionAction eAction = ea.getAction();
if (eAction.isNone()) {
return;
}
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", ACTION, "", eAction.toString());
handler.startElement("", EVICTION_ATTRIBUTES, EVICTION_ATTRIBUTES, EMPTY);
if (ea.getAlgorithm() == EvictionAlgorithm.LRU_ENTRY) {
atts.addAttribute("", "", MAXIMUM, "", String.valueOf(ea.getMaximum()));
handler.startElement("", LRU_ENTRY_COUNT, LRU_ENTRY_COUNT, atts);
handler.endElement("", LRU_ENTRY_COUNT, LRU_ENTRY_COUNT);
} else if (ea.getAlgorithm() == EvictionAlgorithm.LRU_MEMORY) {
atts.addAttribute("", "", MAXIMUM, "", String.valueOf(ea.getMaximum()));
handler.startElement("", LRU_MEMORY_SIZE, LRU_MEMORY_SIZE, atts);
ObjectSizer os = ea.getObjectSizer();
if (os != null && os != ObjectSizer.DEFAULT) {
generate((Declarable) os, false);
}
handler.endElement("", LRU_MEMORY_SIZE, LRU_MEMORY_SIZE);
} else if (ea.getAlgorithm() == EvictionAlgorithm.LRU_HEAP) {
handler.startElement("", LRU_HEAP_PERCENTAGE, LRU_HEAP_PERCENTAGE, atts);
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
ObjectSizer os = ea.getObjectSizer();
if (!(os instanceof SizeClassOnceObjectSizer)) {
if (os != null) {
generate((Declarable) os, false);
}
}
}
handler.endElement("", LRU_HEAP_PERCENTAGE, LRU_HEAP_PERCENTAGE);
} else {
// all other algos are ignored
}
handler.endElement("", EVICTION_ATTRIBUTES, EVICTION_ATTRIBUTES);
}
use of org.apache.geode.cache.EvictionAction in project geode by apache.
the class CacheXmlParser method startLRUEntryCount.
/**
* Create an <code>lru-entry-count</code> eviction controller, assigning it to the enclosed
* <code>region-attributes</code>. Allow any combination of attributes to be provided. Use the
* default values for any attribute that is not provided.
*
* @param atts
*/
/**
* @param atts
*/
private void startLRUEntryCount(Attributes atts) {
final String maximum = atts.getValue(MAXIMUM);
int max = LRUCapacityController.DEFAULT_MAXIMUM_ENTRIES;
if (maximum != null) {
max = parseInt(maximum);
}
final String lruAction = atts.getValue(ACTION);
EvictionAction action = EvictionAction.DEFAULT_EVICTION_ACTION;
if (lruAction != null) {
action = EvictionAction.parseAction(lruAction);
}
RegionAttributesCreation regAttrs = peekRegionAttributesContext(LRU_ENTRY_COUNT);
regAttrs.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(max, action));
}
use of org.apache.geode.cache.EvictionAction in project geode by apache.
the class AbstractLRURegionMap method evictEntry.
/**
* Evicts the given entry from the cache. Returns the total number of bytes evicted. 1. For action
* local destroy, returns size(key + value) 2. For action evict to disk, returns size(value)
*
* @return number of bytes evicted, zero if no eviction took place
*/
protected int evictEntry(LRUEntry entry, LRUStatistics stats) throws RegionClearedException {
EvictionAction action = _getCCHelper().getEvictionAction();
LocalRegion region = _getOwner();
if (action.isLocalDestroy()) {
int size = entry.getEntrySize();
if (region.evictDestroy(entry)) {
return size;
} else {
return 0;
}
} else if (action.isOverflowToDisk()) {
Assert.assertTrue(entry instanceof DiskEntry);
int change = 0;
synchronized (entry) {
if (entry.isInUseByTransaction()) {
entry.unsetEvicted();
if (logger.isTraceEnabled(LogMarker.LRU)) {
logger.trace(LogMarker.LRU, "No eviction of transactional entry for key={}", entry.getKey());
}
return 0;
}
// Do the following check while synchronized to fix bug 31761
Token entryVal = entry.getValueAsToken();
if (entryVal == null) {
if (logger.isTraceEnabled(LogMarker.LRU)) {
logger.trace(LogMarker.LRU, "no need to evict already evicted key={}", entry.getKey());
}
return 0;
}
if (Token.isInvalidOrRemoved(entryVal)) {
// and the destroyed token needs to stay in memory
if (logger.isTraceEnabled(LogMarker.LRU)) {
logger.trace(LogMarker.LRU, "no need to evict {} token for key={}", entryVal, entry.getKey());
}
return 0;
}
entry.setEvicted();
change = DiskEntry.Helper.overflowToDisk((DiskEntry) entry, region, _getCCHelper());
}
boolean result = change < 0;
if (result) {
if (_getOwner() instanceof BucketRegion) {
BucketRegion bucketRegion = (BucketRegion) _getOwner();
bucketRegion.updateCounter(change);
// if(bucketRegion.getBucketAdvisor().isPrimary()){
stats.updateCounter(change);
// }
} else {
stats.updateCounter(change);
}
} else {
if (logger.isTraceEnabled(LogMarker.LRU)) {
logger.trace(LogMarker.LRU, "no need to evict token for key={} because moving its value to disk resulted in a net change of {} bytes.", entry.getKey(), change);
}
}
return change * -1;
} else {
throw new InternalGemFireException(LocalizedStrings.AbstractLRURegionMap_UNKNOWN_EVICTION_ACTION_0.toLocalizedString(action));
}
}
use of org.apache.geode.cache.EvictionAction in project geode by apache.
the class DiskInitFile method basicModifyRegion.
private String basicModifyRegion(boolean printInfo, DiskRegionView drv, String lruOption, String lruActionOption, String lruLimitOption, String concurrencyLevelOption, String initialCapacityOption, String loadFactorOption, String compressorClassNameOption, String statisticsEnabledOption, String offHeapOption, boolean printToConsole) {
byte lruAlgorithm = drv.getLruAlgorithm();
byte lruAction = drv.getLruAction();
int lruLimit = drv.getLruLimit();
int concurrencyLevel = drv.getConcurrencyLevel();
int initialCapacity = drv.getInitialCapacity();
float loadFactor = drv.getLoadFactor();
String compressorClassName = drv.getCompressorClassName();
boolean statisticsEnabled = drv.getStatisticsEnabled();
boolean offHeap = drv.getOffHeap();
StringBuffer sb = new StringBuffer();
final String lineSeparator = System.getProperty("line.separator");
if (lruOption != null) {
EvictionAlgorithm ea = EvictionAlgorithm.parseAction(lruOption);
if (ea != null) {
lruAlgorithm = (byte) ea.getValue();
} else {
throw new IllegalArgumentException("Expected lru to be one of the following: \"none\", \"lru-entry-count\", \"lru-heap-percentage\", or \"lru-memory-size\"");
}
if (ea.isNone()) {
lruAction = (byte) EvictionAction.NONE.getValue();
lruLimit = 0;
} else if (ea.isLRUHeap()) {
lruLimit = 0;
}
}
if (lruActionOption != null) {
EvictionAction ea = EvictionAction.parseAction(lruActionOption);
if (ea != null) {
lruAction = (byte) ea.getValue();
} else {
throw new IllegalArgumentException("Expected lruAction to be one of the following: \"none\", \"overflow-to-disk\", or \"local-destroy\"");
}
}
if (lruLimitOption != null) {
lruLimit = Integer.parseInt(lruLimitOption);
if (lruLimit < 0) {
throw new IllegalArgumentException("Expected lruLimit to be greater than or equal to zero");
}
}
if (concurrencyLevelOption != null) {
concurrencyLevel = Integer.parseInt(concurrencyLevelOption);
if (concurrencyLevel < 0) {
throw new IllegalArgumentException("Expected concurrencyLevel to be greater than or equal to zero");
}
}
if (initialCapacityOption != null) {
initialCapacity = Integer.parseInt(initialCapacityOption);
if (initialCapacity < 0) {
throw new IllegalArgumentException("Expected initialCapacity to be greater than or equal to zero");
}
}
if (loadFactorOption != null) {
loadFactor = Float.parseFloat(loadFactorOption);
if (loadFactor < 0.0) {
throw new IllegalArgumentException("Expected loadFactor to be greater than or equal to zero");
}
}
if (compressorClassNameOption != null) {
compressorClassName = (compressorClassNameOption.isEmpty() ? null : compressorClassNameOption);
}
if (statisticsEnabledOption != null) {
statisticsEnabled = Boolean.parseBoolean(statisticsEnabledOption);
if (!statisticsEnabled) {
// make sure it is "false"
if (!statisticsEnabledOption.equalsIgnoreCase("false")) {
throw new IllegalArgumentException("Expected statisticsEnabled to be \"true\" or \"false\"");
}
}
}
if (offHeapOption != null) {
offHeap = Boolean.parseBoolean(offHeapOption);
if (!offHeap) {
// make sure it is "false"
if (!offHeapOption.equalsIgnoreCase("false")) {
throw new IllegalArgumentException("Expected offHeap to be \"true\" or \"false\"");
}
}
}
sb.append("Before modification: ");
sb.append(lineSeparator);
sb.append(((PlaceHolderDiskRegion) drv).dump2());
sb.append(lineSeparator);
drv.setConfig(lruAlgorithm, lruAction, lruLimit, concurrencyLevel, initialCapacity, loadFactor, statisticsEnabled, drv.isBucket(), drv.getFlags(), drv.getPartitionName(), drv.getStartingBucketId(), compressorClassName, offHeap);
// Make sure the combined lru args can still produce a legal eviction attributes
// before writing them to disk.
((PlaceHolderDiskRegion) drv).getEvictionAttributes();
writeRegionConfig(drv);
sb.append("After modification: ");
sb.append(lineSeparator);
sb.append(((PlaceHolderDiskRegion) drv).dump2());
sb.append(lineSeparator);
String message = sb.toString();
if (printInfo && printToConsole) {
System.out.println(message);
}
return message;
}
use of org.apache.geode.cache.EvictionAction in project geode by apache.
the class CacheXmlParser method startLRUHeapPercentage.
/**
* Create an <code>lru-heap-percentage</code> eviction controller, assigning it to the enclosed
* <code>region-attributes</code>
*
* @param atts
*/
private void startLRUHeapPercentage(Attributes atts) {
final String lruAction = atts.getValue(ACTION);
EvictionAction action = EvictionAction.DEFAULT_EVICTION_ACTION;
if (lruAction != null) {
action = EvictionAction.parseAction(lruAction);
}
// Store for later addition of ObjectSizer, if any
stack.push(EvictionAttributes.createLRUHeapAttributes(null, action));
}
Aggregations