Search in sources :

Example 66 with IgniteUuid

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.
        }
    };
}
Also used : GridCloseableIteratorAdapter(org.apache.ignite.internal.util.GridCloseableIteratorAdapter) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) IgniteUuid(org.apache.ignite.lang.IgniteUuid) GridSetQueryPredicate(org.apache.ignite.internal.processors.datastructures.GridSetQueryPredicate) SetItemKey(org.apache.ignite.internal.processors.datastructures.SetItemKey)

Example 67 with IgniteUuid

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;
    }
}
Also used : HashMap(java.util.HashMap) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteUuid(org.apache.ignite.lang.IgniteUuid) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) UUID(java.util.UUID) HashSet(java.util.HashSet) GridBoundedConcurrentLinkedHashSet(org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashSet)

Example 68 with IgniteUuid

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;
}
Also used : GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteUuid(org.apache.ignite.lang.IgniteUuid) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)

Example 69 with IgniteUuid

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();
    }
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid) GridCacheQueueProxy(org.apache.ignite.internal.processors.datastructures.GridCacheQueueProxy) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 70 with IgniteUuid

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() + ']');
        }
    }
}
Also used : IgfsMetaFileRangeUpdateProcessor(org.apache.ignite.internal.processors.igfs.meta.IgfsMetaFileRangeUpdateProcessor) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgfsMetaFileRangeDeleteProcessor(org.apache.ignite.internal.processors.igfs.meta.IgfsMetaFileRangeDeleteProcessor)

Aggregations

IgniteUuid (org.apache.ignite.lang.IgniteUuid)107 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)25 UUID (java.util.UUID)23 IgniteException (org.apache.ignite.IgniteException)17 HashMap (java.util.HashMap)15 Map (java.util.Map)13 IgfsPath (org.apache.ignite.igfs.IgfsPath)11 ArrayList (java.util.ArrayList)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)10 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 Nullable (org.jetbrains.annotations.Nullable)9 IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)7 HashSet (java.util.HashSet)6 TreeSet (java.util.TreeSet)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 Ignite (org.apache.ignite.Ignite)6 IgfsException (org.apache.ignite.igfs.IgfsException)6 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5