use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.
the class MetaStorage method init.
/**
*/
public void init(GridCacheDatabaseSharedManager db) throws IgniteCheckedException {
dataRegion.metrics().clear();
initInternal(db);
if (!PRESERVE_LEGACY_METASTORAGE_PARTITION_ID) {
if (partId == OLD_METASTORE_PARTITION)
db.temporaryMetaStorage(copyDataToTmpStorage());
else if (db.temporaryMetaStorage() != null) {
restoreDataFromTmpStorage(db.temporaryMetaStorage());
db.temporaryMetaStorage(null);
db.addCheckpointListener(new CheckpointListener() {
/**
* {@inheritDoc}
*/
@Override
public void onMarkCheckpointBegin(Context ctx) {
}
/**
* {@inheritDoc}
*/
@Override
public void onCheckpointBegin(Context ctx) throws IgniteCheckedException {
assert cctx.pageStore() != null;
int partTag = ((PageMemoryEx) dataRegion.pageMemory()).invalidate(METASTORAGE_CACHE_ID, OLD_METASTORE_PARTITION);
cctx.pageStore().truncate(METASTORAGE_CACHE_ID, OLD_METASTORE_PARTITION, partTag);
int idxTag = ((PageMemoryEx) dataRegion.pageMemory()).invalidate(METASTORAGE_CACHE_ID, PageIdAllocator.INDEX_PARTITION);
PageStore store = ((FilePageStoreManager) cctx.pageStore()).getStore(METASTORAGE_CACHE_ID, PageIdAllocator.INDEX_PARTITION);
store.truncate(idxTag);
db.removeCheckpointListener(this);
}
/**
* {@inheritDoc}
*/
@Override
public void beforeCheckpointBegin(Context ctx) {
}
}, dataRegion);
}
}
}
use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.
the class PageReadWriteManagerImpl method write.
/**
* {@inheritDoc}
*/
@Override
public PageStore write(int grpId, long pageId, ByteBuffer pageBuf, int tag, boolean calculateCrc) throws IgniteCheckedException {
int partId = PageIdUtils.partId(pageId);
PageStore store = pageStores.getStore(grpId, partId);
try {
int pageSize = store.getPageSize();
int compressedPageSize = pageSize;
GridCacheContext<?, ?> cctx0 = ctx.cache().context().cacheContext(grpId);
if (cctx0 != null) {
assert pageBuf.position() == 0 && pageBuf.limit() == pageSize : pageBuf;
ByteBuffer compressedPageBuf = cctx0.compress().compressPage(pageBuf, store);
if (compressedPageBuf != pageBuf) {
compressedPageSize = PageIO.getCompressedSize(compressedPageBuf);
if (!calculateCrc) {
calculateCrc = true;
// It will be recalculated over compressed data further.
PageIO.setCrc(compressedPageBuf, 0);
}
// It is expected to be reset to 0 after each write.
PageIO.setCrc(pageBuf, 0);
pageBuf = compressedPageBuf;
}
}
store.write(pageId, pageBuf, tag, calculateCrc);
if (pageSize > compressedPageSize)
// TODO maybe add async punch mode?
store.punchHole(pageId, compressedPageSize);
} catch (StorageException e) {
ctx.failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e));
throw e;
}
return store;
}
use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.
the class PageReadWriteManagerImpl method read.
/**
* {@inheritDoc}
*/
@Override
public void read(int grpId, long pageId, ByteBuffer pageBuf, boolean keepCrc) throws IgniteCheckedException {
PageStore store = pageStores.getStore(grpId, PageIdUtils.partId(pageId));
try {
store.read(pageId, pageBuf, keepCrc);
ctx.compress().decompressPage(pageBuf, store.getPageSize());
} catch (StorageException e) {
ctx.failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e));
throw e;
}
}
use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.
the class Checkpointer method writePages.
/**
* @param workProgressDispatcher Work progress dispatcher.
* @param tracker Checkpoint metrics tracker.
* @param cpPages List of pages to write.
* @param curCpProgress Current checkpoint data.
* @param shutdownNow Checker of stop operation.
*/
boolean writePages(CheckpointMetricsTracker tracker, GridConcurrentMultiPairQueue<PageMemoryEx, FullPageId> cpPages, CheckpointProgressImpl curCpProgress, WorkProgressDispatcher workProgressDispatcher, BooleanSupplier shutdownNow) throws IgniteCheckedException {
IgniteThreadPoolExecutor pageWritePool = checkpointWritePagesPool;
int checkpointWritePageThreads = pageWritePool == null ? 1 : pageWritePool.getMaximumPoolSize();
// Identity stores set.
ConcurrentLinkedHashMap<PageStore, LongAdder> updStores = new ConcurrentLinkedHashMap<>();
CountDownFuture doneWriteFut = new CountDownFuture(checkpointWritePageThreads);
tracker.onPagesWriteStart();
for (int i = 0; i < checkpointWritePageThreads; i++) {
Runnable write = checkpointPagesWriterFactory.build(tracker, cpPages, updStores, doneWriteFut, workProgressDispatcher::updateHeartbeat, curCpProgress, shutdownNow);
if (pageWritePool == null)
write.run();
else {
try {
pageWritePool.execute(write);
} catch (RejectedExecutionException ignore) {
// Run the task synchronously.
write.run();
}
}
}
workProgressDispatcher.updateHeartbeat();
// Wait and check for errors.
doneWriteFut.get();
// If so, we should not put finish checkpoint mark.
if (shutdownNow.getAsBoolean()) {
curCpProgress.fail(new NodeStoppingException("Node is stopping."));
return false;
}
tracker.onFsyncStart();
if (!skipSync) {
for (Map.Entry<PageStore, LongAdder> updStoreEntry : updStores.entrySet()) {
if (shutdownNow.getAsBoolean()) {
curCpProgress.fail(new NodeStoppingException("Node is stopping."));
return false;
}
workProgressDispatcher.blockingSectionBegin();
try {
updStoreEntry.getKey().sync();
} finally {
workProgressDispatcher.blockingSectionEnd();
}
curCpProgress.updateSyncedPages(updStoreEntry.getValue().intValue());
}
}
return true;
}
use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.
the class CachePartitionDefragmentationManager method createIndexPageStore.
/**
*/
public void createIndexPageStore(int grpId, File workDir, FileVersionCheckingFactory pageStoreFactory, DataRegion partRegion, LongConsumer allocatedTracker) throws IgniteCheckedException {
// Index partition file has to be deleted before we begin, otherwise there's a chance of reading corrupted file.
// There is a time period when index is already defragmented but marker file is not created yet. If node is
// failed in that time window then index will be deframented once again. That's fine, situation is rare but code
// to fix that would add unnecessary complications.
U.delete(defragmentedIndexTmpFile(workDir));
PageStore idxPageStore;
defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadLock();
try {
idxPageStore = pageStoreFactory.createPageStore(FLAG_IDX, () -> defragmentedIndexTmpFile(workDir).toPath(), allocatedTracker);
} finally {
defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadUnlock();
}
idxPageStore.sync();
PageMemoryEx partPageMem = (PageMemoryEx) partRegion.pageMemory();
DefragmentationPageReadWriteManager partMgr = (DefragmentationPageReadWriteManager) partPageMem.pageManager();
partMgr.pageStoreMap().addPageStore(grpId, INDEX_PARTITION, idxPageStore);
}
Aggregations