📄 request.cc
字号:
/*! * \brief Parse out the headers from a STATS message. */intparseHandlerOpenFiles(Properties &prop, MetaRequest **r){ seq_t seq = prop.getValue("Cseq", (seq_t) -1); *r = new MetaOpenFiles(seq); return 0;}/*! * \brief Generate response (a string) for various requests that * describes the result of the request execution. The generated * response string is based on the KFS protocol. All follow the same * model: * @param[out] os: A string stream that contains the response. */voidMetaLookup::response(ostringstream &os){ static string fname[] = { "empty", "file", "dir" }; os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n"; if (status < 0) { os << "\r\n"; return; } os << "File-handle: " << toString(result.id()) << "\r\n"; os << "Type: " << fname[result.type] << "\r\n"; os << "Chunk-count: " << toString(result.chunkcount) << "\r\n"; os << "File-size: " << toString(result.filesize) << "\r\n"; os << "Replication: " << toString(result.numReplicas) << "\r\n"; sendtime(os, "M-Time:", result.mtime, "\r\n"); sendtime(os, "C-Time:", result.ctime, "\r\n"); sendtime(os, "CR-Time:", result.crtime, "\r\n\r\n");}voidMetaLookupPath::response(ostringstream &os){ static string fname[] = { "empty", "file", "dir" }; os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n"; if (status < 0) { os << "\r\n"; return; } os << "File-handle: " << toString(result.id()) << "\r\n"; os << "Type: " << fname[result.type] << "\r\n"; os << "Chunk-count: " << toString(result.chunkcount) << "\r\n"; os << "File-size: " << toString(result.filesize) << "\r\n"; os << "Replication: " << toString(result.numReplicas) << "\r\n"; sendtime(os, "M-Time:", result.mtime, "\r\n"); sendtime(os, "C-Time:", result.ctime, "\r\n"); sendtime(os, "CR-Time:", result.crtime, "\r\n\r\n");}voidMetaCreate::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n"; if (status < 0) { os << "\r\n"; return; } os << "File-handle: " << toString(fid) << "\r\n\r\n";}voidMetaRemove::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n\r\n";}voidMetaMkdir::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n"; if (status < 0) { os << "\r\n"; return; } os << "File-handle: " << toString(fid) << "\r\n\r\n";}voidMetaRmdir::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n\r\n";}voidMetaReaddir::response(ostringstream &os){ vector<MetaDentry>::iterator iter; string res; int numEntries = 0; os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n"; if (status < 0) { os << "\r\n"; return; } // Send over the names---1 name per line so it is easy to // extract it out // XXX This should include the file id also, and probably // the other NFS READDIR elements, namely a cookie and // eof indicator to support reading less than a whole // directory at a time. for (iter = v.begin(); iter != v.end(); ++iter) { // "/" doesn't have "/" as an entry in it. if ((dir == ROOTFID) && (iter->getName() == "/")) continue; res = res + iter->getName() + "\n"; ++numEntries; } os << "Num-Entries: " << numEntries << "\r\n"; os << "Content-length: " << res.length() << "\r\n\r\n"; if (res.length() > 0) os << res;}voidMetaReaddirPlus::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n"; if (status < 0) { os << "\r\n"; return; } os << "Num-Entries: " << numEntries << "\r\n"; os << "Content-length: " << v.str().length() << "\r\n\r\n"; os << v.str();}voidMetaRename::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n\r\n";}voidMetaGetalloc::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n"; if (status < 0) { os << "\r\n"; return; } os << "Chunk-handle: " << chunkId << "\r\n"; os << "Chunk-version: " << chunkVersion << "\r\n"; os << "Num-replicas: " << locations.size() << "\r\n"; assert(locations.size() > 0); os << "Replicas:"; for_each(locations.begin(), locations.end(), ListServerLocations(os)); os << "\r\n\r\n";}voidMetaGetlayout::response(ostringstream &os){ vector<ChunkLayoutInfo>::iterator iter; ChunkLayoutInfo l; string res; os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n"; if (status < 0) { os << "\r\n"; return; } os << "Num-chunks: " << v.size() << "\r\n"; // Send over the layout info for (iter = v.begin(); iter != v.end(); ++iter) { l = *iter; res = res + l.toString(); } os << "Content-length: " << res.length() << "\r\n\r\n"; if (res.length() > 0) os << res;}voidMetaGetDirSummary::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n"; if (status < 0) { os << "\r\n"; return; } os << "Num-files: " << numFiles << "\r\n"; os << "Num-bytes: " << numBytes << "\r\n\r\n";}class PrintChunkServerLocations { ostringstream &os;public: PrintChunkServerLocations(ostringstream &out): os(out) { } void operator () (ChunkServerPtr &s) { os << " " << s->ServerID(); }};voidMetaAllocate::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n"; if (status < 0) { os << "\r\n"; return; } os << "Chunk-handle: " << chunkId << "\r\n"; os << "Chunk-version: " << chunkVersion << "\r\n"; os << "Master: " << master->ServerID() << "\r\n"; os << "Num-replicas: " << servers.size() << "\r\n"; assert(servers.size() > 0); os << "Replicas:"; for_each(servers.begin(), servers.end(), PrintChunkServerLocations(os)); os << "\r\n\r\n";}voidMetaLeaseAcquire::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n"; if (status >= 0) { os << "Lease-id: " << leaseId << "\r\n"; } os << "\r\n";}voidMetaLeaseRenew::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n\r\n";}voidMetaLeaseRelinquish::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n\r\n";}voidMetaHello::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n\r\n";}voidMetaChunkCorrupt::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n\r\n";}voidMetaTruncate::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n\r\n";}voidMetaChangeFileReplication::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Num-replicas: " << numReplicas << "\r\n"; os << "Status: " << status << "\r\n\r\n";}voidMetaRetireChunkserver::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n\r\n";}voidMetaToggleRebalancing::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n\r\n";}voidMetaToggleWORM::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n\r\n";}voidMetaExecuteRebalancePlan::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n\r\n";}voidMetaPing::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n"; os << "Build-version: " << KFS::KFS_BUILD_VERSION_STRING << "\r\n"; os << "Source-version: " << KFS::KFS_SOURCE_REVISION_STRING << "\r\n"; if (gWormMode) os << "WORM: " << 1 << "\r\n"; else os << "WORM: " << 0 << "\r\n"; os << "System Info: " << systemInfo << "\r\n"; os << "Servers: " << servers << "\r\n"; os << "Retiring Servers: " << retiringServers << "\r\n"; os << "Down Servers: " << downServers << "\r\n\r\n";}voidMetaUpServers::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n"; os << "Content-length: " << stringStream.str().length() << "\r\n\r\n"; if (stringStream.str().length() > 0) os << stringStream.str();}voidMetaStats::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n"; os << stats << "\r\n";}voidMetaDumpChunkToServerMap::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n\r\n"; /* ostringstream v; gLayoutManager.DumpChunkToServerMap(v); os << "Content-length: " << v.str().length() << "\r\n\r\n"; if (v.str().length() > 0) os << v.str(); */}voidMetaOpenFiles::response(ostringstream &os){ os << "OK\r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Status: " << status << "\r\n"; os << "Read: " << openForRead << "\r\n"; os << "Write: " << openForWrite << "\r\n\r\n";}/*! * \brief Generate request (a string) that should be sent to the chunk * server. The generated request string is based on the KFS * protocol. All follow the same model: * @param[out] os: A string stream that contains the response. */voidMetaChunkAllocate::request(ostringstream &os){ MetaAllocate *allocOp = static_cast<MetaAllocate *>(req); assert(allocOp != NULL); os << "ALLOCATE \r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Version: KFS/1.0\r\n"; os << "File-handle: " << allocOp->fid << "\r\n"; os << "Chunk-handle: " << allocOp->chunkId << "\r\n"; os << "Chunk-version: " << allocOp->chunkVersion << "\r\n"; if (leaseId >= 0) { os << "Lease-id: " << leaseId << "\r\n"; } os << "Num-servers: " << allocOp->servers.size() << "\r\n"; assert(allocOp->servers.size() > 0); os << "Servers:"; for_each(allocOp->servers.begin(), allocOp->servers.end(), PrintChunkServerLocations(os)); os << "\r\n\r\n";}voidMetaChunkDelete::request(ostringstream &os){ os << "DELETE \r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Version: KFS/1.0\r\n"; os << "Chunk-handle: " << chunkId << "\r\n\r\n";}voidMetaChunkTruncate::request(ostringstream &os){ os << "TRUNCATE \r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Version: KFS/1.0\r\n"; os << "Chunk-handle: " << chunkId << "\r\n"; os << "Chunk-size: " << chunkSize << "\r\n\r\n";}voidMetaChunkHeartbeat::request(ostringstream &os){ os << "HEARTBEAT \r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Version: KFS/1.0\r\n\r\n";}voidMetaChunkStaleNotify::request(ostringstream &os){ string s; vector<chunkId_t>::size_type i; os << "STALE_CHUNKS \r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Version: KFS/1.0\r\n"; os << "Num-chunks: " << staleChunkIds.size() << "\r\n"; for (i = 0; i < staleChunkIds.size(); ++i) { s += toString(staleChunkIds[i]); s += " "; } os << "Content-length: " << s.length() << "\r\n\r\n"; os << s;}voidMetaChunkRetire::request(ostringstream &os){ os << "RETIRE \r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Version: KFS/1.0\r\n\r\n";}voidMetaChunkVersChange::request(ostringstream &os){ os << "CHUNK_VERS_CHANGE \r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Version: KFS/1.0\r\n"; os << "File-handle: " << fid << "\r\n"; os << "Chunk-handle: " << chunkId << "\r\n"; os << "Chunk-version: " << chunkVersion << "\r\n\r\n";}voidMetaChunkReplicate::request(ostringstream &os){ os << "REPLICATE \r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Version: KFS/1.0\r\n"; os << "File-handle: " << fid << "\r\n"; os << "Chunk-handle: " << chunkId << "\r\n"; os << "Chunk-version: " << chunkVersion << "\r\n"; os << "Chunk-location: " << srcLocation.ToString() << "\r\n\r\n";}voidMetaChunkSize::request(ostringstream &os){ os << "SIZE \r\n"; os << "Cseq: " << opSeqno << "\r\n"; os << "Version: KFS/1.0\r\n"; os << "File-handle: " << fid << "\r\n"; os << "Chunk-handle: " << chunkId << "\r\n\r\n";}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -