小編給大家分享一下ceph中l(wèi)ibrados接口怎么用,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
成都創(chuàng)新互聯(lián)公司是專業(yè)的富民網(wǎng)站建設(shè)公司,富民接單;提供網(wǎng)站設(shè)計制作、網(wǎng)站設(shè)計,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行富民網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
rados_getxattr獲取對象屬性
rados_getxattrs獲取對象屬性列表
rados_getxattrs_next從獲取的對象屬性列表中讀取值
rados_getxattrs_end釋放rados_getxattrs獲取的指針
rados_setxattr設(shè)置對象的自定義屬性
rados_rmxattr刪除對象的自定義屬性
rados_stat返回對象的時間、大小
rados_tmap_update
rados_tmap_put
rados_tmap_get
rados_tmap_to_omap
使用示例
#include <rados/librados.hpp>
#include <string>
#include <list>
int main(int argc, const char **argv)
{
int ret = 0 ;
/*
* Errors are not checked to avoid pollution.
* After each Ceph operation:
* if (ret < 0) error_condition
* else success
*/
// Get cluster handle and connect to cluster
std::string cluster_name("ceph");
std::string user_name("client.admin");
librados::Rados cluster ;
cluster.init2(user_name.c_str(), cluster_name.c_str(), 0);
cluster.conf_read_file("/etc/ceph/ceph.conf");
cluster.connect();
// IO context
librados::IoCtx io_ctx ;
std::string pool_name("data");
cluster.ioctx_create(pool_name.c_str(), io_ctx);
// Write an object synchronously
librados::bufferlist bl;
std::string objectId("hw");
std::string objectContent("Hello World!");
bl.append(objectContent);
io_ctx.write(objectId, bl, objectContent.size(), 0);
// Add an xattr to the object.
librados::bufferlist lang_bl;
lang_bl.append("en_US");
io_ctx.setxattr(objectId, "lang", lang_bl);
// Read the object back asynchronously
librados::bufferlist read_buf;
int read_len = 4194304;
//Create I/O Completion.
librados::AioCompletion *read_completion = librados::Rados::aio_create_completion();
//Send read request.
io_ctx.aio_read(objectId, read_completion, &read_buf, read_len, 0 );
// Wait for the request to complete, and print content
read_completion->wait_for_complete();
read_completion->get_return_value();
std::cout<< "Object name: " << objectId << "\n"
<< "Content: " << read_buf.c_str() << std::endl ;
// Read the xattr.
librados::bufferlist lang_res;
io_ctx.getxattr(objectId, "lang", lang_res);
std::cout<< "Object xattr: " << lang_res.c_str() << std::endl ;
// Print the list of pools
std::list<std::string> pools ;
cluster.pool_list(pools );
std::cout << "List of pools from this cluster handle" << std::endl ;
for (std::list<std::string>::iterator i = pools.begin(); i != pools.end(); ++i)
std::cout << *i << std::endl;
// Print the list of objects
librados::ObjectIterator oit=io_ctx.objects_begin();
librados::ObjectIterator oet=io_ctx.objects_end();
std::cout<< "List of objects from this pool" << std::endl ;
for(; oit!= oet; oit++ ) {
std::cout << "\t" << oit->first << std::endl ;
}
// Remove the xattr
io_ctx.rmxattr(objectId, "lang");
// Remove the object.
io_ctx.remove(objectId);
// Cleanup
io_ctx.close();
cluster.shutdown();
return 0 ;
}
保存為cephrados.cpp,編譯命令行如下
g++ cephrados.cpp -lrados -o cephrados
rados getxattr rbd.py lang -p data顯示data池中對象rbd.py的擴展屬性lang的值
rados listxattr -p data rbd.py顯示data池中對象rbd.py的擴展屬性,如果沒有設(shè)置顯示為空
rados stat rbd.py -p data 顯示data池中對象rbd.py的大小、時間
以上是“ceph中l(wèi)ibrados接口怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
網(wǎng)站名稱:ceph中l(wèi)ibrados接口怎么用
瀏覽路徑:http://chinadenli.net/article38/gphdsp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、建站公司、網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)