public long getFd() { return fileInfo.getFd(); }
public synchronized CrailOutputStream getDirectOutputStream(long writeHint) throws Exception { if (fileInfo.getType().isDirectory()){ throw new Exception("Cannot open stream for directory"); } if (fileInfo.getToken() == 0){ throw new Exception("File is in read mode, cannot create outputstream, fd " + fileInfo.getFd()); } if (!outputStreams.tryAcquire()){ throw new Exception("Only one concurrent output stream per file allowed"); } return super.getOutputStream(writeHint); }
@Override public RpcFuture<RpcVoid> setFile(FileInfo fileInfo, boolean close) throws IOException { int index = computeIndex(fileInfo.getFd()); // LOG.info("issuing set file for fd [" + fileInfo.getFd() + "], on index " + index); return connections[index].setFile(fileInfo, close); }
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; }
public void setFileInfo(FileInfo fileInfo){ this.fd = fileInfo.getFd(); this.type = fileInfo.getType(); this.dirOffset = fileInfo.getDirOffset(); this.capacity.set(fileInfo.getCapacity()); this.token = fileInfo.getToken(); this.modificationTime = fileInfo.getModificationTime(); }
CoreStream(CoreNode node, long streamId, long fileOffset) throws Exception { this.node = node; this.fs = node.getFileSystem(); this.fileInfo = node.getFileInfo(); this.endpointCache = fs.getDatanodeEndpointCache(); this.namenodeClientRpc = fs.getNamenodeClientRpc(); this.blockCache = fs.getBlockCache(fileInfo.getFd()); this.nextBlockCache = fs.getNextBlockCache(fileInfo.getFd()); this.bufferCheckpoint = fs.getBufferCheckpoint(); this.position = fileOffset; this.syncedCapacity = fileInfo.getCapacity(); this.streamId = streamId; this.ioStats = new CoreIOStatistics("core"); this.blockMap = new HashMap<Integer, CoreSubOperation>(); this.pendingBlocks = new LinkedList<RpcFuture<RpcGetBlock>>(); }
blockCache.remove(fileInfo.getFd()); nextBlockCache.remove(fileInfo.getFd()); CoreNode node = CoreNode.create(this, fileInfo, path); getBlockCache(fileInfo.getFd()).put(CoreSubOperation.createKey(fileInfo.getFd(), 0), fileBlock); getBlockCache(dirInfo.getFd()).put(CoreSubOperation.createKey(dirInfo.getFd(), fileInfo.getDirOffset()), dirBlock); CoreSyncOperation syncOperation = getSyncOperation(dirInfo, fileInfo, path, true); node.addSyncOperation(syncOperation); LOG.info("createFile: name " + path + ", success, fd " + fileInfo.getFd() + ", token " + fileInfo.getToken());
final void prefetchMetadata() throws Exception { long key = CoreSubOperation.createKey(fileInfo.getFd(), position); if (blockCache.containsKey(key)){ return; } if (nextBlockCache.containsKey(key)){ return; } this.syncedCapacity = fileInfo.getCapacity(); RpcFuture<RpcGetBlock> nextBlock = namenodeClientRpc.getBlock(fileInfo.getFd(), fileInfo.getToken(), position, syncedCapacity); nextBlock.setPrefetched(true); nextBlockCache.put(key, nextBlock); this.ioStats.incPrefetchedOps(); }
@Override public DaRPCNameNodeFuture<RpcVoid> setFile(FileInfo fileInfo, boolean close) throws IOException { if (CrailConstants.DEBUG){ LOG.debug("RPC: setFile, id " + fileInfo.getFd() + ", close " + close); } RpcRequestMessage.SetFileReq setFileReq = new RpcRequestMessage.SetFileReq(fileInfo, close); DaRPCNameNodeRequest request = new DaRPCNameNodeRequest(setFileReq); request.setCommand(RpcProtocol.CMD_SET_FILE); RpcResponseMessage.VoidRes voidRes = new RpcResponseMessage.VoidRes(); DaRPCNameNodeResponse response = new DaRPCNameNodeResponse(voidRes); DaRPCFuture<DaRPCNameNodeRequest, DaRPCNameNodeResponse> future = issueRPC(request, response); DaRPCNameNodeFuture<RpcVoid> nameNodeFuture = new DaRPCNameNodeFuture<RpcVoid>(future, voidRes); return nameNodeFuture; }
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; }
@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; }
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); blockCache.remove(srcFile.getFd());
case RpcProtocol.CMD_CREATE_FILE: error = service.createFile(record.createFile(), response.createFile(), response); long fd = response.createFile().getFile().getFd(); long token = response.createFile().getFile().getToken(); tokens.put(response.createFile().getFile().getFd(), response.createFile().getFile().getToken()); tokens.put(response.createFile().getParent().getFd(), response.createFile().getParent().getToken()); break; case RpcProtocol.CMD_SET_FILE: record.setFile().getFileInfo().setToken(tokens.get(record.setFile().getFileInfo().getFd())); error = service.setFile(record.setFile(), response.getVoid(), response); break;
long blockRemaining = blockRemaining(); int opLen = CrailUtils.minFileBuf(blockRemaining, multiOperation.remaining()); CoreSubOperation subOperation = new CoreSubOperation(fileInfo.getFd(), position, multiOperation.getCurrentBufferPosition(), opLen); } else { this.syncedCapacity = fileInfo.getCapacity(); RpcFuture<RpcGetBlock> rpcFuture = namenodeClientRpc.getBlock(fileInfo.getFd(), fileInfo.getToken(), position, syncedCapacity); blockMap.put(rpcFuture.getTicket(), subOperation); pendingBlocks.add(rpcFuture);