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

📄 kfsops.cc

📁 nandflash文件系统源代码
💻 CC
📖 第 1 页 / 共 2 页
字号:
    os << "LEASE_RENEW \r\n";    os << "Cseq: " << seq << "\r\n";    os << "Version: " << KFS_VERSION_STR << "\r\n";    os << "Chunk-handle: " << chunkId << "\r\n";    os << "Lease-id: " << leaseId << "\r\n";    os << "Lease-type: READ_LEASE" << "\r\n\r\n";}voidLeaseRelinquishOp::Request(ostringstream &os){    os << "LEASE_RELINQUISH\r\n";    os << "Version: " << KFS_VERSION_STR << "\r\n";    os << "Cseq: " << seq << "\r\n";    os << "Chunk-handle:" << chunkId << "\r\n";    os << "Lease-id: " << leaseId << "\r\n";    os << "Lease-type: READ_LEASE" << "\r\n\r\n";}voidChangeFileReplicationOp::Request(ostringstream &os){    os << "CHANGE_FILE_REPLICATION \r\n";    os << "Cseq: " << seq << "\r\n";    os << "Version: " << KFS_VERSION_STR << "\r\n";    os << "File-handle: " << fid << "\r\n";    os << "Num-replicas: " << numReplicas << "\r\n\r\n";}////// Handlers to parse a response sent by the server.  The model is/// similar to what is done by ChunkServer/metaserver: put the/// response into a properties object and then extract out the values.////// \brief Parse the response common to all RPC requests./// @param[in] resp: a string consisting of header/value pairs in/// which header/value is separated by a ':' character./// @param[out] prop: a properties object that contains the result of/// parsing.///voidKfsOp::ParseResponseHeaderCommon(string &resp, Properties &prop){    istringstream ist(resp);    kfsSeq_t resSeq;    const char separator = ':';    prop.loadProperties(ist, separator, false);    resSeq = prop.getValue("Cseq", (kfsSeq_t) -1);    status = prop.getValue("Status", -1);    contentLength = prop.getValue("Content-length", 0);}////// Default parse response handler./// @param[in] buf: buffer containing the response/// @param[in] len: str-len of the buffer.voidKfsOp::ParseResponseHeader(char *buf, int len){    string resp(buf, len);    Properties prop;    // XXX: Need to extract out the status: OK or what?    ParseResponseHeaderCommon(resp, prop);}////// Specific response parsing handlers.///voidCreateOp::ParseResponseHeader(char *buf, int len){    string resp(buf, len);    Properties prop;    ParseResponseHeaderCommon(resp, prop);    fileId = prop.getValue("File-handle", (kfsFileId_t) -1);}voidReaddirOp::ParseResponseHeader(char *buf, int len){    string resp(buf, len);    Properties prop;    ParseResponseHeaderCommon(resp, prop);    numEntries = prop.getValue("Num-Entries", 0);}voidGetDirSummaryOp::ParseResponseHeader(char *buf, int len){    string resp(buf, len);    Properties prop;    ParseResponseHeaderCommon(resp, prop);    numFiles = prop.getValue("Num-files", 0);    numBytes = prop.getValue("Num-bytes", 0);}voidDumpChunkServerMapOp::ParseResponseHeader(char *buf, int len){	string resp(buf, len);	Properties prop;	ParseResponseHeaderCommon(resp, prop);}voidDumpChunkMapOp::ParseResponseHeader(char *buf, int len){	string resp(buf, len);	Properties prop;	ParseResponseHeaderCommon(resp, prop);}voidUpServersOp::ParseResponseHeader(char *buf, int len){	string resp(buf, len);	Properties prop;	ParseResponseHeaderCommon(resp, prop);}voidReaddirPlusOp::ParseResponseHeader(char *buf, int len){    string resp(buf, len);    Properties prop;    ParseResponseHeaderCommon(resp, prop);    numEntries = prop.getValue("Num-Entries", 0);}voidMkdirOp::ParseResponseHeader(char *buf, int len){    string resp(buf, len);    Properties prop;    ParseResponseHeaderCommon(resp, prop);    fileId = prop.getValue("File-handle", (kfsFileId_t) -1);}voidLookupOp::ParseResponseHeader(char *buf, int len){    string resp(buf, len);    Properties prop;    string s;    ParseResponseHeaderCommon(resp, prop);    fattr.fileId = prop.getValue("File-handle", (kfsFileId_t) -1);    s = prop.getValue("Type", "");    fattr.isDirectory = (s == "dir");    fattr.chunkCount = prop.getValue("Chunk-count", 0);    fattr.fileSize = prop.getValue("File-size", (off_t) -1);    fattr.numReplicas = prop.getValue("Replication", 1);    s = prop.getValue("M-Time", "");    GetTimeval(s, fattr.mtime);    s = prop.getValue("C-Time", "");    GetTimeval(s, fattr.ctime);    s = prop.getValue("CR-Time", "");    GetTimeval(s, fattr.crtime);}voidLookupPathOp::ParseResponseHeader(char *buf, int len){    string resp(buf, len);    Properties prop;    string s;    istringstream ist;    ParseResponseHeaderCommon(resp, prop);    fattr.fileId = prop.getValue("File-handle", (kfsFileId_t) -1);    s = prop.getValue("Type", "");    fattr.isDirectory = (s == "dir");    fattr.fileSize = prop.getValue("File-size", (off_t) -1);    fattr.chunkCount = prop.getValue("Chunk-count", 0);    fattr.numReplicas = prop.getValue("Replication", 1);    s = prop.getValue("M-Time", "");    GetTimeval(s, fattr.mtime);    s = prop.getValue("C-Time", "");    GetTimeval(s, fattr.ctime);    s = prop.getValue("CR-Time", "");    GetTimeval(s, fattr.crtime);}voidAllocateOp::ParseResponseHeader(char *buf, int len){    string resp(buf, len);    Properties prop;    ParseResponseHeaderCommon(resp, prop);    chunkId = prop.getValue("Chunk-handle", (kfsFileId_t) -1);    chunkVersion = prop.getValue("Chunk-version", (int64_t) -1);    string master = prop.getValue("Master", "");    if (master != "") {	istringstream ist(master);	ist >> masterServer.hostname;	ist >> masterServer.port;	// put the master the first in the list	chunkServers.push_back(masterServer);    }    int numReplicas = prop.getValue("Num-replicas", 0);    string replicas = prop.getValue("Replicas", "");    if (replicas != "") {	istringstream ser(replicas);	ServerLocation loc;	for (int i = 0; i < numReplicas; ++i) {	    ser >> loc.hostname;	    ser >> loc.port;	    if (loc != masterServer)		chunkServers.push_back(loc);	}    }}voidGetAllocOp::ParseResponseHeader(char *buf, int len){    string resp(buf, len);    Properties prop;    ParseResponseHeaderCommon(resp, prop);    chunkId = prop.getValue("Chunk-handle", (kfsFileId_t) -1);    chunkVersion = prop.getValue("Chunk-version", (int64_t) -1);    int numReplicas = prop.getValue("Num-replicas", 0);    string replicas = prop.getValue("Replicas", "");    if (replicas != "") {	istringstream ser(replicas);	ServerLocation loc;	for (int i = 0; i < numReplicas; ++i) {	    ser >> loc.hostname;	    ser >> loc.port;	    chunkServers.push_back(loc);	}    }}voidGetLayoutOp::ParseResponseHeader(char *buf, int len){    string resp(buf, len);    Properties prop;    ParseResponseHeaderCommon(resp, prop);    numChunks = prop.getValue("Num-chunks", 0);}intGetLayoutOp::ParseLayoutInfo(){    if (numChunks == 0 || contentBuf == NULL)	return 0;    istringstream ist(contentBuf);    for (int i = 0; i < numChunks; ++i) {	ChunkLayoutInfo l;	ServerLocation s;	int numServers;	ist >> l.fileOffset;	ist >> l.chunkId;	ist >> l.chunkVersion;	ist >> numServers;	for (int j = 0; j < numServers; j++) {	    ist >> s.hostname;	    ist >> s.port;	    l.chunkServers.push_back(s);	}	chunks.push_back(l);    }    return 0;}voidSizeOp::ParseResponseHeader(char *buf, int len){    string resp(buf, len);    Properties prop;    ParseResponseHeaderCommon(resp, prop);    size = prop.getValue("Size", (long long) 0);}voidReadOp::ParseResponseHeader(char *buf, int len){    string resp(buf, len);    Properties prop;    string checksumStr;    uint32_t nentries;    ParseResponseHeaderCommon(resp, prop);    nentries = prop.getValue("Checksum-entries", 0);    checksumStr = prop.getValue("Checksums", "");    diskIOTime = prop.getValue("DiskIOtime", 0.0);    istringstream ist(checksumStr);    checksums.clear();    for (uint32_t i = 0; i < nentries; i++) {        uint32_t cksum;        ist >> cksum;        checksums.push_back(cksum);    }}voidWriteIdAllocOp::ParseResponseHeader(char *buf, int len){    string resp(buf, len);    Properties prop;    ParseResponseHeaderCommon(resp, prop);    writeIdStr = prop.getValue("Write-id", "");}voidLeaseAcquireOp::ParseResponseHeader(char *buf, int len){    string resp(buf, len);    Properties prop;    ParseResponseHeaderCommon(resp, prop);    leaseId = prop.getValue("Lease-id", (long long) -1);}voidChangeFileReplicationOp::ParseResponseHeader(char *buf, int len){    string resp(buf, len);    Properties prop;    ParseResponseHeaderCommon(resp, prop);    numReplicas = prop.getValue("Num-replicas", 1);}

⌨️ 快捷键说明

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