Search in sources :

Example 11 with IgniteKernal

use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.

the class GridCacheContext method readResolve.

/**
 * Reconstructs object on unmarshalling.
 *
 * @return Reconstructed object.
 * @throws ObjectStreamException Thrown in case of unmarshalling error.
 */
protected Object readResolve() throws ObjectStreamException {
    try {
        IgniteBiTuple<String, String> t = stash.get();
        IgniteKernal grid = IgnitionEx.localIgnite();
        GridCacheAdapter<K, V> cache = grid.internalCache(t.get2());
        if (cache == null)
            throw new IllegalStateException("Failed to find cache for name: " + t.get2());
        return cache.context();
    } catch (IllegalStateException e) {
        throw U.withCause(new InvalidObjectException(e.getMessage()), e);
    } finally {
        stash.remove();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) InvalidObjectException(java.io.InvalidObjectException)

Example 12 with IgniteKernal

use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.

the class GridCacheQueryJdbcMetadataTask method map.

/**
 * {@inheritDoc}
 */
@NotNull
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable String cacheName) {
    Map<JdbcDriverMetadataJob, ClusterNode> map = new HashMap<>();
    IgniteKernal kernal = (IgniteKernal) ignite;
    GridDiscoveryManager discoMgr = kernal.context().discovery();
    for (ClusterNode n : subgrid) if (discoMgr.cacheAffinityNode(n, cacheName)) {
        map.put(new JdbcDriverMetadataJob(cacheName), n);
        break;
    }
    return map;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) HashMap(java.util.HashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with IgniteKernal

use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.

the class CacheGetEntryAbstractTest method compareVersionWithPrimaryNode.

/**
 * @param e Entry.
 * @param cache Cache.
 * @throws Exception If failed.
 */
private void compareVersionWithPrimaryNode(CacheEntry<Integer, ?> e, IgniteCache<Integer, TestValue> cache) throws Exception {
    CacheConfiguration cfg = cache.getConfiguration(CacheConfiguration.class);
    if (cfg.getCacheMode() != LOCAL) {
        Ignite prim = primaryNode(e.getKey(), cache.getName());
        GridCacheAdapter<Object, Object> cacheAdapter = ((IgniteKernal) prim).internalCache(cache.getName());
        if (cfg.getNearConfiguration() != null)
            cacheAdapter = ((GridNearCacheAdapter) cacheAdapter).dht();
        IgniteCacheObjectProcessor cacheObjects = cacheAdapter.context().cacheObjects();
        CacheObjectContext cacheObjCtx = cacheAdapter.context().cacheObjectContext();
        GridCacheEntryEx mapEntry = cacheAdapter.entryEx(cacheObjects.toCacheKeyObject(cacheObjCtx, cacheAdapter.context(), e.getKey(), true));
        mapEntry.unswap();
        assertNotNull("No entry for key: " + e.getKey(), mapEntry);
        assertEquals(mapEntry.version(), e.version());
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter) IgniteCacheObjectProcessor(org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor) Ignite(org.apache.ignite.Ignite) BinaryObject(org.apache.ignite.binary.BinaryObject) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 14 with IgniteKernal

use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.

the class GridCacheBinaryObjectsAbstractSelfTest method afterTest.

/**
 * {@inheritDoc}
 */
@Override
protected void afterTest() throws Exception {
    for (int i = 0; i < gridCount(); i++) {
        GridCacheAdapter<Object, Object> c = ((IgniteKernal) grid(i)).internalCache(DEFAULT_CACHE_NAME);
        for (GridCacheEntryEx e : c.map().entries(c.context().cacheId())) {
            Object key = e.key().value(c.context().cacheObjectContext(), false);
            Object val = CU.value(e.rawGet(), c.context(), false);
            if (key instanceof BinaryObject)
                assert ((BinaryObjectImpl) key).detached() : val;
            if (val instanceof BinaryObject)
                assert ((BinaryObjectImpl) val).detached() : val;
        }
    }
    IgniteCache<Object, Object> c = jcache(0);
    for (int i = 0; i < ENTRY_CNT; i++) c.remove(i);
    assertEquals(0, c.size());
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObject(org.apache.ignite.binary.BinaryObject)

Example 15 with IgniteKernal

use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.

the class ViewCacheClosure method call.

/**
 * {@inheritDoc}
 */
@Override
public List<CacheInfo> call() throws Exception {
    Pattern compiled = Pattern.compile(regex);
    List<CacheInfo> cacheInfo = new ArrayList<>();
    IgniteKernal k = (IgniteKernal) ignite;
    if (cmd == null)
        cmd = VisorViewCacheCmd.CACHES;
    switch(cmd) {
        case SEQ:
            collectSequences(k.context(), compiled, cacheInfo);
            return cacheInfo;
        case GROUPS:
            Collection<CacheGroupContext> contexts = k.context().cache().cacheGroups();
            for (CacheGroupContext context : contexts) {
                if (!context.userCache() || !compiled.matcher(context.cacheOrGroupName()).find())
                    continue;
                CacheInfo ci = new CacheInfo();
                ci.setGrpName(context.cacheOrGroupName());
                ci.setGrpId(context.groupId());
                ci.setCachesCnt(context.caches().size());
                ci.setPartitions(context.config().getAffinity().partitions());
                ci.setBackupsCnt(context.config().getBackups());
                ci.setAffinityClsName(context.config().getAffinity().getClass().getSimpleName());
                ci.setMode(context.config().getCacheMode());
                ci.setAtomicityMode(context.config().getAtomicityMode());
                ci.setMapped(mapped(context.caches().iterator().next().name()));
                cacheInfo.add(ci);
            }
            return cacheInfo;
        default:
            Map<String, DynamicCacheDescriptor> descMap = k.context().cache().cacheDescriptors();
            for (Map.Entry<String, DynamicCacheDescriptor> entry : descMap.entrySet()) {
                DynamicCacheDescriptor desc = entry.getValue();
                if (!desc.cacheType().userCache() || !compiled.matcher(desc.cacheName()).find())
                    continue;
                CacheInfo ci = new CacheInfo();
                ci.setCacheName(desc.cacheName());
                ci.setCacheId(desc.cacheId());
                ci.setGrpName(desc.groupDescriptor().groupName());
                ci.setGrpId(desc.groupDescriptor().groupId());
                ci.setPartitions(desc.cacheConfiguration().getAffinity().partitions());
                ci.setBackupsCnt(desc.cacheConfiguration().getBackups());
                ci.setAffinityClsName(desc.cacheConfiguration().getAffinity().getClass().getSimpleName());
                ci.setMode(desc.cacheConfiguration().getCacheMode());
                ci.setAtomicityMode(desc.cacheConfiguration().getAtomicityMode());
                ci.setMapped(mapped(desc.cacheName()));
                cacheInfo.add(ci);
            }
            return cacheInfo;
    }
}
Also used : Pattern(java.util.regex.Pattern) IgniteKernal(org.apache.ignite.internal.IgniteKernal) ArrayList(java.util.ArrayList) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) Map(java.util.Map)

Aggregations

IgniteKernal (org.apache.ignite.internal.IgniteKernal)203 Ignite (org.apache.ignite.Ignite)88 Test (org.junit.Test)70 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)63 ClusterNode (org.apache.ignite.cluster.ClusterNode)38 ArrayList (java.util.ArrayList)36 Transaction (org.apache.ignite.transactions.Transaction)36 Map (java.util.Map)35 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)29 IgniteCache (org.apache.ignite.IgniteCache)29 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)28 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)28 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)27 IgniteEx (org.apache.ignite.internal.IgniteEx)27 UUID (java.util.UUID)25 IgniteException (org.apache.ignite.IgniteException)25 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)23 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)20 CacheException (javax.cache.CacheException)17 HashMap (java.util.HashMap)16