Search in sources :

Example 1 with EvictionAlgorithm

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));
    }
}
Also used : HeapLRUCapacityController(org.apache.geode.internal.cache.lru.HeapLRUCapacityController) LRUAlgorithm(org.apache.geode.internal.cache.lru.LRUAlgorithm) MemLRUCapacityController(org.apache.geode.internal.cache.lru.MemLRUCapacityController) NewLIFOClockHand(org.apache.geode.internal.cache.lru.NewLIFOClockHand) NewLRUClockHand(org.apache.geode.internal.cache.lru.NewLRUClockHand) EvictionAlgorithm(org.apache.geode.cache.EvictionAlgorithm)

Example 2 with EvictionAlgorithm

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;
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) EvictionAlgorithm(org.apache.geode.cache.EvictionAlgorithm)

Example 3 with EvictionAlgorithm

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;
}
Also used : EvictionAction(org.apache.geode.cache.EvictionAction) EvictionAlgorithm(org.apache.geode.cache.EvictionAlgorithm)

Aggregations

EvictionAlgorithm (org.apache.geode.cache.EvictionAlgorithm)3 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 EvictionAction (org.apache.geode.cache.EvictionAction)1 EvictionAttributes (org.apache.geode.cache.EvictionAttributes)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 HeapLRUCapacityController (org.apache.geode.internal.cache.lru.HeapLRUCapacityController)1 LRUAlgorithm (org.apache.geode.internal.cache.lru.LRUAlgorithm)1 MemLRUCapacityController (org.apache.geode.internal.cache.lru.MemLRUCapacityController)1 NewLIFOClockHand (org.apache.geode.internal.cache.lru.NewLIFOClockHand)1 NewLRUClockHand (org.apache.geode.internal.cache.lru.NewLRUClockHand)1