/** * update stats */ private void updateStatsForPut(long startPut) { getCachePerfStats().endPut(startPut, false); }
void incClearCount(LocalRegion lr) { if (lr != null && !(lr instanceof HARegion)) { CachePerfStats stats = lr.getCachePerfStats(); if (stats != null) { stats.incClearCount(); } } }
/** * Update stats */ private void updateStatsForInvalidate() { getCachePerfStats().incInvalidates(); }
/** * Update stats */ private void updateStatsForDestroy() { getCachePerfStats().incDestroys(); }
/** * Update CachePerfStats */ private void updateStatsForCreate() { getCachePerfStats().incCreates(); }
private static void assertNoClearTimeouts() { // if there are timeouts on waiting for version vector dominance then // some operation was not properly recorded in the VM throwing this // assertion error. All ops need to be recorded in the version vector assertThat(CCRegion.getCachePerfStats().getClearTimeouts()).describedAs( "expected there to be no timeouts - something is broken").isEqualTo(0); }
@Override public void run() { try { long stopTime = System.currentTimeMillis() + 5000; Random ran = new Random(System.currentTimeMillis()); while (System.currentTimeMillis() < stopTime) { for (int i = 0; i < 10; i++) { CCRegion.put("cckey" + i, new DeltaValue("ccvalue" + ran.nextInt())); } } long events = CCRegion.getCachePerfStats().getDeltaFailedUpdates(); assertThat(events > 0).describedAs("expected some failed deltas").isTrue(); } catch (CacheException e) { fail("while performing concurrent operations", e); } } };
@Override public void incEntryCount(int delta) { LocalRegion lr = _getOwner(); if (lr != null) { CachePerfStats stats = lr.getCachePerfStats(); if (stats != null) { stats.incEntryCount(delta); } } }
private void cacheWriteBeforeRegionClear(RegionEventImpl event) throws CacheWriterException, TimeoutException { // copy into local var to prevent race condition CacheWriter writer = basicGetWriter(); if (writer != null) { final long start = getCachePerfStats().startCacheWriterCall(); try { writer.beforeRegionClear(event); } finally { getCachePerfStats().endCacheWriterCall(start); } } serverRegionClear(event); }
private void setupLocalRegion() { when(owner.getCachePerfStats()).thenReturn(cachePerfStats); when(owner.getCache()).thenReturn(mock(InternalCache.class)); when(owner.getMyId()).thenReturn(myId); when(owner.getKeyInfo(any(), any(), any())).thenReturn(keyInfo); }
/** * @return true if cacheWrite was performed * @see DistributedRegion#cacheWriteBeforeRegionDestroy(RegionEventImpl) */ boolean cacheWriteBeforeRegionDestroy(RegionEventImpl event) throws CacheWriterException, TimeoutException { boolean result = false; // copy into local var to prevent race condition CacheWriter writer = basicGetWriter(); if (writer != null) { final long start = getCachePerfStats().startCacheWriterCall(); try { writer.beforeRegionDestroy(event); } finally { getCachePerfStats().endCacheWriterCall(start); } result = true; } serverRegionDestroy(event); return result; }
private static LocalRegion createOwner(boolean withConcurrencyChecks) { LocalRegion owner = mock(LocalRegion.class); CachePerfStats cachePerfStats = mock(CachePerfStats.class); when(owner.getCachePerfStats()).thenReturn(cachePerfStats); when(owner.getEvictionAttributes()).thenReturn(evictionAttributes); when(owner.getConcurrencyChecksEnabled()).thenReturn(withConcurrencyChecks); when(owner.getDataPolicy()).thenReturn(DataPolicy.REPLICATE); doThrow(EntryNotFoundException.class).when(owner).checkEntryNotFound(any()); return owner; }
protected TestableAbstractRegionMap(boolean withConcurrencyChecks, boolean isDistributedRegion, ConcurrentMapWithReusableEntries map, RegionEntryFactory factory, RegionEntry regionEntryForGetEntry) { super(null); this.regionEntryForGetEntry = regionEntryForGetEntry; LocalRegion owner = isDistributedRegion ? mock(DistributedRegion.class, RETURNS_DEEP_STUBS) : mock(LocalRegion.class); CachePerfStats cachePerfStats = mock(CachePerfStats.class); when(owner.getCachePerfStats()).thenReturn(cachePerfStats); when(owner.getConcurrencyChecksEnabled()).thenReturn(withConcurrencyChecks); when(owner.getDataPolicy()).thenReturn(DataPolicy.REPLICATE); when(owner.getScope()).thenReturn(Scope.LOCAL); when(owner.isInitialized()).thenReturn(true); doThrow(EntryNotFoundException.class).when(owner).checkEntryNotFound(any()); initialize(owner, new Attributes(), null, false); if (map != null) { setEntryMap(map); } if (factory != null) { setEntryFactory(factory); } }
@Override public void putAll(Map map, Object aCallbackArgument) { long startPut = CachePerfStats.getStatTime(); final DistributedPutAllOperation putAllOp = newPutAllOperation(map, aCallbackArgument); if (putAllOp != null) { try { basicPutAll(map, putAllOp, null); } finally { putAllOp.getBaseEvent().release(); putAllOp.freeOffHeapResources(); } } getCachePerfStats().endPutAll(startPut); }
@Override public void removeAll(Collection keys, Object aCallbackArgument) { long startOp = CachePerfStats.getStatTime(); DistributedRemoveAllOperation operation = newRemoveAllOperation(keys, aCallbackArgument); if (operation != null) { try { basicRemoveAll(keys, operation, null); } finally { operation.getBaseEvent().release(); operation.freeOffHeapResources(); } } getCachePerfStats().endRemoveAll(startOp); }
public VersionedObjectList basicImportPutAll(Map map, boolean skipCallbacks) { long startPut = CachePerfStats.getStatTime(); @Released EntryEventImpl event = EntryEventImpl.create(this, Operation.PUTALL_CREATE, null, null, null, true, getMyId(), !skipCallbacks); try { DistributedPutAllOperation putAllOp = new DistributedPutAllOperation(event, map.size(), false); try { VersionedObjectList result = basicPutAll(map, putAllOp, null); getCachePerfStats().endPutAll(startPut); return result; } finally { putAllOp.freeOffHeapResources(); } } finally { event.release(); } }
private Object doLocalLoad(CacheLoader loader, boolean netSearchAllowed, boolean preferCD) throws CacheLoaderException { Object obj = null; if (loader != null && !this.attemptedLocalLoad) { this.attemptedLocalLoad = true; CachePerfStats stats = region.getCachePerfStats(); LoaderHelper loaderHelper = this.region.loaderHelperFactory.createLoaderHelper(this.key, this.aCallbackArgument, netSearchAllowed, true /* netLoadAllowed */, this); long statStart = stats.startLoad(); try { obj = loader.load(loaderHelper); obj = this.region.getCache().convertPdxInstanceIfNeeded(obj, preferCD); } finally { stats.endLoad(statStart); } if (obj != null) { this.localLoad = true; } } return obj; }
@Override public void cacheWriteBeforePut(EntryEventImpl event, Set netWriteRecipients, CacheWriter localWriter, boolean requireOldValue, Object expectedOldValue) throws CacheWriterException, TimeoutException { Assert.assertTrue(netWriteRecipients == null); Operation operation = event.getOperation(); boolean isPutIfAbsentOrReplace = operation == Operation.PUT_IF_ABSENT || operation == Operation.REPLACE; if (!isPutIfAbsentOrReplace && localWriter != null && !event.inhibitAllNotifications()) { final long start = getCachePerfStats().startCacheWriterCall(); final boolean newEntry = event.getOperation().isCreate(); event.setReadOldValueFromDisk(true); try { if (!newEntry) { localWriter.beforeUpdate(event); } else { localWriter.beforeCreate(event); } } finally { event.setReadOldValueFromDisk(false); getCachePerfStats().endCacheWriterCall(start); } } serverPut(event, requireOldValue, expectedOldValue); }
private void validatedCreate(EntryEventImpl event, long startPut) throws TimeoutException, EntryExistsException, CacheWriterException { if (event.getEventId() == null && generateEventID()) { event.setNewEventId(this.cache.getDistributedSystem()); } // Fix for 42448 - Only make create with null a local invalidate for // normal regions. Otherwise, it will become a distributed invalidate. if (getDataPolicy() == DataPolicy.NORMAL) { event.setLocalInvalid(true); } discoverJTA(); if (!basicPut(event, true, // ifNew false, // ifOld null, // expectedOldValue true // requireOldValue TODO txMerge why is oldValue required for // create? I think so that the EntryExistsException will have it. )) { throw new EntryExistsException(event.getKey().toString(), event.getOldValue()); } else { if (!getDataView().isDeferredStats()) { getCachePerfStats().endPut(startPut, false); } } }
Object validatedPut(EntryEventImpl event, long startPut) throws TimeoutException, CacheWriterException { if (event.getEventId() == null && generateEventID()) { event.setNewEventId(this.cache.getDistributedSystem()); } Object oldValue = null; if (basicPut(event, false, // ifNew false, // ifOld null, // expectedOldValue false // requireOldValue )) { if (!event.isOldValueOffHeap()) { // don't copy it to heap just to return from put. // TODO: come up with a better way to do this. oldValue = event.getOldValue(); } if (!getDataView().isDeferredStats()) { getCachePerfStats().endPut(startPut, false); } } return handleNotAvailable(oldValue); }