pathIds.add(idsForPath(path)); try (GridNearTxLocal tx = startTx()) { Map<IgniteUuid, IgfsEntryInfo> idToInfo = lockIds(lockArr); !F.eq(entry.getValue(), fileId(entry.getKey(), true))) { changed = entry.getKey(); finished = true; throw fsException(new IgfsConcurrentModificationException("File system entry has been " + "modified concurrently: " + changed)); List<IgniteUuid> newIds = fileIds(paths[i], true); infos.put(path, info(pathToId.get(path))); infos.put(parentPath, info(pathToId.get(parentPath))); assert pathToId.get(firstParentPath) != null; IgfsEntryInfo info = synchronize(fs, firstParentPath, idToInfo.get(pathToId.get(firstParentPath)),
/** * List child files for specified file ID. * * @param fileId File to list child files for. * @return Directory listing for the specified file. * @throws IgniteCheckedException If failed. */ public Map<String, IgfsListingEntry> directoryListing(IgniteUuid fileId) throws IgniteCheckedException { if (busyLock.enterBusy()) { try { return directoryListing(fileId, false); } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to get directory listing because Grid is stopping: " + fileId); }
/** * Get primary file system info for listing operation. * * @param path Path. * @return Info or {@code null} if not found. * @throws IgniteCheckedException If failed. */ private IgfsEntryInfo primaryInfoForListing(IgfsPath path) throws IgniteCheckedException { IgniteUuid fileId = meta.fileId(path); return fileId != null ? meta.info(fileId) : null; }
/** * Get info for the given path. * * @param path Path. * @return Info. * @throws IgniteCheckedException If failed. */ @Nullable public IgfsEntryInfo infoForPath(IgfsPath path) throws IgniteCheckedException { return client ? runClientTask(new IgfsClientMetaInfoForPathCallable(cfg.getName(), IgfsUserContext.currentUser(), path)) : info(fileId(path)); }
/** * Get IDs for the given path. * * @param path Path. * @return IDs. * @throws IgniteCheckedException If failed. */ public List<IgniteUuid> idsForPath(IgfsPath path) throws IgniteCheckedException { return client ? runClientTask(new IgfsClientMetaIdsForPathCallable(cfg.getName(), IgfsUserContext.currentUser(), path)) : fileIds(path); }
assertEmpty(mgr.directoryListing(ROOT_ID)); assertEquals(rootInfo, mgr.info(ROOT_ID)); assertEquals(F.asMap(ROOT_ID, rootInfo), mgr.infos(Arrays.asList(ROOT_ID))); mgr.directoryListing(ROOT_ID)); mgr.directoryListing(a.id())); "k", new IgfsListingEntry(k)), mgr.directoryListing(b.id())); assertEmpty(mgr.directoryListing(info.id())); assertEquals(info, mgr.info(info.id())); assertEquals(F.asMap(info.id(), info), mgr.infos(Arrays.asList(info.id()))); assertEquals(ROOT_ID, mgr.fileId(IgfsPath.ROOT)); assertEquals(a.id(), mgr.fileId(new IgfsPath("/a"))); assertEquals(b.id(), mgr.fileId(new IgfsPath("/a/b"))); assertEquals(f1.id(), mgr.fileId(new IgfsPath("/f1"))); assertEquals(f2.id(), mgr.fileId(new IgfsPath("/a/f2"))); assertEquals(f3.id(), mgr.fileId(new IgfsPath("/a/b/f3"))); assertNull(mgr.fileId(new IgfsPath("/f4"))); assertNull(mgr.fileId(new IgfsPath("/a/f5"))); assertNull(mgr.fileId(new IgfsPath("/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"));
assertEmpty(mgr.directoryListing(ROOT_ID)); assertTrue(mgr.mkdirs(new IgfsPath("/dir"), IgfsImpl.DFLT_DIR_META)); assertNotNull(mgr.create(new IgfsPath("/file"), null, false, 400, null, false, null, null)); IgfsListingEntry dirEntry = mgr.directoryListing(ROOT_ID).get("dir"); assertNotNull(dirEntry); assertTrue(dirEntry.isDirectory()); IgfsEntryInfo dir = mgr.info(dirEntry.fileId()); IgfsListingEntry fileEntry = mgr.directoryListing(ROOT_ID).get("file"); assertNotNull(fileEntry); assertTrue(!fileEntry.isDirectory()); IgfsEntryInfo file = mgr.info(fileEntry.fileId()); assertEquals(2, mgr.directoryListing(ROOT_ID).size()); IgfsEntryInfo info = mgr.info(fileId); info = mgr.updateProperties(fileId, F.asMap(key1, "1")); info = mgr.updateProperties(fileId, F.asMap(key2, "2")); info = mgr.updateProperties(fileId, F.<String, String>asMap(key1, null)); info = mgr.updateProperties(fileId, F.<String, String>asMap(key2, null)); mgr.softDelete(new IgfsPath("/dir"), true, null); mgr.softDelete(new IgfsPath("/file"), false, null);
validTxState(false); log.debug("Reserve file space: " + fileId); try (GridNearTxLocal tx = startTx()) { IgfsEntryInfo oldInfo = info(fileId); throw fsException("File has been deleted concurrently: " + fileId); invokeAndGet(fileId, new IgfsMetaFileReserveSpaceProcessor(space, affRange));
int bufSize, short replication, long blockSize, IgniteUuid affKey, Map<IgfsPath, IgfsEntryInfo> infos, final Deque<IgfsEvent> pendingEvts, final T1<OutputStream> t1) throws Exception { validTxState(true); parentInfo = synchronize(fs, parentPath, parentInfo, parent0, true, null); throw fsException("Failed to open output stream to the file created in " + "the secondary file system because it no longer exists: " + path); else if (status.isDirectory()) throw fsException("Failed to open output stream to the file created in " + "the secondary file system because the path points to a directory: " + path); status.length(), affKey, createFileLockId(false), igfsCtx.igfs().evictExclude(path, false), status.properties(), IgniteUuid oldId = putIfAbsentNonTx(parentInfo.id(), path.name(), newInfo); IgfsEntryInfo oldInfo = info(oldId); throw fsException("Failed to overwrite file (file is opened for writing) [path=" + path + ", fileId=" + oldId + ", lockId=" + oldInfo.lockId() + ']'); path.name(), parentInfo.listing().get(path.name()).fileId())); createNewEntry(newInfo, parentInfo.id(), path.name()); // Put new one.
/** * Ensure that entry with the given ID exists in meta cache. * * @param fileId File id. * @return {@code True} in case such entry exists. * @throws IgniteCheckedException IF failed. */ public boolean exists(IgniteUuid fileId) throws IgniteCheckedException{ if (busyLock.enterBusy()) { try { assert fileId != null; // containsKey() doesn't work here since meta cache can be PARTITIONED (we do not restrict if!). return info(fileId) != null; } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to check file system entry existence because Grid is stopping: " + fileId); }
/** * Gets all file IDs for components of specified path possibly skipping existing transaction. 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. * @param skipTx Whether to skip existing transaction. * @return Collection of file IDs for components of specified path. * @throws IgniteCheckedException If failed. */ private List<IgniteUuid> fileIds(IgfsPath path, boolean skipTx) throws IgniteCheckedException { assert path != null; // Path components. Collection<String> components = path.components(); // Collection of file IDs for components of specified path. List<IgniteUuid> ids = new ArrayList<>(components.size() + 1); ids.add(IgfsUtils.ROOT_ID); // Always add root ID. IgniteUuid fileId = IgfsUtils.ROOT_ID; for (String s : components) { assert !s.isEmpty(); if (fileId != null) fileId = fileId(fileId, s, skipTx); ids.add(fileId); } return ids; }
/** * Add file into file system structure. Do not create new transaction expecting that the one already exists. * * @param parentId Parent file ID. * @param fileName File name in the parent's listing. * @param newFileInfo File info to store in the parent's listing. * @return File id already stored in meta cache or {@code null} if passed file info was stored. * @throws IgniteCheckedException If failed. */ private IgniteUuid putIfAbsentNonTx(IgniteUuid parentId, String fileName, IgfsEntryInfo newFileInfo) throws IgniteCheckedException { if (log.isDebugEnabled()) log.debug("Locking parent id [parentId=" + parentId + ", fileName=" + fileName + ", newFileInfo=" + newFileInfo + ']'); validTxState(true); // Lock only parent file ID. IgfsEntryInfo parentInfo = info(parentId); if (parentInfo == null) throw fsException(new IgfsPathNotFoundException("Failed to lock parent directory (not found): " + parentId)); if (!parentInfo.isDirectory()) throw fsException(new IgfsPathIsNotDirectoryException("Parent file is not a directory: " + parentInfo)); IgfsListingEntry childEntry = parentInfo.listing().get(fileName); if (childEntry != null) return childEntry.fileId(); createNewEntry(newFileInfo, parentId, fileName); return null; }
if (busyLock.enterBusy()) { try { validTxState(false); try (GridNearTxLocal tx = startTx()) { IgfsEntryInfo oldInfo = info(fileId); return null; // The file is already locked, we cannot lock it. IgfsEntryInfo newInfo = invokeLock(fileId, del);
/** * Update file info (file properties) in cache in existing transaction. * * @param fileId File ID to update information for. * @param props Properties to set for the file. * @return Updated file info or {@code null} if such file ID not found. * @throws IgniteCheckedException If operation failed. */ @Nullable private IgfsEntryInfo updatePropertiesNonTx(final IgniteUuid fileId, Map<String, String> props) throws IgniteCheckedException { assert fileId != null; assert !F.isEmpty(props) : "Expects not-empty file's properties"; validTxState(true); if (log.isDebugEnabled()) log.debug("Update file properties [fileId=" + fileId + ", props=" + props + ']'); try { final IgfsEntryInfo oldInfo = info(fileId); if (oldInfo == null) return null; return invokeAndGet(fileId, new IgfsMetaUpdatePropertiesProcessor(props)); } catch (GridClosureException e) { throw U.cast(e); } }
List<IgniteUuid> ids = runClientTask(new IgfsClientMetaIdsForPathCallable(cfg.getName(), IgfsUserContext.currentUser(), path)); if (busyLock.enterBusy()) { try { validTxState(false); IgniteUuid id = fileId(ids[i - 1], parts[i], false);
assert startPath != null && startPathInfo != null && endPath != null; validTxState(true); IgniteUuid oldId = putIfAbsentNonTx(parentInfo.id(), components.get(i), curInfo); curInfo = info(oldId);
/** * Gets file ID for specified path. * * @param path Path. * @return File ID for specified path or {@code null} if such file doesn't exist. * @throws IgniteCheckedException If failed. */ @Nullable public IgniteUuid fileId(IgfsPath path) throws IgniteCheckedException { if (busyLock.enterBusy()) { try { validTxState(false); return fileId(path, false); } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to get file ID because Grid is stopping: " + path); }
IgfsEntryInfo info = info(parentId); IgfsEntryInfo fileInfo = info(entry.fileId()); IgfsEntryInfo fileInfo = fileForFragmentizer0(entry.fileId(), exclude);