Esempio n. 1
0
  /**
   * Gets a file status.
   *
   * @param cache FileInfo cache.
   * @param key the key in the cache.
   * @param fileId the id of the queried file. If it is -1, uses path.
   * @param path the path of the queried file. If fielId is not -1, this parameter is ignored.
   * @param useCachedMetaData whether to use the cached data or not.
   * @return the clientFileInfo.
   * @throws IOException if the underlying master RPC fails
   */
  private synchronized <K> FileInfo getFileStatus(
      Map<K, FileInfo> cache, K key, long fileId, String path, boolean useCachedMetaData)
      throws IOException {
    FileInfo info = null;
    if (useCachedMetaData) {
      info = cache.get(key);
      if (info != null) {
        return info;
      }
    }

    if (fileId == -1) {
      try {
        fileId = mFSMasterClient.getFileId(path);
      } catch (InvalidPathException e) {
        throw new IOException(e);
      }
    }
    if (fileId == -1) {
      cache.remove(key);
      return null;
    }
    try {
      info = mFSMasterClient.getFileInfo(fileId);
    } catch (FileDoesNotExistException e) {
      throw new IOException(e);
    }
    path = info.getPath();

    // TODO(hy): LRU
    mIdToClientFileInfo.put(fileId, info);
    mPathToClientFileInfo.put(path, info);

    return info;
  }
Esempio n. 2
0
 /**
  * Advanced API.
  *
  * <p>Gets the FileInfo object that represents the fileId, or the path if fileId is -1.
  *
  * @param fileId the file id of the file or folder.
  * @param path the path of the file or folder. valid iff fileId is -1.
  * @param useCachedMetadata if true use the local cached meta data
  * @return the FileInfo of the file. null if the file does not exist.
  * @throws IOException if the underlying master RPC fails
  */
 public synchronized FileInfo getFileStatus(
     long fileId, TachyonURI path, boolean useCachedMetadata) throws IOException {
   if (fileId == -1) {
     try {
       fileId = mFSMasterClient.getFileId(path.getPath());
     } catch (InvalidPathException e) {
       throw new IOException(e);
     }
   }
   return getFileStatus(
       mIdToClientFileInfo, fileId, fileId, TachyonURI.EMPTY_URI.getPath(), useCachedMetadata);
 }
Esempio n. 3
0
 /**
  * Frees an in-memory file or folder.
  *
  * @param fileId The id of the file / folder. If it is not -1, path parameter is ignored.
  *     Otherwise, the method uses the path parameter.
  * @param path The path of the file / folder. It could be empty iff id is not -1.
  * @param recursive If fileId or path represents a non-empty folder, free the folder recursively
  *     or not
  * @return true if in-memory free successfully, false otherwise.
  * @throws IOException if the underlying master RPC fails
  */
 @Override
 public synchronized boolean freepath(long fileId, TachyonURI path, boolean recursive)
     throws IOException {
   validateUri(path);
   if (fileId == -1) {
     try {
       fileId = mFSMasterClient.getFileId(path.getPath());
     } catch (InvalidPathException e) {
       throw new IOException(e);
     }
   }
   try {
     return mFSMasterClient.free(fileId, recursive);
   } catch (FileDoesNotExistException e) {
     throw new IOException(e);
   }
 }
Esempio n. 4
0
 /**
  * Renames a file or folder to the indicated new path.
  *
  * @param fileId The id of the source file / folder. If it is not -1, path parameter is ignored.
  *     Otherwise, the method uses the srcPath parameter.
  * @param srcPath The path of the source file / folder. It could be empty iff id is not -1.
  * @param dstPath The path of the destination file / folder. It could be empty iff id is not -1.
  * @return true if renames successfully, false otherwise.
  * @throws IOException if the underlying master RPC fails
  */
 @Override
 public synchronized boolean rename(long fileId, TachyonURI srcPath, TachyonURI dstPath)
     throws IOException {
   validateUri(srcPath);
   validateUri(dstPath);
   if (fileId == -1) {
     try {
       fileId = mFSMasterClient.getFileId(srcPath.getPath());
     } catch (InvalidPathException e) {
       throw new IOException(e);
     }
   }
   try {
     return mFSMasterClient.renameFile(fileId, dstPath.getPath());
   } catch (FileDoesNotExistException e) {
     throw new IOException(e);
   }
 }