use of org.apache.ignite.spi.systemview.view.MetastorageView in project ignite by apache.
the class SystemViewSelfTest method testMetastorage.
/**
*/
@Test
public void testMetastorage() throws Exception {
cleanPersistenceDir();
try (IgniteEx ignite = startGrid(getConfiguration().setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true))))) {
ignite.cluster().state(ClusterState.ACTIVE);
IgniteCacheDatabaseSharedManager db = ignite.context().cache().context().database();
SystemView<MetastorageView> metaStoreView = ignite.context().systemView().view(METASTORE_VIEW);
assertNotNull(metaStoreView);
String name = "test-key";
String val = "test-value";
String unmarshalledName = "unmarshalled-key";
String unmarshalledVal = "[Raw data. 0 bytes]";
db.checkpointReadLock();
try {
db.metaStorage().write(name, val);
db.metaStorage().writeRaw(unmarshalledName, new byte[0]);
} finally {
db.checkpointReadUnlock();
}
assertNotNull(F.find(metaStoreView, null, (IgnitePredicate<? super MetastorageView>) view -> name.equals(view.name()) && val.equals(view.value())));
assertNotNull(F.find(metaStoreView, null, (IgnitePredicate<? super MetastorageView>) view -> unmarshalledName.equals(view.name()) && unmarshalledVal.equals(view.value())));
}
}
use of org.apache.ignite.spi.systemview.view.MetastorageView in project ignite by apache.
the class GridCacheDatabaseSharedManager method registerSystemView.
/**
* Registers system view.
*/
private void registerSystemView() {
cctx.kernalContext().systemView().registerView(METASTORE_VIEW, METASTORE_VIEW_DESC, new MetastorageViewWalker(), () -> {
try {
List<MetastorageView> data = new ArrayList<>();
metaStorage.iterate("", (key, valBytes) -> {
try {
Serializable val = metaStorage.marshaller().unmarshal((byte[]) valBytes, U.gridClassLoader());
data.add(new MetastorageView(key, IgniteUtils.toStringSafe(val)));
} catch (IgniteCheckedException ignored) {
data.add(new MetastorageView(key, "[Raw data. " + (((byte[]) valBytes).length + " bytes]")));
}
}, false);
return data;
} catch (IgniteCheckedException e) {
log.warning("Metastore iteration error", e);
return emptyList();
}
}, identity());
}
use of org.apache.ignite.spi.systemview.view.MetastorageView in project ignite by apache.
the class DistributedMetaStorageImpl method registerSystemView.
/**
*/
private void registerSystemView() {
ctx.systemView().registerView(DISTRIBUTED_METASTORE_VIEW, DISTRIBUTED_METASTORE_VIEW_DESC, new MetastorageViewWalker(), () -> {
try {
List<MetastorageView> data = new ArrayList<>();
iterate("", (key, val) -> data.add(new MetastorageView(key, IgniteUtils.toStringSafe(val))));
return data;
} catch (IgniteCheckedException e) {
log.warning("Metastore iteration error", e);
return Collections.emptyList();
}
}, identity());
}
use of org.apache.ignite.spi.systemview.view.MetastorageView in project ignite by apache.
the class SystemViewSelfTest method testDistributedMetastorage.
/**
*/
@Test
public void testDistributedMetastorage() throws Exception {
cleanPersistenceDir();
try (IgniteEx ignite = startGrid(getConfiguration().setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true))))) {
ignite.cluster().state(ClusterState.ACTIVE);
DistributedMetaStorage dms = ignite.context().distributedMetastorage();
SystemView<MetastorageView> metaStoreView = ignite.context().systemView().view(DISTRIBUTED_METASTORE_VIEW);
assertNotNull(metaStoreView);
String name = "test-distributed-key";
String val = "test-distributed-value";
dms.write(name, val);
MetastorageView testKey = F.find(metaStoreView, null, (IgnitePredicate<? super MetastorageView>) view -> name.equals(view.name()) && val.equals(view.value()));
assertNotNull(testKey);
}
}
use of org.apache.ignite.spi.systemview.view.MetastorageView in project ignite by apache.
the class SqlViewExporterSpiTest method testMetastorage.
/**
*/
@Test
public void testMetastorage() throws Exception {
IgniteCacheDatabaseSharedManager db = ignite0.context().cache().context().database();
SystemView<MetastorageView> metaStoreView = ignite0.context().systemView().view(METASTORE_VIEW);
assertNotNull(metaStoreView);
String name = "test-key";
String val = "test-value";
String unmarshalledName = "unmarshalled-key";
String unmarshalledVal = "[Raw data. 0 bytes]";
db.checkpointReadLock();
try {
db.metaStorage().write(name, val);
db.metaStorage().writeRaw(unmarshalledName, new byte[0]);
} finally {
db.checkpointReadUnlock();
}
assertEquals(1, execute(ignite0, "SELECT * FROM SYS.METASTORAGE WHERE name = ? AND value = ?", name, val).size());
assertEquals(1, execute(ignite0, "SELECT * FROM SYS.METASTORAGE WHERE name = ? AND value = ?", unmarshalledName, unmarshalledVal).size());
}
Aggregations