Search in sources :

Example 61 with IgniteUuid

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

the class IgfsStreamsSelfTest method testCreateFileColocated.

/** @throws Exception If failed. */
public void testCreateFileColocated() throws Exception {
    IgfsPath path = new IgfsPath("/colocated");
    UUID uuid = UUID.randomUUID();
    IgniteUuid affKey;
    long idx = 0;
    while (true) {
        affKey = new IgniteUuid(uuid, idx);
        if (grid(0).affinity(grid(0).igfsx("igfs").configuration().getDataCacheConfiguration().getName()).mapKeyToNode(affKey).id().equals(grid(0).localNode().id()))
            break;
        idx++;
    }
    try (IgfsOutputStream out = fs.create(path, 1024, true, affKey, 0, 1024, null)) {
        // Write 5M, should be enough to test distribution.
        for (int i = 0; i < 15; i++) out.write(new byte[1024 * 1024]);
    }
    IgfsFile info = fs.info(path);
    Collection<IgfsBlockLocation> affNodes = fs.affinity(path, 0, info.length());
    assertEquals(1, affNodes.size());
    Collection<UUID> nodeIds = F.first(affNodes).nodeIds();
    assertEquals(1, nodeIds.size());
    assertEquals(grid(0).localNode().id(), F.first(nodeIds));
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgfsBlockLocation(org.apache.ignite.igfs.IgfsBlockLocation) UUID(java.util.UUID) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream) IgfsFile(org.apache.ignite.igfs.IgfsFile)

Example 62 with IgniteUuid

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

the class CacheUtils method sparseMap.

/**
     * @param matrixUuid Matrix UUID.
     * @param mapper Mapping {@link IgniteFunction}.
     */
public static <K, V> void sparseMap(IgniteUuid matrixUuid, IgniteFunction<Double, Double> mapper) {
    foreach(SparseDistributedMatrixStorage.ML_CACHE_NAME, (CacheEntry<IgniteBiTuple<Integer, IgniteUuid>, Map<Integer, Double>> ce) -> {
        IgniteBiTuple k = ce.entry().getKey();
        Map<Integer, Double> v = ce.entry().getValue();
        for (Map.Entry<Integer, Double> e : v.entrySet()) e.setValue(mapper.apply(e.getValue()));
        ce.cache().put(k, v);
    }, key -> key.get2().equals(matrixUuid));
}
Also used : IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) IgniteUuid(org.apache.ignite.lang.IgniteUuid) Map(java.util.Map)

Example 63 with IgniteUuid

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

the class KMeansDistributedClusterer method initClusterCenters.

/** Initialize cluster centers. */
private Vector[] initClusterCenters(SparseDistributedMatrix points, int k) {
    // Initialize empty centers and point costs.
    int ptsCount = points.rowSize();
    // Initialize the first center to a random point.
    Vector sample = localCopyOf(points.viewRow(rnd.nextInt(ptsCount)));
    List<Vector> centers = new ArrayList<>();
    List<Vector> newCenters = new ArrayList<>();
    newCenters.add(sample);
    centers.add(sample);
    final ConcurrentHashMap<Integer, Double> costs = new ConcurrentHashMap<>();
    // On each step, sample 2 * k points on average with probability proportional
    // to their squared distance from the centers. Note that only distances between points
    // and new centers are computed in each iteration.
    int step = 0;
    IgniteUuid uid = points.getUUID();
    while (step < initSteps) {
        // We assume here that costs can fit into memory of one node.
        ConcurrentHashMap<Integer, Double> newCosts = getNewCosts(points, newCenters);
        // Merge costs with new costs.
        for (Integer ind : newCosts.keySet()) costs.merge(ind, newCosts.get(ind), Math::min);
        double sumCosts = costs.values().stream().mapToDouble(Double::valueOf).sum();
        newCenters = getNewCenters(k, costs, uid, sumCosts);
        centers.addAll(newCenters);
        step++;
    }
    List<Vector> distinctCenters = centers.stream().distinct().collect(Collectors.toList());
    if (distinctCenters.size() <= k)
        return distinctCenters.toArray(new Vector[] {});
    else {
        // Finally, we might have a set of more than k distinct candidate centers; weight each
        // candidate by the number of points in the dataset mapping to it and run a local k-means++
        // on the weighted centers to pick k of them
        ConcurrentHashMap<Integer, Integer> centerInd2Weight = weightCenters(uid, distinctCenters);
        List<Double> weights = new ArrayList<>(centerInd2Weight.size());
        for (int i = 0; i < distinctCenters.size(); i++) weights.add(i, Double.valueOf(centerInd2Weight.getOrDefault(i, 0)));
        DenseLocalOnHeapMatrix dCenters = MatrixUtil.fromList(distinctCenters, true);
        return new KMeansLocalClusterer(getDistanceMeasure(), 30, seed).cluster(dCenters, k, weights).centers();
    }
}
Also used : ArrayList(java.util.ArrayList) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix) IgniteUuid(org.apache.ignite.lang.IgniteUuid) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 64 with IgniteUuid

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

the class IgfsFragmentizerAbstractSelfTest method awaitFileFragmenting.

/**
     * @param gridIdx Grid index.
     * @param path Path to await.
     * @throws Exception If failed.
     */
protected void awaitFileFragmenting(int gridIdx, IgfsPath path) throws Exception {
    IgfsEx igfs = (IgfsEx) grid(gridIdx).fileSystem("igfs");
    IgfsMetaManager meta = igfs.context().meta();
    IgniteUuid fileId = meta.fileId(path);
    if (fileId == null)
        throw new IgfsPathNotFoundException("File not found: " + path);
    IgfsEntryInfo fileInfo = meta.info(fileId);
    do {
        if (fileInfo == null)
            throw new IgfsPathNotFoundException("File not found: " + path);
        if (fileInfo.fileMap().ranges().isEmpty())
            return;
        U.sleep(100);
        fileInfo = meta.info(fileId);
    } while (true);
}
Also used : IgfsEx(org.apache.ignite.internal.processors.igfs.IgfsEx) IgfsMetaManager(org.apache.ignite.internal.processors.igfs.IgfsMetaManager) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgfsEntryInfo(org.apache.ignite.internal.processors.igfs.IgfsEntryInfo)

Example 65 with IgniteUuid

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

the class IgfsMetaManagerSelfTest method mkdirsAndGetInfo.

private IgfsEntryInfo mkdirsAndGetInfo(String path) throws IgniteCheckedException {
    IgfsPath p = path(path);
    mgr.mkdirs(p, IgfsImpl.DFLT_DIR_META);
    IgniteUuid id = mgr.fileId(p);
    IgfsEntryInfo info = mgr.info(id);
    assert info.isDirectory();
    return info;
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) 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