use of org.apache.ignite.spi.systemview.view.FiltrableSystemView 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.FiltrableSystemView in project ignite by apache.
the class SystemViewMBean method viewContent.
/**
* Gets tabular data with system view content.
*/
private TabularDataSupport viewContent(Map<String, Object> filter) {
TabularDataSupport rows = new TabularDataSupport(sysViewType);
AttributeToMapVisitor visitor = new AttributeToMapVisitor();
try {
int idx = 0;
Iterable<R> iter = filter != null && sysView instanceof FiltrableSystemView ? () -> ((FiltrableSystemView<R>) sysView).iterator(filter) : sysView;
for (R row : iter) {
Map<String, Object> data = new HashMap<>();
visitor.data(data);
sysView.walker().visitAll(row, visitor);
data.put(ID, idx++);
rows.put(new CompositeDataSupport(rowType, data));
}
} catch (OpenDataException e) {
throw new IgniteException(e);
}
return rows;
}
use of org.apache.ignite.spi.systemview.view.FiltrableSystemView in project ignite by apache.
the class SystemViewSelfTest method testBaselineNodeAttributes.
/**
*/
@Test
public void testBaselineNodeAttributes() throws Exception {
cleanPersistenceDir();
try (IgniteEx ignite = startGrid(getConfiguration().setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setName("pds").setPersistenceEnabled(true))).setUserAttributes(F.asMap("name", "val")).setConsistentId("consId"))) {
ignite.cluster().state(ClusterState.ACTIVE);
SystemView<BaselineNodeAttributeView> view = ignite.context().systemView().view(BASELINE_NODE_ATTRIBUTES_SYS_VIEW);
assertEquals(ignite.cluster().localNode().attributes().size(), view.size());
assertEquals(1, F.size(view.iterator(), row -> "consId".equals(row.nodeConsistentId()) && "name".equals(row.name()) && "val".equals(row.value())));
// Test filtering.
assertTrue(view instanceof FiltrableSystemView);
Iterator<BaselineNodeAttributeView> iter = ((FiltrableSystemView<BaselineNodeAttributeView>) view).iterator(F.asMap(BaselineNodeAttributeViewWalker.NODE_CONSISTENT_ID_FILTER, "consId", BaselineNodeAttributeViewWalker.NAME_FILTER, "name"));
assertEquals(1, F.size(iter));
iter = ((FiltrableSystemView<BaselineNodeAttributeView>) view).iterator(F.asMap(BaselineNodeAttributeViewWalker.NODE_CONSISTENT_ID_FILTER, "consId"));
assertEquals(1, F.size(iter, row -> "name".equals(row.name())));
iter = ((FiltrableSystemView<BaselineNodeAttributeView>) view).iterator(F.asMap(BaselineNodeAttributeViewWalker.NAME_FILTER, "name"));
assertEquals(1, F.size(iter));
}
}
use of org.apache.ignite.spi.systemview.view.FiltrableSystemView in project ignite by apache.
the class SystemViewSelfTest method testNodeAttributes.
/**
*/
@Test
public void testNodeAttributes() throws Exception {
try (IgniteEx ignite0 = startGrid(getConfiguration(getTestIgniteInstanceName(0)).setUserAttributes(F.asMap("name", "val0")));
IgniteEx ignite1 = startGrid(getConfiguration(getTestIgniteInstanceName(1)).setUserAttributes(F.asMap("name", "val1")))) {
awaitPartitionMapExchange();
SystemView<NodeAttributeView> view = ignite0.context().systemView().view(NODE_ATTRIBUTES_SYS_VIEW);
assertEquals(ignite0.cluster().localNode().attributes().size() + ignite1.cluster().localNode().attributes().size(), view.size());
assertEquals(1, F.size(view.iterator(), row -> "name".equals(row.name()) && "val0".equals(row.value())));
assertEquals(1, F.size(view.iterator(), row -> "name".equals(row.name()) && "val1".equals(row.value())));
// Test filtering.
assertTrue(view instanceof FiltrableSystemView);
Iterator<NodeAttributeView> iter = ((FiltrableSystemView<NodeAttributeView>) view).iterator(F.asMap(NodeAttributeViewWalker.NODE_ID_FILTER, ignite0.cluster().localNode().id()));
assertEquals(1, F.size(iter, row -> "name".equals(row.name()) && "val0".equals(row.value())));
iter = ((FiltrableSystemView<NodeAttributeView>) view).iterator(F.asMap(NodeAttributeViewWalker.NODE_ID_FILTER, ignite1.cluster().localNode().id().toString()));
assertEquals(1, F.size(iter, row -> "name".equals(row.name()) && "val1".equals(row.value())));
iter = ((FiltrableSystemView<NodeAttributeView>) view).iterator(F.asMap(NodeAttributeViewWalker.NODE_ID_FILTER, "malformed-id"));
assertEquals(0, F.size(iter));
iter = ((FiltrableSystemView<NodeAttributeView>) view).iterator(F.asMap(NodeAttributeViewWalker.NAME_FILTER, "name"));
assertEquals(2, F.size(iter));
iter = ((FiltrableSystemView<NodeAttributeView>) view).iterator(F.asMap(NodeAttributeViewWalker.NODE_ID_FILTER, ignite0.cluster().localNode().id(), NodeAttributeViewWalker.NAME_FILTER, "name"));
assertEquals(1, F.size(iter));
}
}
use of org.apache.ignite.spi.systemview.view.FiltrableSystemView in project ignite by apache.
the class SqlViewExporterSpi method register.
/**
* Registers system view as SQL View.
*
* @param sysView System view.
*/
private void register(SystemView<?> sysView) {
if (log.isDebugEnabled())
log.debug("Found new system view [name=" + sysView.name() + ']');
GridKernalContext ctx = ((IgniteEx) ignite()).context();
SystemViewLocal<?> view = sysView instanceof FiltrableSystemView ? new FiltrableSystemViewLocal<>(ctx, sysView) : new SystemViewLocal<>(ctx, sysView);
mgr.createSystemView(SCHEMA_SYS, view);
}
Aggregations