📄 request.cc
字号:
// Meta server <-> Chunk server ops gParseHandlers["HELLO"] = parseHandlerHello; gParseHandlers["PING"] = parseHandlerPing; gParseHandlers["UPSERVERS"] = parseHandlerUpServers; gParseHandlers["TOGGLE_WORM"] = parseHandlerToggleWORM; gParseHandlers["STATS"] = parseHandlerStats; gParseHandlers["DUMP_CHUNKTOSERVERMAP"] = parseHandlerDumpChunkToServerMap; gParseHandlers["OPEN_FILES"] = parseHandlerOpenFiles;}/*! * \brief request queue initialization */voidKFS::initialize_request_handlers(){ setup_handlers();}/*! * \brief remove successive requests for the queue and carry them out. */voidKFS::process_request(){ MetaRequest *r = requestList.dequeue(); map <MetaOp, ReqHandler>::iterator h = handler.find(r->op); if (h == handler.end()) r->status = -ENOSYS; else ((*h).second)(r); if (!r->suspended) { UpdateCounter(r->op); oplog.add_pending(r); }}/*! * \brief add a new request to the queue * \param[in] r the request */voidKFS::submit_request(MetaRequest *r){ requestList.enqueue(r);}/*! * \brief print out the leaf nodes for debugging */voidKFS::printleaves(){ metatree.printleaves();}/*! * \brief log lookup request (nop) */intMetaLookup::log(ofstream &file) const{ return 0;}/*! * \brief log lookup path request (nop) */intMetaLookupPath::log(ofstream &file) const{ return 0;}/*! * \brief log a file create */intMetaCreate::log(ofstream &file) const{ // use the log entry time as a proxy for when the file was created struct timeval t; gettimeofday(&t, NULL); file << "create/dir/" << dir << "/name/" << name << "/id/" << fid << "/numReplicas/" << (int) numReplicas << "/ctime/" << showtime(t) << '\n'; return file.fail() ? -EIO : 0;}/*! * \brief log a directory create */intMetaMkdir::log(ofstream &file) const{ struct timeval t; gettimeofday(&t, NULL); file << "mkdir/dir/" << dir << "/name/" << name << "/id/" << fid << "/ctime/" << showtime(t) << '\n'; return file.fail() ? -EIO : 0;}/*! * \brief log a file deletion */intMetaRemove::log(ofstream &file) const{ file << "remove/dir/" << dir << "/name/" << name << '\n'; return file.fail() ? -EIO : 0;}/*! * \brief log a directory deletion */intMetaRmdir::log(ofstream &file) const{ file << "rmdir/dir/" << dir << "/name/" << name << '\n'; return file.fail() ? -EIO : 0;}/*! * \brief log directory read (nop) */intMetaReaddir::log(ofstream &file) const{ return 0;}/*! * \brief log directory read (nop) */intMetaReaddirPlus::log(ofstream &file) const{ return 0;}/*! * \brief log getalloc (nop) */intMetaGetalloc::log(ofstream &file) const{ return 0;}/*! * \brief log getlayout (nop) */intMetaGetlayout::log(ofstream &file) const{ return 0;}/*! * \brief log getdirsummary (nop) */intMetaGetDirSummary::log(ofstream &file) const{ return 0;}/*! * \brief log a chunk allocation */intMetaAllocate::log(ofstream &file) const{ // use the log entry time as a proxy for when the block was created/file // was modified struct timeval t; gettimeofday(&t, NULL); file << "allocate/file/" << fid << "/offset/" << offset << "/chunkId/" << chunkId << "/chunkVersion/" << chunkVersion << "/mtime/" << showtime(t) << '\n'; return file.fail() ? -EIO : 0;}/*! * \brief log a file truncation */intMetaTruncate::log(ofstream &file) const{ // use the log entry time as a proxy for when the file was modified struct timeval t; gettimeofday(&t, NULL); file << "truncate/file/" << fid << "/offset/" << offset << "/mtime/" << showtime(t) << '\n'; return file.fail() ? -EIO : 0;}/*! * \brief log a rename */intMetaRename::log(ofstream &file) const{ file << "rename/dir/" << dir << "/old/" << oldname << "/new/" << newname << '\n'; return file.fail() ? -EIO : 0;}/*! * \brief Log a chunk-version-increment change to disk.*/intMetaChangeChunkVersionInc::log(ofstream &file) const{ file << "chunkVersionInc/" << cvi << '\n'; return file.fail() ? -EIO : 0;}/*! * \brief log change file replication (nop) */intMetaChangeFileReplication::log(ofstream &file) const{ return 0;}/*! * \brief log retire chunkserver (nop) */intMetaRetireChunkserver::log(ofstream &file) const{ return 0;}/*! * \brief log toggling of chunkserver rebalancing state (nop) */intMetaToggleRebalancing::log(ofstream &file) const{ return 0;}/*! * \brief log toggling of metaserver WORM state (nop) */intMetaToggleWORM::log(ofstream &file) const{ return 0;}/*! * \brief log execution of rebalance plan (nop) */intMetaExecuteRebalancePlan::log(ofstream &file) const{ return 0;}/*! * \brief close log and open a new one */intMetaLogRollover::log(ofstream &file) const{ return oplog.finishLog();}/*! * \brief for a chunkserver hello, there is nothing to log */intMetaHello::log(ofstream &file) const{ return 0;}/*! * \brief for a chunkserver's death, there is nothing to log */intMetaBye::log(ofstream &file) const{ return 0;}/*! * \brief for a chunkserver allocate, there is nothing to log */intMetaChunkAllocate::log(ofstream &file) const{ return 0;}/*! * \brief log a chunk delete; (nop) */intMetaChunkDelete::log(ofstream &file) const{ return 0;}/*! * \brief log a chunk truncation; (nop) */intMetaChunkTruncate::log(ofstream &file) const{ return 0;}/*! * \brief log a heartbeat to a chunk server; (nop) */intMetaChunkHeartbeat::log(ofstream &file) const{ return 0;}/*! * \brief log a stale notify to a chunk server; (nop) */intMetaChunkStaleNotify::log(ofstream &file) const{ return 0;}/*! * \brief log a chunk server retire; (nop) */intMetaChunkRetire::log(ofstream &file) const{ return 0;}/*! * \brief when a chunkserver tells us of a corrupted chunk, there is nothing to log */intMetaChunkCorrupt::log(ofstream &file) const{ return 0;}/*! * \brief When notifying a chunkserver of a version # change, there is * nothing to log. */intMetaChunkVersChange::log(ofstream &file) const{ return 0;}/*! * \brief When asking a chunkserver to replicate a chunk, there is * nothing to log. */intMetaChunkReplicate::log(ofstream &file) const{ return 0;}/*! * \brief When asking a chunkserver for a chunk's size, there is * nothing to log. */intMetaChunkSize::log(ofstream &file) const{ return 0;}/*! * \brief for a ping, there is nothing to log */intMetaPing::log(ofstream &file) const{ return 0;}/*! * \brief for a request of upserver, there is nothing to log */intMetaUpServers::log(ofstream &file) const{ return 0;}/*! * \brief for a stats request, there is nothing to log */intMetaStats::log(ofstream &file) const{ return 0;}/*! * \brief for a map dump request, there is nothing to log */intMetaDumpChunkToServerMap::log(ofstream &file) const{ return 0;}/*! * \brief for an open files request, there is nothing to log */intMetaOpenFiles::log(ofstream &file) const{ return 0;}/*! * \brief for a lease acquire request, there is nothing to log */intMetaLeaseAcquire::log(ofstream &file) const{ return 0;}/*! * \brief for a lease renew request, there is nothing to log */intMetaLeaseRenew::log(ofstream &file) const{ return 0;}/*! * \brief for a lease renew relinquish, there is nothing to log */intMetaLeaseRelinquish::log(ofstream &file) const{ return 0;}/*! * \brief for a lease cleanup request, there is nothing to log */intMetaLeaseCleanup::log(ofstream &file) const{ return 0;}/*! * \brief This is an internally generated op. There is * nothing to log. */intMetaChunkReplicationCheck::log(ofstream &file) const{ return 0;}/*! * \brief parse a command sent by a client * * Commands are of the form: * <COMMAND NAME> \r\n * {header: value \r\n}+\r\n * * The general model in parsing the client command: * 1. Each command has its own parser * 2. Extract out the command name and find the parser for that * command * 3. Dump the header/value pairs into a properties object, so that we * can extract the header/value fields in any order. * 4. Finally, call the parser for the command sent by the client. * * @param[in] cmdBuf: buffer containing the request sent by the client * @param[in] cmdLen: length of cmdBuf * @param[out] res: A piece of memory allocated by calling new that * contains the data for the request. It is the caller's * responsibility to delete the memory returned in res. * @retval 0 on success; -1 if there is an error */intKFS::ParseCommand(char *cmdBuf, int cmdLen, MetaRequest **res){ const char *delims = " \r\n"; // header/value pairs are separated by a : const char separator = ':'; string cmdStr; string::size_type cmdEnd; Properties prop; istringstream ist(cmdBuf); ParseHandlerMapIter entry; ParseHandler handler; // get the first line and find the command name ist >> cmdStr; // trim the command cmdEnd = cmdStr.find_first_of(delims); if (cmdEnd != cmdStr.npos) { cmdStr.erase(cmdEnd); } // find the parse handler and parse the thing entry = gParseHandlers.find(cmdStr); if (entry == gParseHandlers.end()) return -1; handler = entry->second; prop.loadProperties(ist, separator, false);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -