Search in sources :

Example 46 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class CacheAffinitySharedManager method checkRebalanceState.

/**
 * @param top Topology.
 * @param checkGrpId Group ID.
 */
void checkRebalanceState(GridDhtPartitionTopology top, Integer checkGrpId) {
    CacheAffinityChangeMessage msg = null;
    synchronized (mux) {
        if (waitInfo == null || !waitInfo.topVer.equals(lastAffVer))
            return;
        Map<Integer, UUID> partWait = waitInfo.waitGrps.get(checkGrpId);
        boolean rebalanced = true;
        if (partWait != null) {
            CacheGroupHolder grpHolder = grpHolders.get(checkGrpId);
            if (grpHolder != null) {
                for (Iterator<Map.Entry<Integer, UUID>> it = partWait.entrySet().iterator(); it.hasNext(); ) {
                    Map.Entry<Integer, UUID> e = it.next();
                    Integer part = e.getKey();
                    UUID waitNode = e.getValue();
                    GridDhtPartitionState state = top.partitionState(waitNode, part);
                    if (state != GridDhtPartitionState.OWNING) {
                        rebalanced = false;
                        break;
                    } else
                        it.remove();
                }
            }
            if (rebalanced) {
                waitInfo.waitGrps.remove(checkGrpId);
                if (waitInfo.waitGrps.isEmpty()) {
                    msg = affinityChangeMessage(waitInfo);
                    waitInfo = null;
                }
            }
        }
        try {
            if (msg != null)
                cctx.discovery().sendCustomEvent(msg);
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to send affinity change message.", e);
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState) UUID(java.util.UUID) GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)

Example 47 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class CacheAffinitySharedManager method onChangeAffinityMessage.

/**
 * Called on exchange initiated by {@link CacheAffinityChangeMessage} which sent after rebalance finished.
 *
 * @param exchFut Exchange future.
 * @param crd Coordinator flag.
 * @param msg Message.
 * @throws IgniteCheckedException If failed.
 */
public void onChangeAffinityMessage(final GridDhtPartitionsExchangeFuture exchFut, boolean crd, final CacheAffinityChangeMessage msg) throws IgniteCheckedException {
    assert msg.topologyVersion() != null && msg.exchangeId() == null : msg;
    final AffinityTopologyVersion topVer = exchFut.initialVersion();
    if (log.isDebugEnabled()) {
        log.debug("Process affinity change message [exchVer=" + topVer + ", msgVer=" + msg.topologyVersion() + ']');
    }
    final Map<Integer, Map<Integer, List<UUID>>> affChange = msg.assignmentChange();
    assert !F.isEmpty(affChange) : msg;
    final Map<Integer, IgniteUuid> deploymentIds = msg.cacheDeploymentIds();
    final Map<Object, List<List<ClusterNode>>> affCache = new HashMap<>();
    forAllCacheGroups(crd, new IgniteInClosureX<GridAffinityAssignmentCache>() {

        @Override
        public void applyx(GridAffinityAssignmentCache aff) throws IgniteCheckedException {
            AffinityTopologyVersion affTopVer = aff.lastVersion();
            assert affTopVer.topologyVersion() > 0 : affTopVer;
            CacheGroupDescriptor desc = caches.group(aff.groupId());
            assert desc != null : aff.cacheOrGroupName();
            IgniteUuid deploymentId = desc.deploymentId();
            if (!deploymentId.equals(deploymentIds.get(aff.groupId()))) {
                aff.clientEventTopologyChange(exchFut.firstEvent(), topVer);
                return;
            }
            Map<Integer, List<UUID>> change = affChange.get(aff.groupId());
            if (change != null) {
                assert !change.isEmpty() : msg;
                List<List<ClusterNode>> curAff = aff.assignments(affTopVer);
                List<List<ClusterNode>> assignment = new ArrayList<>(curAff);
                for (Map.Entry<Integer, List<UUID>> e : change.entrySet()) {
                    Integer part = e.getKey();
                    List<ClusterNode> nodes = toNodes(topVer, e.getValue());
                    assert !nodes.equals(assignment.get(part)) : "Assignment did not change " + "[cacheGrp=" + aff.cacheOrGroupName() + ", part=" + part + ", cur=" + F.nodeIds(assignment.get(part)) + ", new=" + F.nodeIds(nodes) + ", exchVer=" + exchFut.initialVersion() + ", msgVer=" + msg.topologyVersion() + ']';
                    assignment.set(part, nodes);
                }
                aff.initialize(topVer, cachedAssignment(aff, assignment, affCache));
            } else
                aff.clientEventTopologyChange(exchFut.firstEvent(), topVer);
        }
    });
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteUuid(org.apache.ignite.lang.IgniteUuid) GridAffinityAssignmentCache(org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache) GridLongList(org.apache.ignite.internal.util.GridLongList) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID) GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)

