Search in sources :

Example 1 with GridKernalContext

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

the class GridCacheQueryManager method backupsFilter.

/**
     * @param <K> Key type.
     * @param <V> Value type.
     * @param includeBackups Include backups.
     * @return Predicate.
     */
@SuppressWarnings("unchecked")
@Nullable
public <K, V> IndexingQueryFilter backupsFilter(boolean includeBackups) {
    if (includeBackups)
        return null;
    return new IndexingQueryFilter() {

        @Nullable
        @Override
        public IgniteBiPredicate<K, V> forCache(final String cacheName) {
            final GridKernalContext ctx = cctx.kernalContext();
            final GridCacheAdapter<Object, Object> cache = ctx.cache().internalCache(cacheName);
            if (cache.context().isReplicated() || cache.configuration().getBackups() == 0)
                return null;
            return new IgniteBiPredicate<K, V>() {

                @Override
                public boolean apply(K k, V v) {
                    return cache.context().affinity().primaryByKey(ctx.discovery().localNode(), k, NONE);
                }
            };
        }

        @Override
        public boolean isValueRequired() {
            return false;
        }
    };
}
Also used : IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) IndexingQueryFilter(org.apache.ignite.spi.indexing.IndexingQueryFilter) GridKernalContext(org.apache.ignite.internal.GridKernalContext) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with GridKernalContext

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

