use of org.apache.crail.metadata.FileName in project incubator-crail by apache.
the class CoreDataStore method lookup.
public Upcoming<CrailNode> lookup(String path) throws Exception {
FileName name = new FileName(path);
if (CrailConstants.DEBUG) {
LOG.info("lookupDirectory: path " + path);
}
RpcFuture<RpcGetFile> fileRes = rpcConnection.getFile(name, false);
return new LookupNodeFuture(this, path, fileRes);
}
use of org.apache.crail.metadata.FileName in project incubator-crail by apache.
the class CoreDataStore method rename.
public Upcoming<CrailNode> rename(String src, String dst) throws Exception {
FileName srcPath = new FileName(src);
FileName dstPath = new FileName(dst);
if (CrailConstants.DEBUG) {
LOG.info("rename: srcname " + src + ", dstname " + dst);
}
RpcFuture<RpcRenameFile> renameRes = rpcConnection.renameFile(srcPath, dstPath);
return new RenameNodeFuture(this, src, dst, renameRes);
}
use of org.apache.crail.metadata.FileName in project incubator-crail by apache.
the class CrailFsck method directoryDump.
public void directoryDump(String filename, boolean randomize) throws Exception {
CrailConfiguration conf = new CrailConfiguration();
CrailConstants.updateConstants(conf);
CoreDataStore fs = new CoreDataStore(conf);
DirectoryInputStream iter = fs._listEntries(filename, randomize);
System.out.println("#hash \t\tname\t\tfilecomponent");
int i = 0;
while (iter.hasRecord()) {
DirectoryRecord record = iter.nextRecord();
String path = CrailUtils.combinePath(record.getParent(), record.getFile());
FileName hash = new FileName(path);
System.out.format(i + ": " + "%08d\t\t%s\t%d\n", record.isValid() ? 1 : 0, padRight(record.getFile(), 8), hash.getFileComponent());
i++;
}
iter.close();
fs.closeFileSystem();
}
use of org.apache.crail.metadata.FileName in project incubator-crail by apache.
the class NameNodeService method getFile.
@Override
public short getFile(RpcRequestMessage.GetFileReq request, RpcResponseMessage.GetFileRes response, RpcNameNodeState errorState) throws Exception {
// check protocol
if (!RpcProtocol.verifyProtocol(RpcProtocol.CMD_GET_FILE, request, response)) {
return RpcErrors.ERR_PROTOCOL_MISMATCH;
}
// get params
FileName fileHash = request.getFileName();
boolean writeable = request.isWriteable();
// rpc
AbstractNode fileInfo = fileTree.retrieveFile(fileHash, errorState);
if (errorState.getError() != RpcErrors.ERR_OK) {
return errorState.getError();
}
if (fileInfo == null) {
return RpcErrors.ERR_GET_FILE_FAILED;
}
if (writeable && !fileInfo.tokenFree()) {
return RpcErrors.ERR_TOKEN_TAKEN;
}
if (writeable) {
fileInfo.updateToken();
}
fileTable.put(fileInfo.getFd(), fileInfo);
BlockInfo fileBlock = fileInfo.getBlock(0);
response.setFileInfo(fileInfo);
response.setFileBlock(fileBlock);
if (writeable) {
response.shipToken();
}
if (CrailConstants.DEBUG) {
LOG.info("getFile: fd " + fileInfo.getFd() + ", isDir " + fileInfo.getType().isDirectory() + ", token " + fileInfo.getToken() + ", capacity " + fileInfo.getCapacity());
}
return RpcErrors.ERR_OK;
}
use of org.apache.crail.metadata.FileName in project incubator-crail by apache.
the class NameNodeService method removeFile.
@Override
public short removeFile(RpcRequestMessage.RemoveFileReq request, RpcResponseMessage.DeleteFileRes response, RpcNameNodeState errorState) throws Exception {
// check protocol
if (!RpcProtocol.verifyProtocol(RpcProtocol.CMD_REMOVE_FILE, request, response)) {
return RpcErrors.ERR_PROTOCOL_MISMATCH;
}
// get params
FileName fileHash = request.getFileName();
// rpc
AbstractNode parentInfo = fileTree.retrieveParent(fileHash, errorState);
if (errorState.getError() != RpcErrors.ERR_OK) {
return errorState.getError();
}
if (parentInfo == null) {
return RpcErrors.ERR_CREATE_FILE_FAILED;
}
AbstractNode fileInfo = fileTree.retrieveFile(fileHash, errorState);
if (errorState.getError() != RpcErrors.ERR_OK) {
return errorState.getError();
}
if (fileInfo == null) {
return RpcErrors.ERR_GET_FILE_FAILED;
}
response.setParentInfo(parentInfo);
response.setFileInfo(fileInfo);
fileInfo = parentInfo.removeChild(fileInfo.getComponent());
if (fileInfo == null) {
return RpcErrors.ERR_GET_FILE_FAILED;
}
appendToDeleteQueue(fileInfo);
if (CrailConstants.DEBUG) {
LOG.info("removeFile: filename, fd " + fileInfo.getFd());
}
return RpcErrors.ERR_OK;
}
Aggregations