/** * Count total number of locked keys on local node. */ private long txLockedKeysNum() { GridCacheMvccManager mvccManager = gridKernalCtx.cache().context().mvcc(); return mvccManager.lockedKeys().size() + mvccManager.nearLockedKeys().size(); }
/** * @return Cache object context. */ private CacheObjectContext objectContext() { if (ctx == null) return null; return ctx.cache().internalCache(cacheName).context().cacheObjectContext(); }
/** * Gets cache mode. * * @param cacheName Cache name to check. * @return Cache mode. */ public CacheMode cacheMode(String cacheName) { assert cacheName != null; DynamicCacheDescriptor desc = cacheDescriptor(cacheName); return desc != null ? desc.cacheConfiguration().getCacheMode() : null; }
/** * @param cacheName Cache name to close. * @return Future that will be completed when cache is closed. */ IgniteInternalFuture<?> dynamicCloseCache(String cacheName) { assert cacheName != null; IgniteCacheProxy<?, ?> proxy = jcacheProxy(cacheName, false); if (proxy == null || proxy.isProxyClosed()) return new GridFinishedFuture<>(); // No-op. checkEmptyTransactions(); if (proxy.context().isLocal()) return dynamicDestroyCache(cacheName, false, true, false, null); return startClientCacheChange(null, Collections.singleton(cacheName)); }
/** * @param msg Message. * @return Cache or group descriptor. */ private Object descriptorForMessage(GridCacheMessage msg) { if (msg instanceof GridCacheIdMessage) return cctx.cache().cacheDescriptor(((GridCacheIdMessage)msg).cacheId()); else if (msg instanceof GridCacheGroupIdMessage) return cctx.cache().cacheGroupDescriptors().get(((GridCacheGroupIdMessage)msg).groupId()); return null; }
/** * */ private void assertCachesAfterStop(IgniteEx igniteEx) { assertNull(igniteEx .context() .cache() .cacheGroup(CU.cacheId(STATIC_CACHE_CACHE_GROUP_NAME))); assertTrue(igniteEx.context().cache().cacheGroups().isEmpty()); for (int i = 0; i < CACHES_COUNT; i++) { assertNull(igniteEx.context().cache().cache(STATIC_CACHE_PREFIX + i)); assertNull(igniteEx.context().cache().internalCache(STATIC_CACHE_PREFIX + i)); } }
/** * Check whether cache restarting in progress. * * @param ignite Grid. * @param cacheName Cache name to check. * @return {@code true} when cache restarting in progress. */ public static boolean isRestartingCache(IgniteEx ignite, String cacheName) { IgniteCacheProxy<Object, Object> proxy = ignite.context().cache().jcache(cacheName); return proxy instanceof IgniteCacheProxyImpl && ((IgniteCacheProxyImpl) proxy).isRestarting(); } }
/** * @param grpCtx Group context. Can be {@code null} in case of crash recovery. * @param grpId Group ID. * @param partId Partition ID. */ private void schedulePartitionDestroy(@Nullable CacheGroupContext grpCtx, int grpId, int partId) { synchronized (this) { scheduledCp.destroyQueue.addDestroyRequest(grpCtx, grpId, partId); } if (log.isDebugEnabled()) log.debug("Partition file has been scheduled to destroy [grpId=" + grpId + ", partId=" + partId + "]"); if (grpCtx != null) wakeupForCheckpoint(PARTITION_DESTROY_CHECKPOINT_TIMEOUT, "partition destroy"); }
/** {@inheritDoc} */ @Override public IgniteFuture<?> destroyAsync() { GridCacheContext<K, V> ctx = getContextSafe(); return new IgniteFutureImpl<>(ctx.kernalContext().cache().dynamicDestroyCache(cacheName, false, true, false, null)); }
/** * 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; }
/** * @param cacheName Name of the cache. * @return Instance on the named cache. * @throws IgniteCheckedException If cache not found. */ protected IgniteInternalCache<Object, Object> localCache(String cacheName) throws IgniteCheckedException { IgniteInternalCache<Object, Object> cache = ctx.cache().cache(cacheName); if (cache == null) throw new IgniteCheckedException( "Failed to find cache for given cache name: " + cacheName); return cache; }
/** {@inheritDoc} */ @Override public long getRowCount() { return ctx.cache().cacheDescriptors().size(); } }
/** * @param f Consumer. * @return Accumulated result for all page stores. */ public long forAllPageStores(ToLongFunction<PageStore> f) { long res = 0; for (CacheGroupContext gctx : cctx.cache().cacheGroups()) res += forGroupPageStores(gctx, f); return res; }
/** {@inheritDoc} */ @Override public long getRowCount() { return ctx.cache().cacheGroupDescriptors().size(); } }
/** */ private void verifyCachesAndGroups(IgniteEx ignite) { Map<String, DynamicCacheDescriptor> caches = ignite.context().cache().cacheDescriptors(); assertEquals(2, caches.size()); caches.keySet().contains(GridCacheUtils.UTILITY_CACHE_NAME); caches.keySet().contains(STATIC_CACHE_NAME); Map<Integer, CacheGroupDescriptor> groups = ignite.context().cache().cacheGroupDescriptors(); assertEquals(2, groups.size()); boolean defaultGroupFound = false; boolean staticCachesGroupFound = false; for (CacheGroupDescriptor grpDesc : groups.values()) { if (grpDesc.cacheOrGroupName().equals(GridCacheUtils.UTILITY_CACHE_NAME)) defaultGroupFound = true; else if (grpDesc.cacheOrGroupName().equals(GROUP_WITH_STATIC_CACHES)) staticCachesGroupFound = true; } assertTrue(String.format("Default group found: %b, static group found: %b", defaultGroupFound, staticCachesGroupFound), defaultGroupFound && staticCachesGroupFound); }
/** * Test metrics for failed SQL queries. * * @throws Exception In case of error. */ @Test public void testSqlFieldsQueryFailedMetrics() throws Exception { IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A"); SqlFieldsQuery qry = new SqlFieldsQuery("select * from UNKNOWN"); checkQueryFailedMetrics(cache, qry); }
/** * Checks WAL disabled for cache group. * * @param grpId Group id. * @return {@code True} if WAL disable for group. {@code False} If not. */ public boolean isDisabled(int grpId) { CacheGroupContext ctx = cctx.cache().cacheGroup(grpId); return ctx != null && !ctx.walEnabled(); }
@Override public Object call() throws Exception { futs.add(kernal.context().cache().dynamicDestroyCache(DYNAMIC_CACHE_NAME, false, true, false, null)); return null; } }, threadNum, "cache-stopper");
/** * Validate propose message. * * @param msg Message. * @return Error message or {@code null} if everything is OK. */ @Nullable private String validate(WalStateProposeMessage msg) { // Is group still there? CacheGroupDescriptor grpDesc = cacheProcessor().cacheGroupDescriptors().get(msg.groupId()); if (grpDesc == null) return "Failed to change WAL mode because some caches no longer exist: " + msg.caches().keySet(); // Are specified caches still there? for (Map.Entry<String, IgniteUuid> cache : msg.caches().entrySet()) { String cacheName = cache.getKey(); DynamicCacheDescriptor cacheDesc = cacheProcessor().cacheDescriptor(cacheName); if (cacheDesc == null || !F.eq(cacheDesc.deploymentId(), cache.getValue())) return "Cache doesn't exist: " + cacheName; } // Are there any new caches in the group? HashSet<String> grpCacheNames = new HashSet<>(grpDesc.caches().keySet()); grpCacheNames.removeAll(msg.caches().keySet()); if (!grpCacheNames.isEmpty()) { return "Cannot change WAL mode because not all cache names belonging to the " + "group are provided [group=" + grpDesc.groupName() + ", missingCaches=" + grpCacheNames + ']'; } return null; }
/** {@inheritDoc} */ @Nullable @Override public final Object execute() { if (!waitAffinityReadyFuture()) return null; IgniteInternalCache cache = ((IgniteEx)ignite).context().cache().cache(cacheName); return localExecute(cache); }