use of org.apache.ignite.util.AttributeNodeFilter in project ignite by apache.
the class CacheContinuousQueryManager method executeQuery0.
/**
* @param locLsnr Local listener.
* @param clsr Closure to create CacheContinuousQueryHandler.
* @param bufSize Buffer size.
* @param timeInterval Time interval.
* @param autoUnsubscribe Auto unsubscribe flag.
* @param internal Internal flag.
* @param notifyExisting Notify existing flag.
* @param loc Local flag.
* @param keepBinary Keep binary flag.
* @param onStart Waiting topology exchange.
* @return Continuous routine ID.
* @throws IgniteCheckedException In case of error.
*/
private UUID executeQuery0(CacheEntryUpdatedListener locLsnr, IgniteOutClosure<CacheContinuousQueryHandler> clsr, int bufSize, long timeInterval, boolean autoUnsubscribe, boolean internal, boolean notifyExisting, boolean loc, final boolean keepBinary, boolean onStart) throws IgniteCheckedException {
cctx.checkSecurity(SecurityPermission.CACHE_READ);
int taskNameHash = !internal && cctx.kernalContext().security().enabled() ? cctx.kernalContext().job().currentTaskNameHash() : 0;
boolean skipPrimaryCheck = loc && cctx.config().getCacheMode() == CacheMode.REPLICATED && cctx.affinityNode();
final CacheContinuousQueryHandler hnd = clsr.apply();
boolean locOnly = cctx.isLocal() || loc;
hnd.taskNameHash(taskNameHash);
hnd.skipPrimaryCheck(skipPrimaryCheck);
hnd.notifyExisting(notifyExisting);
hnd.internal(internal);
hnd.keepBinary(keepBinary);
hnd.localOnly(locOnly);
IgnitePredicate<ClusterNode> pred = (loc || cctx.config().getCacheMode() == CacheMode.LOCAL) ? F.nodeForNodeId(cctx.localNodeId()) : new IsAllPredicate<>(cctx.group().nodeFilter(), new AttributeNodeFilter(ATTR_CLIENT_MODE, false));
assert pred != null : cctx.config();
UUID id = null;
try {
id = cctx.kernalContext().continuous().startRoutine(hnd, locOnly, bufSize, timeInterval, autoUnsubscribe, pred).get();
if (hnd.isQuery() && cctx.userCache() && !locOnly && !onStart)
hnd.waitTopologyFuture(cctx.kernalContext());
} catch (NodeStoppingException e) {
// Wrap original exception to show the source of continuous query start stacktrace.
throw new NodeStoppingException(e);
} catch (IgniteCheckedException e) {
log.warning("Failed to start continuous query.", e);
if (id != null)
cctx.kernalContext().continuous().stopRoutine(id);
throw new IgniteCheckedException("Failed to start continuous query.", e);
}
if (notifyExisting) {
assert locLsnr != null : "Local listener can't be null if notification for existing entries are enabled";
final Iterator<CacheDataRow> it = cctx.offheap().cacheIterator(cctx.cacheId(), true, true, AffinityTopologyVersion.NONE, null, null);
locLsnr.onUpdated(new Iterable<CacheEntryEvent>() {
@Override
public Iterator<CacheEntryEvent> iterator() {
return new Iterator<CacheEntryEvent>() {
private CacheContinuousQueryEvent next;
{
advance();
}
@Override
public boolean hasNext() {
return next != null;
}
@Override
public CacheEntryEvent next() {
if (!hasNext())
throw new NoSuchElementException();
CacheEntryEvent next0 = next;
advance();
return next0;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
private void advance() {
next = null;
while (next == null) {
if (!it.hasNext())
break;
CacheDataRow e = it.next();
CacheContinuousQueryEntry entry = new CacheContinuousQueryEntry(cctx.cacheId(), CREATED, e.key(), e.value(), null, keepBinary, 0, -1, null, (byte) 0);
next = new CacheContinuousQueryEvent<>(cctx.kernalContext().cache().jcache(cctx.name()), cctx, entry);
if (!hnd.filter(next))
next = null;
}
}
};
}
});
}
return id;
}
use of org.apache.ignite.util.AttributeNodeFilter in project ignite by apache.
the class NodeFilter method attributeNodeFilter.
@Test
void attributeNodeFilter() {
// tag::add-attribute[]
IgniteConfiguration cfg = new IgniteConfiguration();
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("host_myCache", true);
cfg.setUserAttributes(attributes);
Ignite ignite = Ignition.start(cfg);
// end::add-attribute[]
// tag::attribute-node-filter[]
CacheConfiguration<Integer, String> cacheCfg = new CacheConfiguration<>("myCache");
cacheCfg.setNodeFilter(new AttributeNodeFilter("host_myCache", "true"));
// end::attribute-node-filter[]
ignite.createCache(cacheCfg);
ignite.close();
}
use of org.apache.ignite.util.AttributeNodeFilter in project ignite by apache.
the class CacheMvccClientTopologyTest method getConfiguration.
/**
* Configure nodes in client mode (filtered by AttributeNodeFilter, no CacheConfiguration is set)
* or in ordinary server mode.
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
if (getTestIgniteInstanceIndex(igniteInstanceName) != clientModeIdx) {
String attrName = "has_cache";
Object attrVal = Boolean.TRUE;
CacheConfiguration ccfg = defaultCacheConfiguration().setNearConfiguration(null).setNodeFilter(new AttributeNodeFilter(attrName, attrVal)).setAtomicityMode(TRANSACTIONAL_SNAPSHOT);
return cfg.setCacheConfiguration(ccfg).setUserAttributes(F.asMap(attrName, attrVal));
}
return cfg;
}
use of org.apache.ignite.util.AttributeNodeFilter in project ignite by apache.
the class GridCachePartitionedSetWithNodeFilterSelfTest method collectionConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected CollectionConfiguration collectionConfiguration() {
CollectionConfiguration cfg = super.collectionConfiguration();
cfg.setNodeFilter(new AttributeNodeFilter(ATTR_IGNITE_INSTANCE_NAME, getTestIgniteInstanceName(0)));
return cfg;
}
use of org.apache.ignite.util.AttributeNodeFilter in project ignite by apache.
the class CachePartitionLossWithRestartsTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setActiveOnStart(false);
cfg.setConsistentId(igniteInstanceName);
if (getTestIgniteInstanceIndex(igniteInstanceName) == clientIdx)
cfg.setClientMode(true);
cfg.setIncludeEventTypes(EventType.EVTS_ALL);
DataStorageConfiguration dsCfg = new DataStorageConfiguration();
dsCfg.setWalSegmentSize(4 * 1024 * 1024);
dsCfg.setWalMode(WALMode.LOG_ONLY);
final int size = 50 * 1024 * 1024;
DataRegionConfiguration dfltRegCfg = new DataRegionConfiguration();
dfltRegCfg.setName(DEFAULT_CACHE_NAME).setInitialSize(size).setMaxSize(size).setPersistenceEnabled(dfltRegionPersistence);
dsCfg.setDefaultDataRegionConfiguration(dfltRegCfg);
cfg.setDataStorageConfiguration(dsCfg);
// Do not start cache on non-affinity node.
CacheConfiguration ccfg = defaultCacheConfiguration().setNearConfiguration(null).setNodeFilter(new AttributeNodeFilter(START_CACHE_ATTR, Boolean.TRUE)).setBackups(0).setAffinity(new RendezvousAffinityFunction(false, PARTS_CNT));
if (mvccEnabled)
ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT);
if (startClientCache)
cfg.setCacheConfiguration(ccfg);
if (getTestIgniteInstanceIndex(igniteInstanceName) != nonAffIdx) {
cfg.setUserAttributes(F.asMap(START_CACHE_ATTR, Boolean.TRUE));
if (!startClientCache)
cfg.setCacheConfiguration(ccfg);
}
return cfg;
}
Aggregations