Package org.gridgain.grid.kernal.processors.ggfs

Examples of org.gridgain.grid.kernal.processors.ggfs.GridGgfsFileInfo


        assert fs != null;
        assert startPath != null && startPathInfo != null && endPath != null;

        validTxState(true);

        GridGgfsFileInfo parentInfo = startPathInfo;

        List<String> components = endPath.components();

        GridGgfsPath curPath = startPath;

        for (int i = startPath.components().size(); i < components.size(); i++) {
            curPath = new GridGgfsPath(curPath, components.get(i));

            if (created != null && created.containsKey(curPath))
                // Re-use already created info.
                parentInfo = created.get(curPath);
            else {
                // Get file status from the secondary file system.
                GridGgfsFile status = fs.info(curPath);

                if (status != null) {
                    if (!status.isDirectory() && !curPath.equals(endPath))
                        throw new GridException("Failed to create path the locally because secondary file system " +
                            "directory structure was modified concurrently and the path is not a directory as " +
                            "expected: " + curPath);
                }
                else {
                    if (strict) {
                        throw new GridException("Failed to create path locally due to secondary file system " +
                            "exception: " + curPath);
                    }
                    else if (created != null)
                        created.put(curPath.parent(), parentInfo);

                    return null;
                }

                // Recreate the path locally.
                GridGgfsFileInfo curInfo = status.isDirectory() ? new GridGgfsFileInfo(true, status.properties()) :
                    new GridGgfsFileInfo(ggfsCtx.configuration().getBlockSize(), status.length(),
                        ggfsCtx.ggfs().evictExclude(curPath, false), status.properties());

                GridUuid oldId = putIfAbsentNonTx(parentInfo.id(), components.get(i), curInfo);

                if (oldId != null)
View Full Code Here


                                GridGgfsPath firstParentPath = pathToParent.get(path);

                                assert firstParentPath != null;
                                assert pathToId.get(firstParentPath) != null;

                                GridGgfsFileInfo info = synchronize(fs, firstParentPath,
                                    idToInfo.get(pathToId.get(firstParentPath)), path, strict, created);

                                assert strict && info != null || !strict;

                                if (info != null)
View Full Code Here

                GridCacheTx tx = metaCache.txStart(PESSIMISTIC, REPEATABLE_READ);

                try {
                    Map<GridUuid, GridGgfsFileInfo> infoMap = lockIds(fileId, parentId);

                    GridGgfsFileInfo fileInfo = infoMap.get(fileId);

                    if (fileInfo == null)
                        throw new GridGgfsFileNotFoundException("Failed to update times (path was not found): " +
                            fileName);

                    GridGgfsFileInfo parentInfo = infoMap.get(parentId);

                    if (parentInfo == null)
                        throw new GridGgfsInvalidPathException("Failed to update times (parent was not found): " +
                            fileName);

                    GridGgfsListingEntry entry = parentInfo.listing().get(fileName);

                    // Validate listing.
                    if (entry == null || !entry.fileId().equals(fileId))
                        throw new GridGgfsInvalidPathException("Failed to update times (file concurrently modified): " +
                            fileName);

                    assert parentInfo.isDirectory();

                    GridGgfsFileInfo updated = new GridGgfsFileInfo(fileInfo,
                        accessTime == -1 ? fileInfo.accessTime() : accessTime,
                        modificationTime == -1 ? fileInfo.modificationTime() : modificationTime);

                    id2InfoPrj.putx(fileId, updated);
View Full Code Here

            listing = new HashMap<>(listing);

            // Modify listing map in-place since map is serialization-safe.
            listing.put(fileName, entry);

            return new GridGgfsFileInfo(listing, fileInfo);
        }
View Full Code Here

                    throw new GridRuntimeException("Directory listing contains unexpected file" +
                        " [listing=" + listing + ", fileName=" + fileName + ", entry=" + entry +
                        ", oldEntry=" + oldEntry + ']');
            }

            return new GridGgfsFileInfo(listing, fileInfo);
        }