Example 48 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class CacheAffinitySharedManager method onExchangeChangeAffinityMessage.

/**
 * Called when received {@link CacheAffinityChangeMessage} which should complete exchange.
 *
 * @param exchFut Exchange future.
 * @param crd Coordinator flag.
 * @param msg Affinity change message.
 */
public void onExchangeChangeAffinityMessage(GridDhtPartitionsExchangeFuture exchFut, boolean crd, CacheAffinityChangeMessage msg) {
    if (log.isDebugEnabled()) {
        log.debug("Process exchange affinity change message [exchVer=" + exchFut.initialVersion() + ", msg=" + msg + ']');
    }
    assert exchFut.exchangeId().equals(msg.exchangeId()) : msg;
    final AffinityTopologyVersion topVer = exchFut.initialVersion();
    final Map<Integer, Map<Integer, List<UUID>>> assignment = msg.assignmentChange();
    assert assignment != null;
    final Map<Object, List<List<ClusterNode>>> affCache = new HashMap<>();
    forAllCacheGroups(crd, new IgniteInClosureX<GridAffinityAssignmentCache>() {

        @Override
        public void applyx(GridAffinityAssignmentCache aff) throws IgniteCheckedException {
            List<List<ClusterNode>> idealAssignment = aff.idealAssignment();
            assert idealAssignment != null;
            Map<Integer, List<UUID>> cacheAssignment = assignment.get(aff.groupId());
            List<List<ClusterNode>> newAssignment;
            if (cacheAssignment != null) {
                newAssignment = new ArrayList<>(idealAssignment);
                for (Map.Entry<Integer, List<UUID>> e : cacheAssignment.entrySet()) newAssignment.set(e.getKey(), toNodes(topVer, e.getValue()));
            } else
                newAssignment = idealAssignment;
            aff.initialize(topVer, cachedAssignment(aff, newAssignment, affCache));
        }
    });
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridAffinityAssignmentCache(org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache) GridLongList(org.apache.ignite.internal.util.GridLongList) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID) GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)

Example 49 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException 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);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteCacheObjectProcessor(org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor) IgniteException(org.apache.ignite.IgniteException) Nullable(org.jetbrains.annotations.Nullable)

Example 50 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class OdbcConnectionContext method initializeFromHandshake.

/**
 * {@inheritDoc}
 */
@Override
public void initializeFromHandshake(ClientListenerProtocolVersion ver, BinaryReaderExImpl reader) throws IgniteCheckedException {
    assert SUPPORTED_VERS.contains(ver) : "Unsupported ODBC protocol version.";
    boolean distributedJoins = reader.readBoolean();
    boolean enforceJoinOrder = reader.readBoolean();
    boolean replicatedOnly = reader.readBoolean();
    boolean collocated = reader.readBoolean();
    boolean lazy = false;
    if (ver.compareTo(VER_2_1_5) >= 0)
        lazy = reader.readBoolean();
    boolean skipReducerOnUpdate = false;
    if (ver.compareTo(VER_2_3_0) >= 0)
        skipReducerOnUpdate = reader.readBoolean();
    String user = null;
    String passwd = null;
    if (ver.compareTo(VER_2_5_0) >= 0) {
        user = reader.readString();
        passwd = reader.readString();
    }
    AuthorizationContext actx = null;
    try {
        if (ctx.authentication().enabled()) {
            if (F.isEmpty(user))
                throw new IgniteCheckedException("Unauthenticated sessions are prohibited");
            actx = ctx.authentication().authenticate(user, passwd);
            if (actx == null)
                throw new IgniteCheckedException("Unknown authentication error");
        } else {
            if (!F.isEmpty(user))
                throw new IgniteCheckedException("Authentication is disabled for the node.");
        }
    } catch (Exception e) {
        throw new IgniteCheckedException("Handshake error: " + e.getMessage(), e);
    }
    handler = new OdbcRequestHandler(ctx, busyLock, maxCursors, distributedJoins, enforceJoinOrder, replicatedOnly, collocated, lazy, skipReducerOnUpdate, actx);
    parser = new OdbcMessageParser(ctx, ver);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AuthorizationContext(org.apache.ignite.internal.processors.authentication.AuthorizationContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1568 IgniteException (org.apache.ignite.IgniteException)388 ArrayList (java.util.ArrayList)237 IOException (java.io.IOException)226 ClusterNode (org.apache.ignite.cluster.ClusterNode)215 Map (java.util.Map)181 UUID (java.util.UUID)163 HashMap (java.util.HashMap)160 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)150 Test (org.junit.Test)143 List (java.util.List)139 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)138 Nullable (org.jetbrains.annotations.Nullable)134 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)118 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)109 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)105 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)104 Collection (java.util.Collection)97 HashSet (java.util.HashSet)97 Ignite (org.apache.ignite.Ignite)96