public boolean isNoEviction() { return getAction() == EvictionAction.NONE; }
protected boolean isEntryEvictDestroyEnabled() { return getEvictionAttributes() != null && EvictionAction.LOCAL_DESTROY.equals(getEvictionAttributes().getAction()); }
@Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (!(obj instanceof EvictionAttributes)) { return false; } final EvictionAttributes other = (EvictionAttributes) obj; if (!getAlgorithm().equals(other.getAlgorithm())) { return false; } if (!getAction().equals(other.getAction())) { return false; } if (getMaximum() != other.getMaximum()) { return false; } return true; }
@Override public String toString() { final StringBuilder buffer = new StringBuilder(128); buffer.append(" algorithm=").append(this.getAlgorithm()); if (!this.getAlgorithm().isNone()) { buffer.append("; action=").append(this.getAction()); if (!getAlgorithm().isLRUHeap()) { buffer.append("; maximum=").append(this.getMaximum()); } if (this.getObjectSizer() != null) { buffer.append("; sizer=").append(this.getObjectSizer()); } } return buffer.toString(); }
/** * copy constructor */ public EvictionAttributesImpl(EvictionAttributes other) { this.algorithm = other.getAlgorithm(); this.sizer = other.getObjectSizer(); this.maximum = other.getMaximum(); this.action = other.getAction(); }
protected boolean isOverflowToDisk(final Region region) { return (region.getAttributes().getEvictionAttributes() != null && EvictionAction.OVERFLOW_TO_DISK .equals(region.getAttributes().getEvictionAttributes().getAction())); }
/** * The 3rd step of EvictionAttributes validation, where mutation is acceptible This should be done * before buckets are created. Validate EvictionAttributes with respect to localMaxMemory * potentially changing the eviction attributes. * * @see AttributesFactory#validateAttributes(RegionAttributes) * @see #validateDistributedEvictionAttributes(EvictionAttributes) */ void validateEvictionAttributesAgainstLocalMaxMemory() { final EvictionAttributes ea = pr.getEvictionAttributes(); if (pr.getLocalMaxMemory() == 0 && !ea.getAction().isNone()) { // This is an accessor which won't ever do eviction, say so logger.info( "EvictionAttributes {} will have no effect for Partitioned Region {} on this VM because localMaxMemory is {}.", new Object[] {ea, pr.getFullPath(), Integer.valueOf(pr.localMaxMemory)}); } }
private boolean isOverflowEnabled() { EvictionAttributes ea = getAttributes().getEvictionAttributes(); return ea != null && ea.getAction().isOverflowToDisk(); }
/** * Dump the attributes which are common across the PR to the string builder. */ public void dumpCommonAttributes(StringBuilder msg) { msg.append("\n\tlru=").append(getEvictionAttributes().getAlgorithm()); if (!getEvictionAttributes().getAlgorithm().isNone()) { msg.append("\n\tlruAction=").append(getEvictionAttributes().getAction()); if (!getEvictionAttributes().getAlgorithm().isLRUHeap()) { msg.append("\n\tlruLimit=").append(getEvictionAttributes().getMaximum()); } } msg.append("\n\tconcurrencyLevel=").append(getConcurrencyLevel()); msg.append("\n\tinitialCapacity=").append(getInitialCapacity()); msg.append("\n\tloadFactor=").append(getLoadFactor()); msg.append("\n\toffHeap=").append(getOffHeap()); msg.append("\n\tstatisticsEnabled=").append(getStatisticsEnabled()); msg.append("\n\tdrId=").append(getId()); msg.append("\n\tisBucket=").append(isBucket()); msg.append("\n\tclearEntryId=").append(getClearOplogEntryId()); msg.append("\n\tflags=").append(getFlags()); }
static void validateRegionAttributes(RegionAttributes attrs) { 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"); } }
public EvictionAttributesInfo(EvictionAttributes ea) { EvictionAction evictAction = ea.getAction(); if (evictAction != null) { evictionAction = evictAction.toString(); } EvictionAlgorithm evictionAlgo = ea.getAlgorithm(); if (evictionAlgo != null) { evictionAlgorithm = evictionAlgo.toString(); } evictionMaxValue = ea.getMaximum(); }
public EvictionAttributesInfo(EvictionAttributes ea) { EvictionAction evictAction = ea.getAction(); if (evictAction != null) { evictionAction = evictAction.toString(); } EvictionAlgorithm evictionAlgo = ea.getAlgorithm(); if (evictionAlgo != null) { evictionAlgorithm = evictionAlgo.toString(); } evictionMaxValue = ea.getMaximum(); }
@Test public void testIsRegionOverflowToDiskWhenEvictionActionIsOverflowToDisk() { final Region mockRegion = mock(Region.class, "Region"); final RegionAttributes mockRegionAttributes = mock(RegionAttributes.class, "RegionAttributes"); final EvictionAttributes mockEvictionAttributes = mock(EvictionAttributes.class, "EvictionAttributes"); when(mockRegion.getAttributes()).thenReturn(mockRegionAttributes); when(mockRegionAttributes.getEvictionAttributes()).thenReturn(mockEvictionAttributes); when(mockEvictionAttributes.getAction()).thenReturn(EvictionAction.OVERFLOW_TO_DISK); final DescribeDiskStoreFunction function = new DescribeDiskStoreFunction(); assertThat(function.isOverflowToDisk(mockRegion)).isTrue(); verify(mockRegion, times(2)).getAttributes(); verify(mockRegionAttributes, times(2)).getEvictionAttributes(); }
@Test public void testIsRegionOverflowToDiskWhenEvictionActionIsLocalDestroy() { final Region mockRegion = mock(Region.class, "Region"); final RegionAttributes mockRegionAttributes = mock(RegionAttributes.class, "RegionAttributes"); final EvictionAttributes mockEvictionAttributes = mock(EvictionAttributes.class, "EvictionAttributes"); when(mockRegion.getAttributes()).thenReturn(mockRegionAttributes); when(mockRegionAttributes.getEvictionAttributes()).thenReturn(mockEvictionAttributes); when(mockEvictionAttributes.getAction()).thenReturn(EvictionAction.LOCAL_DESTROY); final DescribeDiskStoreFunction function = new DescribeDiskStoreFunction(); assertThat(function.isOverflowToDisk(mockRegion)).isFalse(); verify(mockRegion, times(2)).getAttributes(); verify(mockRegionAttributes, times(2)).getEvictionAttributes(); }
@Test public void testIsRegionUsingDiskStoreWhenOverflowing() { final String diskStoreName = "testDiskStore"; final Region mockRegion = mock(Region.class, "Region"); final DiskStore mockDiskStore = mock(DiskStore.class, "DiskStore"); final RegionAttributes mockRegionAttributes = mock(RegionAttributes.class, "RegionAttributes"); final EvictionAttributes mockEvictionAttributes = mock(EvictionAttributes.class, "EvictionAttributes"); when(mockRegion.getAttributes()).thenReturn(mockRegionAttributes); when(mockRegionAttributes.getDataPolicy()).thenReturn(DataPolicy.PARTITION); when(mockRegionAttributes.getDiskStoreName()).thenReturn(diskStoreName); when(mockRegionAttributes.getEvictionAttributes()).thenReturn(mockEvictionAttributes); when(mockEvictionAttributes.getAction()).thenReturn(EvictionAction.OVERFLOW_TO_DISK); when(mockDiskStore.getName()).thenReturn(diskStoreName); final DescribeDiskStoreFunction function = new DescribeDiskStoreFunction(); assertThat(function.isUsingDiskStore(mockRegion, mockDiskStore)).isTrue(); verify(mockRegion, times(4)).getAttributes(); verify(mockRegionAttributes, times(2)).getEvictionAttributes(); }
@Override public void run2() throws CacheException { RegionAttributes<Object, Object> ra = getRegionAttributes(); AttributesFactory<Object, Object> factory = new AttributesFactory<>(ra); if (ra.getEvictionAttributes() == null || !ra.getEvictionAttributes().getAction().isOverflowToDisk()) { factory.setDiskStoreName(null); } factory.setDataPolicy(DataPolicy.REPLICATE); createRegion(name, factory.create()); } });
@Override public void run2() throws CacheException { RegionAttributes<Object, Object> ra = getRegionAttributes(); AttributesFactory<Object, Object> factory = new AttributesFactory<>(ra); if (ra.getEvictionAttributes() == null || !ra.getEvictionAttributes().getAction().isOverflowToDisk()) { factory.setDiskStoreName(null); } factory.setDataPolicy(DataPolicy.REPLICATE); factory.addCacheListener(new MirroredDataFromNonMirroredListener()); createRegion(name, factory.create()); } });
public int getSizeForEviction() { EvictionAttributes ea = this.getAttributes().getEvictionAttributes(); if (ea == null) return 0; EvictionAlgorithm algo = ea.getAlgorithm(); if (!algo.isLRUHeap()) return 0; EvictionAction action = ea.getAction(); int size = action.isLocalDestroy() ? this.getRegionMap().sizeInVM() : (int) this.getNumEntriesInVM(); return size; }
public IndexManager(InternalCache cache, Region region) { this.cache = cache; this.region = region; // must be a SortedMap to ensure the indexes are iterated over in fixed // order // to avoid deadlocks when acquiring locks // indexes = Collections.synchronizedSortedMap(new TreeMap()); indexMaintenanceSynchronous = region.getAttributes().getIndexMaintenanceSynchronous(); isOverFlowToDisk = region.getAttributes().getEvictionAttributes().getAction().isOverflowToDisk(); this.offHeap = region.getAttributes().getOffHeap(); if (!indexMaintenanceSynchronous) { updater = new IndexUpdaterThread(this.INDEX_MAINTENANCE_BUFFER, "OqlIndexUpdater:" + region.getFullPath()); updater.start(); } }
public static EvictionAttributesData getEvictionAttributesData(RegionAttributes regAttrs) { String algorithm = ""; Integer maximum = null; if (regAttrs.getEvictionAttributes().getAlgorithm() != null) { algorithm = regAttrs.getEvictionAttributes().getAlgorithm().toString(); if (algorithm.equals(EvictionAlgorithm.NONE.toString())) { EvictionAttributesData evictionAttributesData = new EvictionAttributesData(algorithm, null, EvictionAlgorithm.NONE.toString()); return evictionAttributesData; } if (!regAttrs.getEvictionAttributes().getAlgorithm().isLRUHeap()) { maximum = regAttrs.getEvictionAttributes().getMaximum(); } } String action = regAttrs.getEvictionAttributes().getAction().toString(); EvictionAttributesData evictionAttributesData = new EvictionAttributesData(algorithm, maximum, action); return evictionAttributesData; }