use of org.apache.geode.internal.cache.CachePerfStats in project geode by apache.
the class OffHeapRegionEntryHelperJUnitTest method addressToObjectShouldReturnDecompressedValueFromChunkIfAskedToDecompress.
@Test
public void addressToObjectShouldReturnDecompressedValueFromChunkIfAskedToDecompress() {
byte[] data = ByteBuffer.allocate(Long.SIZE / Byte.SIZE).putLong(Long.MAX_VALUE).array();
boolean isSerialized = false;
boolean isCompressed = true;
OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocateAndInitialize(data, isSerialized, isCompressed);
// create the mock context
RegionEntryContext regionContext = mock(RegionEntryContext.class);
CachePerfStats cacheStats = mock(CachePerfStats.class);
Compressor compressor = mock(Compressor.class);
long startTime = 10000L;
// mock required things
when(regionContext.getCompressor()).thenReturn(compressor);
when(compressor.decompress(data)).thenReturn(data);
when(regionContext.getCachePerfStats()).thenReturn(cacheStats);
when(cacheStats.startDecompression()).thenReturn(startTime);
Object actual = OffHeapRegionEntryHelper.addressToObject(chunk.getAddress(), true, regionContext);
assertThat(actual).isInstanceOf(byte[].class);
assertThat(actual).isEqualTo(data);
}
use of org.apache.geode.internal.cache.CachePerfStats in project geode by apache.
the class MemberHealthEvaluator method checkCacheRequiredRolesMeet.
/**
* The function keeps updating the health of the cache based on roles required by the regions and
* their reliability policies.
*/
private void checkCacheRequiredRolesMeet(List status) {
try {
InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
CachePerfStats cPStats = cache.getCachePerfStats();
if (cPStats.getReliableRegionsMissingFullAccess() > 0) {
// health is okay.
int numRegions = cPStats.getReliableRegionsMissingFullAccess();
status.add(okayHealth(LocalizedStrings.MemberHealthEvaluator_THERE_ARE_0_REGIONS_MISSING_REQUIRED_ROLES_BUT_ARE_CONFIGURED_FOR_FULL_ACCESS.toLocalizedString(numRegions)));
} else if (cPStats.getReliableRegionsMissingLimitedAccess() > 0) {
// health is poor
int numRegions = cPStats.getReliableRegionsMissingLimitedAccess();
status.add(poorHealth(LocalizedStrings.MemberHealthEvaluator_THERE_ARE_0_REGIONS_MISSING_REQUIRED_ROLES_AND_CONFIGURED_WITH_LIMITED_ACCESS.toLocalizedString(numRegions)));
} else if (cPStats.getReliableRegionsMissingNoAccess() > 0) {
// health is poor
int numRegions = cPStats.getReliableRegionsMissingNoAccess();
status.add(poorHealth(LocalizedStrings.MemberHealthEvaluator_THERE_ARE_0_REGIONS_MISSING_REQUIRED_ROLES_AND_CONFIGURED_WITHOUT_ACCESS.toLocalizedString(numRegions)));
}
} catch (CancelException ignore) {
}
}
use of org.apache.geode.internal.cache.CachePerfStats in project geode by apache.
the class AbstractGatewaySender method initializeEventIdIndexMetaDataRegion.
@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
private static synchronized Region<String, Integer> initializeEventIdIndexMetaDataRegion(AbstractGatewaySender sender) {
final InternalCache cache = sender.getCache();
Region<String, Integer> region = cache.getRegion(META_DATA_REGION_NAME);
if (region == null) {
// Create region attributes (must be done this way to use InternalRegionArguments)
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
RegionAttributes ra = factory.create();
// Create a stats holder for the meta data stats
final HasCachePerfStats statsHolder = new HasCachePerfStats() {
public CachePerfStats getCachePerfStats() {
return new CachePerfStats(cache.getDistributedSystem(), META_DATA_REGION_NAME);
}
};
// Create internal region arguments
InternalRegionArguments ira = new InternalRegionArguments().setIsUsedForMetaRegion(true).setCachePerfStatsHolder(statsHolder);
// Create the region
try {
region = cache.createVMRegion(META_DATA_REGION_NAME, ra, ira);
} catch (RegionExistsException e) {
region = cache.getRegion(META_DATA_REGION_NAME);
} catch (Exception e) {
throw new IllegalStateException(LocalizedStrings.AbstractGatewaySender_META_REGION_CREATION_EXCEPTION_0.toLocalizedString(sender), e);
}
}
return region;
}
use of org.apache.geode.internal.cache.CachePerfStats in project geode by apache.
the class MemberMBeanBridge method init.
public MemberMBeanBridge init() {
CachePerfStats cachePerfStats = this.cache.getCachePerfStats();
addCacheStats(cachePerfStats);
addFunctionStats(system.getFunctionServiceStats());
if (system.getDistributionManager().getStats() instanceof DistributionStats) {
DistributionStats distributionStats = (DistributionStats) system.getDistributionManager().getStats();
addDistributionStats(distributionStats);
}
if (PureJavaMode.osStatsAreAvailable()) {
Statistics[] systemStats = null;
if (HostStatHelper.isSolaris()) {
systemStats = system.findStatisticsByType(SolarisSystemStats.getType());
} else if (HostStatHelper.isLinux()) {
systemStats = system.findStatisticsByType(LinuxSystemStats.getType());
} else if (HostStatHelper.isOSX()) {
// @TODO once OSX stats are implemented
systemStats = null;
} else if (HostStatHelper.isWindows()) {
systemStats = system.findStatisticsByType(WindowsSystemStats.getType());
}
if (systemStats != null) {
systemStat = systemStats[0];
}
}
MemoryAllocator allocator = this.cache.getOffHeapStore();
if ((null != allocator)) {
OffHeapMemoryStats offHeapStats = allocator.getStats();
if (null != offHeapStats) {
addOffHeapStats(offHeapStats);
}
}
addSystemStats();
addVMStats();
initializeStats();
return this;
}
use of org.apache.geode.internal.cache.CachePerfStats in project geode by apache.
the class TXJUnitTest method testNoopInvalidates.
@Test
public void testNoopInvalidates() throws CacheException {
final CachePerfStats stats = this.cache.getCachePerfStats();
TransactionListener tl = new TransactionListenerAdapter() {
@Override
public void afterRollback(TransactionEvent event) {
te = event;
}
};
this.txMgr.addListener(tl);
// Make sure invalidates done on invalid entries are noops
{
// distributed invalidate
// first make sure invalidate is counted as a change
int txRollbackChanges = stats.getTxRollbackChanges();
this.region.create("key1", "value1");
this.txMgr.begin();
this.region.invalidate("key1");
this.txMgr.rollback();
assertEquals(txRollbackChanges + 1, stats.getTxRollbackChanges());
assertEquals(1, te.getEvents().size());
this.region.destroy("key1");
this.region.create("key1", "value1");
this.txMgr.begin();
this.region.invalidate("key1");
this.txMgr.commit();
assertEquals(1, te.getEvents().size());
this.region.destroy("key1");
// now make sure a committed entry that is invalid is not counted as a change
txRollbackChanges = stats.getTxRollbackChanges();
this.region.create("key1", "value1");
this.region.invalidate("key1");
this.txMgr.begin();
this.region.invalidate("key1");
this.txMgr.rollback();
assertEquals(txRollbackChanges, stats.getTxRollbackChanges());
assertEquals(0, te.getEvents().size());
this.region.destroy("key1");
this.region.create("key1", "value1");
this.region.invalidate("key1");
this.txMgr.begin();
this.region.invalidate("key1");
this.txMgr.commit();
assertEquals(0, te.getEvents().size());
this.region.destroy("key1");
// now make sure that multiple invalidates of same entry are a single change
txRollbackChanges = stats.getTxRollbackChanges();
this.region.create("key1", "value1");
this.txMgr.begin();
this.region.invalidate("key1");
this.region.invalidate("key1");
this.region.invalidate("key1");
this.txMgr.rollback();
assertEquals(txRollbackChanges + 1, stats.getTxRollbackChanges());
assertEquals(1, te.getEvents().size());
this.region.destroy("key1");
this.region.create("key1", "value1");
this.txMgr.begin();
this.region.invalidate("key1");
this.region.invalidate("key1");
this.region.invalidate("key1");
this.txMgr.commit();
assertEquals(1, te.getEvents().size());
this.region.destroy("key1");
}
{
// local invalidate
// first make sure invalidate is counted as a change
int txRollbackChanges = stats.getTxRollbackChanges();
this.region.create("key1", "value1");
this.txMgr.begin();
this.region.localInvalidate("key1");
this.txMgr.rollback();
assertEquals(txRollbackChanges + 1, stats.getTxRollbackChanges());
this.region.destroy("key1");
// now make sure a committed entry that is invalid is not counted as a change
txRollbackChanges = stats.getTxRollbackChanges();
this.region.create("key1", "value1");
this.region.localInvalidate("key1");
this.txMgr.begin();
this.region.localInvalidate("key1");
this.txMgr.rollback();
assertEquals(txRollbackChanges, stats.getTxRollbackChanges());
this.region.destroy("key1");
// now make sure that multiple localInvalidates of same entry are a single change
txRollbackChanges = stats.getTxRollbackChanges();
this.region.create("key1", "value1");
this.txMgr.begin();
this.region.localInvalidate("key1");
this.region.localInvalidate("key1");
this.region.localInvalidate("key1");
this.txMgr.rollback();
assertEquals(txRollbackChanges + 1, stats.getTxRollbackChanges());
this.region.destroy("key1");
}
}
Aggregations