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;
}
};
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations