use of org.apache.ignite.spi.systemview.view.CachePagesListView in project ignite by apache.
the class SystemViewSelfTest method testPagesList.
/**
*/
@Test
public void testPagesList() throws Exception {
cleanPersistenceDir();
try (IgniteEx ignite = startGrid(getConfiguration().setDataStorageConfiguration(new DataStorageConfiguration().setDataRegionConfigurations(new DataRegionConfiguration().setName("dr0").setMaxSize(100L * 1024 * 1024), new DataRegionConfiguration().setName("dr1").setMaxSize(100L * 1024 * 1024).setPersistenceEnabled(true))))) {
ignite.cluster().active(true);
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ignite.context().cache().context().database();
int pageSize = dbMgr.pageSize();
dbMgr.enableCheckpoints(false).get();
for (int i = 0; i < 2; i++) {
IgniteCache<Object, Object> cache = ignite.getOrCreateCache(new CacheConfiguration<>("cache" + i).setDataRegionName("dr" + i).setAffinity(new RendezvousAffinityFunction().setPartitions(2)));
int key = 0;
// Fill up different free-list buckets.
for (int j = 0; j < pageSize / 2; j++) cache.put(key++, new byte[j + 1]);
// Put some pages to one bucket to overflow pages cache.
for (int j = 0; j < 1000; j++) cache.put(key++, new byte[pageSize / 2]);
}
long dr0flPages = 0;
int dr0flStripes = 0;
SystemView<PagesListView> dataRegionPageLists = ignite.context().systemView().view(DATA_REGION_PAGE_LIST_VIEW);
for (PagesListView pagesListView : dataRegionPageLists) {
if (pagesListView.name().startsWith("dr0")) {
dr0flPages += pagesListView.bucketSize();
dr0flStripes += pagesListView.stripesCount();
}
}
assertTrue(dr0flPages > 0);
assertTrue(dr0flStripes > 0);
SystemView<CachePagesListView> cacheGrpPageLists = ignite.context().systemView().view(CACHE_GRP_PAGE_LIST_VIEW);
long dr1flPages = 0;
int dr1flStripes = 0;
int dr1flCached = 0;
for (CachePagesListView pagesListView : cacheGrpPageLists) {
if (pagesListView.cacheGroupId() == cacheId("cache1")) {
dr1flPages += pagesListView.bucketSize();
dr1flStripes += pagesListView.stripesCount();
dr1flCached += pagesListView.cachedPagesCount();
}
}
assertTrue(dr1flPages > 0);
assertTrue(dr1flStripes > 0);
assertTrue(dr1flCached > 0);
// Test filtering.
assertTrue(cacheGrpPageLists instanceof FiltrableSystemView);
Iterator<CachePagesListView> iter = ((FiltrableSystemView<CachePagesListView>) cacheGrpPageLists).iterator(U.map(CachePagesListViewWalker.CACHE_GROUP_ID_FILTER, cacheId("cache1"), CachePagesListViewWalker.PARTITION_ID_FILTER, 0, CachePagesListViewWalker.BUCKET_NUMBER_FILTER, 0));
assertEquals(1, F.size(iter));
iter = ((FiltrableSystemView<CachePagesListView>) cacheGrpPageLists).iterator(U.map(CachePagesListViewWalker.CACHE_GROUP_ID_FILTER, cacheId("cache1"), CachePagesListViewWalker.BUCKET_NUMBER_FILTER, 0));
assertEquals(2, F.size(iter));
}
}
use of org.apache.ignite.spi.systemview.view.CachePagesListView in project ignite by apache.
the class GridCacheProcessor method pagesListViewSupplier.
/**
* Pages list view supplier.
*
* @param filter Filter.
*/
private Iterable<CachePagesListView> pagesListViewSupplier(Map<String, Object> filter) {
Integer cacheGrpId = (Integer) filter.get(CachePagesListViewWalker.CACHE_GROUP_ID_FILTER);
Integer partId = (Integer) filter.get(CachePagesListViewWalker.PARTITION_ID_FILTER);
Integer bucketNum = (Integer) filter.get(CachePagesListViewWalker.BUCKET_NUMBER_FILTER);
Iterable<IgniteCacheOffheapManager.CacheDataStore> dataStores = F.flat(F.iterator(filteredMap(cacheGrps, cacheGrpId).values(), grp -> grp.offheap().cacheDataStores(), true));
return F.flat(F.iterator(dataStores, dataStore -> {
RowStore rowStore = dataStore.rowStore();
if (rowStore == null || !(dataStore instanceof GridCacheOffheapManager.GridCacheDataStore))
return Collections.emptySet();
PagesList pagesList = (PagesList) rowStore.freeList();
if (bucketNum != null) {
return bucketNum >= 0 && bucketNum < pagesList.bucketsCount() ? Collections.singleton(new CachePagesListView(pagesList, bucketNum, dataStore.partId())) : Collections.emptyList();
}
return IntStream.range(0, pagesList.bucketsCount()).mapToObj(bucket -> new CachePagesListView(pagesList, bucket, dataStore.partId())).collect(toList());
}, true, cacheDataStore -> partId == null || cacheDataStore.partId() == partId));
}
Aggregations