@Override public int hashCode() { return this.getAlgorithm().hashCode() ^ this.getMaximum(); }
@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(); }
/** * 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()); }
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();
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(); }
if (!ea.getAlgorithm().isLRUHeap() && ea.getMaximum() != prconfEa.getMaximum()) { logger.warn( "For Partitioned Region {} the locally configured EvictionAttributes {} do not match with other EvictionAttributes {} and may cause misses during reads from VMs with smaller maximums.",
@Test public void evictionAttributes() throws Exception { args.setEvictionAttributes(null, 0, 0, null); assertThat(args.getEvictionAttributes()).isNull(); args.setEvictionAttributes("local-destroy", null, null, null); EvictionAttributes attributes = args.getEvictionAttributes() .convertToEvictionAttributes(); assertThat(attributes.getAlgorithm()).isEqualTo(EvictionAlgorithm.LRU_HEAP); assertThat(attributes.getAction()).isEqualTo(EvictionAction.LOCAL_DESTROY); assertThat(attributes.getMaximum()).isEqualTo(0); args.setEvictionAttributes("overflow-to-disk", 1000, null, null); EvictionAttributes attributes1 = args.getEvictionAttributes() .convertToEvictionAttributes(); assertThat(attributes1.getAlgorithm()).isEqualTo(EvictionAlgorithm.LRU_MEMORY); assertThat(attributes1.getAction()).isEqualTo(EvictionAction.OVERFLOW_TO_DISK); assertThat(attributes1.getMaximum()).isEqualTo(1000); args.setEvictionAttributes("local-destroy", null, 1000, null); EvictionAttributes attributes2 = args.getEvictionAttributes() .convertToEvictionAttributes(); assertThat(attributes2.getAlgorithm()).isEqualTo(EvictionAlgorithm.LRU_ENTRY); assertThat(attributes2.getAction()).isEqualTo(EvictionAction.LOCAL_DESTROY); assertThat(attributes2.getMaximum()).isEqualTo(1000); }
Optional<String> objectSizerClass = Optional.ofNullable(getObjectSizer()) .map(c -> c.getClass().toString()); Integer maximum = getMaximum();
/** * Create and return the appropriate eviction controller using the attributes provided. */ public static EvictionController create(EvictionAttributes evictionAttributes, boolean isOffHeap, StatisticsFactory statsFactory, String statsName) { EvictionAlgorithm algorithm = evictionAttributes.getAlgorithm(); EvictionAction action = evictionAttributes.getAction(); ObjectSizer sizer = evictionAttributes.getObjectSizer(); int maximum = evictionAttributes.getMaximum(); EvictionStats evictionStats; EvictionCounters evictionCounters; if (algorithm == EvictionAlgorithm.LRU_HEAP) { evictionStats = new HeapLRUStatistics(statsFactory, statsName); evictionCounters = new EvictionCountersImpl(evictionStats); return new HeapLRUController(evictionCounters, action, sizer, algorithm); } if (algorithm == EvictionAlgorithm.LRU_MEMORY || algorithm == EvictionAlgorithm.LIFO_MEMORY) { evictionStats = new MemoryLRUStatistics(statsFactory, statsName); evictionCounters = new EvictionCountersImpl(evictionStats); return new MemoryLRUController(evictionCounters, maximum, sizer, action, isOffHeap, algorithm); } if (algorithm == EvictionAlgorithm.LRU_ENTRY || algorithm == EvictionAlgorithm.LIFO_ENTRY) { evictionStats = new CountLRUStatistics(statsFactory, statsName); evictionCounters = new EvictionCountersImpl(evictionStats); return new CountLRUEviction(evictionCounters, maximum, action, algorithm); } throw new IllegalStateException("Unhandled algorithm " + algorithm); }
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; }
/** * Note: hydra invokes this with setRefid=false. */ public void setAttributes(RegionAttributes attrs, boolean setRefid) { this.hasAttributes = true; if (attrs instanceof RegionAttributesCreation) { this.attrs = (RegionAttributesCreation) attrs; } else { this.attrs = new RegionAttributesCreation(this.cache, attrs, false); } if ((setRefid && (this.attrs.getRefid() == null))) { this.attrs.setRefid(getRefid()); } if (attrs.getPartitionAttributes() != null && attrs.getEvictionAttributes() != null && attrs.getEvictionAttributes().getAlgorithm().isLRUMemory() && attrs.getPartitionAttributes().getLocalMaxMemory() != 0 && attrs.getEvictionAttributes() .getMaximum() != attrs.getPartitionAttributes().getLocalMaxMemory()) { getCache().getLogger().warning(String.format( "For region %s with data policy PARTITION, memory LRU eviction attribute maximum has been reset from %sMB to local-max-memory %sMB", new Object[] {this.getName(), attrs.getEvictionAttributes().getMaximum(), attrs.getPartitionAttributes().getLocalMaxMemory()})); this.attrs.setEvictionAttributes(attrs.getEvictionAttributes().createLRUMemoryAttributes( attrs.getPartitionAttributes().getLocalMaxMemory(), attrs.getEvictionAttributes().getObjectSizer(), attrs.getEvictionAttributes().getAction())); } }
public void dump(PrintStream printStream) { String name = getName(); if (isBucket() && !logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY_VERBOSE)) { name = getPrName(); } String msg = name + ":" + " -lru=" + getEvictionAttributes().getAlgorithm(); if (!getEvictionAttributes().getAlgorithm().isNone()) { msg += " -lruAction=" + getEvictionAttributes().getAction(); if (!getEvictionAttributes().getAlgorithm().isLRUHeap()) { msg += " -lruLimit=" + getEvictionAttributes().getMaximum(); } } msg += " -concurrencyLevel=" + getConcurrencyLevel() + " -initialCapacity=" + getInitialCapacity() + " -loadFactor=" + getLoadFactor() + " -offHeap=" + getOffHeap() + " -compressor=" + (getCompressorClassName() == null ? "none" : getCompressorClassName()) + " -statisticsEnabled=" + getStatisticsEnabled(); if (logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY_VERBOSE)) { msg += " drId=" + getId() + " isBucket=" + isBucket() + " clearEntryId=" + getClearOplogEntryId() + " MyInitializingID=<" + getMyInitializingID() + ">" + " MyPersistentID=<" + getMyPersistentID() + ">" + " onlineMembers=" + getOnlineMembers() + " offlineMembers=" + getOfflineMembers() + " equalsMembers=" + getOfflineAndEqualMembers(); } printStream.println(msg); }
byte raLruAlgorithm = (byte) (ra.getEvictionAttributes().getAlgorithm().getValue()); byte raLruAction = (byte) (ra.getEvictionAttributes().getAction().getValue()); int raLruLimit = ra.getEvictionAttributes().getMaximum(); if (isRecreated()) {
private BiConsumer<Region<?, ?>, Health.Builder> withRegionEvictionPolicyDetails() { return (region, builder) -> { String regionName = region.getName(); Optional.of(region) .filter(this::isRegionAttributesPresent) .map(Region::getAttributes) .map(RegionAttributes::getEvictionAttributes) .ifPresent(evictionAttributes -> { builder.withDetail(cacheRegionEvictionKey(regionName, "action"), String.valueOf(evictionAttributes.getAction())) .withDetail(cacheRegionEvictionKey(regionName, "algorithm"), String.valueOf(evictionAttributes.getAlgorithm())); // NOTE: Careful! Eviction Maximum does not apply when Eviction Algorithm is Heap LRU. Optional.ofNullable(evictionAttributes.getAlgorithm()) .filter(it -> !it.isLRUHeap()) .ifPresent(it -> builder .withDetail(cacheRegionEvictionKey(regionName,"maximum"), evictionAttributes.getMaximum())); }); }; }
when(mockEvictionAttibutes.getMaximum()).thenAnswer(newGetter(evictionMaximum)); when(mockEvictionAttibutes.getObjectSizer()).thenAnswer(newGetter(regionEvictionAttributes::getObjectSizer));
protected void assertEvictionAttributes(EvictionAttributes evictionAttributes, EvictionAction expectedAction, EvictionAlgorithm expectedAlgorithm, int expectedMaximum) { assertNotNull("EvictionAttributes must not be null!", evictionAttributes); assertEquals(expectedAction, evictionAttributes.getAction()); assertEquals(expectedAlgorithm, evictionAttributes.getAlgorithm()); assertEquals(expectedMaximum, evictionAttributes.getMaximum()); }