public long getToken() { return fileInfo.getToken(); }
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); }
public void closeFile(FileInfo fileInfo) throws Exception { if (fileInfo.getToken() > 0){ rpcConnection.setFile(fileInfo, true).get(CrailConstants.RPC_TIMEOUT, TimeUnit.MILLISECONDS); } }
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(); }
Future<Void> sync() throws IOException { Future<Void> future = null; if (fileInfo.getToken() > 0 && syncedCapacity < fileInfo.getCapacity()){ syncedCapacity = fileInfo.getCapacity(); future = new SyncNodeFuture(namenodeClientRpc.setFile(fileInfo, false)); } else { future = new NoOperation(); } return future; }
@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; }
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(); }
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:
LOG.info("createFile: name " + path + ", success, fd " + fileInfo.getFd() + ", token " + fileInfo.getToken());
} else { this.syncedCapacity = fileInfo.getCapacity(); RpcFuture<RpcGetBlock> rpcFuture = namenodeClientRpc.getBlock(fileInfo.getFd(), fileInfo.getToken(), position, syncedCapacity); blockMap.put(rpcFuture.getTicket(), subOperation); pendingBlocks.add(rpcFuture);