View Full Code Here

     */
    @SuppressWarnings("NullableProblems")
    public void testUpdateProperties() throws Exception {
        assertEmpty(mgr.directoryListing(ROOT_ID));

        GridGgfsFileInfo dir = new GridGgfsFileInfo(true, null);
        GridGgfsFileInfo file = new GridGgfsFileInfo(new GridGgfsFileInfo(400, null, false, null), 1);

        assertNull(mgr.putIfAbsent(ROOT_ID, "dir", dir));
        assertNull(mgr.putIfAbsent(ROOT_ID, "file", file));

        assertEquals(F.asMap("dir", new GridGgfsListingEntry(dir), "file", new GridGgfsListingEntry(file)),
            mgr.directoryListing(ROOT_ID));

        //GridGgfsFileInfo tmp = mgr.info(dir.id());

        assertEquals(dir, mgr.info(dir.id()));
        assertEquals(file, mgr.info(file.id()));

        for (GridBiTuple<GridUuid, String> tup: Arrays.asList(F.t(dir.id(), "dir"), F.t(file.id(), "file"))) {
            GridUuid fileId = tup.get1();
            String fileName = tup.get2();

            for (Map<String, String> props : Arrays.asList(null, Collections.<String, String>emptyMap()))
                expectsUpdatePropertiesFail(fileId, props, AssertionError.class, "Expects not-empty file's properties");

            String key1 = UUID.randomUUID().toString();
            String key2 = UUID.randomUUID().toString();

            GridGgfsFileInfo info = mgr.info(fileId);

            assertNull("Expects empty properties are not stored: " + info, getFieldValue(info, "props"));
            assertEquals("Expects empty properties are not stored: " + info, Collections.emptyMap(), info.properties());

            info = mgr.updateProperties(ROOT_ID, fileId, fileName, F.asMap(key1, "1"));

            assertEquals("Unexpected stored properties: " + info, F.asMap(key1, "1"), info.properties());

            info = mgr.updateProperties(ROOT_ID, fileId, fileName, F.asMap(key2, "2"));

            assertEquals("Unexpected stored properties: " + info, F.asMap(key1, "1", key2, "2"), info.properties());

            info = mgr.updateProperties(ROOT_ID, fileId, fileName, F.<String, String>asMap(key1, null));

            assertEquals("Unexpected stored properties: " + info, F.asMap(key2, "2"), info.properties());

            info = mgr.updateProperties(ROOT_ID, fileId, fileName, F.<String, String>asMap(key2, null));

            assertNull("Expects empty properties are not stored: " + info, getFieldValue(info, "props"));
            assertEquals("Expects empty properties are not stored: " + info, Collections.emptyMap(), info.properties());

            assertNull(mgr.updateProperties(ROOT_ID, fileId, "not_exists", F.<String, String>asMap(key2, null)));
        }

        mgr.removeIfEmpty(ROOT_ID, "dir", dir.id(), new GridGgfsPath("/dir"), true);
View Full Code Here

     * Test file system structure in meta-cache.
     *
     * @throws Exception If failed.
     */
    public void testStructure() throws Exception {
        GridGgfsFileInfo rootInfo = new GridGgfsFileInfo();
        // Test empty structure.
        assertEmpty(mgr.directoryListing(ROOT_ID));
        assertEquals(rootInfo, mgr.info(ROOT_ID));
        assertEquals(F.asMap(ROOT_ID, rootInfo), mgr.infos(Arrays.asList(ROOT_ID)));

        GridGgfsFileInfo a = new GridGgfsFileInfo(true, null);
        GridGgfsFileInfo b = new GridGgfsFileInfo(true, null);
        GridGgfsFileInfo f1 = new GridGgfsFileInfo(400, null, false, null);
        GridGgfsFileInfo f2 = new GridGgfsFileInfo(new GridGgfsFileInfo(400, null, false, null), 0);
        GridGgfsFileInfo f3 = new GridGgfsFileInfo(new GridGgfsFileInfo(400, null, false, null), 200000L);

        // Validate 'add file' operation.
        assertNull(mgr.putIfAbsent(ROOT_ID, "a", a));
        assertNull(mgr.putIfAbsent(ROOT_ID, "f1", f1));
        assertNull(mgr.putIfAbsent(a.id(), "b", b));
        assertNull(mgr.putIfAbsent(a.id(), "f2", f2));
        assertNull(mgr.putIfAbsent(b.id(), "f3", f3));

        assertEquals(b.id(), mgr.putIfAbsent(a.id(), "b", f3));
        expectsPutIfAbsentFail(a.id(), "c", f3, "Failed to add file details into cache");

        assertEquals(F.asMap("a", new GridGgfsListingEntry(a), "f1", new GridGgfsListingEntry(f1)),
            mgr.directoryListing(ROOT_ID));

        assertEquals(F.asMap("b", new GridGgfsListingEntry(b), "f2", new GridGgfsListingEntry(f2)),
            mgr.directoryListing(a.id()));

        assertEquals(F.asMap("f3", new GridGgfsListingEntry(f3)), mgr.directoryListing(b.id()));

        // Validate empty files listings.
        for (GridGgfsFileInfo info : Arrays.asList(f1, f2, f3)) {
            assertEmpty(mgr.directoryListing(info.id()));
        }

        // Validate 'file info' operations.
        for (GridGgfsFileInfo info : Arrays.asList(rootInfo, a, b, f1, f2, f3)) {
            assertEquals(info, mgr.info(info.id()));
            assertEquals(F.asMap(info.id(), info), mgr.infos(Arrays.asList(info.id())));
        }

        // Validate 'file ID' operations.
        assertEquals(ROOT_ID, mgr.fileId(new GridGgfsPath("/")));
        assertEquals(a.id(), mgr.fileId(new GridGgfsPath("/a")));
        assertEquals(b.id(), mgr.fileId(new GridGgfsPath("/a/b")));
        assertEquals(f1.id(), mgr.fileId(new GridGgfsPath("/f1")));
        assertEquals(f2.id(), mgr.fileId(new GridGgfsPath("/a/f2")));
        assertEquals(f3.id(), mgr.fileId(new GridGgfsPath("/a/b/f3")));
        assertNull(mgr.fileId(new GridGgfsPath("/f4")));
        assertNull(mgr.fileId(new GridGgfsPath("/a/f5")));
        assertNull(mgr.fileId(new GridGgfsPath("/a/b/f6")));

        assertEquals(a.id(), mgr.fileId(ROOT_ID, "a"));
        assertEquals(b.id(), mgr.fileId(a.id(), "b"));
        assertEquals(f1.id(), mgr.fileId(ROOT_ID, "f1"));
        assertEquals(f2.id(), mgr.fileId(a.id(), "f2"));
        assertEquals(f3.id(), mgr.fileId(b.id(), "f3"));
        assertNull(mgr.fileId(ROOT_ID, "f4"));
        assertNull(mgr.fileId(a.id(), "f5"));
        assertNull(mgr.fileId(b.id(), "f6"));

        assertEquals(Arrays.asList(ROOT_ID), mgr.fileIds(new GridGgfsPath("/")));
        assertEquals(Arrays.asList(ROOT_ID, a.id()), mgr.fileIds(new GridGgfsPath("/a")));
        assertEquals(Arrays.asList(ROOT_ID, a.id(), b.id()), mgr.fileIds(new GridGgfsPath("/a/b")));
        assertEquals(Arrays.asList(ROOT_ID, f1.id()), mgr.fileIds(new GridGgfsPath("/f1")));
        assertEquals(Arrays.asList(ROOT_ID, a.id(), f2.id()), mgr.fileIds(new GridGgfsPath("/a/f2")));
        assertEquals(Arrays.asList(ROOT_ID, a.id(), b.id(), f3.id()), mgr.fileIds(new GridGgfsPath("/a/b/f3")));
        assertEquals(Arrays.asList(ROOT_ID, null), mgr.fileIds(new GridGgfsPath("/f4")));
        assertEquals(Arrays.asList(ROOT_ID, a.id(), null), mgr.fileIds(new GridGgfsPath("/a/f5")));
        assertEquals(Arrays.asList(ROOT_ID, a.id(), b.id(), null), mgr.fileIds(new GridGgfsPath("/a/b/f6")));
        assertEquals(Arrays.asList(ROOT_ID, null, null, null, null), mgr.fileIds(new GridGgfsPath("/f7/a/b/f6")));

        // Validate 'rename' operation.
        final GridUuid rndId = GridUuid.randomUuid();

        // One of participated files does not exist in cache.
        expectsRenameFail(ROOT_ID, "b", rndId, "b2", rndId, "Failed to lock source directory (not found?)");
        expectsRenameFail(b.id(), "b", rndId, "b2", rndId, "Failed to lock source directory (not found?)");
        expectsRenameFail(ROOT_ID, "b", ROOT_ID, "b2", rndId, "Failed to lock destination directory (not found?)");
        expectsRenameFail(b.id(), "b", ROOT_ID, "b2", rndId, "Failed to lock destination directory (not found?)");
        expectsRenameFail(rndId, "b", ROOT_ID, "b2", ROOT_ID, "Failed to lock target file (not found?)");
        expectsRenameFail(rndId, "b", b.id(), "b2", b.id(), "Failed to lock target file (not found?)");

        // Target file ID differ from the file ID resolved from the source directory for source file name.
        expectsRenameFail(b.id(), "a", ROOT_ID, "q", ROOT_ID, "Failed to remove file name from the source directory");
        expectsRenameFail(f1.id(), "a", ROOT_ID, "q", ROOT_ID, "Failed to remove file name from the source directory");
        expectsRenameFail(f2.id(), "a", ROOT_ID, "q", ROOT_ID, "Failed to remove file name from the source directory");
        expectsRenameFail(f3.id(), "a", ROOT_ID, "q", ROOT_ID, "Failed to remove file name from the source directory");

        // Invalid source file name (not found).
        expectsRenameFail(a.id(), "u1", ROOT_ID, "q", ROOT_ID, "Failed to remove file name from the source");
        expectsRenameFail(a.id(), "u2", ROOT_ID, "q", ROOT_ID, "Failed to remove file name from the source");
        expectsRenameFail(a.id(), "u3", ROOT_ID, "q", ROOT_ID, "Failed to remove file name from the source");

        // Invalid destination file - already exists.
        expectsRenameFail(a.id(), "a", ROOT_ID, "f1", ROOT_ID, "Failed to add file name into the destination");
        expectsRenameFail(f2.id(), "f2", a.id(), "f1", ROOT_ID, "Failed to add file name into the destination");
        expectsRenameFail(f3.id(), "f3", b.id(), "f1", ROOT_ID, "Failed to add file name into the destination");
        expectsRenameFail(b.id(), "b", a.id(), "f2", a.id(), "Failed to add file name into the destination");

        System.out.println("/: " + mgr.directoryListing(ROOT_ID));
        System.out.println("a: " + mgr.directoryListing(a.id()));
        System.out.println("b: " + mgr.directoryListing(b.id()));
        System.out.println("f3: " + mgr.directoryListing(f3.id()));

        mgr.move(a.id(), "a", ROOT_ID, "a2", ROOT_ID);
        mgr.move(b.id(), "b", a.id(), "b2", a.id());

        assertNotNull(mgr.info(b.id()));

        mgr.move(f3.id(), "f3", b.id(), "f3-2", a.id());

        assertNotNull(mgr.info(b.id()));

        mgr.move(f3.id(), "f3-2", a.id(), "f3", b.id());
        mgr.move(b.id(), "b2", a.id(), "b", a.id());
        mgr.move(a.id(), "a2", ROOT_ID, "a", ROOT_ID);

        // Validate 'remove' operation.
        for (int i = 0; i < 100; i++) {
            // One of participants doesn't exist.
            assertNull(mgr.removeIfEmpty(ROOT_ID, "a", GridUuid.randomUuid(), new GridGgfsPath("/a"), true));
            assertNull(mgr.removeIfEmpty(GridUuid.randomUuid(), "a", GridUuid.randomUuid(),
                new GridGgfsPath("/" + GridUuid.randomUuid() + "/a"), true));
        }

        expectsRemoveFail(ROOT_ID, "a", a.id(), new GridGgfsPath("/a"),
            "Failed to remove file (directory is not empty)");
        expectsRemoveFail(a.id(), "b", b.id(), new GridGgfsPath("/a/b"),
            "Failed to remove file (directory is not empty)");
        assertNull(mgr.removeIfEmpty(ROOT_ID, "a", f1.id(), new GridGgfsPath("/a"), true));
        assertNull(mgr.removeIfEmpty(a.id(), "b", f1.id(), new GridGgfsPath("/a/b"), true));

        assertEquals(f3, mgr.removeIfEmpty(b.id(), "f3", f3.id(), new GridGgfsPath("/a/b/f3"), true));

        assertEquals(F.asMap("a", new GridGgfsListingEntry(a), "f1", new GridGgfsListingEntry(f1)),
            mgr.directoryListing(ROOT_ID));

        assertEquals(F.asMap("b", new GridGgfsListingEntry(b), "f2", new GridGgfsListingEntry(f2)),
            mgr.directoryListing(a.id()));

        assertEmpty(mgr.directoryListing(b.id()));

        assertEquals(b, mgr.removeIfEmpty(a.id(), "b", b.id(), new GridGgfsPath("/a/b"), true));

        assertEquals(F.asMap("a", new GridGgfsListingEntry(a), "f1", new GridGgfsListingEntry(f1)),
            mgr.directoryListing(ROOT_ID));

        assertEquals(F.asMap("f2", new GridGgfsListingEntry(f2)), mgr.directoryListing(a.id()));

        assertEmpty(mgr.directoryListing(b.id()));

        // Validate last actual data received from 'remove' operation.
        GridGgfsFileInfo newF2 = mgr.updateInfo(f2.id(), new C1<GridGgfsFileInfo, GridGgfsFileInfo>() {
            @Override public GridGgfsFileInfo apply(GridGgfsFileInfo e) {
                return new GridGgfsFileInfo(e, e.length() + 20);
            }
        });

        assertNotNull(newF2);
        assertEquals(f2.id(), newF2.id());
        assertNotSame(f2, newF2);

        assertEquals(newF2, mgr.removeIfEmpty(a.id(), "f2", f2.id(), new GridGgfsPath("/a/f2"), true));

        assertEquals(F.asMap("a", new GridGgfsListingEntry(a), "f1", new GridGgfsListingEntry(f1)),
View Full Code Here

        final GridCache<GridUuid, GridGgfsFileInfo> metaCache = ggfs.context().kernalContext().cache().cache(
            ggfs.configuration().getMetaCacheName());

        // Start a transaction in a separate thread which will lock file ID.
        final GridUuid id = ggfs.context().meta().fileId(path);
        final GridGgfsFileInfo info = ggfs.context().meta().info(id);

        final AtomicReference<Throwable> err = new AtomicReference<>();

        try {
            new Thread(new Runnable() {
                @Override public void run() {
                    try {

                        try (GridCacheTx tx = metaCache.txStart(PESSIMISTIC, REPEATABLE_READ)) {
                            metaCache.get(id);

                            latch.await();

                            U.sleep(1000); // Sleep here so that data manager could "see" oversize.

                            tx.commit();
                        }
                    }
                    catch (Throwable e) {
                        err.set(e);
                    }
                }
            }).start();

            // Now add file ID to trash listing so that delete worker could "see" it.

            try (GridCacheTx tx = metaCache.txStart(PESSIMISTIC, REPEATABLE_READ)) {
                Map<String, GridGgfsListingEntry> listing = Collections.singletonMap(path.name(),
                    new GridGgfsListingEntry(info));

                // Clear root listing.
                metaCache.put(ROOT_ID, new GridGgfsFileInfo(ROOT_ID));

                // Add file to trash listing.
                GridGgfsFileInfo trashInfo = metaCache.get(TRASH_ID);

                if (trashInfo == null)
                    metaCache.put(TRASH_ID, new GridGgfsFileInfo(listing, new GridGgfsFileInfo(TRASH_ID)));
                else
                    metaCache.put(TRASH_ID, new GridGgfsFileInfo(listing, trashInfo));

                tx.commit();
            }

            assert metaCache.get(TRASH_ID) != null;
View Full Code Here

TOP

Related Classes of org.gridgain.grid.kernal.processors.ggfs.GridGgfsFileInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.