Search in sources :

Example 81 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)

Example 82 with IgniteUuid

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

the class IgniteUtils method readGridUuid.

/**
     * @param arr Array.
     * @param off Offset.
     * @return UUID.
     */
@Nullable
public static IgniteUuid readGridUuid(byte[] arr, long off) {
    if (GridUnsafe.getBoolean(arr, off++)) {
        long most = GridUnsafe.getLong(arr, off);
        off += 8;
        long least = GridUnsafe.getLong(arr, off);
        off += 8;
        UUID globalId = new UUID(most, least);
        long locId = GridUnsafe.getLong(arr, off);
        return new IgniteUuid(globalId, locId);
    }
    return null;
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid) UUID(java.util.UUID) Nullable(org.jetbrains.annotations.Nullable)

Example 83 with IgniteUuid

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

the class IgniteUtils method writeGridUuids.

/**
     * Writes Grid UUIDs to output stream. This method is meant to be used by
     * implementations of {@link Externalizable} interface.
     *
     * @param out Output stream.
     * @param col Grid UUIDs to write.
     * @throws IOException If write failed.
     */
public static void writeGridUuids(DataOutput out, @Nullable Collection<IgniteUuid> col) throws IOException {
    if (col != null) {
        out.writeBoolean(true);
        out.writeInt(col.size());
        for (IgniteUuid id : col) writeGridUuid(out, id);
    } else
        out.writeBoolean(false);
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid)

Example 84 with IgniteUuid

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

the class BinaryMarshallerSelfTest method testIgniteUuid.

/**
     * @throws Exception If failed.
     */
public void testIgniteUuid() throws Exception {
    IgniteUuid uuid = IgniteUuid.randomUuid();
    assertEquals(uuid, marshalUnmarshal(uuid));
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid)

Example 85 with IgniteUuid

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

the class IgfsMetaManager method pathIds.

/**
     * Gets all file IDs for components of specified path. Result cannot be empty - there is at least root element.
     * But each element (except the first) can be {@code null} if such files don't exist.
     *
     * @param path Path.
     * @return Collection of file IDs for components of specified path.
     * @throws IgniteCheckedException If failed.
     */
public IgfsPathIds pathIds(IgfsPath path) throws IgniteCheckedException {
    // Prepare parts.
    String[] components = path.componentsArray();
    String[] parts = new String[components.length + 1];
    System.arraycopy(components, 0, parts, 1, components.length);
    // Get IDs.
    if (client) {
        List<IgniteUuid> ids = runClientTask(new IgfsClientMetaIdsForPathCallable(cfg.getName(), IgfsUserContext.currentUser(), path));
        return new IgfsPathIds(path, parts, ids.toArray(new IgniteUuid[ids.size()]));
    } else {
        if (busyLock.enterBusy()) {
            try {
                validTxState(false);
                IgniteUuid[] ids = new IgniteUuid[parts.length];
                ids[0] = IgfsUtils.ROOT_ID;
                for (int i = 1; i < ids.length; i++) {
                    IgniteUuid id = fileId(ids[i - 1], parts[i], false);
                    if (id != null)
                        ids[i] = id;
                    else
                        break;
                }
                // Return.
                return new IgfsPathIds(path, parts, ids);
            } finally {
                busyLock.leaveBusy();
            }
        } else
            throw new IllegalStateException("Failed to get file IDS because Grid is stopping: " + path);
    }
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgfsClientMetaIdsForPathCallable(org.apache.ignite.internal.processors.igfs.client.meta.IgfsClientMetaIdsForPathCallable)

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