/** * @return a set of keys, intended for use by the various Region set operations such as * {@link EntriesSet} */ Set getRegionKeysForIteration() { return getRegionMap().keySet(); }
@Override public Collection<?> getRegionKeysForIteration(LocalRegion currRegion) { // return currRegion.getRegionKeysForIteration(); return currRegion.getRegionMap().regionEntries(); }
@Override public EvictionController getEvictionController() { return getRegionMap().getEvictionController(); }
/** Internal method for getting the underlying RegionEntry */ public RegionEntry getRegionEntry() { RegionEntry regionEntry = LocalRegion.this.getRegionMap().getEntry(this.key); if (regionEntry == null) { throw new EntryDestroyedException(this.key.toString()); } return regionEntry; }
public int testHookGetValuesOnDisk() { int result = 0; for (RegionEntry re : getRegionMap().regionEntries()) { if (re.getValueAsToken() == null) { result++; } } return result; }
public int testHookGetValuesInVM() { int result = 0; for (RegionEntry re : getRegionMap().regionEntries()) { if (re.getValueAsToken() == Token.NOT_A_TOKEN) { result++; } } return result; }
@Override protected void expireTombstone(Tombstone tombstone) { if (logger.isTraceEnabled(LogMarker.TOMBSTONE_VERBOSE)) { logger.trace(LogMarker.TOMBSTONE_VERBOSE, "removing expired tombstone {}", tombstone); } updateMemoryEstimate(-tombstone.getSize()); tombstone.region.getRegionMap().removeTombstone(tombstone.entry, tombstone, false, true); }
t.region.getRegionMap().removeTombstone(t.entry, t, false, true);
/** a fast estimate of total number of entries locally in the region */ public long getEstimatedLocalSize() { if (!this.isDestroyed) { long size; // if region has not been initialized yet, then get the estimate from // disk region's recovery map if available RegionMap regionMap; if (!this.initialized && this.diskRegion != null && (regionMap = this.diskRegion.getRecoveredEntryMap()) != null && (size = regionMap.size()) > 0) { return size; } if ((regionMap = getRegionMap()) != null) { return regionMap.size(); } } return 0; }
DataInputStream in = new DataInputStream(inputStream); try { RegionMap map = getRegionMap(); byte snapshotVersion = in.readByte(); if (snapshotVersion != SNAPSHOT_VERSION) {
/** * @return size after considering imageState */ @Override public int getRegionSize() { synchronized (getSizeGuard()) { int result = getRegionMap().size(); // if this is a client with no tombstones then we subtract the number // of entries being affected by register-interest refresh if (this.imageState.isClient() && !this.getConcurrencyChecksEnabled()) { return result - this.imageState.getDestroyedEntriesCount(); } return result - this.tombstoneCount.get(); } }
@Before public void setup() { region = mock(LocalRegion.class); event = mock(EntryEventImpl.class); eventID = mock(EventID.class); serverRegionProxy = mock(ServerRegionProxy.class); cancelCriterion = mock(CancelCriterion.class); exception = mock(PutAllPartialResultException.class); when(event.getEventId()).thenReturn(eventID); when(event.getCallbackArgument()).thenReturn(callbacks); when(region.hasServerProxy()).thenReturn(true); when(region.getServerProxy()).thenReturn(serverRegionProxy); when(region.getRegionMap()).thenReturn(mock(RegionMap.class)); when(region.getDataView()).thenReturn(mock(InternalDataView.class)); when(region.getCancelCriterion()).thenReturn(cancelCriterion); when(exception.getFailure()).thenReturn(cacheClosedException); when(cancelCriterion.generateCancelledException(cacheClosedException)) .thenReturn(cacheClosedException); }
/** * Allows null as new value to accommodate create with a null value. * * @param event the event object for this operation, with the exception that the oldValue * parameter is not yet filled in. The oldValue will be filled in by this operation. * @param lastModified the lastModified time to set with the value; if 0L then the lastModified * time will be set to now. * @return null if put not done; otherwise the put entry */ protected RegionEntry basicPutEntry(final EntryEventImpl event, final long lastModified) throws TimeoutException, CacheWriterException { discoverJTA(); TXStateInterface tx = getTXState(); // Note we are doing a load or netsearch result so it seems like we should set ifNew to true. // The entry should not yet exist. However since the non-tx code sets ifNew to false this code // will also. final boolean ifNew = false; if (isTX()) { tx.txPutEntry(event, ifNew, false, false, null); return null; } else { if (DistTXState.internalBeforeNonTXBasicPut != null) { DistTXState.internalBeforeNonTXBasicPut.run(); } return getRegionMap().basicPut(event, lastModified, ifNew, false, null, false, false); } }
private void createAndSubmitWeightedRegionEvictionTasks() { List<LocalRegion> allRegionList = getAllSortedRegionList(); float numEntriesInVM = 0; for (LocalRegion region : allRegionList) { if (region instanceof BucketRegion) { numEntriesInVM += ((BucketRegion) region).getSizeForEviction(); } else { numEntriesInVM += region.getRegionMap().sizeInVM(); } } for (LocalRegion region : allRegionList) { float regionEntryCount; if (region instanceof BucketRegion) { regionEntryCount = ((BucketRegion) region).getSizeForEviction(); } else { regionEntryCount = region.getRegionMap().sizeInVM(); } float percentage = regionEntryCount / numEntriesInVM; long bytesToEvictPerTask = (long) (getTotalBytesToEvict() * percentage); List<LocalRegion> regionsForSingleTask = new ArrayList<>(1); regionsForSingleTask.add(region); if (mustEvict()) { executeInThreadPool(new RegionEvictorTask(cache.getCachePerfStats(), regionsForSingleTask, this, bytesToEvictPerTask)); } else { break; } } }
protected boolean nonTXContainsKey(KeyInfo keyInfo) { boolean contains = getRegionMap().containsKey(keyInfo.getKey()); if (contains && this.imageState.isClient()) { // fix for bug #40871 - concurrent RI causes containsKey for destroyed entry // to return true RegionEntry regionEntry = this.entries.getEntry(keyInfo.getKey()); if (regionEntry == null || regionEntry.isDestroyedOrRemoved()) { contains = false; } } return contains; }
if (tombstone.region.getRegionMap().isTombstoneNotNeeded(tombstone.entry, tombstone.getEntryVersion())) { if (logger.isTraceEnabled(LogMarker.TOMBSTONE_VERBOSE)) {
private void unlockRVVForBulkOp() { ARMLockTestHook testHook = getRegionMap().getARMLockTestHook(); if (testHook != null) { testHook.beforeBulkRelease(this); } if (this.versionVector != null && this.getDataPolicy().withReplication()) { this.versionVector.releaseCacheModificationLock(this); } if (testHook != null) { testHook.afterBulkRelease(this); } }
LocalRegion region = iterator.next(); try { long bytesEvicted = region.getRegionMap().centralizedLruUpdateCallback(); if (bytesEvicted == 0) { iterator.remove();
/** * bug #46924 - putAll can be partially applied when a clear() occurs, leaving the cache in an * inconsistent state. Set the RVV to "cache op in progress" so clear() will block until the * putAll completes. This won't work for non-replicate regions though since they uses one-hop * during basicPutPart2 to get a valid version tag. */ private void lockRVVForBulkOp() { ARMLockTestHook testHook = getRegionMap().getARMLockTestHook(); if (testHook != null) { testHook.beforeBulkLock(this); } if (this.versionVector != null && this.getDataPolicy().withReplication()) { this.versionVector.lockForCacheModification(this); } if (testHook != null) { testHook.afterBulkLock(this); } }
/** * Okay, deep breath. Instead of basing the LRU calculation on the number of entries in the region * or on their "size" (which turned out to be incorrectly estimated in the general case), we use * the amount of memory currently in use. If the amount of memory current in use * {@linkplain Runtime#maxMemory} - {@linkplain Runtime#freeMemory} is greater than the overflow * threshold, then we evict the LRU entry. */ @Override public boolean mustEvict(EvictionCounters stats, InternalRegion region, int delta) { InternalCache cache = (InternalCache) region.getRegionService(); boolean offheap = region.getAttributes().getOffHeap(); boolean shouldEvict = cache.getInternalResourceManager().getMemoryMonitor(offheap).getState().isEviction(); if (region instanceof BucketRegion) { return shouldEvict && ((BucketRegion) region).getSizeForEviction() > 0; } return shouldEvict && ((LocalRegion) region).getRegionMap().sizeInVM() > 0; }