use of org.apache.crail.metadata.FileInfo in project incubator-crail by apache.
the class CoreDataStore method _createNode.
CoreNode _createNode(String path, CrailNodeType type, RpcCreateFile fileRes) throws Exception {
if (fileRes.getError() == RpcErrors.ERR_PARENT_MISSING) {
throw new IOException("createNode: " + RpcErrors.messages[fileRes.getError()] + ", name " + path);
} else if (fileRes.getError() == RpcErrors.ERR_FILE_EXISTS) {
throw new IOException("createNode: " + RpcErrors.messages[fileRes.getError()] + ", name " + path);
} else if (fileRes.getError() != RpcErrors.ERR_OK) {
LOG.info("createNode: " + RpcErrors.messages[fileRes.getError()] + ", name " + path);
throw new IOException("createNode: " + RpcErrors.messages[fileRes.getError()] + ", error " + fileRes.getError());
}
FileInfo fileInfo = fileRes.getFile();
FileInfo dirInfo = fileRes.getParent();
if (fileInfo == null || dirInfo == null) {
throw new IOException("createFile: " + RpcErrors.messages[RpcErrors.ERR_UNKNOWN]);
}
if (fileInfo.getType() != type) {
throw new IOException("createFile: " + "file type mismatch");
}
blockCache.remove(fileInfo.getFd());
nextBlockCache.remove(fileInfo.getFd());
CoreNode node = CoreNode.create(this, fileInfo, path);
BlockInfo fileBlock = fileRes.getFileBlock();
getBlockCache(fileInfo.getFd()).put(CoreSubOperation.createKey(fileInfo.getFd(), 0), fileBlock);
// write directory record is a directory slot has been assigned to the file
if (fileInfo.getDirOffset() >= 0) {
BlockInfo dirBlock = fileRes.getDirBlock();
getBlockCache(dirInfo.getFd()).put(CoreSubOperation.createKey(dirInfo.getFd(), fileInfo.getDirOffset()), dirBlock);
CoreSyncOperation syncOperation = getSyncOperation(dirInfo, fileInfo, path, true);
node.addSyncOperation(syncOperation);
}
if (CrailConstants.DEBUG) {
LOG.info("createFile: name " + path + ", success, fd " + fileInfo.getFd() + ", token " + fileInfo.getToken());
}
return node;
}
use of org.apache.crail.metadata.FileInfo in project incubator-crail by apache.
the class CoreDataStore method _delete.
CrailNode _delete(RpcDeleteFile fileRes, String path, boolean recursive) throws Exception {
if (fileRes.getError() == RpcErrors.ERR_HAS_CHILDREN) {
LOG.info("delete: " + RpcErrors.messages[fileRes.getError()]);
throw new IOException(RpcErrors.messages[fileRes.getError()]);
}
if (fileRes.getError() != RpcErrors.ERR_OK) {
LOG.info("delete: " + RpcErrors.messages[fileRes.getError()]);
return null;
}
FileInfo fileInfo = fileRes.getFile();
FileInfo dirInfo = fileRes.getParent();
CoreSyncOperation syncOperation = getSyncOperation(dirInfo, fileInfo, path, false);
blockCache.remove(fileInfo.getFd());
if (CrailConstants.DEBUG) {
LOG.info("delete: name " + path + ", recursive " + recursive + ", success");
}
CoreNode node = CoreNode.create(this, fileInfo, path);
node.addSyncOperation(syncOperation);
return node;
}
use of org.apache.crail.metadata.FileInfo in project incubator-crail by apache.
the class CoreDataStore method _rename.
CrailNode _rename(RpcRenameFile renameRes, String src, String dst) throws Exception {
if (renameRes.getError() == RpcErrors.ERR_SRC_FILE_NOT_FOUND) {
LOG.info("rename: " + RpcErrors.messages[renameRes.getError()]);
return null;
}
if (renameRes.getError() == RpcErrors.ERR_DST_PARENT_NOT_FOUND) {
LOG.info("rename: " + RpcErrors.messages[renameRes.getError()]);
return null;
}
if (renameRes.getError() == RpcErrors.ERR_FILE_EXISTS) {
LOG.info("rename: " + RpcErrors.messages[renameRes.getError()]);
return null;
}
if (renameRes.getError() != RpcErrors.ERR_OK) {
LOG.info("rename: " + RpcErrors.messages[renameRes.getError()]);
throw new IOException(RpcErrors.messages[renameRes.getError()]);
}
if (renameRes.getDstParent().getCapacity() < renameRes.getDstFile().getDirOffset() + CrailConstants.DIRECTORY_RECORD) {
LOG.info("rename: parent capacity does not match dst file offset, capacity " + renameRes.getDstParent().getCapacity() + ", offset " + renameRes.getDstFile().getDirOffset());
}
FileInfo srcParent = renameRes.getSrcParent();
FileInfo srcFile = renameRes.getSrcFile();
FileInfo dstDir = renameRes.getDstParent();
FileInfo dstFile = renameRes.getDstFile();
BlockInfo srcBlock = renameRes.getSrcBlock();
getBlockCache(srcParent.getFd()).put(CoreSubOperation.createKey(srcParent.getFd(), srcFile.getDirOffset()), srcBlock);
BlockInfo dirBlock = renameRes.getDstBlock();
getBlockCache(dstDir.getFd()).put(CoreSubOperation.createKey(dstDir.getFd(), dstFile.getDirOffset()), dirBlock);
CoreSyncOperation syncOperationSrc = getSyncOperation(srcParent, srcFile, src, false);
CoreSyncOperation syncOperationDst = getSyncOperation(dstDir, dstFile, dst, true);
blockCache.remove(srcFile.getFd());
if (CrailConstants.DEBUG) {
LOG.info("rename: srcname " + src + ", dstname " + dst + ", success");
}
CoreNode node = CoreNode.create(this, dstFile, dst);
node.addSyncOperation(syncOperationSrc);
node.addSyncOperation(syncOperationDst);
return node;
}
use of org.apache.crail.metadata.FileInfo in project incubator-crail by apache.
the class NameNodeService method setFile.
@Override
public short setFile(RpcRequestMessage.SetFileReq request, RpcResponseMessage.VoidRes response, RpcNameNodeState errorState) throws Exception {
// check protocol
if (!RpcProtocol.verifyProtocol(RpcProtocol.CMD_SET_FILE, request, response)) {
return RpcErrors.ERR_PROTOCOL_MISMATCH;
}
// get params
FileInfo fileInfo = request.getFileInfo();
boolean close = request.isClose();
// rpc
AbstractNode storedFile = fileTable.get(fileInfo.getFd());
if (storedFile == null) {
return RpcErrors.ERR_FILE_NOT_OPEN;
}
if (storedFile.getToken() > 0 && storedFile.getToken() == fileInfo.getToken()) {
storedFile.setCapacity(fileInfo.getCapacity());
}
if (close) {
storedFile.resetToken();
}
if (CrailConstants.DEBUG) {
LOG.info("setFile: " + fileInfo.toString() + ", close " + close);
}
return RpcErrors.ERR_OK;
}
use of org.apache.crail.metadata.FileInfo in project incubator-crail by apache.
the class CoreDataStore method _lookupNode.
CoreNode _lookupNode(RpcGetFile fileRes, String path) throws Exception {
if (fileRes.getError() == RpcErrors.ERR_GET_FILE_FAILED) {
return null;
} else if (fileRes.getError() != RpcErrors.ERR_OK) {
LOG.info("lookupDirectory: " + RpcErrors.messages[fileRes.getError()]);
return null;
}
FileInfo fileInfo = fileRes.getFile();
CoreNode node = null;
if (fileInfo != null) {
if (CrailConstants.DEBUG) {
LOG.info("lookup: name " + path + ", success, fd " + fileInfo.getFd());
}
BlockInfo fileBlock = fileRes.getFileBlock();
getBlockCache(fileInfo.getFd()).put(CoreSubOperation.createKey(fileInfo.getFd(), 0), fileBlock);
node = CoreNode.create(this, fileInfo, path);
}
return node;
}
Aggregations