Search in sources :

Example 46 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.

the class IgfsFileMapSelfTest method testRangeUpdate1.

/**
     * @throws Exception If failed.
     */
public void testRangeUpdate1() throws Exception {
    IgfsFileMap map = new IgfsFileMap();
    IgniteUuid affKey = IgniteUuid.randomUuid();
    for (int i = 0; i < 4; i++) map.addRange(new IgfsFileAffinityRange(i * 20 + 10, i * 20 + 19, affKey));
    // Middle, first, last.
    map.updateRangeStatus(new IgfsFileAffinityRange(30, 39, affKey), RANGE_STATUS_MOVING);
    map.updateRangeStatus(new IgfsFileAffinityRange(10, 19, affKey), RANGE_STATUS_MOVING);
    map.updateRangeStatus(new IgfsFileAffinityRange(70, 79, affKey), RANGE_STATUS_MOVING);
    List<IgfsFileAffinityRange> ranges = map.ranges();
    assertEquals(RANGE_STATUS_MOVING, ranges.get(0).status());
    assertEquals(RANGE_STATUS_MOVING, ranges.get(1).status());
    assertEquals(RANGE_STATUS_INITIAL, ranges.get(2).status());
    assertEquals(RANGE_STATUS_MOVING, ranges.get(3).status());
    // Middle, first, last.
    map.updateRangeStatus(new IgfsFileAffinityRange(30, 39, affKey), RANGE_STATUS_MOVED);
    map.updateRangeStatus(new IgfsFileAffinityRange(10, 19, affKey), RANGE_STATUS_MOVED);
    map.updateRangeStatus(new IgfsFileAffinityRange(70, 79, affKey), RANGE_STATUS_MOVED);
    ranges = map.ranges();
    assertEquals(RANGE_STATUS_MOVED, ranges.get(0).status());
    assertEquals(RANGE_STATUS_MOVED, ranges.get(1).status());
    assertEquals(RANGE_STATUS_INITIAL, ranges.get(2).status());
    assertEquals(RANGE_STATUS_MOVED, ranges.get(3).status());
    // Middle, first, last.
    map.deleteRange(new IgfsFileAffinityRange(30, 39, affKey));
    map.deleteRange(new IgfsFileAffinityRange(10, 19, affKey));
    map.deleteRange(new IgfsFileAffinityRange(70, 79, affKey));
    ranges = map.ranges();
    assertEquals(1, ranges.size());
    assertEquals(RANGE_STATUS_INITIAL, ranges.get(0).status());
    assertTrue(ranges.get(0).regionEqual(new IgfsFileAffinityRange(50, 59, affKey)));
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid)

Example 47 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.

the class GridDeploymentLocalStore method deploy.

/**
     * @param depMode Deployment mode.
     * @param ldr Class loader to deploy.
     * @param cls Class.
     * @param alias Class alias.
     * @param recordEvt {@code True} to record event.
     * @return Deployment.
     */
private GridDeployment deploy(DeploymentMode depMode, ClassLoader ldr, Class<?> cls, String alias, boolean recordEvt) {
    GridDeployment dep = null;
    synchronized (mux) {
        boolean fireEvt = false;
        try {
            ConcurrentLinkedDeque8<GridDeployment> cachedDeps = null;
            // Find existing class loader info.
            for (ConcurrentLinkedDeque8<GridDeployment> deps : cache.values()) {
                for (GridDeployment d : deps) {
                    if (d.classLoader() == ldr) {
                        // Cache class and alias.
                        fireEvt = d.addDeployedClass(cls, alias);
                        cachedDeps = deps;
                        dep = d;
                        break;
                    }
                }
                if (cachedDeps != null)
                    break;
            }
            if (cachedDeps != null) {
                assert dep != null;
                cache.put(alias, cachedDeps);
                if (!cls.getName().equals(alias))
                    // Cache by class name as well.
                    cache.put(cls.getName(), cachedDeps);
                return dep;
            }
            IgniteUuid ldrId = IgniteUuid.fromUuid(ctx.localNodeId());
            String userVer = userVersion(ldr);
            dep = new GridDeployment(depMode, ldr, ldrId, userVer, cls.getName(), true);
            fireEvt = dep.addDeployedClass(cls, alias);
            assert fireEvt : "Class was not added to newly created deployment [cls=" + cls + ", depMode=" + depMode + ", dep=" + dep + ']';
            ConcurrentLinkedDeque8<GridDeployment> deps = F.addIfAbsent(cache, alias, F.<GridDeployment>newDeque());
            if (!deps.isEmpty()) {
                for (GridDeployment d : deps) {
                    if (!d.undeployed()) {
                        U.error(log, "Found more than one active deployment for the same resource " + "[cls=" + cls + ", depMode=" + depMode + ", dep=" + d + ']');
                        return null;
                    }
                }
            }
            // Add at the beginning of the list for future fast access.
            deps.addFirst(dep);
            if (!cls.getName().equals(alias))
                // Cache by class name as well.
                cache.put(cls.getName(), deps);
            if (log.isDebugEnabled())
                log.debug("Created new deployment: " + dep);
        } finally {
            if (fireEvt)
                recordDeploy(cls, alias, recordEvt);
        }
    }
    return dep;
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid)

