@Override public boolean mount(TachyonURI tachyonPath, TachyonURI ufsPath, MountOptions options) throws IOException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { return masterClient.mount(tachyonPath, ufsPath); } finally { mContext.releaseMasterClient(masterClient); } }
private void getNextBlock() throws IOException { if (mCurrentBlockOutStream != null) { Preconditions.checkState(mCurrentBlockOutStream.remaining() <= 0, ERR_BLOCK_REMAINING); mPreviousBlockOutStreams.add(mCurrentBlockOutStream); } if (mTachyonStorageType.isStore()) { mCurrentBlockOutStream = mContext.getTachyonBlockStore().getOutStream(getNextBlockId(), mBlockSize, mHostname); mShouldCacheCurrentBlock = true; } }
private TachyonFS(TachyonConf tachyonConf) { super(tachyonConf); mMasterAddress = NetworkAddressUtils.getConnectAddress(ServiceType.MASTER_RPC, tachyonConf); mZookeeperMode = mTachyonConf.getBoolean(Constants.ZOOKEEPER_ENABLED); mFSMasterClient = mCloser.register(FileSystemContext.INSTANCE.acquireMasterClient()); mBlockMasterClient = mCloser.register(BlockStoreContext.INSTANCE.acquireMasterClient()); mRawTableMasterClient = mCloser.register(new RawTableMasterClient(mMasterAddress, mTachyonConf)); mWorkerClient = mCloser.register(BlockStoreContext.INSTANCE.acquireWorkerClient()); mUserFailedSpaceRequestLimits = mTachyonConf.getInt(Constants.USER_FAILED_SPACE_REQUEST_LIMITS); String scheme = mZookeeperMode ? Constants.SCHEME_FT : Constants.SCHEME; String authority = mMasterAddress.getHostName() + ":" + mMasterAddress.getPort(); mRootUri = new TachyonURI(scheme, authority, TachyonURI.SEPARATOR); }
/** * Initializes the client context singleton with a given conf. */ public static synchronized void reset(TachyonConf conf) { sTachyonConf = conf; String masterHostname = Preconditions.checkNotNull(sTachyonConf.get(Constants.MASTER_HOSTNAME)); int masterPort = sTachyonConf.getInt(Constants.MASTER_PORT); sMasterAddress = new InetSocketAddress(masterHostname, masterPort); sClientMetrics = new ClientMetrics(); sRandom = new Random(); if (sExecutorService != null) { sExecutorService.shutdown(); } sExecutorService = Executors.newFixedThreadPool( sTachyonConf.getInt(Constants.USER_BLOCK_WORKER_CLIENT_THREADS), ThreadFactoryUtils.build("block-worker-heartbeat-%d", true)); // We must set sInitialized to true before resetting BlockStoreContext and FileSystemContext // as they need ClientContext initialized. sInitialized = true; BlockStoreContext.INSTANCE.reset(); FileSystemContext.INSTANCE.reset(); }
if (mTachyonStorageType.isPromote()) { try { mContext.getTachyonBlockStore().promote(blockId); } catch (IOException ioe) { mCurrentBlockInStream = mContext.getTachyonBlockStore().getInStream(blockId); mShouldCacheCurrentBlock = !(mCurrentBlockInStream instanceof LocalBlockInStream) && mTachyonStorageType.isStore();
@Override public boolean unmount(TachyonURI tachyonPath, UnmountOptions options) throws IOException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { return masterClient.unmount(tachyonPath); } finally { mContext.releaseMasterClient(masterClient); } }
/** * Convenience method for updating mCurrentBlockInStream, mShouldCacheCurrentBlock, and * mCurrentCacheStream. If the block boundary has been reached, the current BlockInStream is * closed and a the next one is opened. mShouldCacheCurrent block is set to * mTachyonStorageType.isCache(). mCurrentCacheStream is also closed and a new one is created for * the next block. * * @throws IOException if the next BlockInStream cannot be obtained */ private void checkAndAdvanceBlockInStream() throws IOException { long currentBlockId = getCurrentBlockId(); if (mCurrentBlockInStream == null || mCurrentBlockInStream.remaining() == 0) { closeCacheStream(); updateBlockInStream(currentBlockId); if (mShouldCacheCurrentBlock) { try { // TODO(calvin): Specify the location to be local. mCurrentCacheStream = mContext.getTachyonBlockStore().getOutStream(currentBlockId, -1, NetworkAddressUtils.getLocalHostName(ClientContext.getConf())); } catch (IOException ioe) { LOG.warn("Failed to get TachyonStore stream, the block " + currentBlockId + " will not be in TachyonStorage. Exception:" + ioe.getMessage()); mShouldCacheCurrentBlock = false; } } } }
private long getNextBlockId() throws IOException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { return masterClient.getNewBlockIdForFile(mFileId); } catch (TachyonException e) { throw new IOException(e); } finally { mContext.releaseMasterClient(masterClient); } }
/** * Similar to checkAndAdvanceBlockInStream, but a specific position can be specified and the * stream pointer will be at that offset after this method completes. * * @param newPos the new position to set the stream to * @throws IOException if the stream at the specified position cannot be opened */ private void seekBlockInStream(long newPos) throws IOException { long oldBlockId = getCurrentBlockId(); mPos = newPos; closeCacheStream(); long currentBlockId = getCurrentBlockId(); if (oldBlockId != currentBlockId) { updateBlockInStream(currentBlockId); // Reading next block entirely. if (mPos % mBlockSize == 0 && mShouldCacheCurrentBlock) { try { mCurrentCacheStream = mContext.getTachyonBlockStore().getOutStream(currentBlockId, -1, NetworkAddressUtils.getLocalHostName(ClientContext.getConf())); } catch (IOException ioe) { LOG.warn("Failed to write to TachyonStore stream, block " + getCurrentBlockId() + " will not be in TachyonStorage. Exception:" + ioe.getMessage()); mShouldCacheCurrentBlock = false; } } else { mShouldCacheCurrentBlock = false; } } }
private FileInfo getFileInfo() throws IOException { FileSystemMasterClient client = mContext.acquireMasterClient(); try { return client.getFileInfo(mFileId); } catch (TachyonException e) { throw new IOException(e.getMessage()); } finally { mContext.releaseMasterClient(client); } } }
public void reportLostFile(TachyonFile file) throws IOException, FileDoesNotExistException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { masterClient.reportLostFile(file.getFileId()); } catch (TachyonException e) { TachyonException.unwrap(e, FileDoesNotExistException.class); throw e; } finally { mContext.releaseMasterClient(masterClient); } } }
@Override public TachyonFile openIfExists(TachyonURI path, OpenOptions openOptions) throws IOException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { long fileId = masterClient.getFileId(path.getPath()); if (fileId == -1) { return null; } return new TachyonFile(fileId); } finally { mContext.releaseMasterClient(masterClient); } }
/** * {@inheritDoc} * * The file infos are snapshots of the file metadata, and the locations, last modified time, and * path are possibly inconsistent. */ @Override public List<FileInfo> listStatus(TachyonFile file, ListStatusOptions options) throws IOException, FileDoesNotExistException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { return masterClient.getFileInfoList(file.getFileId()); } catch (TachyonException e) { TachyonException.unwrap(e, FileDoesNotExistException.class); throw e; } finally { mContext.releaseMasterClient(masterClient); } }
/** * {@inheritDoc} * * The file info is a snapshot of the file metadata, and the locations, last modified time, and * path are possibly inconsistent. */ @Override public FileInfo getInfo(TachyonFile file, GetInfoOptions options) throws IOException, FileDoesNotExistException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { return masterClient.getFileInfo(file.getFileId()); } catch (TachyonException e) { TachyonException.unwrap(e, FileDoesNotExistException.class); throw e; } finally { mContext.releaseMasterClient(masterClient); } }
@Override public boolean mkdir(TachyonURI path, MkdirOptions options) throws IOException, FileAlreadyExistsException, InvalidPathException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { boolean result = masterClient.mkdir(path.getPath(), options); if (result) { LOG.info("Created directory " + path.getPath()); } return result; } catch (TachyonException e) { TachyonException.unwrap(e, FileAlreadyExistsException.class); TachyonException.unwrap(e, InvalidPathException.class); throw e; } finally { mContext.releaseMasterClient(masterClient); } }
@Override public void setState(TachyonFile file, SetStateOptions options) throws IOException, FileDoesNotExistException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); Boolean pinned = options.getPinned(); try { if (pinned != null) { masterClient.setPinned(file.getFileId(), pinned); LOG.info(pinned ? "Pinned" : "Unpinned" + " file " + file.getFileId()); } } catch (TachyonException e) { TachyonException.unwrap(e, FileDoesNotExistException.class); throw e; } finally { mContext.releaseMasterClient(masterClient); } }
@Override public boolean rename(TachyonFile src, TachyonURI dst, RenameOptions options) throws IOException, FileDoesNotExistException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { boolean result = masterClient.renameFile(src.getFileId(), dst.getPath()); if (result) { LOG.info("Renamed file " + src.getFileId() + " to " + dst.getPath()); } return result; } catch (TachyonException e) { TachyonException.unwrap(e, FileDoesNotExistException.class); throw e; } finally { mContext.releaseMasterClient(masterClient); } }
/** * {@inheritDoc} * * This method is asynchronous and will be propagated to the workers through their heartbeats. */ @Override public void free(TachyonFile file, FreeOptions options) throws IOException, FileDoesNotExistException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { masterClient.free(file.getFileId(), options.isRecursive()); LOG.info("Removed file " + file.getFileId() + " from Tachyon Storage"); } catch (TachyonException e) { TachyonException.unwrap(e, FileDoesNotExistException.class); throw e; } finally { mContext.releaseMasterClient(masterClient); } }
/** * {@inheritDoc} * * The delete will abort on a failure, but previous deletes (if deleting more than one file) that * occurred will still be effective. The delete will only synchronously be propagated to the * master. The file metadata will not be available after this call, but the data in Tachyon or * under storage space may still reside until the delete is propagated and all current readers * have relinquished their locks. */ @Override public void delete(TachyonFile file, DeleteOptions options) throws IOException, FileDoesNotExistException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { masterClient.deleteFile(file.getFileId(), options.isRecursive()); LOG.info( "Deleted file " + file.getFileId() + " from both Tachyon Storage and under file system"); } catch (TachyonException e) { TachyonException.unwrap(e, FileDoesNotExistException.class); throw e; } finally { mContext.releaseMasterClient(masterClient); } }
@Override public TachyonFile loadMetadata(TachyonURI path, LoadMetadataOptions options) throws IOException, FileDoesNotExistException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { final long fileId = masterClient.loadMetadata(path.getPath(), options.isRecursive()); LOG.info("Loaded file " + path.getPath() + (options.isRecursive() ? " recursively" : "")); return new TachyonFile(fileId); } catch (TachyonException e) { TachyonException.unwrap(e, FileDoesNotExistException.class); throw e; } finally { mContext.releaseMasterClient(masterClient); } }