/** * 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 GridException If failed. */ private List<GridUuid> fileIds(GridGgfsPath path, boolean skipTx) throws GridException { assert path != null; // Path components. Collection<String> components = path.components(); // Collection of file IDs for components of specified path. List<GridUuid> ids = new ArrayList<>(components.size() + 1); ids.add(ROOT_ID); // Always add root ID. GridUuid fileId = ROOT_ID; for (String s : components) { assert !s.isEmpty(); if (fileId != null) fileId = fileId(fileId, s, skipTx); ids.add(fileId); } return ids; }
/** * 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 GridException If failed. */ private List<GridUuid> fileIds(GridGgfsPath path, boolean skipTx) throws GridException { assert path != null; // Path components. Collection<String> components = path.components(); // Collection of file IDs for components of specified path. List<GridUuid> ids = new ArrayList<>(components.size() + 1); ids.add(ROOT_ID); // Always add root ID. GridUuid fileId = ROOT_ID; for (String s : components) { assert !s.isEmpty(); if (fileId != null) fileId = fileId(fileId, s, skipTx); ids.add(fileId); } return ids; }
/** * Gets file ID by its name from parent directory listing. * * @param parentId Parent directory ID to get child ID for. * @param fileName File name in parent listing to get file ID for. * @return File ID. * @throws GridException If failed. */ @Nullable public GridUuid fileId(GridUuid parentId, String fileName) throws GridException { if (busyLock.enterBusy()) { try { return fileId(parentId, fileName, false); } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to get file ID because Grid is stopping [parentId=" + parentId + ", fileName=" + fileName + ']'); }
/** * Gets file ID by its name from parent directory listing. * * @param parentId Parent directory ID to get child ID for. * @param fileName File name in parent listing to get file ID for. * @return File ID. * @throws GridException If failed. */ @Nullable public GridUuid fileId(GridUuid parentId, String fileName) throws GridException { if (busyLock.enterBusy()) { try { return fileId(parentId, fileName, false); } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to get file ID because Grid is stopping [parentId=" + parentId + ", fileName=" + fileName + ']'); }
/** * 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 GridException If failed. */ @Nullable public GridUuid fileId(GridGgfsPath path) throws GridException { if (busyLock.enterBusy()) { try { assert validTxState(false); return fileId(path, false); } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to get file ID because Grid is stopping: " + path); }
/** * 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 GridException If failed. */ @Nullable public GridUuid fileId(GridGgfsPath path) throws GridException { if (busyLock.enterBusy()) { try { assert validTxState(false); return fileId(path, false); } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to get file ID because Grid is stopping: " + path); }
/** {@inheritDoc} */ @Override public boolean exists(GridGgfsPath path) throws GridException { A.notNull(path, "path"); if (log.isDebugEnabled()) log.debug("Check file exists: " + path); GridGgfsMode mode = modeRslvr.resolveMode(path); if (mode == PROXY) throw new GridException("PROXY mode cannot be used in GGFS directly: " + path); boolean res = false; switch (mode) { case PRIMARY: res = meta.fileId(path) != null; break; case DUAL_SYNC: case DUAL_ASYNC: res = meta.fileId(path) != null; if (!res) res = secondaryFs.exists(path); break; default: assert false : "Unknown mode."; } return res; }
/** {@inheritDoc} */ @Override public boolean exists(GridGgfsPath path) throws GridException { A.notNull(path, "path"); if (log.isDebugEnabled()) log.debug("Check file exists: " + path); GridGgfsMode mode = modeRslvr.resolveMode(path); if (mode == PROXY) throw new GridException("PROXY mode cannot be used in GGFS directly: " + path); boolean res = false; switch (mode) { case PRIMARY: res = meta.fileId(path) != null; break; case DUAL_SYNC: case DUAL_ASYNC: res = meta.fileId(path) != null; if (!res) res = secondaryFs.exists(path); break; default: assert false : "Unknown mode."; } return res; }
try { GridGgfsFileInfo info = info(fileId(path));
/** {@inheritDoc} */ @Override public long size(GridGgfsPath path) throws GridException { if (enterBusy()) { try { A.notNull(path, "path"); GridUuid nextId = meta.fileId(path); if (nextId == null) return 0; GridGgfsPathSummary sum = new GridGgfsPathSummary(path); summary0(nextId, sum); return sum.totalLength(); } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to get path size because Grid is stopping."); }
/** {@inheritDoc} */ @Override public long size(GridGgfsPath path) throws GridException { if (busyLock.enterBusy()) { try { A.notNull(path, "path"); GridUuid nextId = meta.fileId(path); if (nextId == null) return 0; GridGgfsPathSummary sum = new GridGgfsPathSummary(path); summary0(nextId, sum); return sum.totalLength(); } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to get path size because Grid is stopping."); }
GridUuid fileId = meta.fileId(path);
GridUuid fileId = meta.fileId(path);
/** {@inheritDoc} */ @Override public GridGgfsPathSummary summary(GridGgfsPath path) throws GridException { if (busyLock.enterBusy()) { try { A.notNull(path, "path"); if (log.isDebugEnabled()) log.debug("Calculating path summary: " + path); GridUuid fileId = meta.fileId(path); if (fileId == null) throw new GridGgfsFileNotFoundException("Failed to get path summary (path not found): " + path); GridGgfsPathSummary sum = new GridGgfsPathSummary(path); summary0(fileId, sum); return sum; } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to get path summary because Grid is stopping."); }
/** {@inheritDoc} */ @Override public GridGgfsPathSummary summary(GridGgfsPath path) throws GridException { if (enterBusy()) { try { A.notNull(path, "path"); if (log.isDebugEnabled()) log.debug("Calculating path summary: " + path); GridUuid fileId = meta.fileId(path); if (fileId == null) throw new GridGgfsFileNotFoundException("Failed to get path summary (path not found): " + path); GridGgfsPathSummary sum = new GridGgfsPathSummary(path); summary0(fileId, sum); return sum; } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to get path summary because Grid is stopping."); }
GridUuid fileId = meta.fileId(path);
GridUuid fileId = meta.fileId(path); GridGgfsFileInfo info = meta.info(fileId);
GridUuid fileId = meta.fileId(path); GridGgfsFileInfo info = meta.info(fileId);