the class CacheObjectImpl method value.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Nullable
@Override
public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
    cpy = cpy && needCopy(ctx);
    try {
        GridKernalContext kernalCtx = ctx.kernalContext();
        IgniteCacheObjectProcessor proc = ctx.kernalContext().cacheObjects();
        if (cpy) {
            if (valBytes == null) {
                assert val != null;
                valBytes = proc.marshal(ctx, val);
            }
            ClassLoader clsLdr;
            if (val != null)
                clsLdr = val.getClass().getClassLoader();
            else if (kernalCtx.config().isPeerClassLoadingEnabled())
                clsLdr = kernalCtx.cache().context().deploy().globalLoader();
            else
                clsLdr = null;
            return (T) proc.unmarshal(ctx, valBytes, clsLdr);
        }
        if (val != null)
            return (T) val;
        assert valBytes != null;
        Object val = proc.unmarshal(ctx, valBytes, kernalCtx.config().isPeerClassLoadingEnabled() ? kernalCtx.cache().context().deploy().globalLoader() : null);
        if (ctx.storeValue())
            this.val = val;
        return (T) val;
    } catch (IgniteCheckedException e) {
        throw new IgniteException("Failed to unmarshall object.", e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteCacheObjectProcessor(org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor) IgniteException(org.apache.ignite.IgniteException) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with GridKernalContext

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

the class IgnitePageMemReplaceDelayedWriteUnitTest method createPageMemory.

/**
 * @param cfg configuration
 * @param pageWriter writer for page replacement.
 * @param pageSize page size
 * @return implementation for test
 */
@NotNull
private PageMemoryImpl createPageMemory(IgniteConfiguration cfg, ReplacedPageWriter pageWriter, int pageSize) {
    IgniteCacheDatabaseSharedManager db = mock(GridCacheDatabaseSharedManager.class);
    when(db.checkpointLockIsHeldByThread()).thenReturn(true);
    GridCacheSharedContext sctx = Mockito.mock(GridCacheSharedContext.class);
    when(sctx.pageStore()).thenReturn(new NoOpPageStoreManager());
    when(sctx.wal()).thenReturn(new NoOpWALManager());
    when(sctx.database()).thenReturn(db);
    when(sctx.logger(any(Class.class))).thenReturn(log);
    GridKernalContext kernalCtx = mock(GridKernalContext.class);
    when(kernalCtx.config()).thenReturn(cfg);
    when(sctx.kernalContext()).thenReturn(kernalCtx);
    DataRegionConfiguration regCfg = cfg.getDataStorageConfiguration().getDefaultDataRegionConfiguration();
    DataRegionMetricsImpl memMetrics = new DataRegionMetricsImpl(regCfg);
    long[] sizes = prepareSegmentSizes(regCfg.getMaxSize());
    DirectMemoryProvider provider = new UnsafeMemoryProvider(log);
    PageMemoryImpl memory = new PageMemoryImpl(provider, sizes, sctx, pageSize, pageWriter, null, () -> true, memMetrics, PageMemoryImpl.ThrottlingPolicy.DISABLED, null);
    memory.start();
    return memory;
}
Also used : DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) DirectMemoryProvider(org.apache.ignite.internal.mem.DirectMemoryProvider) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GridKernalContext

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

the class IgniteWalIteratorFactory method prepareSharedCtx.

/**
 * @return fake shared context required for create minimal services for record reading
 */
@NotNull
private GridCacheSharedContext prepareSharedCtx() throws IgniteCheckedException {
    final GridKernalContext kernalCtx = new StandaloneGridKernalContext(log, binaryMetadataFileStoreDir, marshallerMappingFileStoreDir);
    final StandaloneIgniteCacheDatabaseSharedManager dbMgr = new StandaloneIgniteCacheDatabaseSharedManager();
    dbMgr.setPageSize(pageSize);
    return new GridCacheSharedContext<>(kernalCtx, null, null, null, null, null, null, dbMgr, null, null, null, null, null, null, null, null);
}
Also used : GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GridKernalContext

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

the class MapQueryResult method fetchNextPage.

/**
 * @param rows Collection to fetch into.
 * @param pageSize Page size.
 * @return {@code true} If there are no more rows available.
 */
synchronized boolean fetchNextPage(List<Value[]> rows, int pageSize) {
    assert lazyWorker == null || lazyWorker == MapQueryLazyWorker.currentWorker();
    if (closed)
        return true;
    boolean readEvt = cctx != null && cctx.name() != null && cctx.events().isRecordable(EVT_CACHE_QUERY_OBJECT_READ);
    page++;
    for (int i = 0; i < pageSize; i++) {
        if (!res.next())
            return true;
        Value[] row = res.currentRow();
        if (cpNeeded) {
            boolean copied = false;
            for (int j = 0; j < row.length; j++) {
                Value val = row[j];
                if (val instanceof GridH2ValueCacheObject) {
                    GridH2ValueCacheObject valCacheObj = (GridH2ValueCacheObject) val;
                    row[j] = new GridH2ValueCacheObject(valCacheObj.getCacheObject(), h2.objectContext()) {

                        @Override
                        public Object getObject() {
                            return getObject(true);
                        }
                    };
                    copied = true;
                }
            }
            if (i == 0 && !copied)
                // No copy on read caches, skip next checks.
                cpNeeded = false;
        }
        assert row != null;
        if (readEvt) {
            GridKernalContext ctx = h2.kernalContext();
            ctx.event().record(new CacheQueryReadEvent<>(ctx.discovery().localNode(), "SQL fields query result set row read.", EVT_CACHE_QUERY_OBJECT_READ, CacheQueryType.SQL.name(), cctx.name(), null, qry.query(), null, null, params, qrySrcNodeId, null, null, null, null, row(row)));
        }
        rows.add(res.currentRow());
    }
    return false;
}
Also used : GridKernalContext(org.apache.ignite.internal.GridKernalContext) Value(org.h2.value.Value) GridH2ValueCacheObject(org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject) GridH2ValueCacheObject(org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject)

Aggregations

GridKernalContext (org.apache.ignite.internal.GridKernalContext)61 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)14 IgniteEx (org.apache.ignite.internal.IgniteEx)13 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)12 ClusterNode (org.apache.ignite.cluster.ClusterNode)11 ArrayList (java.util.ArrayList)10 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)10 List (java.util.List)9 IgniteLogger (org.apache.ignite.IgniteLogger)9 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)9 File (java.io.File)8 Map (java.util.Map)8 UUID (java.util.UUID)8 Ignite (org.apache.ignite.Ignite)8 IgniteKernal (org.apache.ignite.internal.IgniteKernal)8 Nullable (org.jetbrains.annotations.Nullable)8 Test (org.junit.Test)8 Collection (java.util.Collection)7 IgniteException (org.apache.ignite.IgniteException)7 FilePageStoreManager (org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager)7