Skip to content

Commit

Permalink
Update TachyonFS to use FSMasterClient.
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinjia committed Aug 27, 2015
1 parent d3a798d commit b6b5798
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
Expand Up @@ -15,6 +15,7 @@


package tachyon.client.next.file; package tachyon.client.next.file;


import tachyon.client.FileSystemMasterClient;
import tachyon.client.next.ClientContext; import tachyon.client.next.ClientContext;
import tachyon.client.next.block.BlockMasterClientPool; import tachyon.client.next.block.BlockMasterClientPool;
import tachyon.client.next.block.TachyonBS; import tachyon.client.next.block.TachyonBS;
Expand All @@ -28,20 +29,20 @@ public enum FSContext {
INSTANCE; INSTANCE;


// TODO: Separate this when block master and file system master use different clients // TODO: Separate this when block master and file system master use different clients
private final BlockMasterClientPool mFileSystemMasterClientPool; private final FSMasterClientPool mFileSystemMasterClientPool;
private final TachyonBS mTachyonBS; private final TachyonBS mTachyonBS;


private FSContext() { private FSContext() {
mFileSystemMasterClientPool = mFileSystemMasterClientPool =
new BlockMasterClientPool(ClientContext.getMasterAddress(), ClientContext.getConf()); new FSMasterClientPool(ClientContext.getMasterAddress(), ClientContext.getConf());
mTachyonBS = TachyonBS.get(); mTachyonBS = TachyonBS.get();
} }


public MasterClient acquireMasterClient() { public FileSystemMasterClient acquireMasterClient() {
return mFileSystemMasterClientPool.acquire(); return mFileSystemMasterClientPool.acquire();
} }


public void releaseMasterClient(MasterClient masterClient) { public void releaseMasterClient(FileSystemMasterClient masterClient) {
mFileSystemMasterClientPool.release(masterClient); mFileSystemMasterClientPool.release(masterClient);
} }


Expand Down
Expand Up @@ -20,8 +20,8 @@
import java.util.List; import java.util.List;


import tachyon.TachyonURI; import tachyon.TachyonURI;
import tachyon.client.FileSystemMasterClient;
import tachyon.client.next.ClientOptions; import tachyon.client.next.ClientOptions;
import tachyon.master.MasterClient;
import tachyon.thrift.FileInfo; import tachyon.thrift.FileInfo;


/** /**
Expand Down Expand Up @@ -63,9 +63,9 @@ public synchronized void close() {
*/ */
@Override @Override
public void delete(TachyonFile file) throws IOException { public void delete(TachyonFile file) throws IOException {
MasterClient masterClient = mContext.acquireMasterClient(); FileSystemMasterClient masterClient = mContext.acquireMasterClient();
try { try {
masterClient.user_delete(file.getFileId(), "", true); masterClient.deleteFile(file.getFileId(), true);
} finally { } finally {
mContext.releaseMasterClient(masterClient); mContext.releaseMasterClient(masterClient);
} }
Expand All @@ -80,9 +80,9 @@ public void delete(TachyonFile file) throws IOException {
*/ */
@Override @Override
public void free(TachyonFile file) throws IOException { public void free(TachyonFile file) throws IOException {
MasterClient masterClient = mContext.acquireMasterClient(); FileSystemMasterClient masterClient = mContext.acquireMasterClient();
try { try {
masterClient.user_freepath(file.getFileId(), "", true); masterClient.freePath(file.getFileId(), true);
} finally { } finally {
mContext.releaseMasterClient(masterClient); mContext.releaseMasterClient(masterClient);
} }
Expand All @@ -98,9 +98,9 @@ public void free(TachyonFile file) throws IOException {
// TODO: Consider FileInfo caching // TODO: Consider FileInfo caching
@Override @Override
public FileInfo getInfo(TachyonFile file) throws IOException { public FileInfo getInfo(TachyonFile file) throws IOException {
MasterClient masterClient = mContext.acquireMasterClient(); FileSystemMasterClient masterClient = mContext.acquireMasterClient();
try { try {
return masterClient.getFileStatus(file.getFileId(), ""); return masterClient.getFileInfo(file.getFileId());
} finally { } finally {
mContext.releaseMasterClient(masterClient); mContext.releaseMasterClient(masterClient);
} }
Expand All @@ -117,10 +117,10 @@ public FileInfo getInfo(TachyonFile file) throws IOException {
* @throws IOException if the file does not exist or the stream cannot be opened * @throws IOException if the file does not exist or the stream cannot be opened
*/ */
public FileInStream getInStream(TachyonFile file, ClientOptions options) throws IOException { public FileInStream getInStream(TachyonFile file, ClientOptions options) throws IOException {
MasterClient masterClient = mContext.acquireMasterClient(); FileSystemMasterClient masterClient = mContext.acquireMasterClient();
try { try {
// TODO: Make sure the file is not a folder // TODO: Make sure the file is not a folder
FileInfo info = masterClient.getFileStatus(file.getFileId(), ""); FileInfo info = masterClient.getFileInfo(file.getFileId());
return new ClientFileInStream(info, options); return new ClientFileInStream(info, options);
} finally { } finally {
mContext.releaseMasterClient(masterClient); mContext.releaseMasterClient(masterClient);
Expand All @@ -138,9 +138,10 @@ public FileInStream getInStream(TachyonFile file, ClientOptions options) throws
* @throws IOException if the file already exists or if the stream cannot be opened * @throws IOException if the file already exists or if the stream cannot be opened
*/ */
public FileOutStream getOutStream(TachyonURI path, ClientOptions options) throws IOException { public FileOutStream getOutStream(TachyonURI path, ClientOptions options) throws IOException {
MasterClient masterClient = mContext.acquireMasterClient(); FileSystemMasterClient masterClient = mContext.acquireMasterClient();
try { try {
int fileId = masterClient.user_createFile(path.getPath(), "", options.getBlockSize(), true); // TODO: Fix the RPC arguments
int fileId = masterClient.createFile(path.getPath(), options.getBlockSize(), true);
return new ClientFileOutStream(fileId, options); return new ClientFileOutStream(fileId, options);
} finally { } finally {
mContext.releaseMasterClient(masterClient); mContext.releaseMasterClient(masterClient);
Expand All @@ -157,10 +158,10 @@ public FileOutStream getOutStream(TachyonURI path, ClientOptions options) throws
*/ */
@Override @Override
public List<FileInfo> listStatus(TachyonFile file) throws IOException { public List<FileInfo> listStatus(TachyonFile file) throws IOException {
MasterClient masterClient = mContext.acquireMasterClient(); FileSystemMasterClient masterClient = mContext.acquireMasterClient();
try { try {
// TODO: Change this RPC // TODO: Change this RPC
return masterClient.listStatus(null); return masterClient.getFileInfo(file.getFileId());
} finally { } finally {
mContext.releaseMasterClient(masterClient); mContext.releaseMasterClient(masterClient);
} }
Expand All @@ -175,9 +176,10 @@ public List<FileInfo> listStatus(TachyonFile file) throws IOException {
*/ */
@Override @Override
public boolean mkdirs(TachyonURI path) throws IOException { public boolean mkdirs(TachyonURI path) throws IOException {
MasterClient masterClient = mContext.acquireMasterClient(); FileSystemMasterClient masterClient = mContext.acquireMasterClient();
try { try {
return masterClient.user_mkdirs(path.getPath(), true); // TODO: Change this RPC's arguments
return masterClient.createDirectory(path.getPath(), true);
} finally { } finally {
mContext.releaseMasterClient(masterClient); mContext.releaseMasterClient(masterClient);
} }
Expand All @@ -193,10 +195,10 @@ public boolean mkdirs(TachyonURI path) throws IOException {
*/ */
@Override @Override
public TachyonFile open(TachyonURI path) throws IOException { public TachyonFile open(TachyonURI path) throws IOException {
MasterClient masterClient = mContext.acquireMasterClient(); FileSystemMasterClient masterClient = mContext.acquireMasterClient();
try { try {
// TODO: Remove path from this RPC // TODO: Remove path from this RPC
return new TachyonFile(masterClient.getFileStatus(-1, path.getPath()).getFileId()); return new TachyonFile(masterClient.getFileId(path.getPath()));
} finally { } finally {
mContext.releaseMasterClient(masterClient); mContext.releaseMasterClient(masterClient);
} }
Expand All @@ -212,10 +214,10 @@ public TachyonFile open(TachyonURI path) throws IOException {
*/ */
@Override @Override
public boolean rename(TachyonFile src, TachyonURI dst) throws IOException { public boolean rename(TachyonFile src, TachyonURI dst) throws IOException {
MasterClient masterClient = mContext.acquireMasterClient(); FileSystemMasterClient masterClient = mContext.acquireMasterClient();
try { try {
// TODO: Remove path from this RPC // TODO: Remove path from this RPC
return masterClient.user_rename(src.getFileId(), "", dst.getPath()); return masterClient.renameFile(src.getFileId(), dst.getPath());
} finally { } finally {
mContext.releaseMasterClient(masterClient); mContext.releaseMasterClient(masterClient);
} }
Expand Down
Expand Up @@ -123,7 +123,7 @@ public synchronized String getUfsAddress() throws IOException {
return null; return null;
} }


public synchronized long createFile(long fileId, long blockSizeBytes, boolean recursive) public synchronized long createFile(String fileId, long blockSizeBytes, boolean recursive)
throws IOException { throws IOException {
return -1; return -1;
} }
Expand Down

0 comments on commit b6b5798

Please sign in to comment.