這篇文章主要講解了“RGW中request的處理流程是什么”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“RGW中request的處理流程是什么”吧!
閩清網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),閩清網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為閩清超過(guò)千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的閩清做網(wǎng)站的公司定做!
以civetweb為例
1. rgw_main.cc為整個(gè)radosgw服務(wù)的入口,main()函數(shù)中根據(jù)在ceph.conf的rgw frontends參數(shù)設(shè)置來(lái)選擇不同的前端類型,之后執(zhí)行相應(yīng)的run()方法實(shí)現(xiàn)整個(gè)frontend服務(wù)的啟動(dòng)。注意這里會(huì)根據(jù)ceph.conf中rgw_enable_apis的設(shè)置,實(shí)現(xiàn)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))); #設(shè)置S3接口默認(rèn)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;#設(shè)置swift接口默認(rèn)handler為RGWRESTMgr_SWIFT ...
2. 之后在對(duì)應(yīng)的rgw_civetweb_fronted.cc中,根據(jù)之前介紹的civetweb啟動(dòng)流程,設(shè)置相應(yīng)啟動(dòng)參數(shù),之后使用mg_start()完成civetweb的啟動(dòng)。(注意參數(shù)中callback設(shè)置的是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默認(rèn)啟動(dòng)監(jiān)聽(tīng)端口 set_conf_default(conf_map, "enable_keep_alive", "yes"); #keep_alive參數(shù)設(shè)置 set_conf_default(conf_map, "num_threads", thread_pool_buf); #默認(rèn)threads設(shè)置 set_conf_default(conf_map, "decode_url", "no"); ... struct mg_callbacks cb; memset((void *)&cb, 0, sizeof(cb)); cb.begin_request = civetweb_callback; #回調(diào)函數(shù)設(shè)置 cb.log_message = rgw_civetweb_log_callback; cb.log_access = rgw_civetweb_log_access_callback; ctx = mg_start(&cb, &env, (const char **)&options); #啟動(dòng)服務(wù) if (!ctx) { return -EIO; } return 0; } /* RGWMongooseFrontend::run */
3. 經(jīng)過(guò)上一步的設(shè)置,在civetweb_callback中每一個(gè)request請(qǐng)求都需要經(jīng)過(guò)process_request()進(jìn)行處理,注意每個(gè)request請(qǐng)求都會(huì)綁定一組RGWRados(負(fù)責(zé)底層Librados的數(shù)據(jù)讀寫)/RGWREST(對(duì)應(yīng)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); #每個(gè)request請(qǐng)求綁定一組前面的RGWRados、RGWREST、OpsLogSocket ...
4. 之后調(diào)用rgw_process.cc中的process_request(),其中rest->get_handler根據(jù)請(qǐng)求的URL是否包含bucket、object信息,獲取到對(duì)應(yīng)的handler類型,之后調(diào)用handler->get_op(store)根據(jù)前面取得的handler對(duì)應(yīng)request_method獲取到最終的handler,之后觸發(fā)handler對(duì)應(yīng)的pre_exec()、execute()、complete()完整整個(gè)request請(qǐng)求的處理,代碼如下:
#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); #這里根據(jù)URL里面是否包含bucket、Object字段會(huì)進(jìn)一步獲取到對(duì)應(yīng)的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); #這里根據(jù)request_method獲取到最終處理request請(qǐng)求的handler類型 ... req->log(s, "pre-executing"); op->pre_exec(); #請(qǐng)求預(yù)處理 req->log(s, "executing"); op->execute(); #具體請(qǐng)求的具體實(shí)現(xiàn) req->log(s, "completing"); op->complete(); #完成請(qǐng)求處理
#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對(duì)應(yīng)一個(gè)req_state的結(jié)構(gòu)體 { 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 */
結(jié)構(gòu)體定義 struct req_state { CephContext *cct; RGWClientIO *cio; RGWRequest *req; /// XXX: re-remove?? http_op op; #對(duì)應(yīng)一個(gè)枚舉類型,具體如下 RGWOpType op_type; ... enum http_op { OP_GET, OP_PUT, OP_DELETE, OP_HEAD, OP_POST, OP_COPY, OP_OPTIONS, OP_UNKNOWN, };
理解整個(gè)URL轉(zhuǎn)換handler的過(guò)程,能夠感覺(jué)request信息快速定位具體的op操作,方便debug,整個(gè)過(guò)程用下面一張圖總結(jié)。
感謝各位的閱讀,以上就是“RGW中request的處理流程是什么”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)RGW中request的處理流程是什么這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
名稱欄目:RGW中request的處理流程是什么
文章來(lái)源:http://aaarwkj.com/article0/iipgoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、外貿(mào)建站、電子商務(wù)、網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、軟件開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)