use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.
the class CachePageWriteLockUnlockTest method preloadPartition.
/**
* Preload partition fast by iterating on all pages in disk order.
*
* @param grid Grid.
* @param cacheName Cache name.
* @param p P.
*/
private void preloadPartition(Ignite grid, String cacheName, int p) throws IgniteCheckedException {
GridDhtCacheAdapter<Object, Object> dht = ((IgniteKernal) grid).internalCache(cacheName).context().dht();
GridDhtLocalPartition part = dht.topology().localPartition(p);
assertNotNull(part);
assertTrue(part.state() == OWNING);
CacheGroupContext grpCtx = dht.context().group();
if (part.state() != OWNING)
return;
IgnitePageStoreManager pageStoreMgr = grpCtx.shared().pageStore();
if (pageStoreMgr instanceof FilePageStoreManager) {
FilePageStoreManager filePageStoreMgr = (FilePageStoreManager) pageStoreMgr;
PageStore pageStore = filePageStoreMgr.getStore(grpCtx.groupId(), part.id());
PageMemoryEx pageMemory = (PageMemoryEx) grpCtx.dataRegion().pageMemory();
long pageId = pageMemory.partitionMetaPageId(grpCtx.groupId(), part.id());
for (int pageNo = 0; pageNo < pageStore.pages(); pageId++, pageNo++) {
long pagePointer = -1;
try {
pagePointer = pageMemory.acquirePage(grpCtx.groupId(), pageId);
} finally {
if (pagePointer != -1)
pageMemory.releasePage(grpCtx.groupId(), pageId, pagePointer);
}
}
}
}
use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.
the class WalRecoveryTxLogicalRecordsTest method allocatedPages.
/**
* @param ignite Node.
* @param cacheName Cache name.
* @return Allocated pages per-store.
* @throws Exception If failed.
*/
private List<Integer> allocatedPages(Ignite ignite, String cacheName) throws Exception {
GridCacheProcessor cacheProc = ((IgniteEx) ignite).context().cache();
FilePageStoreManager storeMgr = (FilePageStoreManager) cacheProc.context().pageStore();
int parts = ignite.affinity(cacheName).partitions();
List<Integer> res = new ArrayList<>(parts);
for (int p = 0; p < parts; p++) {
PageStore store = storeMgr.getStore(CU.cacheId(cacheName), p);
cacheProc.context().database().checkpointReadLock();
try {
GridDhtLocalPartition part = cacheProc.cache(cacheName).context().topology().localPartition(p);
if (part.dataStore().rowStore() != null) {
AbstractFreeList freeList = (AbstractFreeList) part.dataStore().rowStore().freeList();
// Flush free-list onheap cache to page memory.
freeList.saveMetadata(IoStatisticsHolderNoOp.INSTANCE);
}
} finally {
cacheProc.context().database().checkpointReadUnlock();
}
store.sync();
res.add(store.pages());
}
PageStore store = storeMgr.getStore(CU.cacheId(cacheName), PageIdAllocator.INDEX_PARTITION);
store.sync();
res.add(store.pages());
return res;
}
use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.
the class FilePageStoreManager method writeInternal.
/**
* @param cacheId Cache ID to write.
* @param pageId Page ID.
* @param pageBuf Page buffer.
* @param tag Partition tag (growing 1-based partition file version). Used to validate page is not outdated
* @param calculateCrc if {@code False} crc calculation will be forcibly skipped.
* @return PageStore to which the page has been written.
* @throws IgniteCheckedException If IO error occurred.
*/
public PageStore writeInternal(int cacheId, long pageId, ByteBuffer pageBuf, int tag, boolean calculateCrc) throws IgniteCheckedException {
int partId = PageIdUtils.partId(pageId);
PageStore store = getStore(cacheId, partId);
try {
store.write(pageId, pageBuf, tag, calculateCrc);
} catch (PersistentStorageIOException e) {
NodeInvalidator.INSTANCE.invalidate(cctx.kernalContext(), e);
throw e;
}
return store;
}
use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.
the class DiskPageCompressionIntegrationTest method doTestPageCompression.
/**
* @throws Exception If failed.
*/
@Override
protected void doTestPageCompression() throws Exception {
IgniteEx ignite = startGrid(0);
ignite.cluster().active(true);
String cacheName = "test";
CacheConfiguration<Integer, TestVal> ccfg = new CacheConfiguration<Integer, TestVal>().setName(cacheName).setBackups(0).setAtomicityMode(ATOMIC).setIndexedTypes(Integer.class, TestVal.class).setDiskPageCompression(compression).setDiskPageCompressionLevel(compressionLevel);
IgniteCache<Integer, TestVal> cache = ignite.getOrCreateCache(ccfg);
int cnt = 2_000;
for (int i = 0; i < cnt; i++) assertTrue(cache.putIfAbsent(i, new TestVal(i)));
for (int i = 0; i < cnt; i += 2) assertEquals(new TestVal(i), cache.getAndRemove(i));
GridCacheDatabaseSharedManager dbMgr = ((GridCacheDatabaseSharedManager) ignite.context().cache().context().database());
dbMgr.forceCheckpoint("test compression").futureFor(FINISHED).get();
FilePageStoreManager storeMgr = dbMgr.getFileStoreManager();
checkFileIOFactory(storeMgr.getPageStoreFileIoFactory());
// Wait for metrics update.
Thread.sleep(100);
long storeSize = ignite.dataStorageMetrics().getStorageSize();
long sparseStoreSize = ignite.dataStorageMetrics().getSparseStorageSize();
assertTrue("storeSize: " + storeSize, storeSize > 0);
if (U.isLinux()) {
assertTrue("sparseSize: " + sparseStoreSize, sparseStoreSize > 0);
assertTrue(storeSize + " > " + sparseStoreSize, storeSize > sparseStoreSize);
} else
assertTrue(sparseStoreSize < 0);
GridCacheContext<?, ?> cctx = ignite.cachex(cacheName).context();
int cacheId = cctx.cacheId();
int groupId = cctx.groupId();
assertEquals(cacheId, groupId);
MetricRegistry mreg = ignite.context().metric().registry(metricName(CACHE_GROUP_METRICS_PREFIX, cctx.group().cacheOrGroupName()));
storeSize = mreg.<LongMetric>findMetric("StorageSize").value();
sparseStoreSize = mreg.<LongMetric>findMetric("SparseStorageSize").value();
assertTrue("storeSize: " + storeSize, storeSize > 0);
if (U.isLinux()) {
assertTrue("sparseSize: " + sparseStoreSize, sparseStoreSize > 0);
assertTrue(storeSize + " > " + sparseStoreSize, storeSize > sparseStoreSize);
} else
assertTrue(sparseStoreSize < 0);
int parts = cctx.affinity().partitions();
for (int i = 0; i < parts; i++) {
PageStore store = storeMgr.getStore(cacheId, i);
long realSize = store.size();
long virtualSize = store.getPageSize() * store.pages();
long sparseSize = store.getSparseSize();
assertTrue(virtualSize > 0);
error("virt: " + virtualSize + ", real: " + realSize + ", sparse: " + sparseSize);
if (!store.exists())
continue;
if (virtualSize > sparseSize)
return;
}
fail("No files were compacted.");
}
use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.
the class FilePageStoreManager method getStore.
/**
* @param grpId Cache group ID.
* @param partId Partition ID.
* @return Page store for the corresponding parameters.
* @throws IgniteCheckedException If cache or partition with the given ID was not created.
*
* Note: visible for testing.
*/
@Override
public PageStore getStore(int grpId, int partId) throws IgniteCheckedException {
CacheStoreHolder holder = getHolder(grpId);
if (holder == null)
throw new IgniteCheckedException("Failed to get page store for the given cache ID " + "(cache has not been started): " + grpId);
if (partId == INDEX_PARTITION)
return holder.idxStore;
if (partId > MAX_PARTITION_ID)
throw new IgniteCheckedException("Partition ID is reserved: " + partId);
PageStore store = holder.partStores[partId];
if (store == null)
throw new IgniteCheckedException("Failed to get page store for the given partition ID " + "(partition has not been created) [grpId=" + grpId + ", partId=" + partId + ']');
return store;
}
Aggregations