⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kfsclientint.h

📁 nandflash文件系统源代码
💻 H
📖 第 1 页 / 共 3 页
字号:
    LeaseClerk  mLeaseClerk;    /// a tcp socket that holds the connection with the server    TcpSocket	mMetaServerSock;    /// seq # that we send in each command    kfsSeq_t	mCmdSeqNum;    /// The current working directory in KFS    std::string	mCwd;    std::string mHostname;    /// keep a table of open files/directory handles.    std::vector <FileTableEntry *> mFileTable;    NameToFdMap mPathCache;    TelemetryClient mTelemetryReporter;    /// set of slow nodes as flagged by the telemetry service    std::vector<struct in_addr> mSlowNodes;    /// Check that fd is in range    bool valid_fd(int fd) { return (fd >= 0 && fd < MAX_FILES); }    /// Connect to the meta server and return status.    /// @retval true if connect succeeds; false otherwise.    bool ConnectToMetaServer();    /// Lookup the attributes of a file given its parent file-id    /// @param[in] parentFid  file-id of the parent directory    /// @param[in] filename   filename whose attributes are being    /// asked    /// @param[out] result   the resultant attributes    /// @param[in] computeFilesize  when set, for files, the size of    /// the file is computed and returned in result.fileSize    /// @retval 0 on success; -errno otherwise    ///    int LookupAttr(kfsFileId_t parentFid, const char *filename,		   KfsFileAttr &result, bool computeFilesize);    /// Helper functions that operate on individual chunks.    /// Allocate the "current" chunk of fd.    /// @param[in] fd  The index from mFileTable[] that corresponds to    /// the file being accessed    int AllocChunk(int fd);    /// Open the "current" chunk of fd.  This involves setting up the    /// socket to the chunkserver and determining the size of the chunk.    /// For reads, since there are 3 copies of a chunk, we use the    /// nonblocking connect; this allows us to switch servers one of    /// the replicas is non-reachable    ///    /// @param[in] fd  The index from mFileTable[] that corresponds to    /// the file being accessed    int OpenChunk(int fd, bool nonblockingConnect = false);    bool IsChunkReadable(int fd);    /// Given a chunkid, is our lease on that chunk "good"?  That is,    /// if it is close to expiring, renew it; if it is expired, get a    /// new one.    /// @param[in] chunkId  The chunk for which we are trying to get a    /// "good" lease.    /// @retval true if our lease is good; false otherwise.    bool IsChunkLeaseGood(kfsChunkId_t chunkId);    /// Helper function that reads from the "current" chunk.    /// @param[in] fd  The file from which data is to be read    /// @param[out] buf  The buffer which will be filled with data    /// @param[in] numBytes  The desired # of bytes to be read    /// @retval  On success, # of bytes read; -1 on error    ///    ssize_t ReadChunk(int fd, char *buf, size_t numBytes);    /// Helper function that reads from the "current" chunk from the    /// chunk server.  For performance, depending on the # of bytes to    /// be read, the read could be pipelined to overlap disk/network    /// transfer from the chunkserver.    ///    /// @param[in] fd  The file from which data is to be read    /// @param[out] buf  The buffer which will be filled with data    /// @param[in] numBytes  The desired # of bytes to be read    /// @retval  On success, # of bytes read; -1 on error    ///    ssize_t ReadFromServer(int fd, char *buf, size_t numBytes);    /// Helper function that does a single read op to the chunkserver    /// to get data back.    /// @param[in] fd  The file from which data is to be read    /// @param[out] buf  The buffer which will be filled with data    /// @param[in] numBytes  The desired # of bytes to be read    /// @retval  On success, # of bytes read; -1 on error    ///    ssize_t DoSmallReadFromServer(int fd, char *buf, size_t numBytes);    /// Helper function that breaks up a single read into a bunch of    /// small reads and pipelines the read to reduce latency.    ssize_t DoLargeReadFromServer(int fd, char *buf, size_t numBytes);    /// Helper function that copies out data from the chunk buffer    /// corresponding to the "current" chunk.    /// @param[in] fd  The file from which data is to be read    /// @param[out] buf  The buffer which will be filled with data    /// @param[in] numBytes  The desired # of bytes to be read    /// @retval  # of bytes copied ( value >= 0).    ///    size_t CopyFromChunkBuf(int fd, char *buf, size_t numBytes);    /// Helper function that zero-fills a buffer whenever there are    /// holes in a file.    /// @param[in] fd  The file from which data is to be read    /// @param[out] buf  The buffer which will be filled with 0    /// @param[in] numBytes  The desired # of bytes to be filled with 0    /// @retval  # of bytes copied ( value >= 0).    ///    size_t ZeroFillBuf(int fd, char *buf, size_t numBytes);    /// Given a chunk, find out which chunk-server is hosting it.  It    /// is possible that no server is hosting the chunk---if there is    /// a hole in the file.    /// @retval status code: 0 on success; < 0 => failure    int LocateChunk(int fd, int chunkNum);    // Helper functions to deal with write and buffering at the client.    /// Write the data to the chunk buffer and ack the application.    /// This can be used for doing delayed write-backs.    /// @param[in] fd  The file to which data is to be written    /// @param[out] buf  The buffer with the data to be written out    /// @param[in] numBytes  The desired # of bytes to be written    /// @retval  # of bytes written; -1 on failure    ssize_t WriteToBuffer(int fd, const char *buf, size_t numBytes);    /// Flush the contents of the chunk buffer back to the chunk    /// server.    /// @param[in] fd  The file to which data is to be written    /// @retval  # of bytes written; -1 on failure    ssize_t FlushBuffer(int fd);    /// Helper function that does the write RPC.    /// @param[in] fd  The file to which data is to be written    /// @param[in] offset  The offset in the chunk at which data has    /// to be written out    /// @param[out] buf  The buffer with the data to be written out    /// @param[in] numBytes  The desired # of bytes to be written    /// @retval  # of bytes written; -1 on failure    ///    ssize_t WriteToServer(int fd, off_t offset, const char *buf, size_t numBytes);    /// Helper function that does a single write op to the server.    /// @param[in] fd  The file to which data is to be written    /// @param[in] offset  The offset in the chunk at which data has    /// to be written out    /// @param[out] buf  The buffer with the data to be written out    /// @param[in] numBytes  The desired # of bytes to be written    /// @retval  # of bytes written; -1 on failure    ///    ssize_t DoSmallWriteToServer(int fd, off_t offset, const char *buf, size_t numBytes);    /// Helper function that does a pipelined write to server.    /// Basically, break a write into smaller writes and pipeline them.    ssize_t DoLargeWriteToServer(int fd, off_t offset, const char *buf, size_t numBytes);    /// Request a chunk allocation with the metaserver if necessary.    /// The 2nd argument "forces" an allocation with the server.    int DoAllocation(int fd, bool force = false);    // Return true if the attributes of the "current" chunk are    // known, i.e., they were downloaded from meta server.    bool IsCurrChunkAttrKnown(int fd);    /// Get the size of the "current" chunk from the chunkserver.    /// @param[in] fd  The index in mFileTable[] that corresponds to a    /// previously opened file.    int SizeChunk(int fd);    /// Given a kfsfid with some # of chunks, compute the size of the    /// file.  This involves looking up the size of the last chunk of    /// the file and then adding with the size of the remaining (full) chunks.    off_t ComputeFilesize(kfsFileId_t kfsfid);    /// Given the attributes for a set of files and the location info    /// of the last chunk of each file, compute the filesizes for each file    void ComputeFilesizes(vector<KfsFileAttr> &fattrs, vector<FileChunkInfo> &lastChunkInfo);    /// Helper function: given a starting index to the two vectors,    /// compute the file sizes for each file whose last chunk is    /// stored in chunkserver at location loc.    void ComputeFilesizes(vector<KfsFileAttr> &fattrs, vector<FileChunkInfo> &lastChunkInfo,                          uint32_t startIdx, const ServerLocation &loc);    FileTableEntry *FdInfo(int fd) { return mFileTable[fd]; }    FilePosition *FdPos(int fd) { return &FdInfo(fd)->currPos; }    FileAttr *FdAttr(int fd) { return &FdInfo(fd)->fattr; }    ChunkBuffer *FdBuffer(int fd) { return &FdInfo(fd)->buffer; }    ChunkAttr *GetCurrChunk(int fd) {	return &FdInfo(fd)->cattr[FdPos(fd)->chunkNum];    }    /// Do the work for an op with the metaserver; if the metaserver    /// dies in the middle, retry the op a few times before giving up.    int DoMetaOpWithRetry(KfsOp *op);    /// Do the work for pipelined read: send a few    /// requests to plumb the pipe and then whenever an op finishes,    /// submit a new one.    int DoPipelinedRead(std::vector<ReadOp *> &ops, TcpSocket *sock);    int DoPipelinedWrite(int fd, std::vector<WritePrepareOp *> &ops, TcpSocket *masterSock);    /// Helpers for pipelined write    int AllocateWriteId(int fd, off_t offset, size_t numBytes, std::vector<WriteInfo> &writeId,                         TcpSocket *masterSock);    int PushData(int fd, vector<WritePrepareOp *> &ops,                  uint32_t start, uint32_t count, TcpSocket *masterSock);    int SendCommit(int fd, vector<WriteInfo> &writeId, TcpSocket *masterSock,                   WriteSyncOp &sop);    int GetCommitReply(WriteSyncOp &sop, TcpSocket *masterSock);    // this is going away...    int IssueCommit(int fd, std::vector<WriteInfo> &writeId, TcpSocket *masterSock);    /// Get a response from the server, where, the response is    /// terminated by "\r\n\r\n".    int GetResponse(char *buf, int bufSize, int *delims, TcpSocket *sock);    /// Given a path, get the parent fileid and the name following the    /// trailing "/"    int GetPathComponents(const char *pathname, kfsFileId_t *parentFid,			  std::string &name);    /// File table management utilities: find a free entry in the    /// table, find the entry corresponding to a pathname, "mark" an    /// entry in the table as in use, and "mark" an entry in the table    /// as free.    int FindFreeFileTableEntry();    bool IsFileTableEntryValid(int fte);    /// Wrapper function that calls LookupFileTableEntry with the parentFid    int LookupFileTableEntry(const char *pathname);    /// Return the file table entry corresponding to parentFid/name,    /// where "name" is either a file or directory that resides in    /// directory corresponding to parentFid.    int LookupFileTableEntry(kfsFileId_t parentFid, const char *name);    /// Given a parent fid and name, get the corresponding entry in    /// the file table.  Note: if needed, attributes will be    /// downloaded from the server.    int Lookup(kfsFileId_t parentFid, const char *name);    // name -- is the last component of the pathname    int ClaimFileTableEntry(kfsFileId_t parentFid, const char *name, std::string pathname);    int AllocFileTableEntry(kfsFileId_t parentFid, const char *name, std::string pathname);    void ReleaseFileTableEntry(int fte);    /// Helper functions that interact with the leaseClerk to    /// get/renew leases    int GetLease(kfsChunkId_t chunkId);    void RenewLease(kfsChunkId_t chunkId);    void RelinquishLease(kfsChunkId_t chunkId);    bool GetDataChecksums(const ServerLocation &loc,                           kfsChunkId_t chunkId,                           uint32_t *checksums);    bool VerifyDataChecksums(int fte, const vector<uint32_t> &checksums);    bool VerifyChecksum(ReadOp* op, TcpSocket* sock);};// Helper functionsextern int DoOpSend(KfsOp *op, TcpSocket *sock);extern int DoOpResponse(KfsOp *op, TcpSocket *sock);extern int DoOpCommon(KfsOp *op, TcpSocket *sock);}#endif // LIBKFSCLIENT_KFSCLIENTINT_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -