@Override public int files() { return (int) fileInfo.getCapacity()/CrailConstants.DIRECTORY_RECORD; }
public long getCapacity() { return fileInfo.getCapacity(); }
void seek(long pos) throws IOException { long newOffset = Math.min(fileInfo.getCapacity(), Math.max(0, pos)); if (newOffset == pos){ this.position = newOffset; } else { throw new IOException("seek position out of range, pos " + pos + ", fileCapacity " + fileInfo.getCapacity()); } }
void updateIOStats() { ioStats.setCapacity(fileInfo.getCapacity()); }
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; }
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(); }
CoreSyncOperation getSyncOperation(FileInfo dirInfo, FileInfo fileInfo, String path, boolean valid) throws Exception{ long adjustedCapacity = fileInfo.getDirOffset()*CrailConstants.DIRECTORY_RECORD + CrailConstants.DIRECTORY_RECORD; dirInfo.setCapacity(Math.max(dirInfo.getCapacity(), adjustedCapacity)); CoreDirectory dirFile = new CoreDirectory(this, dirInfo, CrailUtils.getParent(path)); DirectoryOutputStream stream = dirFile.getDirectoryOutputStream(); DirectoryRecord record = new DirectoryRecord(valid, path); Future<CrailResult> future = stream.writeRecord(record, fileInfo.getDirOffset()); CoreSyncOperation syncOperation = new CoreSyncOperation(stream, future); return syncOperation; } }
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>>(); }
@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(); }
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());
pendingBlocks.add(rpcFuture); } else { this.syncedCapacity = fileInfo.getCapacity(); RpcFuture<RpcGetBlock> rpcFuture = namenodeClientRpc.getBlock(fileInfo.getFd(), fileInfo.getToken(), position, syncedCapacity); blockMap.put(rpcFuture.getTicket(), subOperation);
response.setDstBlock(dstBlock); if (response.getDstParent().getCapacity() < response.getDstFile().getDirOffset() + CrailConstants.DIRECTORY_RECORD){ LOG.info("rename: parent capacity does not match dst file offset, capacity " + response.getDstParent().getCapacity() + ", offset " + response.getDstFile().getDirOffset() + ", capacity " + dstParent.getCapacity() + ", offset " + dstFile.getDirOffset());