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

📄 kfsops.h

📁 nandflash文件系统源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
struct GetAllocOp: public KfsOp {    kfsFileId_t fid;    off_t fileOffset;    kfsChunkId_t chunkId; // result    int64_t chunkVersion; // result    // result: where the chunk is hosted name/port    std::vector<ServerLocation> chunkServers;    GetAllocOp(kfsSeq_t s, kfsFileId_t f, off_t o) :        KfsOp(CMD_GETALLOC, s), fid(f), fileOffset(o)    {    }    void Request(std::ostringstream &os);    void ParseResponseHeader(char *buf, int len);    std::string Show() const {        std::ostringstream os;        os << "getalloc: fid=" << fid << " offset: " << fileOffset;        return os.str();    }};struct ChunkLayoutInfo {    ChunkLayoutInfo() : fileOffset(-1), chunkId(0) { };    off_t fileOffset;    kfsChunkId_t chunkId; // result    int64_t chunkVersion; // result    std::vector<ServerLocation> chunkServers; // where the chunk lives};/// Get the layout information for all chunks in a file.struct GetLayoutOp: public KfsOp {    kfsFileId_t fid;    int numChunks;    std::vector<ChunkLayoutInfo> chunks;    GetLayoutOp(kfsSeq_t s, kfsFileId_t f) :        KfsOp(CMD_GETLAYOUT, s), fid(f)    {    }    void Request(std::ostringstream &os);    void ParseResponseHeader(char *buf, int len);    int ParseLayoutInfo();    std::string Show() const {        std::ostringstream os;        os << "getlayout: fid=" << fid;        return os.str();    }};// Get the chunk metadata (aka checksums) stored on the chunkserversstruct GetChunkMetadataOp: public KfsOp {    kfsChunkId_t chunkId;    GetChunkMetadataOp(kfsSeq_t s, kfsChunkId_t c) :        KfsOp(CMD_GET_CHUNK_METADATA, s), chunkId(c) { }    void Request(std::ostringstream &os);    std::string Show() const {        std::ostringstream os;        os << "get chunk metadata: chunkId=" << chunkId;        return os.str();    }};struct AllocateOp : public KfsOp {    kfsFileId_t fid;    off_t fileOffset;    kfsChunkId_t chunkId; // result    int64_t chunkVersion; // result---version # for the chunk    std::string clientHost; // our hostname    // where is the chunk hosted name/port    ServerLocation masterServer; // master for running the write transaction    std::vector<ServerLocation> chunkServers;    AllocateOp(kfsSeq_t s, kfsFileId_t f) :        KfsOp(CMD_ALLOCATE, s), fid(f), fileOffset(0)    {    }    void Request(std::ostringstream &os);    void ParseResponseHeader(char *buf, int len);    string Show() const {        std::ostringstream os;        os << "allocate: fid=" << fid << " offset: " << fileOffset;        return os.str();    }};struct TruncateOp : public KfsOp {    kfsFileId_t fid;    off_t fileOffset;    TruncateOp(kfsSeq_t s, kfsFileId_t f, off_t o) :        KfsOp(CMD_TRUNCATE, s), fid(f), fileOffset(o)    {    }    void Request(std::ostringstream &os);    std::string Show() const {        std::ostringstream os;        os << "truncate: fid=" << fid << " offset: " << fileOffset;        return os.str();    }};struct OpenOp : public KfsOp {    kfsChunkId_t chunkId;    int openFlags;  // either O_RDONLY, O_WRONLY or O_RDWR    OpenOp(kfsSeq_t s, kfsChunkId_t c) :        KfsOp(CMD_OPEN, s), chunkId(c)    {    }    void Request(std::ostringstream &os);    std::string Show() const {        std::ostringstream os;        os << "open: chunkid=" << chunkId;        return os.str();    }};struct CloseOp : public KfsOp {    kfsChunkId_t chunkId;    CloseOp(kfsSeq_t s, kfsChunkId_t c) :        KfsOp(CMD_CLOSE, s), chunkId(c)    {    }    void Request(std::ostringstream &os);    std::string Show() const {        std::ostringstream os;        os << "close: chunkid=" << chunkId;        return os.str();    }};// used for retrieving a chunk's sizestruct SizeOp : public KfsOp {    kfsChunkId_t chunkId;    int64_t chunkVersion;    off_t     size; /* result */    SizeOp(kfsSeq_t s, kfsChunkId_t c, int64_t v) :        KfsOp(CMD_SIZE, s), chunkId(c), chunkVersion(v)    {    }    void Request(std::ostringstream &os);    void ParseResponseHeader(char *buf, int len);    std::string Show() const {        std::ostringstream os;        os << "size: chunkid=" << chunkId << " version=" << chunkVersion;        return os.str();    }};struct ReadOp : public KfsOp {    kfsChunkId_t chunkId;    int64_t      chunkVersion; /* input */    off_t 	 offset;   /* input */    size_t 	 numBytes; /* input */    struct timeval submitTime; /* when the client sent the request to the server */    std::vector<uint32_t> checksums; /* checksum for each 64KB block */    float   diskIOTime; /* as reported by the server */    float   elapsedTime; /* as measured by the client */    ReadOp(kfsSeq_t s, kfsChunkId_t c, int64_t v) :        KfsOp(CMD_READ, s), chunkId(c), chunkVersion(v),        offset(0), numBytes(0), diskIOTime(0.0), elapsedTime(0.0)    {    }    void Request(std::ostringstream &os);    void ParseResponseHeader(char *buf, int len);    std::string Show() const {        std::ostringstream os;        os << "read: chunkid=" << chunkId << " version=" << chunkVersion;        os << " offset=" << offset << " numBytes=" << numBytes;        os << " checksum = " << checksum;        return os.str();    }};// op that defines the write that is going to happenstruct WriteIdAllocOp : public KfsOp {    kfsChunkId_t chunkId;    int64_t      chunkVersion; /* input */    off_t 	 offset;   /* input */    size_t 	 numBytes; /* input */    std::string	 writeIdStr;  /* output */    std::vector<ServerLocation> chunkServerLoc;    WriteIdAllocOp(kfsSeq_t s, kfsChunkId_t c, int64_t v, off_t o, size_t n) :        KfsOp(CMD_WRITE_ID_ALLOC, s), chunkId(c), chunkVersion(v),        offset(o), numBytes(n)    {    }    void Request(std::ostringstream &os);    void ParseResponseHeader(char *buf, int len);    std::string Show() const {        std::ostringstream os;        os << "write-id-alloc: chunkid=" << chunkId << " version=" << chunkVersion;        return os.str();    }};struct WriteInfo {    ServerLocation serverLoc;    int64_t	 writeId;    WriteInfo() : writeId(-1) { }    WriteInfo(ServerLocation loc, int64_t w) :        serverLoc(loc), writeId(w) { }    WriteInfo & operator = (const WriteInfo &other) {        serverLoc = other.serverLoc;        writeId = other.writeId;        return *this;    }    std::string Show() const {        std::ostringstream os;        os << " location= " << serverLoc.ToString() << " writeId=" << writeId;        return os.str();    }};class ShowWriteInfo {    std::ostringstream &os;public:    ShowWriteInfo(std::ostringstream &o) : os(o) { }    void operator() (WriteInfo w) {        os << w.Show() << ' ';    }};struct WritePrepareOp : public KfsOp {    kfsChunkId_t chunkId;    int64_t      chunkVersion; /* input */    off_t 	 offset;   /* input */    size_t 	 numBytes; /* input */    std::vector<WriteInfo> writeInfo; /* input */    WritePrepareOp(kfsSeq_t s, kfsChunkId_t c, int64_t v, std::vector<WriteInfo> &w) :        KfsOp(CMD_WRITE_PREPARE, s), chunkId(c), chunkVersion(v),        offset(0), numBytes(0), writeInfo(w)    {    }    void Request(std::ostringstream &os);    // void ParseResponseHeader(char *buf, int len);    std::string Show() const {        std::ostringstream os;        os << "write-prepare: chunkid=" << chunkId << " version=" << chunkVersion;        os << " offset=" << offset << " numBytes=" << numBytes;        for_each(writeInfo.begin(), writeInfo.end(), ShowWriteInfo(os));        return os.str();    }};struct WriteSyncOp : public KfsOp {    kfsChunkId_t chunkId;    int64_t chunkVersion;    std::vector<WriteInfo> writeInfo;    WriteSyncOp() : KfsOp(CMD_WRITE_SYNC, 0) { }    WriteSyncOp(kfsSeq_t s, kfsChunkId_t c, int64_t v, std::vector<WriteInfo> &w) :        KfsOp(CMD_WRITE_SYNC, s), chunkId(c), chunkVersion(v), writeInfo(w)    { }    void Init(kfsSeq_t s, kfsChunkId_t c, int64_t v, std::vector<WriteInfo> &w) {        seq = s;        chunkId = c;        chunkVersion = v;        writeInfo = w;    }    void Request(std::ostringstream &os);    std::string Show() const {        std::ostringstream os;        os << "write-sync: chunkid=" << chunkId << " version=" << chunkVersion;	std::for_each(writeInfo.begin(), writeInfo.end(), ShowWriteInfo(os));        return os.str();    }};struct LeaseAcquireOp : public KfsOp {    kfsChunkId_t chunkId; // input    int64_t leaseId; // output    LeaseAcquireOp(kfsSeq_t s, kfsChunkId_t c) :        KfsOp(CMD_LEASE_ACQUIRE, s), chunkId(c), leaseId(-1)    {    }    void Request(std::ostringstream &os);    void ParseResponseHeader(char *buf, int len);    std::string Show() const {        std::ostringstream os;        os << "lease-acquire: chunkid=" << chunkId;        return os.str();    }};struct LeaseRenewOp : public KfsOp {    kfsChunkId_t chunkId; // input    int64_t leaseId; // input    LeaseRenewOp(kfsSeq_t s, kfsChunkId_t c, int64_t l) :        KfsOp(CMD_LEASE_RENEW, s), chunkId(c), leaseId(l)    {    }    void Request(std::ostringstream &os);    // default parsing of status is sufficient    std::string Show() const {        std::ostringstream os;        os << "lease-renew: chunkid=" << chunkId << " leaseId=" << leaseId;        return os.str();    }};// Whenever we want to give up a lease early, we notify the metaserver// using this op.struct LeaseRelinquishOp : public KfsOp {    kfsChunkId_t chunkId;    int64_t leaseId;    std::string leaseType;    LeaseRelinquishOp(kfsSeq_t s, kfsChunkId_t c, int64_t l) :        KfsOp(CMD_LEASE_RELINQUISH, s), chunkId(c), leaseId(l)    {    }    void Request(std::ostringstream &os);    // defaut parsing of status is sufficient    std::string Show() const {        std::ostringstream os;        os << "lease-relinquish: " << " chunkid = " << chunkId;        os << " leaseId: " << leaseId << " type: " << leaseType;        return os.str();    }};struct ChangeFileReplicationOp : public KfsOp {    kfsFileId_t fid; // input    int16_t numReplicas; // desired replication    ChangeFileReplicationOp(kfsSeq_t s, kfsFileId_t f, int16_t r) :        KfsOp(CMD_CHANGE_FILE_REPLICATION, s), fid(f), numReplicas(r)    {    }    void Request(std::ostringstream &os);    void ParseResponseHeader(char *buf, int len);    std::string Show() const {        std::ostringstream os;        os << "change-file-replication: fid=" << fid           << " # of replicas: " << numReplicas;        return os.str();    }};}#endif // _LIBKFSCLIENT_KFSOPS_H

⌨️ 快捷键说明

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