Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use librados Interface in ceph

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you how to use the librados interface in ceph, I believe most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's learn about it!

Rados_getxattr gets object properties

Rados_getxattrs gets the list of object attributes

Rados_getxattrs_next reads values from the acquired list of object properties

Rados_getxattrs_end releases the pointer obtained by rados_getxattrs

Rados_setxattr sets the custom properties of an object

Rados_rmxattr deletes custom properties of an object

Rados_stat returns the time and size of the object

Rados_tmap_update

Rados_tmap_put

Rados_tmap_get

Rados_tmap_to_omap

Use the example

# include

# include

# include

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report