Example 48 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.

the class GridDeploymentPerVersionStore method checkRedeploy.

/**
     * Removes obsolete deployments in case of redeploy.
     *
     * @param meta Request metadata.
     */
private void checkRedeploy(GridDeploymentMetadata meta) {
    assert Thread.holdsLock(mux);
    for (List<SharedDeployment> deps : cache.values()) {
        for (SharedDeployment dep : deps) {
            if (!dep.undeployed() && !dep.pendingUndeploy()) {
                long undeployTimeout = ctx.config().getNetworkTimeout();
                // Only check deployments with no participants.
                if (!dep.hasParticipants() && dep.deployMode() == CONTINUOUS && dep.existingDeployedClass(meta.className()) != null && !meta.userVersion().equals(dep.userVersion())) {
                    // In case of SHARED deployment it is possible to get hear if
                    // unmarshalling happens during undeploy. In this case, we
                    // simply don't do anything.
                    // Change from shared deploy to shared undeploy or user version change.
                    // Simply remove all deployments with no participating nodes.
                    dep.onUndeployScheduled();
                    if (log.isDebugEnabled())
                        log.debug("Deployment was scheduled for undeploy: " + dep);
                    // Lifespan time.
                    final long endTime = U.currentTimeMillis() + undeployTimeout;
                    // Deployment to undeploy.
                    final SharedDeployment undep = dep;
                    if (endTime > 0) {
                        ctx.timeout().addTimeoutObject(new GridTimeoutObject() {

                            @Override
                            public IgniteUuid timeoutId() {
                                return undep.classLoaderId();
                            }

                            @Override
                            public long endTime() {
                                return endTime < 0 ? Long.MAX_VALUE : endTime;
                            }

                            @Override
                            public void onTimeout() {
                                boolean rmv = false;
                                // Hot redeployment.
                                synchronized (mux) {
                                    assert undep.pendingUndeploy();
                                    if (!undep.undeployed()) {
                                        undep.undeploy();
                                        undep.onRemoved();
                                        rmv = true;
                                        Collection<SharedDeployment> deps = cache.get(undep.userVersion());
                                        if (deps != null) {
                                            for (Iterator<SharedDeployment> i = deps.iterator(); i.hasNext(); ) if (i.next() == undep)
                                                i.remove();
                                            if (deps.isEmpty())
                                                cache.remove(undep.userVersion());
                                        }
                                        if (log.isInfoEnabled())
                                            log.info("Undeployed class loader due to deployment mode change, " + "user version change, or hot redeployment: " + undep);
                                    }
                                }
                                // Outside synchronization.
                                if (rmv)
                                    undep.recordUndeployed(null);
                            }
                        });
                    }
                }
            }
        }
    }
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid) Iterator(java.util.Iterator) Collection(java.util.Collection) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject)

Example 49 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.

the class DirectMessageReader method readIgniteUuid.

/** {@inheritDoc} */
@Override
public IgniteUuid readIgniteUuid(String name) {
    DirectByteBufferStream stream = state.item().stream;
    IgniteUuid val = stream.readIgniteUuid();
    lastRead = stream.lastFinished();
    return val;
}
Also used : DirectByteBufferStream(org.apache.ignite.internal.direct.stream.DirectByteBufferStream) IgniteUuid(org.apache.ignite.lang.IgniteUuid)

Example 50 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.

the class GridDhtCacheAdapter method endMultiUpdate.

/**
     * Ends multi-update lock.
     *
     * @throws IgniteCheckedException If failed.
     */
public void endMultiUpdate() throws IgniteCheckedException {
    IgniteBiTuple<IgniteUuid, GridDhtTopologyFuture> tup = multiTxHolder.get();
    if (tup == null)
        throw new IgniteCheckedException("Multi-update was not started or released twice.");
    top.readLock();
    try {
        IgniteUuid lockId = tup.get1();
        MultiUpdateFuture multiFut = multiTxFuts.remove(lockId);
        multiTxHolder.set(null);
        // Finish future.
        multiFut.onDone(lockId);
    } finally {
        top.readUnlock();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteUuid(org.apache.ignite.lang.IgniteUuid)

Aggregations

IgniteUuid (org.apache.ignite.lang.IgniteUuid)98 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)22 UUID (java.util.UUID)19 IgniteException (org.apache.ignite.IgniteException)17 HashMap (java.util.HashMap)13 Map (java.util.Map)11 IgfsPath (org.apache.ignite.igfs.IgfsPath)11 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)10 ArrayList (java.util.ArrayList)9 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 Nullable (org.jetbrains.annotations.Nullable)9 IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)7 TreeSet (java.util.TreeSet)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 IgfsException (org.apache.ignite.igfs.IgfsException)6 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 Event (org.apache.ignite.events.Event)5 TaskEvent (org.apache.ignite.events.TaskEvent)5 IgfsPathIsDirectoryException (org.apache.ignite.igfs.IgfsPathIsDirectoryException)5