use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.
the class GridCachePartitionExchangeManagerWarningsTest method testDumpLongRunningOperationsWaitForFullyInitializedExchangeManager.
/**
*/
@Test
public void testDumpLongRunningOperationsWaitForFullyInitializedExchangeManager() throws Exception {
long waitingTimeout = 5_000;
PrintStream errStream = System.err;
CountDownLatch startLatch = new CountDownLatch(1);
CountDownLatch waitLatch = new CountDownLatch(1);
try {
// GridCachePartitionExchangeManager#dumpLongRunningOperations() uses diagnostic log,
// which can be non-initialized, and so, error messgaes are logged into standard error output stream.
ByteArrayOutputStream testOut = new ByteArrayOutputStream(16 * 1024);
System.setErr(new PrintStream(testOut));
AtomicReference<IgniteInternalFuture<?>> dumpOpsFut = new AtomicReference<>();
IgniteInternalFuture<Ignite> startFut = null;
// Lyficycle bean allows to register DatabaseLifecycleListener and trigger dumpLongRunningOperations
// before GridCachePartitionExchangeManager is started.
lifecycleBean = new LifecycleBean() {
/**
* Ignite instance.
*/
@IgniteInstanceResource
IgniteEx ignite;
/**
* {@inheritDoc}
*/
@Override
public void onLifecycleEvent(LifecycleEventType evt) throws IgniteException {
if (evt == LifecycleEventType.BEFORE_NODE_START) {
ignite.context().internalSubscriptionProcessor().registerDatabaseListener(new DatabaseLifecycleListener() {
@Override
public void onInitDataRegions(IgniteCacheDatabaseSharedManager mgr) throws IgniteCheckedException {
dumpOpsFut.set(GridTestUtils.runAsync(() -> ignite.context().cache().context().exchange().dumpLongRunningOperations(1_000)));
// Let's allow to check that dumpLongRunningOperations is triggered.
startLatch.countDown();
// Wait for the check
try {
if (!waitLatch.await(waitingTimeout * 3, TimeUnit.MILLISECONDS))
throw new IgniteCheckedException("Failed to wait for a check of dumpLongRunningOperations");
} catch (InterruptedException e) {
throw new IgniteCheckedException(e);
}
}
});
}
}
};
startFut = GridTestUtils.runAsync(new Callable<Ignite>() {
@Override
public Ignite call() throws Exception {
return startGrid(0);
}
});
assertTrue("Server node did not start in " + waitingTimeout + " ms.", startLatch.await(waitingTimeout, TimeUnit.MILLISECONDS));
// Check that dumpLongRunningOperations did not produce any error.
if (GridTestUtils.waitForCondition(() -> dumpOpsFut.get().isDone(), waitingTimeout)) {
// Check that error output stream does not contain NullPointerException.
String output = testOut.toString();
assertTrue("Unexpected error [err=" + output + ']', output.isEmpty());
}
// Unblock starting the node.
waitLatch.countDown();
assertTrue("Dumping log running operations is not completed yet.", GridTestUtils.waitForCondition(() -> dumpOpsFut.get().isDone(), waitingTimeout));
// Check that error output stream does not contain any error.
String output = testOut.toString();
assertTrue("Unexpected error [err=" + output + ']', output.isEmpty());
startFut.get(waitingTimeout, TimeUnit.MILLISECONDS);
} finally {
startLatch.countDown();
waitLatch.countDown();
System.setErr(errStream);
}
}
use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager 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.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.
the class IgnitePdsPageReplacementTest method getMemory.
/**
* @param ig Ignite instance.
* @return Memory and store.
* @throws Exception If failed to initialize the store.
*/
private PageMemory getMemory(IgniteEx ig) throws Exception {
final GridCacheSharedContext<Object, Object> sharedCtx = ig.context().cache().context();
final IgniteCacheDatabaseSharedManager db = sharedCtx.database();
return db.dataRegion(null).pageMemory();
}
use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.
the class IgniteDefragmentationImpl method status.
/**
* {@inheritDoc}
*/
@Override
public DefragmentationStatus status() throws IgniteCheckedException {
final MaintenanceRegistry maintenanceRegistry = ctx.maintenanceRegistry();
if (!maintenanceRegistry.isMaintenanceMode())
throw new IgniteCheckedException("Node is not in maintenance mode.");
IgniteCacheDatabaseSharedManager dbMgr = ctx.cache().context().database();
assert dbMgr instanceof GridCacheDatabaseSharedManager;
CachePartitionDefragmentationManager defrgMgr = ((GridCacheDatabaseSharedManager) dbMgr).defragmentationManager();
if (defrgMgr == null)
throw new IgniteCheckedException("There's no active defragmentation process on the node.");
final Status status = defrgMgr.status();
final long startTs = status.getStartTs();
final long finishTs = status.getFinishTs();
final long elapsedTime = finishTs != 0 ? finishTs - startTs : System.currentTimeMillis() - startTs;
Map<String, CompletedDefragmentationInfo> completedCaches = new HashMap<>();
Map<String, InProgressDefragmentationInfo> progressCaches = new HashMap<>();
status.getFinishedGroups().forEach((context, progress) -> {
final String name = context.cacheOrGroupName();
final long oldSize = progress.getOldSize();
final long newSize = progress.getNewSize();
final long cgElapsedTime = progress.getFinishTs() - progress.getStartTs();
final CompletedDefragmentationInfo info = new CompletedDefragmentationInfo(cgElapsedTime, oldSize, newSize);
completedCaches.put(name, info);
});
status.getProgressGroups().forEach((context, progress) -> {
final String name = context.cacheOrGroupName();
final long cgElapsedTime = System.currentTimeMillis() - progress.getStartTs();
final int partsTotal = progress.getPartsTotal();
final int partsCompleted = progress.getPartsCompleted();
final InProgressDefragmentationInfo info = new InProgressDefragmentationInfo(cgElapsedTime, partsCompleted, partsTotal);
progressCaches.put(name, info);
});
return new DefragmentationStatus(completedCaches, progressCaches, status.getScheduledGroups(), status.getSkippedGroups(), status.getTotalPartitionCount(), status.getDefragmentedPartitionCount(), startTs, elapsedTime);
}
use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.
the class InlineIndexFactory method createIndex.
/**
* {@inheritDoc}
*/
@Override
public Index createIndex(GridCacheContext<?, ?> cctx, IndexDefinition def) {
SortedIndexDefinition sdef = (SortedIndexDefinition) def;
InlineIndexTree[] trees = new InlineIndexTree[sdef.segments()];
InlineRecommender recommender = new InlineRecommender(cctx, sdef);
IoStatisticsHolderIndex stats = new IoStatisticsHolderIndex(SORTED_INDEX, cctx.name(), sdef.idxName().idxName(), cctx.kernalContext().metric());
try {
for (int i = 0; i < sdef.segments(); ++i) {
// Required for persistence.
IgniteCacheDatabaseSharedManager db = cctx.shared().database();
db.checkpointReadLock();
try {
RootPage page = rootPage(cctx, sdef.treeName(), i);
trees[i] = createIndexSegment(cctx, sdef, page, stats, recommender, i);
} finally {
db.checkpointReadUnlock();
}
}
return new InlineIndexImpl(cctx, sdef, trees, stats);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations