use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class GridCacheQueryManager method setIterator.
/**
* @param qry Query.
* @return Cache set items iterator.
*/
private GridCloseableIterator<IgniteBiTuple<K, V>> setIterator(GridCacheQueryAdapter<?> qry) {
final GridSetQueryPredicate filter = (GridSetQueryPredicate) qry.scanFilter();
filter.init(cctx);
IgniteUuid id = filter.setId();
Collection<SetItemKey> data = cctx.dataStructures().setData(id);
if (data == null)
data = Collections.emptyList();
final GridIterator<IgniteBiTuple<K, V>> it = F.iterator(data, new C1<SetItemKey, IgniteBiTuple<K, V>>() {
@Override
public IgniteBiTuple<K, V> apply(SetItemKey e) {
return new IgniteBiTuple<>((K) e.item(), (V) Boolean.TRUE);
}
}, true, new P1<SetItemKey>() {
@Override
public boolean apply(SetItemKey e) {
return filter.apply(e, null);
}
});
return new GridCloseableIteratorAdapter<IgniteBiTuple<K, V>>() {
@Override
protected boolean onHasNext() {
return it.hasNext();
}
@Override
protected IgniteBiTuple<K, V> onNext() {
return it.next();
}
@Override
protected void onRemove() {
it.remove();
}
@Override
protected void onClose() {
// No-op.
}
};
}
use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class WalStateManager method init.
/**
* Initiate WAL mode change operation.
*
* @param cacheNames Cache names.
* @param enabled Enabled flag.
* @return Future completed when operation finished.
*/
public IgniteInternalFuture<Boolean> init(Collection<String> cacheNames, boolean enabled) {
if (F.isEmpty(cacheNames))
return errorFuture("Cache names cannot be empty.");
synchronized (mux) {
if (disconnected)
return errorFuture("Failed to initiate WAL mode change because client node is disconnected.");
// Prepare cache and group infos.
Map<String, IgniteUuid> caches = new HashMap<>(cacheNames.size());
CacheGroupDescriptor grpDesc = null;
for (String cacheName : cacheNames) {
DynamicCacheDescriptor cacheDesc = cacheProcessor().cacheDescriptor(cacheName);
if (cacheDesc == null)
return errorFuture("Cache doesn't exist: " + cacheName);
caches.put(cacheName, cacheDesc.deploymentId());
CacheGroupDescriptor curGrpDesc = cacheDesc.groupDescriptor();
if (grpDesc == null)
grpDesc = curGrpDesc;
else if (!F.eq(grpDesc.deploymentId(), curGrpDesc.deploymentId())) {
return errorFuture("Cannot change WAL mode for caches from different cache groups [" + "cache1=" + cacheNames.iterator().next() + ", grp1=" + grpDesc.groupName() + ", cache2=" + cacheName + ", grp2=" + curGrpDesc.groupName() + ']');
}
}
assert grpDesc != null;
HashSet<String> grpCaches = new HashSet<>(grpDesc.caches().keySet());
grpCaches.removeAll(cacheNames);
if (!grpCaches.isEmpty()) {
return errorFuture("Cannot change WAL mode because not all cache names belonging to the group are " + "provided [group=" + grpDesc.groupName() + ", missingCaches=" + grpCaches + ']');
}
if (grpDesc.config().getCacheMode() == CacheMode.LOCAL)
return errorFuture("WAL mode cannot be changed for LOCAL cache(s): " + cacheNames);
// WAL mode change makes sense only for persistent groups.
if (!grpDesc.persistenceEnabled())
return errorFuture("Cannot change WAL mode because persistence is not enabled for cache(s) [" + "caches=" + cacheNames + ", dataRegion=" + grpDesc.config().getDataRegionName() + ']');
// Send request.
final UUID opId = UUID.randomUUID();
GridFutureAdapter<Boolean> fut = new GridFutureAdapter<>();
fut.listen(new IgniteInClosure<IgniteInternalFuture<Boolean>>() {
@Override
public void apply(IgniteInternalFuture<Boolean> fut) {
synchronized (mux) {
userFuts.remove(opId);
}
}
});
WalStateProposeMessage msg = new WalStateProposeMessage(opId, grpDesc.groupId(), grpDesc.deploymentId(), cctx.localNodeId(), caches, enabled);
userFuts.put(opId, fut);
try {
cctx.discovery().sendCustomEvent(msg);
if (log.isDebugEnabled())
log.debug("Initiated WAL state change operation: " + msg);
} catch (Exception e) {
IgniteCheckedException e0 = new IgniteCheckedException("Failed to initiate WAL mode change due to unexpected exception.", e);
fut.onDone(e0);
}
return fut;
}
}
use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class GridDhtPartitionDemander method preloadEntry.
/**
* Adds {@code entry} to partition {@code p}.
*
* @param from Node which sent entry.
* @param p Partition id.
* @param entry Preloaded entry.
* @param topVer Topology version.
* @return {@code False} if partition has become invalid during preloading.
* @throws IgniteInterruptedCheckedException If interrupted.
*/
private boolean preloadEntry(ClusterNode from, int p, GridCacheEntryInfo entry, AffinityTopologyVersion topVer) throws IgniteCheckedException {
ctx.database().checkpointReadLock();
try {
GridCacheEntryEx cached = null;
try {
GridCacheContext cctx = grp.sharedGroup() ? ctx.cacheContext(entry.cacheId()) : grp.singleCacheContext();
cached = cctx.dhtCache().entryEx(entry.key());
if (log.isDebugEnabled())
log.debug("Rebalancing key [key=" + entry.key() + ", part=" + p + ", node=" + from.id() + ']');
cctx.shared().database().checkpointReadLock();
try {
if (preloadPred == null || preloadPred.apply(entry)) {
if (cached.initialValue(entry.value(), entry.version(), entry.ttl(), entry.expireTime(), true, topVer, cctx.isDrEnabled() ? DR_PRELOAD : DR_NONE, false)) {
// Start tracking.
cctx.evicts().touch(cached, topVer);
if (cctx.events().isRecordable(EVT_CACHE_REBALANCE_OBJECT_LOADED) && !cached.isInternal())
cctx.events().addEvent(cached.partition(), cached.key(), cctx.localNodeId(), (IgniteUuid) null, null, EVT_CACHE_REBALANCE_OBJECT_LOADED, entry.value(), true, null, false, null, null, null, true);
} else {
// Start tracking.
cctx.evicts().touch(cached, topVer);
if (log.isDebugEnabled())
log.debug("Rebalancing entry is already in cache (will ignore) [key=" + cached.key() + ", part=" + p + ']');
}
} else if (log.isDebugEnabled())
log.debug("Rebalance predicate evaluated to false for entry (will ignore): " + entry);
} finally {
cctx.shared().database().checkpointReadUnlock();
}
} catch (GridCacheEntryRemovedException ignored) {
if (log.isDebugEnabled())
log.debug("Entry has been concurrently removed while rebalancing (will ignore) [key=" + cached.key() + ", part=" + p + ']');
} catch (GridDhtInvalidPartitionException ignored) {
if (log.isDebugEnabled())
log.debug("Partition became invalid during rebalancing (will ignore): " + p);
return false;
}
} catch (IgniteInterruptedCheckedException e) {
throw e;
} catch (IgniteCheckedException e) {
throw new IgniteCheckedException("Failed to cache rebalanced entry (will stop rebalancing) [local=" + ctx.localNode() + ", node=" + from.id() + ", key=" + entry.key() + ", part=" + p + ']', e);
} finally {
ctx.database().checkpointReadUnlock();
}
return true;
}
use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class CacheDataStructuresManager method onDisconnected.
/**
* {@inheritDoc}
*/
@Override
public void onDisconnected(IgniteFuture reconnectFut) {
super.onDisconnected(reconnectFut);
for (Map.Entry<IgniteUuid, GridCacheQueueProxy> e : queuesMap.entrySet()) {
GridCacheQueueProxy queue = e.getValue();
queue.delegate().onClientDisconnected();
}
}
use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class IgfsFragmentizerManager method processFragmentizerRequest.
/**
* Processes fragmentizer request. For each range assigned to this node:
* <ul>
* <li>Mark range as moving indicating that block copying started.</li>
* <li>Copy blocks to non-colocated keys.</li>
* <li>Update map to indicate that blocks were copied and old blocks should be deleted.</li>
* <li>Delete old blocks.</li>
* <li>Remove range from file map.</li>
* </ul>
*
* @param req Request.
* @throws IgniteCheckedException In case of error.
*/
@SuppressWarnings("fallthrough")
private void processFragmentizerRequest(IgfsFragmentizerRequest req) throws IgniteCheckedException {
req.finishUnmarshal(igfsCtx.kernalContext().config().getMarshaller(), null);
Collection<IgfsFileAffinityRange> ranges = req.fragmentRanges();
IgniteUuid fileId = req.fileId();
IgfsEntryInfo fileInfo = igfsCtx.meta().info(fileId);
if (fileInfo == null) {
if (log.isDebugEnabled())
log.debug("Failed to find file info for fragmentizer request: " + req);
return;
}
if (log.isDebugEnabled())
log.debug("Moving file ranges for fragmentizer request [req=" + req + ", fileInfo=" + fileInfo + ']');
for (IgfsFileAffinityRange range : ranges) {
try {
IgfsEntryInfo updated;
switch(range.status()) {
case RANGE_STATUS_INITIAL:
{
// Mark range as moving.
updated = igfsCtx.meta().updateInfo(fileId, new IgfsMetaFileRangeUpdateProcessor(range, RANGE_STATUS_MOVING));
if (updated == null) {
igfsCtx.data().cleanBlocks(fileInfo, range, true);
continue;
}
// Fall-through.
}
case RANGE_STATUS_MOVING:
{
// Move colocated blocks.
igfsCtx.data().spreadBlocks(fileInfo, range);
// Mark range as moved.
updated = igfsCtx.meta().updateInfo(fileId, new IgfsMetaFileRangeUpdateProcessor(range, RANGE_STATUS_MOVED));
if (updated == null) {
igfsCtx.data().cleanBlocks(fileInfo, range, true);
continue;
}
// Fall-through.
}
case RANGE_STATUS_MOVED:
{
// Remove old blocks.
igfsCtx.data().cleanBlocks(fileInfo, range, false);
// Remove range from map.
updated = igfsCtx.meta().updateInfo(fileId, new IgfsMetaFileRangeDeleteProcessor(range));
if (updated == null)
igfsCtx.data().cleanBlocks(fileInfo, range, true);
}
}
} catch (IgfsInvalidRangeException e) {
if (log.isDebugEnabled())
log.debug("Failed to update file range " + "[range=" + range + "fileId=" + fileId + ", err=" + e.getMessage() + ']');
}
}
}
Aggregations