Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create a worker-specific filesystem master client
- Loading branch information
1 parent
e8d0c83
commit 3b6337e
Showing
6 changed files
with
133 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
common/src/main/java/tachyon/client/WorkerFileSystemMasterClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,113 @@ | |||
/* | |||
* Licensed to the University of California, Berkeley under one or more contributor license | |||
* agreements. See the NOTICE file distributed with this work for additional information regarding | |||
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the | |||
* "License"); you may not use this file except in compliance with the License. You may obtain a | |||
* copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software distributed under the License | |||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |||
* or implied. See the License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
|
|||
package tachyon.client; | |||
|
|||
import java.io.IOException; | |||
import java.net.InetSocketAddress; | |||
import java.util.Set; | |||
import java.util.concurrent.ExecutorService; | |||
|
|||
import org.apache.thrift.TException; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
|
|||
import tachyon.Constants; | |||
import tachyon.MasterClientBase; | |||
import tachyon.conf.TachyonConf; | |||
import tachyon.thrift.FileDoesNotExistException; | |||
import tachyon.thrift.FileSystemMasterService; | |||
import tachyon.thrift.InvalidPathException; | |||
|
|||
/** | |||
* A wrapper for the thrift client to interact with the file system master, used by tachyon worker. | |||
* <p/> | |||
* Since thrift clients are not thread safe, this class is a wrapper to provide thread safety, and | |||
* to provide retries. | |||
*/ | |||
public final class WorkerFileSystemMasterClient extends MasterClientBase { | |||
private static final Logger LOG = LoggerFactory.getLogger(Constants.LOGGER_TYPE); | |||
|
|||
private FileSystemMasterService.Client mClient = null; | |||
|
|||
/** | |||
* Creates a new file system master client for the worker. | |||
* | |||
* @param masterAddress the master address | |||
* @param executorService the executor service | |||
* @param tachyonConf the Tachyon configuration | |||
*/ | |||
public WorkerFileSystemMasterClient(InetSocketAddress masterAddress, | |||
ExecutorService executorService, TachyonConf tachyonConf) { | |||
super(masterAddress, executorService, tachyonConf); | |||
} | |||
|
|||
@Override | |||
protected String getServiceName() { | |||
return Constants.FILE_SYSTEM_MASTER_SERVICE_NAME; | |||
} | |||
|
|||
@Override | |||
protected void afterConnect() { | |||
mClient = new FileSystemMasterService.Client(mProtocol); | |||
} | |||
|
|||
/** | |||
* Adds a checkpoint. | |||
* | |||
* @param workerId the worker id | |||
* @param fileId the file id | |||
* @param length the checkpoint length | |||
* @param checkpointPath the checkpoint path | |||
* @return whether operation succeeded or not | |||
* @throws IOException if an I/O error occurs | |||
*/ | |||
public synchronized boolean addCheckpoint(long workerId, long fileId, long length, | |||
String checkpointPath) throws IOException { | |||
int retry = 0; | |||
while (!mClosed && (retry ++) <= RPC_MAX_NUM_RETRY) { | |||
connect(); | |||
try { | |||
return mClient.addCheckpoint(workerId, fileId, length, checkpointPath); | |||
} catch (FileDoesNotExistException e) { | |||
throw new IOException(e); | |||
} catch (TException e) { | |||
LOG.error(e.getMessage(), e); | |||
mConnected = false; | |||
} | |||
} | |||
throw new IOException("Failed after " + retry + " retries."); | |||
} | |||
|
|||
/** | |||
* @return the set of pinned file ids | |||
* @throws IOException if an I/O error occurs | |||
*/ | |||
public synchronized Set<Long> getPinList() throws IOException { | |||
int retry = 0; | |||
while (!mClosed && (retry ++) <= RPC_MAX_NUM_RETRY) { | |||
connect(); | |||
try { | |||
return mClient.workerGetPinIdList(); | |||
} catch (InvalidPathException e) { | |||
throw new IOException(e); | |||
} catch (TException e) { | |||
LOG.error(e.getMessage(), e); | |||
mConnected = false; | |||
} | |||
} | |||
throw new IOException("Failed after " + retry + " retries."); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters