use of org.apache.geode.cache.EvictionAlgorithm in project geode by apache.
the class AbstractLRURegionMap method initialize.
protected void initialize(Object owner, Attributes attr, InternalRegionArguments internalRegionArgs) {
super.initialize(owner, attr, internalRegionArgs, true);
EvictionAlgorithm ea;
LRUAlgorithm ec;
if (owner instanceof LocalRegion) {
ea = ((LocalRegion) owner).getEvictionAttributes().getAlgorithm();
ec = ((LocalRegion) owner).getEvictionController();
} else if (owner instanceof PlaceHolderDiskRegion) {
PlaceHolderDiskRegion phdr = (PlaceHolderDiskRegion) owner;
ea = phdr.getActualLruAlgorithm();
ec = phdr.getEvictionAttributes().createEvictionController(null, phdr.getOffHeap());
} else {
throw new IllegalStateException("expected LocalRegion or PlaceHolderDiskRegion");
}
this.evictionController = ec;
if (ea.isLRUMemory()) {
((MemLRUCapacityController) ec).setEntryOverHead(getEntryOverHead());
}
if (ea.isLRUHeap()) {
((HeapLRUCapacityController) ec).setEntryOverHead(getEntryOverHead());
}
_setCCHelper(getHelper(ec));
/*
* modification for LIFO Logic incubation
*
*/
if (ea == EvictionAlgorithm.LIFO_ENTRY || ea == EvictionAlgorithm.LIFO_MEMORY) {
_setLruList(new NewLIFOClockHand(owner, _getCCHelper(), internalRegionArgs));
} else {
_setLruList(new NewLRUClockHand(owner, _getCCHelper(), internalRegionArgs));
}
}
use of org.apache.geode.cache.EvictionAlgorithm in project geode by apache.
the class LuceneRegionListener method beforeCreate.
@Override
public RegionAttributes beforeCreate(Region parent, String regionName, RegionAttributes attrs, InternalRegionArguments internalRegionArgs) {
RegionAttributes updatedRA = attrs;
String path = parent == null ? "/" + regionName : parent.getFullPath() + "/" + regionName;
if (path.equals(this.regionPath)) {
if (!attrs.getDataPolicy().withPartitioning()) {
// replicated region
throw new UnsupportedOperationException("Lucene indexes on replicated regions are not supported");
}
// For now we cannot support eviction with local destroy.
// Eviction with overflow to disk still needs to be supported
EvictionAttributes evictionAttributes = attrs.getEvictionAttributes();
EvictionAlgorithm evictionAlgorithm = evictionAttributes.getAlgorithm();
if (evictionAlgorithm != EvictionAlgorithm.NONE && evictionAttributes.getAction().isLocalDestroy()) {
throw new UnsupportedOperationException("Lucene indexes on regions with eviction and action local destroy are not supported");
}
String aeqId = LuceneServiceImpl.getUniqueIndexName(this.indexName, this.regionPath);
if (!attrs.getAsyncEventQueueIds().contains(aeqId)) {
AttributesFactory af = new AttributesFactory(attrs);
af.addAsyncEventQueueId(aeqId);
updatedRA = af.create();
}
// Add index creation profile
internalRegionArgs.addCacheServiceProfile(new LuceneIndexCreationProfile(this.indexName, this.regionPath, this.fields, this.analyzer, this.fieldAnalyzers));
luceneIndex = this.service.beforeDataRegionCreated(this.indexName, this.regionPath, attrs, this.analyzer, this.fieldAnalyzers, aeqId, this.fields);
// Add internal async event id
internalRegionArgs.addInternalAsyncEventQueueId(aeqId);
}
return updatedRA;
}
use of org.apache.geode.cache.EvictionAlgorithm 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;
}
Aggregations