這篇文章主要講解了“RGW中request的處理流程是什么”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“RGW中request的處理流程是什么”吧!
閩清網站建設公司創新互聯,閩清網站設計制作,有大型網站制作公司豐富經驗。已為閩清超過千家提供企業網站建設服務。企業網站搭建\外貿網站制作要多少錢,請找那個售后服務好的閩清做網站的公司定做!
以civetweb為例
1. rgw_main.cc為整個radosgw服務的入口,main()函數中根據在ceph.conf的rgw frontends參數設置來選擇不同的前端類型,之后執行相應的run()方法實現整個frontend服務的啟動。注意這里會根據ceph.conf中rgw_enable_apis的設置,實現s3、swift、admin等多種類型的接口生成不同的handler,具體代碼如下
#src/rgw/rgw_main.cc get_str_list(g_conf->rgw_enable_apis, apis); #獲取接口類型列表 map<string, bool> apis_map; for (list<string>::iterator li = apis.begin(); li != apis.end(); ++li) { apis_map[*li] = true; } ... if (apis_map.count("s3") > 0 || s3website_enabled) { if (! swift_at_root) { rest.register_default_mgr(set_logging(new RGWRESTMgr_S3(s3website_enabled))); #設置S3接口默認handler為RGWRESTMgr_S3 ... if (apis_map.count("swift") > 0) { do_swift = true; swift_init(g_ceph_context); RGWRESTMgr_SWIFT* const swift_resource = new RGWRESTMgr_SWIFT;#設置swift接口默認handler為RGWRESTMgr_SWIFT ...
2. 之后在對應的rgw_civetweb_fronted.cc中,根據之前介紹的civetweb啟動流程,設置相應啟動參數,之后使用mg_start()完成civetweb的啟動。(注意參數中callback設置的是civetweb_callback)
#src/rgw/rgw_civetweb_frontend.cc int RGWMongooseFrontend::run() { char thread_pool_buf[32]; snprintf(thread_pool_buf, sizeof(thread_pool_buf), "%d", (int)g_conf->rgw_thread_pool_size); string port_str; map<string, string> conf_map = conf->get_config_map(); conf->get_val("port", "80", &port_str); conf_map.erase("port"); std::replace(port_str.begin(), port_str.end(), '+', ','); conf_map["listening_ports"] = port_str; #civetweb默認啟動監聽端口 set_conf_default(conf_map, "enable_keep_alive", "yes"); #keep_alive參數設置 set_conf_default(conf_map, "num_threads", thread_pool_buf); #默認threads設置 set_conf_default(conf_map, "decode_url", "no"); ... struct mg_callbacks cb; memset((void *)&cb, 0, sizeof(cb)); cb.begin_request = civetweb_callback; #回調函數設置 cb.log_message = rgw_civetweb_log_callback; cb.log_access = rgw_civetweb_log_access_callback; ctx = mg_start(&cb, &env, (const char **)&options); #啟動服務 if (!ctx) { return -EIO; } return 0; } /* RGWMongooseFrontend::run */
3. 經過上一步的設置,在civetweb_callback中每一個request請求都需要經過process_request()進行處理,注意每個request請求都會綁定一組RGWRados(負責底層Librados的數據讀寫)/RGWREST(對應request和Response的處理)/OpsLogSocket(日志消息記錄)
#src/rgw/rgw_civetweb_frontend.cc static int civetweb_callback(struct mg_connection* conn) { struct mg_request_info* req_info = mg_get_request_info(conn); RGWMongooseEnv* pe = static_cast<RGWMongooseEnv *>(req_info->user_data); { // hold a read lock over access to pe->store for reconfiguration RWLock::RLocker lock(pe->mutex); RGWRados* store = pe->store; RGWREST* rest = pe->rest; OpsLogSocket* olog = pe->olog; RGWRequest req(store->get_new_req_id()); RGWMongoose client_io(conn); int ret = process_request(pe->store, rest, &req, &client_io, olog); #每個request請求綁定一組前面的RGWRados、RGWREST、OpsLogSocket ...
4. 之后調用rgw_process.cc中的process_request(),其中rest->get_handler根據請求的URL是否包含bucket、object信息,獲取到對應的handler類型,之后調用handler->get_op(store)根據前面取得的handler對應request_method獲取到最終的handler,之后觸發handler對應的pre_exec()、execute()、complete()完整整個request請求的處理,代碼如下:
#src/rgw/rgw_process.cc int process_request(RGWRados* store, RGWREST* rest, RGWRequest* req,GWStreamIO* client_io, OpsLogSocket* olog) {int ret = 0; client_io->init(g_ceph_context); ... RGWHandler_REST *handler = rest->get_handler(store, s, client_io, &mgr,&init_error); #這里根據URL里面是否包含bucket、Object字段會進一步獲取到對應的handler類型 if (init_error != 0) { abort_early(s, NULL, init_error, NULL); goto done; } dout(10) << "handler=" << typeid(*handler).name() << dendl; should_log = mgr->get_logging(); req->log_format(s, "getting op %d", s->op); op = handler->get_op(store); #這里根據request_method獲取到最終處理request請求的handler類型 ... req->log(s, "pre-executing"); op->pre_exec(); #請求預處理 req->log(s, "executing"); op->execute(); #具體請求的具體實現 req->log(s, "completing"); op->complete(); #完成請求處理
#src/rgw/rgw_process.cc RGWHandler_REST* RGWRESTMgr_S3::get_handler(struct req_state *s) { bool is_s3website = enable_s3website && (s->prot_flags & RGW_REST_WEBSITE); int ret = RGWHandler_REST_S3::init_from_header(s, is_s3website ? RGW_FORMAT_HTML : RGW_FORMAT_XML, true); if (ret < 0) return NULL; RGWHandler_REST* handler; // TODO: Make this more readable if (is_s3website) { if (s->init_state.url_bucket.empty()) { handler = new RGWHandler_REST_Service_S3Website; } else if (s->object.empty()) { handler = new RGWHandler_REST_Bucket_S3Website; } else { handler = new RGWHandler_REST_Obj_S3Website; } } else { if (s->init_state.url_bucket.empty()) { handler = new RGWHandler_REST_Service_S3; #bucket為空則切換到RGWHandler_REST_Service_S3 } else if (s->object.empty()) { handler = new RGWHandler_REST_Bucket_S3; #obj為空則切換RGWHandler_REST_Bucket_S3 } else { handler = new RGWHandler_REST_Obj_S3; #bucket和Object都不為空,則切換到RGWHandler_REST_Obj_S3 } } ldout(s->cct, 20) << __func__ << " handler=" << typeid(*handler).name() << dendl; return handler; }
#src/rgw/rgw_rest.cc RGWOp* RGWHandler_REST::get_op(RGWRados* store) { RGWOp *op; switch (s->op) #這里s對應一個req_state的結構體 { rest->op case OP_GET: op = op_get(); break; case OP_PUT: op = op_put(); break; case OP_DELETE: op = op_delete(); break; case OP_HEAD: op = op_head(); break; case OP_POST: op = op_post(); break; case OP_COPY: op = op_copy(); break; case OP_OPTIONS: op = op_options(); break; default: return NULL; } if (op) { op->init(store, s, this); } return op; } /* get_op */
結構體定義 struct req_state { CephContext *cct; RGWClientIO *cio; RGWRequest *req; /// XXX: re-remove?? http_op op; #對應一個枚舉類型,具體如下 RGWOpType op_type; ... enum http_op { OP_GET, OP_PUT, OP_DELETE, OP_HEAD, OP_POST, OP_COPY, OP_OPTIONS, OP_UNKNOWN, };
理解整個URL轉換handler的過程,能夠感覺request信息快速定位具體的op操作,方便debug,整個過程用下面一張圖總結。
感謝各位的閱讀,以上就是“RGW中request的處理流程是什么”的內容了,經過本文的學習后,相信大家對RGW中request的處理流程是什么這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創新互聯,小編將為大家推送更多相關知識點的文章,歡迎關注!
名稱欄目:RGW中request的處理流程是什么
文章來源:http://vcdvsql.cn/article0/iipgoo.html
成都網站建設公司_創新互聯,為您提供網站導航、外貿建站、電子商務、網站建設、標簽優化、軟件開發
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