/** {@inheritDoc} */ @Override public void beforeBinaryMemoryRestore(IgniteCacheDatabaseSharedManager mgr) throws IgniteCheckedException { cctx.pageStore().initializeForMetastorage(); }
/** {@inheritDoc} */ @Override protected void checkPageSize(DataStorageConfiguration memCfg) { if (memCfg.getPageSize() == 0) { try { assert cctx.pageStore() instanceof FilePageStoreManager : "Invalid page store manager was created: " + cctx.pageStore(); Path anyIdxPartFile = IgniteUtils.searchFileRecursively( ((FilePageStoreManager)cctx.pageStore()).workDir().toPath(), FilePageStoreManager.INDEX_FILE_NAME); if (anyIdxPartFile != null) { memCfg.setPageSize(resolvePageSizeFromPartitionFile(anyIdxPartFile)); return; } } catch (IgniteCheckedException | IOException | IllegalArgumentException e) { U.quietAndWarn(log, "Attempt to resolve pageSize from store files failed: " + e.getMessage()); U.quietAndWarn(log, "Default page size will be used: " + DataStorageConfiguration.DFLT_PAGE_SIZE + " bytes"); } memCfg.setPageSize(DataStorageConfiguration.DFLT_PAGE_SIZE); } }
/** * Prepare page store for start cache. * * @param desc Cache descriptor. * @param affNode {@code true} if it is affinity node for cache. * @throws IgniteCheckedException if failed. */ public void preparePageStore(DynamicCacheDescriptor desc, boolean affNode) throws IgniteCheckedException { if (sharedCtx.pageStore() != null && affNode) initializationProtector.protect( desc.groupDescriptor().groupId(), () -> sharedCtx.pageStore().initializeForCache(desc.groupDescriptor(), desc.toStoredData()) ); }
/** {@inheritDoc} */ @Override protected CacheDataStore createCacheDataStore0(int p) throws IgniteCheckedException { if (ctx.database() instanceof GridCacheDatabaseSharedManager) ((GridCacheDatabaseSharedManager) ctx.database()).cancelOrWaitPartitionDestroy(grp.groupId(), p); boolean exists = ctx.pageStore() != null && ctx.pageStore().exists(grp.groupId(), p); return new GridCacheDataStore(p, exists); }
/** * @param readOnly Metastorage read-only mode. * @return Instance of Metastorage. * @throws IgniteCheckedException If failed to create metastorage. */ private MetaStorage createMetastorage(boolean readOnly) throws IgniteCheckedException { cctx.pageStore().initializeForMetastorage(); MetaStorage storage = new MetaStorage( cctx, dataRegion(METASTORE_DATA_REGION_NAME), (DataRegionMetricsImpl) memMetricsMap.get(METASTORE_DATA_REGION_NAME), readOnly ); storage.init(this); return storage; }
/** * Remove all persistent files for all registered caches. */ public void cleanupCachesDirectories() throws IgniteCheckedException { if (sharedCtx.pageStore() == null || sharedCtx.kernalContext().clientNode()) return; for (DynamicCacheDescriptor desc : cacheDescriptors().values()) { if (isPersistentCache(desc.cacheConfiguration(), sharedCtx.gridConfig().getDataStorageConfiguration())) sharedCtx.pageStore().cleanupPersistentSpace(desc.cacheConfiguration()); } }
/** * Save cache configuration to persistent store if necessary. * * @param desc Cache descriptor. */ public void saveCacheConfiguration(DynamicCacheDescriptor desc) throws IgniteCheckedException { assert desc != null; if (sharedCtx.pageStore() != null && !sharedCtx.kernalContext().clientNode() && isPersistentCache(desc.cacheConfiguration(), sharedCtx.gridConfig().getDataStorageConfiguration())) sharedCtx.pageStore().storeCacheData(desc.toStoredData(), true); }
/** * Checks whether given cache configuration should be persisted. * * @param cacheCfg Cache config. * @return {@code True} if cache configuration should be persisted, {@code false} in other case. */ private boolean shouldPersist(CacheConfiguration<?, ?> cacheCfg) { return cctx.pageStore() != null && CU.isPersistentCache(cacheCfg, cctx.gridConfig().getDataStorageConfiguration()) && !cctx.kernalContext().clientNode(); }
/** * @param mgr Database shared manager. * @throws IgniteCheckedException If failed. */ private void txLogPageStoreInit(IgniteCacheDatabaseSharedManager mgr) throws IgniteCheckedException { assert CU.isPersistenceEnabled(ctx.config()); //noinspection ConstantConditions ctx.cache().context().pageStore().initialize(TX_LOG_CACHE_ID, 1, TX_LOG_CACHE_NAME, mgr.dataRegion(TX_LOG_CACHE_NAME).memoryMetrics()); }
/** * Get index partition file for specific node and cache. */ private File indexPartition(Ignite ig, String cacheName) { IgniteEx ig0 = (IgniteEx)ig; FilePageStoreManager pageStoreManager = ((FilePageStoreManager) ig0.context().cache().context().pageStore()); return new File(pageStoreManager.cacheWorkDir(false, cacheName), INDEX_FILE_NAME); }
/** * Must be called when the grid is up. */ private List<Path> getIndexBinPaths() { return G.allGrids().stream() .map(grid -> (IgniteEx) grid) .map(grid -> { IgniteInternalCache<Object, Object> cachex = grid.cachex(DEFAULT_CACHE_NAME); assertNotNull(cachex); FilePageStoreManager pageStoreMgr = (FilePageStoreManager) cachex.context().shared().pageStore(); assertNotNull(pageStoreMgr); File cacheWorkDir = pageStoreMgr.cacheWorkDir(cachex.configuration()); return cacheWorkDir.toPath().resolve("index.bin"); }) .collect(Collectors.toList()); }
/** {@inheritDoc} */ @Override protected void start0() throws IgniteCheckedException { if (srv) cctx.kernalContext().io().addMessageListener(TOPIC_WAL, ioLsnr); walDisableContext = new WALDisableContext( cctx.cache().context().database(), cctx.pageStore(), log ); cctx.kernalContext().internalSubscriptionProcessor().registerMetastorageListener(walDisableContext); }
/** * Store temp cache descriptor to PDS. * * @param cacheDescr Cache descr. * @throws IgniteCheckedException If fails. */ private void corruptCacheData(DynamicCacheDescriptor cacheDescr) throws Exception { for (int i = 0; i < NODES; i++) { IgniteEx ig = grid(i); GridCacheSharedContext sharedCtx = ig.context().cache().context(); FilePageStoreManager pageStore = (FilePageStoreManager) sharedCtx.pageStore(); StoredCacheData data = cacheDescr.toStoredData(); data.config().setGroupName(ODD_GROUP_NAME); File config = new File(pageStore.cacheWorkDir(true, ODD_GROUP_NAME), data.config().getName() + CACHE_DATA_FILENAME); try (DataOutputStream os = new DataOutputStream(new FileOutputStream(config))) { os.writeLong(-1L); } } }
/** {@inheritDoc} */ @Override public void preload() throws IgniteCheckedException { IgnitePageStoreManager pageStoreMgr = ctx.pageStore(); if (pageStoreMgr == null) return; final int pages = pageStoreMgr.pages(grp.groupId(), partId); long pageId = pageMem.partitionMetaPageId(grp.groupId(), partId); // For each page sequentially pin/unpin. for (int pageNo = 0; pageNo < pages; pageId++, pageNo++) { long pagePointer = -1; try { pagePointer = pageMem.acquirePage(grp.groupId(), pageId); } finally { if (pagePointer != -1) pageMem.releasePage(grp.groupId(), pageId, pagePointer); } } } };
/** * Invalidates page memory for given partition. Destroys partition store. * <b>NOTE:</b> This method can be invoked only within checkpoint lock or checkpointer thread. * * @param grpId Group ID. * @param partId Partition ID. * * @throws IgniteCheckedException If destroy has failed. */ public void destroyPartitionStore(int grpId, int partId) throws IgniteCheckedException { PageMemoryEx pageMemory = (PageMemoryEx)grp.dataRegion().pageMemory(); int tag = pageMemory.invalidate(grp.groupId(), partId); if (grp.walEnabled()) ctx.wal().log(new PartitionDestroyRecord(grp.groupId(), partId)); ctx.pageStore().onPartitionDestroyed(grpId, partId, tag); }
/** * Store temp cache descriptor to PDS. * * @param cacheDescr Cache descr. * @throws IgniteCheckedException If fails. */ private void storeTmpCacheData(DynamicCacheDescriptor cacheDescr) throws Exception { Marshaller marshaller = new JdkMarshaller(); for (int i = 0; i < NODES; i++) { IgniteEx ig = grid(i); GridCacheSharedContext sharedCtx = ig.context().cache().context(); FilePageStoreManager pageStore = (FilePageStoreManager) sharedCtx.pageStore(); StoredCacheData data = cacheDescr.toStoredData(); data.config().setGroupName(ODD_GROUP_NAME); File tmp = new File(pageStore.cacheWorkDir(true, ODD_GROUP_NAME), data.config().getName() + CACHE_DATA_TMP_FILENAME); try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(tmp))) { marshaller.marshal(data, stream); } } }
/** * @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 { FilePageStoreManager storeMgr = (FilePageStoreManager)((IgniteEx)ignite).context().cache().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); store.sync(); res.add(store.pages()); } PageStore store = storeMgr.getStore(CU.cacheId(cacheName), PageIdAllocator.INDEX_PARTITION); store.sync(); res.add(store.pages()); return res; }
/** * Store cache descriptor to PDS with invalid group name. * * @param cacheDescr Cache descr. * @throws IgniteCheckedException If fails. */ private void storeInvalidCacheData(DynamicCacheDescriptor cacheDescr) throws IgniteCheckedException { for (int i = 0; i < NODES; i++) { IgniteEx ig = grid(i); GridCacheSharedContext sharedCtx = ig.context().cache().context(); FilePageStoreManager pageStore = (FilePageStoreManager) sharedCtx.pageStore(); StoredCacheData corrData = cacheDescr.toStoredData(); corrData.config().setGroupName(ODD_GROUP_NAME); pageStore.storeCacheData(corrData, true); } }
/** * Total count of allocated pages in page store. */ private long pageStoreAllocatedPages() { IgnitePageStoreManager pageStoreMgr = gridCtx.cache().context().pageStore(); assert pageStoreMgr != null; long totalAllocated = pageStoreMgr.pagesAllocated(MetaStorage.METASTORAGE_CACHE_ID); if (MvccUtils.mvccEnabled(gridCtx)) totalAllocated += pageStoreMgr.pagesAllocated(TxLog.TX_LOG_CACHE_ID); for (CacheGroupContext ctx : gridCtx.cache().cacheGroups()) totalAllocated += pageStoreMgr.pagesAllocated(ctx.groupId()); return totalAllocated; }
/** {@inheritDoc} */ @Test public void testIndexRebuild() throws Exception { IgniteEx srv = startServer(); execute(srv, "CREATE TABLE T(k int primary key, v int) WITH \"cache_name=T,wrap_value=false," + "atomicity=transactional_snapshot\""); execute(srv, "CREATE INDEX IDX ON T(v)"); IgniteInternalCache cc = srv.cachex(CACHE_NAME); assertNotNull(cc); lockVersion(srv); putData(srv, false); checkDataState(srv, false); File cacheWorkDir = ((FilePageStoreManager)cc.context().shared().pageStore()).cacheWorkDir(cc.configuration()); File idxPath = cacheWorkDir.toPath().resolve("index.bin").toFile(); stopAllGrids(); assertTrue(U.delete(idxPath)); srv = startServer(); putData(srv, true); checkDataState(srv, true); }