/** {@inheritDoc} */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { filesCnt = in.readInt(); dirCnt = in.readInt(); totalLen = in.readLong(); path = new GridGgfsPath(); path.readExternal(in); }
/** * Update ID with the given index. * * @param newParentPath New parent path. * @param newParentInfo New parent info. */ private void updateParent(GridGgfsPath newParentPath, GridGgfsFileInfo newParentInfo) { assert newParentPath != null; assert newParentInfo != null; assert path.isSubDirectoryOf(newParentPath); parentPath = newParentPath; parentInfo = newParentInfo; ids.set(newParentPath.components().size(), newParentInfo.id()); }
@Override public Boolean onSuccess(Map<GridGgfsPath, GridGgfsFileInfo> infos) throws Exception { fs.mkdirs(path, props); assert !infos.isEmpty(); // Now perform synchronization again starting with the last created parent. GridGgfsPath parentPath = null; for (GridGgfsPath curPath : infos.keySet()) { if (parentPath == null || curPath.isSubDirectoryOf(parentPath)) parentPath = curPath; } assert parentPath != null; GridGgfsFileInfo parentPathInfo = infos.get(parentPath); synchronize(fs, parentPath, parentPathInfo, path, true, null); if (evts.isRecordable(EVT_GGFS_DIR_CREATED)) { GridGgfsPath evtPath = path; while (!parentPath.equals(evtPath)) { pendingEvts.addFirst(new GridGgfsEvent(evtPath, locNode, EVT_GGFS_DIR_CREATED)); evtPath = evtPath.parent(); assert evtPath != null; // If this fails, then ROOT does not exist. } } return true; }
@Override public GridGgfsFileInfo onSuccess(Map<GridGgfsPath, GridGgfsFileInfo> infos) throws Exception { if (infos.get(path) == null) return null; fs.update(path, props); assert path.parent() == null || infos.get(path.parent()) != null; return updatePropertiesNonTx(infos.get(path.parent()).id(), infos.get(path).id(), path.name(), props); }
if (parentPath == null || curPath.isSubDirectoryOf(parentPath)) parentPath = curPath; fs.create(path, bufSize, overwrite, replication, blockSize, props); GridGgfsPath parent0 = path.parent(); if (!parentPath.equals(parent0)) { parentInfo = synchronize(fs, parentPath, parentInfo, parent0, true, null); GridGgfsPath evtPath = parent0; while (!parentPath.equals(evtPath)) { pendingEvts.addFirst(new GridGgfsEvent(evtPath, locNode, EVT_GGFS_DIR_CREATED)); evtPath = evtPath.parent(); GridUuid oldId = putIfAbsentNonTx(parentInfo.id(), path.name(), newInfo); new UpdateListing(path.name(), parentInfo.listing().get(path.name()), true)); id2InfoPrj.transform(parentInfo.id(), new UpdateListing(path.name(), new GridGgfsListingEntry(newInfo), false));
List<String> components = endPath.components(); for (int i = startPath.components().size(); i < components.size(); i++) { curPath = new GridGgfsPath(curPath, components.get(i)); 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 " + created.put(curPath.parent(), parentInfo);
@Override public Boolean onSuccess(Map<GridGgfsPath, GridGgfsFileInfo> infos) throws Exception { GridGgfsFileInfo srcInfo = infos.get(src); GridGgfsFileInfo srcParentInfo = infos.get(src.parent()); GridGgfsFileInfo destInfo = infos.get(dest); GridGgfsFileInfo destParentInfo = dest.parent() != null ? infos.get(dest.parent()) : null; moveNonTx(srcInfo.id(), src.name(), srcParentInfo.id(), dest.name(), destParentInfo.id()); "because destination path already exists and it is a file: " + dest); else moveNonTx(srcInfo.id(), src.name(), srcParentInfo.id(), src.name(), destInfo.id()); pendingEvts.add(new GridGgfsEvent( src, destInfo == null ? dest : new GridGgfsPath(dest, src.name()), locNode, EVT_GGFS_FILE_RENAMED));
List<String> components = path.components(); GridGgfsPath curPath = path.root(); curPath = new GridGgfsPath(curPath, fileName);
/** * Returns a root for this path. * * @return Root for this path. */ public GridGgfsPath root() { return new GridGgfsPath(); }
/** * Get file descriptor for specified path. * * @param path Path to file. * @return Detailed file descriptor or {@code null}, if file does not exist. * @throws GridException If failed. */ @Nullable private FileDescriptor getFileDescriptor(GridGgfsPath path) throws GridException { List<GridUuid> ids = meta.fileIds(path); GridGgfsFileInfo fileInfo = meta.info(ids.get(ids.size() - 1)); if (fileInfo == null) return null; // File does not exist. // Resolve parent ID for removed file. GridUuid parentId = ids.size() >= 2 ? ids.get(ids.size() - 2) : null; return new FileDescriptor(parentId, path.name(), fileInfo.id(), fileInfo.isFile()); }
/** * Await for any pending finished writes on the children paths. * * @param paths Paths to check. */ void await(GridGgfsPath... paths) { assert paths != null; for (Map.Entry<GridGgfsPath, GridGgfsFileWorker> workerEntry : workerMap.entrySet()) { GridGgfsPath workerPath = workerEntry.getKey(); boolean await = false; for (GridGgfsPath path : paths) { if (workerPath.isSubDirectoryOf(path) || workerPath.isSame(path)) { await = true; break; } } if (await) { GridGgfsFileWorkerBatch batch = workerEntry.getValue().currentBatch(); if (batch != null) { try { batch.awaitIfFinished(); } catch (GridException ignore) { // No-op. } } } } }
assert dest != null; if (src.parent() == null) return false; // Root directory cannot be renamed. pendingEvts.add(new GridGgfsEvent( src, destInfo == null ? dest : new GridGgfsPath(dest, src.name()), locNode, EVT_GGFS_FILE_RENAMED));
GridGgfsPath parentPath = path.parent(); GridUuid parentId = ids.get(ids.size() - 2); break; else { parentPath = parentPath.parent(); parentId = ids.get(j); GridGgfsPath parentPath = path.parent(); if (parentPath.equals(firstParentPath)) infos.put(firstParentPath, idToInfo.get(pathToId.get(firstParentPath))); else {
/** * Check if path starts with prefix. * * @param path Path. * @param prefix Prefix. * @return {@code true} if path starts with prefix, {@code false} if not. */ private static boolean startsWith(GridGgfsPath path, GridGgfsPath prefix) { List<String> p1Comps = path.components(); List<String> p2Comps = prefix.components(); if (p2Comps.size() > p1Comps.size()) return false; for (int i = 0; i < p1Comps.size(); i++) { if (i >= p2Comps.size() || p2Comps.get(i) == null) // All prefix components already matched. return true; if (!p1Comps.get(i).equals(p2Comps.get(i))) return false; } // Path and prefix components had same length and all of them matched. return true; } }
/** {@inheritDoc} */ @Override public boolean equals(Object o) { if (o == this) return true; if (o == null || getClass() != o.getClass()) return false; GridGgfsFileImpl that = (GridGgfsFileImpl)o; return path.equals(that.path); }
/** {@inheritDoc} */ @Override public int hashCode() { return path.hashCode(); }
/** * Constructor. * * @param path Path. * @param ids Resolved path IDs. * @param parentPath Parent path. * @param parentInfo Parent info. */ PathDescriptor(GridGgfsPath path, List<GridUuid> ids, GridGgfsPath parentPath, GridGgfsFileInfo parentInfo) { assert path != null; assert ids != null && !ids.isEmpty(); assert parentPath == null && parentInfo == null || parentPath != null && parentInfo != null; assert parentPath == null || parentPath != null && path.isSubDirectoryOf(parentPath); this.path = path; this.ids = ids; this.parentPath = parentPath; this.parentInfo = parentInfo; }
throw new GridException("PROXY mode cannot be used in GGFS directly: " + src); if (src.equals(dest)) return; // Rename to itself is a no-op. if (src.parent() == null) throw new GridGgfsInvalidPathException("Failed to rename root directory."); if (dest.isSubDirectoryOf(src)) throw new GridGgfsInvalidPathException("Failed to rename directory (cannot move directory of " + "upper level to self sub-dir) [src=" + src + ", dest=" + dest + ']'); GridGgfsPath destParent = dest.parent(); String srcFileName = src.name(); "exist): " + dest); destFileName = dest.name(); evts.record(new GridGgfsEvent( src, newDest ? dest : new GridGgfsPath(dest, destFileName), localNode(), EVT_GGFS_FILE_RENAMED));
List<String> components = endPath.components(); for (int i = startPath.components().size(); i < components.size(); i++) { curPath = new GridGgfsPath(curPath, components.get(i)); 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 " + created.put(curPath.parent(), parentInfo);