use of org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryManager in project ignite by apache.
the class GridCacheProcessor method createCache.
/**
* @param cfg Cache configuration to use to create cache.
* @param pluginMgr Cache plugin manager.
* @param desc Cache descriptor.
* @param locStartTopVer Current topology version.
* @param cacheObjCtx Cache object context.
* @param affNode {@code True} if local node affinity node.
* @param updatesAllowed Updates allowed flag.
* @return Cache context.
* @throws IgniteCheckedException If failed to create cache.
*/
private GridCacheContext createCache(CacheConfiguration<?, ?> cfg, @Nullable CachePluginManager pluginMgr, DynamicCacheDescriptor desc, AffinityTopologyVersion locStartTopVer, CacheObjectContext cacheObjCtx, boolean affNode, boolean updatesAllowed) throws IgniteCheckedException {
assert cfg != null;
if (cfg.getCacheStoreFactory() instanceof GridCacheLoaderWriterStoreFactory) {
GridCacheLoaderWriterStoreFactory factory = (GridCacheLoaderWriterStoreFactory) cfg.getCacheStoreFactory();
prepare(cfg, factory.loaderFactory(), false);
prepare(cfg, factory.writerFactory(), false);
} else
prepare(cfg, cfg.getCacheStoreFactory(), false);
CacheStore cfgStore = cfg.getCacheStoreFactory() != null ? cfg.getCacheStoreFactory().create() : null;
validate(ctx.config(), cfg, desc.cacheType(), cfgStore);
if (pluginMgr == null)
pluginMgr = new CachePluginManager(ctx, cfg);
pluginMgr.validate();
sharedCtx.jta().registerCache(cfg);
// Skip suggestions for internal caches.
if (desc.cacheType().userCache())
suggestOptimizations(cfg, cfgStore != null);
Collection<Object> toPrepare = new ArrayList<>();
if (cfgStore instanceof GridCacheLoaderWriterStore) {
toPrepare.add(((GridCacheLoaderWriterStore) cfgStore).loader());
toPrepare.add(((GridCacheLoaderWriterStore) cfgStore).writer());
} else
toPrepare.add(cfgStore);
prepare(cfg, toPrepare);
U.startLifecycleAware(lifecycleAwares(cfg, cfgStore));
boolean nearEnabled = GridCacheUtils.isNearEnabled(cfg);
GridCacheAffinityManager affMgr = new GridCacheAffinityManager();
GridCacheEventManager evtMgr = new GridCacheEventManager();
CacheEvictionManager evictMgr = (nearEnabled || cfg.isOnheapCacheEnabled()) ? new GridCacheEvictionManager() : new CacheOffheapEvictionManager();
GridCacheQueryManager qryMgr = queryManager(cfg);
CacheContinuousQueryManager contQryMgr = new CacheContinuousQueryManager();
CacheDataStructuresManager dataStructuresMgr = new CacheDataStructuresManager();
GridCacheTtlManager ttlMgr = new GridCacheTtlManager();
CacheConflictResolutionManager rslvrMgr = pluginMgr.createComponent(CacheConflictResolutionManager.class);
GridCacheDrManager drMgr = pluginMgr.createComponent(GridCacheDrManager.class);
CacheStoreManager storeMgr = pluginMgr.createComponent(CacheStoreManager.class);
IgniteCacheOffheapManager offheapMgr = pluginMgr.createComponent(IgniteCacheOffheapManager.class);
storeMgr.initialize(cfgStore, sesHolders);
String memPlcName = cfg.getMemoryPolicyName();
MemoryPolicy memPlc = sharedCtx.database().memoryPolicy(memPlcName);
FreeList freeList = sharedCtx.database().freeList(memPlcName);
ReuseList reuseList = sharedCtx.database().reuseList(memPlcName);
GridCacheContext<?, ?> cacheCtx = new GridCacheContext(ctx, sharedCtx, cfg, desc.cacheType(), locStartTopVer, desc.receivedFrom(), affNode, updatesAllowed, memPlc, freeList, reuseList, /*
* Managers in starting order!
* ===========================
*/
evtMgr, storeMgr, evictMgr, qryMgr, contQryMgr, dataStructuresMgr, ttlMgr, drMgr, offheapMgr, rslvrMgr, pluginMgr, affMgr);
cacheCtx.cacheObjectContext(cacheObjCtx);
GridCacheAdapter cache = null;
switch(cfg.getCacheMode()) {
case LOCAL:
{
switch(cfg.getAtomicityMode()) {
case TRANSACTIONAL:
{
cache = new GridLocalCache(cacheCtx);
break;
}
case ATOMIC:
{
cache = new GridLocalAtomicCache(cacheCtx);
break;
}
default:
{
assert false : "Invalid cache atomicity mode: " + cfg.getAtomicityMode();
}
}
break;
}
case PARTITIONED:
case REPLICATED:
{
if (nearEnabled) {
switch(cfg.getAtomicityMode()) {
case TRANSACTIONAL:
{
cache = new GridNearTransactionalCache(cacheCtx);
break;
}
case ATOMIC:
{
cache = new GridNearAtomicCache(cacheCtx);
break;
}
default:
{
assert false : "Invalid cache atomicity mode: " + cfg.getAtomicityMode();
}
}
} else {
switch(cfg.getAtomicityMode()) {
case TRANSACTIONAL:
{
cache = cacheCtx.affinityNode() ? new GridDhtColocatedCache(cacheCtx) : new GridDhtColocatedCache(cacheCtx, new GridNoStorageCacheMap(cacheCtx));
break;
}
case ATOMIC:
{
cache = cacheCtx.affinityNode() ? new GridDhtAtomicCache(cacheCtx) : new GridDhtAtomicCache(cacheCtx, new GridNoStorageCacheMap(cacheCtx));
break;
}
default:
{
assert false : "Invalid cache atomicity mode: " + cfg.getAtomicityMode();
}
}
}
break;
}
default:
{
assert false : "Invalid cache mode: " + cfg.getCacheMode();
}
}
cacheCtx.cache(cache);
GridCacheContext<?, ?> ret = cacheCtx;
/*
* Create DHT cache.
* ================
*/
if (cfg.getCacheMode() != LOCAL && nearEnabled) {
/*
* Specifically don't create the following managers
* here and reuse the one from Near cache:
* 1. GridCacheVersionManager
* 2. GridCacheIoManager
* 3. GridCacheDeploymentManager
* 4. GridCacheQueryManager (note, that we start it for DHT cache though).
* 5. CacheContinuousQueryManager (note, that we start it for DHT cache though).
* 6. GridCacheDgcManager
* 7. GridCacheTtlManager.
* ===============================================
*/
evictMgr = cfg.isOnheapCacheEnabled() ? new GridCacheEvictionManager() : new CacheOffheapEvictionManager();
evtMgr = new GridCacheEventManager();
pluginMgr = new CachePluginManager(ctx, cfg);
drMgr = pluginMgr.createComponent(GridCacheDrManager.class);
cacheCtx = new GridCacheContext(ctx, sharedCtx, cfg, desc.cacheType(), locStartTopVer, desc.receivedFrom(), affNode, true, memPlc, freeList, reuseList, /*
* Managers in starting order!
* ===========================
*/
evtMgr, storeMgr, evictMgr, qryMgr, contQryMgr, dataStructuresMgr, ttlMgr, drMgr, offheapMgr, rslvrMgr, pluginMgr, affMgr);
cacheCtx.cacheObjectContext(cacheObjCtx);
GridDhtCacheAdapter dht = null;
switch(cfg.getAtomicityMode()) {
case TRANSACTIONAL:
{
assert cache instanceof GridNearTransactionalCache;
GridNearTransactionalCache near = (GridNearTransactionalCache) cache;
GridDhtCache dhtCache = cacheCtx.affinityNode() ? new GridDhtCache(cacheCtx) : new GridDhtCache(cacheCtx, new GridNoStorageCacheMap(cacheCtx));
dhtCache.near(near);
near.dht(dhtCache);
dht = dhtCache;
break;
}
case ATOMIC:
{
assert cache instanceof GridNearAtomicCache;
GridNearAtomicCache near = (GridNearAtomicCache) cache;
GridDhtAtomicCache dhtCache = cacheCtx.affinityNode() ? new GridDhtAtomicCache(cacheCtx) : new GridDhtAtomicCache(cacheCtx, new GridNoStorageCacheMap(cacheCtx));
dhtCache.near(near);
near.dht(dhtCache);
dht = dhtCache;
break;
}
default:
{
assert false : "Invalid cache atomicity mode: " + cfg.getAtomicityMode();
}
}
cacheCtx.cache(dht);
}
if (!CU.isUtilityCache(cache.name()) && !CU.isSystemCache(cache.name())) {
registerMbean(cache.localMxBean(), cache.name(), false);
registerMbean(cache.clusterMxBean(), cache.name(), false);
}
return ret;
}
use of org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryManager in project ignite by apache.
the class GridContinuousOperationsLoadTest method main.
/**
* Main method.
*
* @param args Command line arguments.
* @throws Exception If error occurs.
*/
public static void main(String[] args) throws Exception {
final String cfgPath = args.length > 0 ? args[0] : "examples/config/example-cache.xml";
final String cacheName = getStringProperty(CACHE_NAME, "partitioned");
final Integer valSize = getIntProperty(VALUE_SIZE, 1024);
final Integer threadsCnt = getIntProperty(THREADS_CNT, 8);
final Integer testDurSec = getIntProperty(TEST_DUR_SEC, 180);
final Integer filterSkipProb = getIntProperty("FILTER_SKIP_PROBABILITY", 10, new C1<Integer, String>() {
@Nullable
@Override
public String apply(Integer val) {
if (val < 0 || val > 100)
return "The value should be between 1 and 100.";
return null;
}
});
final boolean useQry = getBooleanProperty("IGNITE_USE_QUERIES", true);
final int bufSize = getIntProperty("IGNITE_BUFFER_SIZE", 1);
final long timeInterval = getLongProperty("IGNITE_TIME_INTERVAL", 0);
final int parallelCnt = getIntProperty("IGNITE_PARALLEL_COUNT", 8);
final int keyRange = getIntProperty("IGNITE_KEY_RANGE", 100000);
final long updSleepMs = getLongProperty("IGNITE_UPDATE_SLEEP_MS", 0);
final long filterSleepMs = getLongProperty("IGNITE_FILTER_SLEEP_MS", 0);
final long cbSleepMs = getLongProperty("IGNITE_CALLBACK_SLEEP_MS", 0);
X.println("The test will start with the following parameters:");
dumpProperties(System.out);
try (Ignite ignite = Ignition.start(cfgPath)) {
final IgniteCache<Object, Object> cache = ignite.cache(cacheName);
if (cache == null)
throw new IgniteCheckedException("Cache is not configured: " + cacheName);
// Continuous query manager, used to monitor queue size.
final CacheContinuousQueryManager contQryMgr = ((IgniteKernal) ignite).context().cache().cache(cacheName).context().continuousQueries();
if (contQryMgr == null)
throw new IgniteCheckedException("Could not access CacheContinuousQueryManager");
// Stop flag.
final AtomicBoolean stop = new AtomicBoolean();
// Callback counter.
final AtomicLong cbCntr = new AtomicLong();
// Update counter.
final AtomicLong updCntr = new AtomicLong();
for (int i = 0; i < parallelCnt; i++) {
if (useQry) {
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
if (cbSleepMs > 0) {
try {
U.sleep(cbSleepMs);
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteException(e);
}
}
for (CacheEntryEvent<?, ?> ignored : evts) cbCntr.incrementAndGet();
}
});
qry.setRemoteFilter(new CacheEntryEventSerializableFilter<Object, Object>() {
@Override
public boolean evaluate(CacheEntryEvent<?, ?> evt) {
if (filterSleepMs > 0) {
try {
U.sleep(filterSleepMs);
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteException(e);
}
}
return Math.random() * 100 >= filterSkipProb;
}
});
qry.setPageSize(bufSize);
qry.setTimeInterval(timeInterval);
cache.query(qry);
} else {
ignite.events().remoteListen(bufSize, timeInterval, true, new PX2<UUID, Event>() {
@Override
public boolean applyx(UUID uuid, Event evt) throws IgniteInterruptedCheckedException {
if (cbSleepMs > 0)
U.sleep(cbSleepMs);
cbCntr.incrementAndGet();
// Continue listening.
return true;
}
}, new PX1<Event>() {
@Override
public boolean applyx(Event evt) throws IgniteInterruptedCheckedException {
if (filterSleepMs > 0)
U.sleep(filterSleepMs);
return Math.random() * 100 >= filterSkipProb;
}
}, EVT_CACHE_OBJECT_PUT);
}
}
// Start collector thread.
startDaemon(new Runnable() {
@Override
public void run() {
try {
while (!stop.get() && !Thread.currentThread().isInterrupted()) {
long cbCntr0 = cbCntr.get();
long updCntr0 = updCntr.get();
U.sleep(1000);
long cbDelta = cbCntr.get() - cbCntr0;
long updDelta = updCntr.get() - updCntr0;
X.println("Stats [entriesPerSec=" + cbDelta + ", updatesPerSec=" + updDelta + ']');
}
} catch (IgniteInterruptedCheckedException ignored) {
// No-op.
}
}
});
X.println("Starting " + threadsCnt + " generator thread(s).");
// Start generator threads.
IgniteInternalFuture<Long> genFut = runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
byte[] val = new byte[valSize];
ThreadLocalRandom8 rnd = ThreadLocalRandom8.current();
while (!stop.get() && !Thread.currentThread().isInterrupted()) {
Integer key = rnd.nextInt(keyRange);
cache.put(key, val);
updCntr.incrementAndGet();
if (updSleepMs > 0)
U.sleep(updSleepMs);
}
return true;
}
}, threadsCnt, "load-test-generator");
U.sleep(testDurSec * 1000);
stop.set(true);
genFut.get();
}
}
Aggregations