use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.
the class UpgradePendingTreeToPerPartitionTask method processPendingTree.
/**
* Move pending rows for CacheGroup entries to per-partition PendingTree.
* Invalid pending rows will be ignored.
*
* @param grp Cache group.
* @param oldPendingEntries Old-style PendingTree.
* @throws IgniteCheckedException If error occurs.
*/
private void processPendingTree(CacheGroupContext grp, PendingEntriesTree oldPendingEntries) throws IgniteCheckedException {
final PageMemory pageMemory = grp.dataRegion().pageMemory();
final IgniteCacheDatabaseSharedManager db = grp.shared().database();
final Set<Integer> cacheIds = grp.cacheIds();
PendingRow row = null;
int processedEntriesCnt = 0;
int skippedEntries = 0;
// Re-acquire checkpoint lock for every next batch.
while (!Thread.currentThread().isInterrupted()) {
int cnt = 0;
db.checkpointReadLock();
try {
GridCursor<PendingRow> cursor = oldPendingEntries.find(row, null, WITHOUT_KEY);
while (cnt++ < BATCH_SIZE && cursor.next()) {
row = cursor.get();
assert row.link != 0 && row.expireTime != 0 : row;
GridCacheEntryEx entry;
// Lost cache or lost entry.
if (!cacheIds.contains(row.cacheId) || (entry = getEntry(grp, row)) == null) {
skippedEntries++;
oldPendingEntries.removex(row);
continue;
}
entry.lockEntry();
try {
if (processRow(pageMemory, grp, row))
processedEntriesCnt++;
else
skippedEntries++;
} finally {
entry.unlockEntry();
}
oldPendingEntries.removex(row);
}
if (cnt < BATCH_SIZE)
break;
} finally {
db.checkpointReadUnlock();
}
}
log.info("PendingTree upgraded: " + "[grpId=" + grp.groupId() + ", grpName=" + grp.name() + ", processedEntries=" + processedEntriesCnt + ", failedEntries=" + skippedEntries + ']');
}
use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.
the class UpgradePendingTreeToPerPartitionTask method processCacheGroup.
/**
* Converts CacheGroup pending tree to per-partition basis.
*
* @param grp Cache group.
* @throws IgniteCheckedException If error occurs.
*/
private void processCacheGroup(CacheGroupContext grp) throws IgniteCheckedException {
assert grp.offheap() instanceof GridCacheOffheapManager;
PendingEntriesTree oldPendingTree;
final IgniteCacheDatabaseSharedManager db = grp.shared().database();
db.checkpointReadLock();
try {
IndexStorage indexStorage = ((GridCacheOffheapManager) grp.offheap()).getIndexStorage();
// TODO: IGNITE-5874: replace with some check-method to avoid unnecessary page allocation.
RootPage pendingRootPage = indexStorage.allocateIndex(PENDING_ENTRIES_TREE_NAME);
if (pendingRootPage.isAllocated()) {
log.info("No pending tree found for cache group: [grpId=" + grp.groupId() + ", grpName=" + grp.name() + ']');
// Nothing to do here as just allocated tree is obviously empty.
indexStorage.dropIndex(PENDING_ENTRIES_TREE_NAME);
return;
}
oldPendingTree = new PendingEntriesTree(grp, PENDING_ENTRIES_TREE_NAME, grp.dataRegion().pageMemory(), pendingRootPage.pageId().pageId(), ((GridCacheOffheapManager) grp.offheap()).reuseListForIndex(null), false, grp.shared().diagnostic().pageLockTracker(), PageIdAllocator.FLAG_IDX);
} finally {
db.checkpointReadUnlock();
}
processPendingTree(grp, oldPendingTree);
if (Thread.currentThread().isInterrupted())
return;
db.checkpointReadLock();
try {
oldPendingTree.destroy();
} finally {
db.checkpointReadUnlock();
}
}
use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.
the class GridCommandHandlerIndexingUtils method breakCacheDataTree.
/**
* Deleting a rows from the cache without updating indexes.
*
* @param log Logger.
* @param internalCache Cache.
* @param partId Partition number.
* @param filter Entry filter.
*/
static <K, V> void breakCacheDataTree(IgniteLogger log, IgniteInternalCache<K, V> internalCache, int partId, @Nullable BiPredicate<Integer, Entry<K, V>> filter) {
requireNonNull(log);
requireNonNull(internalCache);
GridCacheContext<K, V> cacheCtx = internalCache.context();
CacheDataStore cacheDataStore = cacheCtx.dht().topology().localPartition(partId).dataStore();
String delegate = "delegate";
if (hasField(cacheDataStore, delegate))
cacheDataStore = field(cacheDataStore, delegate);
CacheDataRowStore cacheDataRowStore = field(cacheDataStore, "rowStore");
CacheDataTree cacheDataTree = field(cacheDataStore, "dataTree");
String cacheName = internalCache.name();
QueryCursor<Entry<K, V>> qryCursor = cacheCtx.kernalContext().grid().cache(cacheName).withKeepBinary().query(new ScanQuery<>(partId));
Iterator<Entry<K, V>> cacheEntryIter = qryCursor.iterator();
IgniteCacheDatabaseSharedManager db = cacheCtx.shared().database();
int cacheId = CU.cacheId(cacheName);
int i = 0;
while (cacheEntryIter.hasNext()) {
Entry<K, V> entry = cacheEntryIter.next();
if (nonNull(filter) && !filter.test(i++, entry))
continue;
db.checkpointReadLock();
try {
CacheDataRow oldRow = cacheDataTree.remove(new SearchRow(cacheId, cacheCtx.toCacheKeyObject(entry.getKey())));
if (nonNull(oldRow))
cacheDataRowStore.removeRow(oldRow.link(), INSTANCE);
} catch (IgniteCheckedException e) {
throw new IgniteException("Failed to remove key skipping indexes: " + entry, e);
} finally {
db.checkpointReadUnlock();
}
}
}
use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.
the class GridCacheProcessor method createSharedContext.
/**
* Creates shared context.
*
* @param kernalCtx Kernal context.
* @param storeSesLsnrs Store session listeners.
* @return Shared context.
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("unchecked")
private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, Collection<CacheStoreSessionListener> storeSesLsnrs) throws IgniteCheckedException {
IgniteTxManager tm = new IgniteTxManager();
GridCacheMvccManager mvccMgr = new GridCacheMvccManager();
GridCacheVersionManager verMgr = new GridCacheVersionManager();
GridCacheDeploymentManager depMgr = new GridCacheDeploymentManager();
GridCachePartitionExchangeManager exchMgr = new GridCachePartitionExchangeManager();
IgniteCacheDatabaseSharedManager dbMgr;
IgnitePageStoreManager pageStoreMgr = null;
IgniteWriteAheadLogManager walMgr = null;
if (CU.isPersistenceEnabled(ctx.config()) && !ctx.clientNode()) {
dbMgr = new GridCacheDatabaseSharedManager(ctx);
pageStoreMgr = ctx.plugins().createComponent(IgnitePageStoreManager.class);
if (pageStoreMgr == null)
pageStoreMgr = new FilePageStoreManager(ctx);
walMgr = ctx.plugins().createComponent(IgniteWriteAheadLogManager.class);
if (walMgr == null)
walMgr = new FileWriteAheadLogManager(ctx);
} else {
if (CU.isPersistenceEnabled(ctx.config()) && ctx.clientNode()) {
U.warn(log, "Persistent Store is not supported on client nodes (Persistent Store's" + " configuration will be ignored).");
}
dbMgr = new IgniteCacheDatabaseSharedManager();
}
WalStateManager walStateMgr = new WalStateManager(ctx);
IgniteSnapshotManager snapshotMgr = new IgniteSnapshotManager(ctx);
IgniteCacheSnapshotManager snpMgr = ctx.plugins().createComponent(IgniteCacheSnapshotManager.class);
if (snpMgr == null)
snpMgr = new IgniteCacheSnapshotManager();
GridCacheIoManager ioMgr = new GridCacheIoManager();
CacheAffinitySharedManager topMgr = new CacheAffinitySharedManager();
GridCacheSharedTtlCleanupManager ttl = new GridCacheSharedTtlCleanupManager();
PartitionsEvictManager evict = new PartitionsEvictManager();
CacheJtaManagerAdapter jta = JTA.createOptional();
MvccCachingManager mvccCachingMgr = new MvccCachingManager();
DeadlockDetectionManager deadlockDetectionMgr = new DeadlockDetectionManager();
CacheDiagnosticManager diagnosticMgr = new CacheDiagnosticManager();
return new GridCacheSharedContext(kernalCtx, tm, verMgr, mvccMgr, pageStoreMgr, walMgr, walStateMgr, dbMgr, snapshotMgr, snpMgr, depMgr, exchMgr, topMgr, ioMgr, ttl, evict, jta, storeSesLsnrs, mvccCachingMgr, deadlockDetectionMgr, diagnosticMgr);
}
use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.
the class SystemViewCommandTest method testMetastorage.
/**
*/
@Test
public void testMetastorage() throws Exception {
IgniteCacheDatabaseSharedManager db = ignite0.context().cache().context().database();
String name = "test-key";
String val = "test-value";
db.checkpointReadLock();
try {
db.metaStorage().write(name, val);
} finally {
db.checkpointReadUnlock();
}
assertEquals(1, systemView(ignite0, METASTORE_VIEW).stream().filter(row -> name.equals(row.get(0)) && val.equals(row.get(1))).count());
}
Aggregations