Exemple #1
0
 /**
  * Creates a new file output stream.
  *
  * @param path the file path
  * @param options the client options
  * @throws IOException if an I/O error occurs
  */
 public FileOutStream(AlluxioURI path, OutStreamOptions options) throws IOException {
   mUri = Preconditions.checkNotNull(path);
   mNonce = IdUtils.getRandomNonNegativeLong();
   mBlockSize = options.getBlockSizeBytes();
   mAlluxioStorageType = options.getAlluxioStorageType();
   mUnderStorageType = options.getUnderStorageType();
   mContext = FileSystemContext.INSTANCE;
   mPreviousBlockOutStreams = new LinkedList<BufferedBlockOutStream>();
   if (mUnderStorageType.isSyncPersist()) {
     updateUfsPath();
     String tmpPath = PathUtils.temporaryFileName(mNonce, mUfsPath);
     UnderFileSystem ufs = UnderFileSystem.get(tmpPath, ClientContext.getConf());
     // TODO(jiri): Implement collection of temporary files left behind by dead clients.
     mUnderStorageOutputStream = ufs.create(tmpPath, (int) mBlockSize);
   } else {
     mUfsPath = null;
     mUnderStorageOutputStream = null;
   }
   mClosed = false;
   mCanceled = false;
   mShouldCacheCurrentBlock = mAlluxioStorageType.isStore();
   mBytesWritten = 0;
   mLocationPolicy =
       Preconditions.checkNotNull(
           options.getLocationPolicy(),
           PreconditionMessage.FILE_WRITE_LOCATION_POLICY_UNSPECIFIED);
 }
 /**
  * Obtains a client for a remote based on the given network address. Illegal argument exception is
  * thrown if the hostname is the local hostname. Runtime exception is thrown if the client cannot
  * be created with a connection to the hostname.
  *
  * @param address the address of the worker
  * @return a worker client with a connection to the specified hostname
  */
 private BlockWorkerClient acquireRemoteWorkerClient(WorkerNetAddress address) {
   // If we couldn't find a worker, crash.
   if (address == null) {
     // TODO(calvin): Better exception usage.
     throw new RuntimeException(ExceptionMessage.NO_WORKER_AVAILABLE.getMessage());
   }
   Preconditions.checkArgument(
       !address.getHost().equals(NetworkAddressUtils.getLocalHostName()),
       PreconditionMessage.REMOTE_CLIENT_BUT_LOCAL_HOSTNAME);
   long clientId = IdUtils.getRandomNonNegativeLong();
   return new RetryHandlingBlockWorkerClient(
       address, ClientContext.getBlockClientExecutorService(), clientId, false);
 }