mirror of https://github.com/ceph/ceph
librados: remove rados_tmap_*
we have switched from tmap to omap long ago. but keep the server side implementation around, in case ancient client is still using these tmap APIs. also, tmap_update() is kept, because librbd is using it for v1 image backward compatibility. Signed-off-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
parent
0a03a4e5c1
commit
0e5bdd9d56
|
@ -145,13 +145,6 @@
|
|||
:Default: ``true``
|
||||
|
||||
|
||||
``mds use tmap``
|
||||
|
||||
:Description: Use trivialmap for directory updates.
|
||||
:Type: Boolean
|
||||
:Default: ``true``
|
||||
|
||||
|
||||
``mds default dir hash``
|
||||
|
||||
:Description: The function to use for hashing files across directory fragments.
|
||||
|
|
|
@ -1050,20 +1050,6 @@ Miscellaneous
|
|||
:Default: ``256``
|
||||
|
||||
|
||||
``osd auto upgrade tmap``
|
||||
|
||||
:Description: Uses ``tmap`` for ``omap`` on old objects.
|
||||
:Type: Boolean
|
||||
:Default: ``true``
|
||||
|
||||
|
||||
``osd tmapput sets users tmap``
|
||||
|
||||
:Description: Uses ``tmap`` for debugging only.
|
||||
:Type: Boolean
|
||||
:Default: ``false``
|
||||
|
||||
|
||||
``osd fast fail on connection refused``
|
||||
|
||||
:Description: If this option is enabled, crashed OSDs are marked down
|
||||
|
|
|
@ -444,14 +444,6 @@ OSD
|
|||
:Default: 1
|
||||
|
||||
|
||||
``osd tmapput sets uses tmap``
|
||||
|
||||
:Description: Uses ``tmap``. For debug only.
|
||||
:Type: Boolean
|
||||
:Required: No
|
||||
:Default: ``false``
|
||||
|
||||
|
||||
``osd min pg log entries``
|
||||
|
||||
:Description: The minimum number of log entries for placement groups.
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
#!/bin/sh -ex
|
||||
|
||||
expect_false()
|
||||
{
|
||||
set -x
|
||||
if "$@"; then return 1; else return 0; fi
|
||||
}
|
||||
|
||||
pool="pool-$$"
|
||||
ceph osd pool create $pool 8
|
||||
|
||||
rados -p $pool tmap set foo key1 value1
|
||||
rados -p $pool tmap set foo key2 value2
|
||||
rados -p $pool tmap set foo key2 value2
|
||||
rados -p $pool tmap dump foo | grep key1
|
||||
rados -p $pool tmap dump foo | grep key2
|
||||
rados -p $pool tmap-to-omap foo
|
||||
expect_false rados -p $pool tmap dump foo
|
||||
expect_false rados -p $pool tmap dump foo
|
||||
|
||||
rados -p $pool listomapkeys foo | grep key1
|
||||
rados -p $pool listomapkeys foo | grep key2
|
||||
rados -p $pool getomapval foo key1 | grep value1
|
||||
rados -p $pool getomapval foo key2 | grep value2
|
||||
|
||||
ceph osd pool rm $pool $pool --yes-i-really-really-mean-it
|
||||
|
||||
echo OK
|
|
@ -1790,97 +1790,6 @@ CEPH_RADOS_API void rados_omap_get_end(rados_omap_iter_t iter);
|
|||
*/
|
||||
CEPH_RADOS_API int rados_stat(rados_ioctx_t io, const char *o, uint64_t *psize,
|
||||
time_t *pmtime);
|
||||
|
||||
/**
|
||||
* Update tmap (trivial map)
|
||||
*
|
||||
* Do compound update to a tmap object, inserting or deleting some
|
||||
* number of records. cmdbuf is a series of operation byte
|
||||
* codes, following by command payload. Each command is a single-byte
|
||||
* command code, whose value is one of CEPH_OSD_TMAP_*.
|
||||
*
|
||||
* - update tmap 'header'
|
||||
* - 1 byte = CEPH_OSD_TMAP_HDR
|
||||
* - 4 bytes = data length (little endian)
|
||||
* - N bytes = data
|
||||
*
|
||||
* - insert/update one key/value pair
|
||||
* - 1 byte = CEPH_OSD_TMAP_SET
|
||||
* - 4 bytes = key name length (little endian)
|
||||
* - N bytes = key name
|
||||
* - 4 bytes = data length (little endian)
|
||||
* - M bytes = data
|
||||
*
|
||||
* - insert one key/value pair; return -EEXIST if it already exists.
|
||||
* - 1 byte = CEPH_OSD_TMAP_CREATE
|
||||
* - 4 bytes = key name length (little endian)
|
||||
* - N bytes = key name
|
||||
* - 4 bytes = data length (little endian)
|
||||
* - M bytes = data
|
||||
*
|
||||
* - remove one key/value pair
|
||||
* - 1 byte = CEPH_OSD_TMAP_RM
|
||||
* - 4 bytes = key name length (little endian)
|
||||
* - N bytes = key name
|
||||
*
|
||||
* Restrictions:
|
||||
* - The HDR update must precede any key/value updates.
|
||||
* - All key/value updates must be in lexicographically sorted order
|
||||
* in cmdbuf.
|
||||
* - You can read/write to a tmap object via the regular APIs, but
|
||||
* you should be careful not to corrupt it. Also be aware that the
|
||||
* object format may change without notice.
|
||||
*
|
||||
* @param io ioctx
|
||||
* @param o object name
|
||||
* @param cmdbuf command buffer
|
||||
* @param cmdbuflen command buffer length in bytes
|
||||
* @returns 0 on success, negative error code on failure
|
||||
*/
|
||||
CEPH_RADOS_API int rados_tmap_update(rados_ioctx_t io, const char *o,
|
||||
const char *cmdbuf, size_t cmdbuflen);
|
||||
|
||||
/**
|
||||
* Store complete tmap (trivial map) object
|
||||
*
|
||||
* Put a full tmap object into the store, replacing what was there.
|
||||
*
|
||||
* The format of buf is:
|
||||
* - 4 bytes - length of header (little endian)
|
||||
* - N bytes - header data
|
||||
* - 4 bytes - number of keys (little endian)
|
||||
*
|
||||
* and for each key,
|
||||
* - 4 bytes - key name length (little endian)
|
||||
* - N bytes - key name
|
||||
* - 4 bytes - value length (little endian)
|
||||
* - M bytes - value data
|
||||
*
|
||||
* @param io ioctx
|
||||
* @param o object name
|
||||
* @param buf buffer
|
||||
* @param buflen buffer length in bytes
|
||||
* @returns 0 on success, negative error code on failure
|
||||
*/
|
||||
CEPH_RADOS_API int rados_tmap_put(rados_ioctx_t io, const char *o,
|
||||
const char *buf, size_t buflen);
|
||||
|
||||
/**
|
||||
* Fetch complete tmap (trivial map) object
|
||||
*
|
||||
* Read a full tmap object. See rados_tmap_put() for the format the
|
||||
* data is returned in.
|
||||
*
|
||||
* @param io ioctx
|
||||
* @param o object name
|
||||
* @param buf buffer
|
||||
* @param buflen buffer length in bytes
|
||||
* @returns 0 on success, negative error code on failure
|
||||
* @returns -ERANGE if buf isn't big enough
|
||||
*/
|
||||
CEPH_RADOS_API int rados_tmap_get(rados_ioctx_t io, const char *o, char *buf,
|
||||
size_t buflen);
|
||||
|
||||
/**
|
||||
* Execute an OSD class method on an object
|
||||
*
|
||||
|
|
|
@ -504,7 +504,6 @@ namespace librados
|
|||
*/
|
||||
void sparse_read(uint64_t off, uint64_t len, std::map<uint64_t,uint64_t> *m,
|
||||
bufferlist *data_bl, int *prval);
|
||||
void tmap_get(bufferlist *pbl, int *prval);
|
||||
|
||||
/**
|
||||
* omap_get_vals: keys and values from the object omap
|
||||
|
@ -788,14 +787,6 @@ namespace librados
|
|||
* NOTE: this call steals the contents of @param bl
|
||||
*/
|
||||
int tmap_update(const std::string& oid, bufferlist& cmdbl);
|
||||
/**
|
||||
* replace object contents with provided encoded tmap data
|
||||
*
|
||||
* NOTE: this call steals the contents of @param bl
|
||||
*/
|
||||
int tmap_put(const std::string& oid, bufferlist& bl);
|
||||
int tmap_get(const std::string& oid, bufferlist& bl);
|
||||
int tmap_to_omap(const std::string& oid, bool nullok=false);
|
||||
|
||||
int omap_get_vals(const std::string& oid,
|
||||
const std::string& start_after,
|
||||
|
|
|
@ -1321,30 +1321,6 @@ int librados::IoCtxImpl::tmap_update(const object_t& oid, bufferlist& cmdbl)
|
|||
return operate(oid, &wr, NULL);
|
||||
}
|
||||
|
||||
int librados::IoCtxImpl::tmap_put(const object_t& oid, bufferlist& bl)
|
||||
{
|
||||
::ObjectOperation wr;
|
||||
prepare_assert_ops(&wr);
|
||||
wr.tmap_put(bl);
|
||||
return operate(oid, &wr, NULL);
|
||||
}
|
||||
|
||||
int librados::IoCtxImpl::tmap_get(const object_t& oid, bufferlist& bl)
|
||||
{
|
||||
::ObjectOperation rd;
|
||||
prepare_assert_ops(&rd);
|
||||
rd.tmap_get(&bl, NULL);
|
||||
return operate_read(oid, &rd, NULL);
|
||||
}
|
||||
|
||||
int librados::IoCtxImpl::tmap_to_omap(const object_t& oid, bool nullok)
|
||||
{
|
||||
::ObjectOperation wr;
|
||||
prepare_assert_ops(&wr);
|
||||
wr.tmap_to_omap(nullok);
|
||||
return operate(oid, &wr, NULL);
|
||||
}
|
||||
|
||||
int librados::IoCtxImpl::exec(const object_t& oid,
|
||||
const char *cls, const char *method,
|
||||
bufferlist& inbl, bufferlist& outbl)
|
||||
|
|
|
@ -143,9 +143,6 @@ struct librados::IoCtxImpl {
|
|||
int cmpext(const object_t& oid, uint64_t off, bufferlist& cmp_bl);
|
||||
|
||||
int tmap_update(const object_t& oid, bufferlist& cmdbl);
|
||||
int tmap_put(const object_t& oid, bufferlist& bl);
|
||||
int tmap_get(const object_t& oid, bufferlist& bl);
|
||||
int tmap_to_omap(const object_t& oid, bool nullok=false);
|
||||
|
||||
int exec(const object_t& oid, const char *cls, const char *method, bufferlist& inbl, bufferlist& outbl);
|
||||
|
||||
|
|
|
@ -1665,61 +1665,6 @@ extern "C" int rados_stat(rados_ioctx_t io, const char *o, uint64_t *psize, time
|
|||
return retval;
|
||||
}
|
||||
|
||||
extern "C" int rados_tmap_update(rados_ioctx_t io, const char *o, const char *cmdbuf, size_t cmdbuflen)
|
||||
{
|
||||
tracepoint(librados, rados_tmap_update_enter, io, o, cmdbuf, cmdbuflen);
|
||||
librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
|
||||
object_t oid(o);
|
||||
bufferlist cmdbl;
|
||||
cmdbl.append(cmdbuf, cmdbuflen);
|
||||
int retval = ctx->tmap_update(oid, cmdbl);
|
||||
tracepoint(librados, rados_tmap_update_exit, retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
extern "C" int rados_tmap_put(rados_ioctx_t io, const char *o, const char *buf, size_t buflen)
|
||||
{
|
||||
tracepoint(librados, rados_tmap_put_enter, io, o, buf, buflen);
|
||||
librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
|
||||
object_t oid(o);
|
||||
bufferlist bl;
|
||||
bl.append(buf, buflen);
|
||||
int retval = ctx->tmap_put(oid, bl);
|
||||
tracepoint(librados, rados_tmap_put_exit, retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
extern "C" int rados_tmap_get(rados_ioctx_t io, const char *o, char *buf, size_t buflen)
|
||||
{
|
||||
tracepoint(librados, rados_tmap_get_enter, io, o, buflen);
|
||||
librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
|
||||
object_t oid(o);
|
||||
bufferlist bl;
|
||||
int r = ctx->tmap_get(oid, bl);
|
||||
if (r < 0) {
|
||||
tracepoint(librados, rados_tmap_get_exit, r, buf, 0);
|
||||
return r;
|
||||
}
|
||||
if (bl.length() > buflen) {
|
||||
tracepoint(librados, rados_tmap_get_exit, -ERANGE, buf, 0);
|
||||
return -ERANGE;
|
||||
}
|
||||
bl.copy(0, bl.length(), buf);
|
||||
int retval = bl.length();
|
||||
tracepoint(librados, rados_tmap_get_exit, retval, buf, retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
extern "C" int rados_tmap_to_omap(rados_ioctx_t io, const char *o, bool nullok)
|
||||
{
|
||||
tracepoint(librados, rados_tmap_to_omap_enter, io, o, nullok);
|
||||
librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
|
||||
object_t oid(o);
|
||||
int retval = ctx->tmap_to_omap(oid, nullok);
|
||||
tracepoint(librados, rados_tmap_to_omap_exit, retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
extern "C" int rados_exec(rados_ioctx_t io, const char *o, const char *cls, const char *method,
|
||||
const char *inbuf, size_t in_len, char *buf, size_t out_len)
|
||||
{
|
||||
|
|
|
@ -221,12 +221,6 @@ void librados::ObjectReadOperation::checksum(rados_checksum_type_t type,
|
|||
pbl, prval, nullptr);
|
||||
}
|
||||
|
||||
void librados::ObjectReadOperation::tmap_get(bufferlist *pbl, int *prval)
|
||||
{
|
||||
::ObjectOperation *o = &impl->o;
|
||||
o->tmap_get(pbl, prval);
|
||||
}
|
||||
|
||||
void librados::ObjectReadOperation::getxattr(const char *name, bufferlist *pbl, int *prval)
|
||||
{
|
||||
::ObjectOperation *o = &impl->o;
|
||||
|
@ -600,13 +594,6 @@ void librados::ObjectWriteOperation::unset_manifest()
|
|||
o->unset_manifest();
|
||||
}
|
||||
|
||||
void librados::ObjectWriteOperation::tmap_put(const bufferlist &bl)
|
||||
{
|
||||
::ObjectOperation *o = &impl->o;
|
||||
bufferlist c = bl;
|
||||
o->tmap_put(c);
|
||||
}
|
||||
|
||||
void librados::ObjectWriteOperation::tmap_update(const bufferlist& cmdbl)
|
||||
{
|
||||
::ObjectOperation *o = &impl->o;
|
||||
|
@ -1266,24 +1253,6 @@ int librados::IoCtx::tmap_update(const std::string& oid, bufferlist& cmdbl)
|
|||
return io_ctx_impl->tmap_update(obj, cmdbl);
|
||||
}
|
||||
|
||||
int librados::IoCtx::tmap_put(const std::string& oid, bufferlist& bl)
|
||||
{
|
||||
object_t obj(oid);
|
||||
return io_ctx_impl->tmap_put(obj, bl);
|
||||
}
|
||||
|
||||
int librados::IoCtx::tmap_get(const std::string& oid, bufferlist& bl)
|
||||
{
|
||||
object_t obj(oid);
|
||||
return io_ctx_impl->tmap_get(obj, bl);
|
||||
}
|
||||
|
||||
int librados::IoCtx::tmap_to_omap(const std::string& oid, bool nullok)
|
||||
{
|
||||
object_t obj(oid);
|
||||
return io_ctx_impl->tmap_to_omap(obj, nullok);
|
||||
}
|
||||
|
||||
int librados::IoCtx::omap_get_vals(const std::string& oid,
|
||||
const std::string& start_after,
|
||||
uint64_t max_return,
|
||||
|
|
|
@ -98,9 +98,6 @@ enum {
|
|||
l_osdc_osdop_cmpxattr,
|
||||
l_osdc_osdop_rmxattr,
|
||||
l_osdc_osdop_resetxattrs,
|
||||
l_osdc_osdop_tmap_up,
|
||||
l_osdc_osdop_tmap_put,
|
||||
l_osdc_osdop_tmap_get,
|
||||
l_osdc_osdop_call,
|
||||
l_osdc_osdop_watch,
|
||||
l_osdc_osdop_notify,
|
||||
|
@ -292,12 +289,6 @@ void Objecter::init()
|
|||
"Remove xattr operations");
|
||||
pcb.add_u64_counter(l_osdc_osdop_resetxattrs, "osdop_resetxattrs",
|
||||
"Reset xattr operations");
|
||||
pcb.add_u64_counter(l_osdc_osdop_tmap_up, "osdop_tmap_up",
|
||||
"TMAP update operations");
|
||||
pcb.add_u64_counter(l_osdc_osdop_tmap_put, "osdop_tmap_put",
|
||||
"TMAP put operations");
|
||||
pcb.add_u64_counter(l_osdc_osdop_tmap_get, "osdop_tmap_get",
|
||||
"TMAP get operations");
|
||||
pcb.add_u64_counter(l_osdc_osdop_call, "osdop_call",
|
||||
"Call (execute) operations");
|
||||
pcb.add_u64_counter(l_osdc_osdop_watch, "osdop_watch",
|
||||
|
@ -2350,9 +2341,6 @@ void Objecter::_send_op_account(Op *op)
|
|||
case CEPH_OSD_OP_CMPXATTR: code = l_osdc_osdop_cmpxattr; break;
|
||||
case CEPH_OSD_OP_RMXATTR: code = l_osdc_osdop_rmxattr; break;
|
||||
case CEPH_OSD_OP_RESETXATTRS: code = l_osdc_osdop_resetxattrs; break;
|
||||
case CEPH_OSD_OP_TMAPUP: code = l_osdc_osdop_tmap_up; break;
|
||||
case CEPH_OSD_OP_TMAPPUT: code = l_osdc_osdop_tmap_put; break;
|
||||
case CEPH_OSD_OP_TMAPGET: code = l_osdc_osdop_tmap_get; break;
|
||||
|
||||
// OMAP read operations
|
||||
case CEPH_OSD_OP_OMAPGETVALS:
|
||||
|
|
|
@ -626,23 +626,6 @@ struct ObjectOperation {
|
|||
void tmap_update(bufferlist& bl) {
|
||||
add_data(CEPH_OSD_OP_TMAPUP, 0, 0, bl);
|
||||
}
|
||||
void tmap_put(bufferlist& bl) {
|
||||
add_data(CEPH_OSD_OP_TMAPPUT, 0, bl.length(), bl);
|
||||
}
|
||||
void tmap_get(bufferlist *pbl, int *prval) {
|
||||
add_op(CEPH_OSD_OP_TMAPGET);
|
||||
unsigned p = ops.size() - 1;
|
||||
out_bl[p] = pbl;
|
||||
out_rval[p] = prval;
|
||||
}
|
||||
void tmap_get() {
|
||||
add_op(CEPH_OSD_OP_TMAPGET);
|
||||
}
|
||||
void tmap_to_omap(bool nullok=false) {
|
||||
OSDOp& osd_op = add_op(CEPH_OSD_OP_TMAP2OMAP);
|
||||
if (nullok)
|
||||
osd_op.op.tmap2omap.flags = CEPH_OSD_TMAP2OMAP_NULLOK;
|
||||
}
|
||||
|
||||
// objectmap
|
||||
void omap_get_keys(const string &start_after,
|
||||
|
|
|
@ -142,242 +142,6 @@ TEST_F(LibRadosMiscPP, LongAttrNamePP) {
|
|||
ASSERT_EQ(-ENAMETOOLONG, ioctx.setxattr("bigattrobj", string(maxlen*2, 'a').c_str(), bl));
|
||||
}
|
||||
|
||||
static std::string read_key_from_tmap(IoCtx& ioctx, const std::string &obj,
|
||||
const std::string &key)
|
||||
{
|
||||
bufferlist bl;
|
||||
int r = ioctx.read(obj, bl, 0, 0);
|
||||
if (r <= 0) {
|
||||
ostringstream oss;
|
||||
oss << "ioctx.read(" << obj << ", bl, 0, 0) returned " << r;
|
||||
return oss.str();
|
||||
}
|
||||
auto p = bl.cbegin();
|
||||
bufferlist header;
|
||||
map<string, bufferlist> m;
|
||||
decode(header, p);
|
||||
decode(m, p);
|
||||
map<string, bufferlist>::iterator i = m.find(key);
|
||||
if (i == m.end())
|
||||
return "";
|
||||
std::string retstring;
|
||||
decode(retstring, i->second);
|
||||
return retstring;
|
||||
}
|
||||
|
||||
static std::string add_key_to_tmap(IoCtx &ioctx, const std::string &obj,
|
||||
const std::string &key, const std::string &val)
|
||||
{
|
||||
__u8 c = CEPH_OSD_TMAP_SET;
|
||||
|
||||
bufferlist tmbl;
|
||||
encode(c, tmbl);
|
||||
encode(key, tmbl);
|
||||
bufferlist blbl;
|
||||
encode(val, blbl);
|
||||
encode(blbl, tmbl);
|
||||
int ret = ioctx.tmap_update(obj, tmbl);
|
||||
if (ret) {
|
||||
ostringstream oss;
|
||||
oss << "ioctx.tmap_update(obj=" << obj << ", key="
|
||||
<< key << ", val=" << val << ") failed with error " << ret;
|
||||
return oss.str();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static int remove_key_from_tmap(IoCtx &ioctx, const std::string &obj,
|
||||
const std::string &key)
|
||||
{
|
||||
__u8 c = CEPH_OSD_TMAP_RM;
|
||||
|
||||
bufferlist tmbl;
|
||||
encode(c, tmbl);
|
||||
encode(key, tmbl);
|
||||
int ret = ioctx.tmap_update(obj, tmbl);
|
||||
if (ret) {
|
||||
ostringstream oss;
|
||||
oss << "ioctx.tmap_update(obj=" << obj << ", key="
|
||||
<< key << ") failed with error " << ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
TEST_F(LibRadosMiscPP, TmapUpdatePP) {
|
||||
// create tmap
|
||||
{
|
||||
__u8 c = CEPH_OSD_TMAP_CREATE;
|
||||
std::string my_tmap("my_tmap");
|
||||
bufferlist emptybl;
|
||||
|
||||
bufferlist tmbl;
|
||||
encode(c, tmbl);
|
||||
encode(my_tmap, tmbl);
|
||||
encode(emptybl, tmbl);
|
||||
ASSERT_EQ(0, ioctx.tmap_update("foo", tmbl));
|
||||
}
|
||||
|
||||
ASSERT_EQ(string(""), add_key_to_tmap(ioctx, "foo", "key1", "val1"));
|
||||
|
||||
ASSERT_EQ(string(""), add_key_to_tmap(ioctx, "foo", "key2", "val2"));
|
||||
|
||||
// read key1 from the tmap
|
||||
ASSERT_EQ(string("val1"), read_key_from_tmap(ioctx, "foo", "key1"));
|
||||
|
||||
// remove key1 from tmap
|
||||
ASSERT_EQ(0, remove_key_from_tmap(ioctx, "foo", "key1"));
|
||||
ASSERT_EQ(-ENOENT, remove_key_from_tmap(ioctx, "foo", "key1"));
|
||||
|
||||
// key should be removed
|
||||
ASSERT_EQ(string(""), read_key_from_tmap(ioctx, "foo", "key1"));
|
||||
}
|
||||
|
||||
TEST_F(LibRadosMiscPP, TmapUpdateMisorderedPP) {
|
||||
// create tmap
|
||||
{
|
||||
__u8 c = CEPH_OSD_TMAP_CREATE;
|
||||
std::string my_tmap("my_tmap");
|
||||
bufferlist emptybl;
|
||||
|
||||
bufferlist tmbl;
|
||||
encode(c, tmbl);
|
||||
encode(my_tmap, tmbl);
|
||||
encode(emptybl, tmbl);
|
||||
ASSERT_EQ(0, ioctx.tmap_update("foo", tmbl));
|
||||
}
|
||||
|
||||
// good update
|
||||
{
|
||||
__u8 c = CEPH_OSD_TMAP_SET;
|
||||
bufferlist tmbl;
|
||||
encode(c, tmbl);
|
||||
encode("a", tmbl);
|
||||
bufferlist blbl;
|
||||
encode("old", blbl);
|
||||
encode(blbl, tmbl);
|
||||
|
||||
encode(c, tmbl);
|
||||
encode("b", tmbl);
|
||||
encode(blbl, tmbl);
|
||||
|
||||
encode(c, tmbl);
|
||||
encode("c", tmbl);
|
||||
encode(blbl, tmbl);
|
||||
|
||||
ASSERT_EQ(0, ioctx.tmap_update("foo", tmbl));
|
||||
}
|
||||
|
||||
// bad update
|
||||
{
|
||||
__u8 c = CEPH_OSD_TMAP_SET;
|
||||
bufferlist tmbl;
|
||||
encode(c, tmbl);
|
||||
encode("b", tmbl);
|
||||
bufferlist blbl;
|
||||
encode("new", blbl);
|
||||
encode(blbl, tmbl);
|
||||
|
||||
encode(c, tmbl);
|
||||
encode("a", tmbl);
|
||||
encode(blbl, tmbl);
|
||||
|
||||
encode(c, tmbl);
|
||||
encode("c", tmbl);
|
||||
encode(blbl, tmbl);
|
||||
|
||||
ASSERT_EQ(0, ioctx.tmap_update("foo", tmbl));
|
||||
}
|
||||
|
||||
// check
|
||||
ASSERT_EQ(string("new"), read_key_from_tmap(ioctx, "foo", "a"));
|
||||
ASSERT_EQ(string("new"), read_key_from_tmap(ioctx, "foo", "b"));
|
||||
ASSERT_EQ(string("new"), read_key_from_tmap(ioctx, "foo", "c"));
|
||||
|
||||
ASSERT_EQ(0, remove_key_from_tmap(ioctx, "foo", "a"));
|
||||
ASSERT_EQ(string(""), read_key_from_tmap(ioctx, "foo", "a"));
|
||||
|
||||
ASSERT_EQ(0, remove_key_from_tmap(ioctx, "foo", "b"));
|
||||
ASSERT_EQ(string(""), read_key_from_tmap(ioctx, "foo", "a"));
|
||||
}
|
||||
|
||||
TEST_F(LibRadosMiscPP, TmapUpdateMisorderedPutPP) {
|
||||
// create unsorted tmap
|
||||
string h("header");
|
||||
bufferlist bl;
|
||||
encode(h, bl);
|
||||
uint32_t n = 3;
|
||||
encode(n, bl);
|
||||
encode(string("b"), bl);
|
||||
encode(string("bval"), bl);
|
||||
encode(string("a"), bl);
|
||||
encode(string("aval"), bl);
|
||||
encode(string("c"), bl);
|
||||
encode(string("cval"), bl);
|
||||
bufferlist orig = bl; // tmap_put steals bl content
|
||||
ASSERT_EQ(0, ioctx.tmap_put("foo", bl));
|
||||
|
||||
// check
|
||||
bufferlist newbl;
|
||||
ioctx.read("foo", newbl, orig.length(), 0);
|
||||
ASSERT_EQ(orig.contents_equal(newbl), false);
|
||||
}
|
||||
|
||||
TEST_F(LibRadosMiscPP, Tmap2OmapPP) {
|
||||
// create tmap
|
||||
bufferlist hdr;
|
||||
hdr.append("header");
|
||||
map<string, bufferlist> omap;
|
||||
omap["1"].append("a");
|
||||
omap["2"].append("b");
|
||||
omap["3"].append("c");
|
||||
{
|
||||
bufferlist bl;
|
||||
encode(hdr, bl);
|
||||
encode(omap, bl);
|
||||
ASSERT_EQ(0, ioctx.tmap_put("foo", bl));
|
||||
}
|
||||
|
||||
// convert tmap to omap
|
||||
ASSERT_EQ(0, ioctx.tmap_to_omap("foo", false));
|
||||
|
||||
// if tmap was truncated ?
|
||||
{
|
||||
uint64_t size;
|
||||
time_t mtime;
|
||||
ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime));
|
||||
ASSERT_EQ(0U, size);
|
||||
}
|
||||
|
||||
// if 'nullok' works
|
||||
ASSERT_EQ(0, ioctx.tmap_to_omap("foo", true));
|
||||
ASSERT_LE(ioctx.tmap_to_omap("foo", false), 0);
|
||||
|
||||
{
|
||||
// read omap
|
||||
bufferlist got;
|
||||
map<string, bufferlist> m;
|
||||
ObjectReadOperation o;
|
||||
o.omap_get_header(&got, NULL);
|
||||
o.omap_get_vals2("", 1024, &m, nullptr, nullptr);
|
||||
ASSERT_EQ(0, ioctx.operate("foo", &o, NULL));
|
||||
|
||||
// compare header
|
||||
ASSERT_TRUE(hdr.contents_equal(got));
|
||||
|
||||
// compare values
|
||||
ASSERT_EQ(omap.size(), m.size());
|
||||
bool same = true;
|
||||
for (map<string, bufferlist>::iterator p = omap.begin(); p != omap.end(); ++p) {
|
||||
map<string, bufferlist>::iterator q = m.find(p->first);
|
||||
if (q == m.end() || !p->second.contents_equal(q->second)) {
|
||||
same = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(same);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(LibRadosMiscPP, ExecPP) {
|
||||
bufferlist bl;
|
||||
ASSERT_EQ(0, ioctx.write("foo", bl, 0, 0));
|
||||
|
|
|
@ -120,7 +120,6 @@ void usage(ostream& out)
|
|||
" clearomap <obj-name> [obj-name2 obj-name3...] clear all the omap keys for the specified objects\n"
|
||||
" getomapheader <obj-name> [file]\n"
|
||||
" setomapheader <obj-name> <val>\n"
|
||||
" tmap-to-omap <obj-name> convert tmap keys/values to omap\n"
|
||||
" watch <obj-name> add watcher on this object\n"
|
||||
" notify <obj-name> <message> notify watcher of this object with message\n"
|
||||
" listwatchers <obj-name> list the watchers of this object\n"
|
||||
|
@ -2927,100 +2926,6 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
|
|||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
else if (strcmp(nargs[0], "tmap") == 0) {
|
||||
if (nargs.size() < 3)
|
||||
usage_exit();
|
||||
if (strcmp(nargs[1], "dump") == 0) {
|
||||
bufferlist outdata;
|
||||
string oid(nargs[2]);
|
||||
ret = io_ctx.read(oid, outdata, 0, 0);
|
||||
if (ret < 0) {
|
||||
cerr << "error reading " << pool_name << "/" << oid << ": " << cpp_strerror(ret) << std::endl;
|
||||
goto out;
|
||||
}
|
||||
auto p = outdata.cbegin();
|
||||
bufferlist header;
|
||||
map<string, bufferlist> kv;
|
||||
try {
|
||||
decode(header, p);
|
||||
decode(kv, p);
|
||||
}
|
||||
catch (buffer::error& e) {
|
||||
cerr << "error decoding tmap " << pool_name << "/" << oid << std::endl;
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
cout << "header (" << header.length() << " bytes):\n";
|
||||
header.hexdump(cout);
|
||||
cout << "\n";
|
||||
cout << kv.size() << " keys\n";
|
||||
for (map<string,bufferlist>::iterator q = kv.begin(); q != kv.end(); ++q) {
|
||||
cout << "key '" << q->first << "' (" << q->second.length() << " bytes):\n";
|
||||
q->second.hexdump(cout);
|
||||
cout << "\n";
|
||||
}
|
||||
}
|
||||
else if (strcmp(nargs[1], "set") == 0 ||
|
||||
strcmp(nargs[1], "create") == 0) {
|
||||
if (nargs.size() < 5)
|
||||
usage_exit();
|
||||
string oid(nargs[2]);
|
||||
string k(nargs[3]);
|
||||
string v(nargs[4]);
|
||||
bufferlist bl;
|
||||
char c = (strcmp(nargs[1], "set") == 0) ? CEPH_OSD_TMAP_SET : CEPH_OSD_TMAP_CREATE;
|
||||
encode(c, bl);
|
||||
encode(k, bl);
|
||||
encode(v, bl);
|
||||
ret = io_ctx.tmap_update(oid, bl);
|
||||
}
|
||||
}
|
||||
|
||||
else if (strcmp(nargs[0], "tmap-to-omap") == 0) {
|
||||
if (!pool_name || nargs.size() < 2)
|
||||
usage_exit();
|
||||
string oid(nargs[1]);
|
||||
|
||||
bufferlist bl;
|
||||
int r = io_ctx.tmap_get(oid, bl);
|
||||
if (r < 0) {
|
||||
ret = r;
|
||||
cerr << "error reading tmap " << pool_name << "/" << oid
|
||||
<< ": " << cpp_strerror(ret) << std::endl;
|
||||
goto out;
|
||||
}
|
||||
bufferlist hdr;
|
||||
map<string, bufferlist> kv;
|
||||
auto p = bl.cbegin();
|
||||
try {
|
||||
decode(hdr, p);
|
||||
decode(kv, p);
|
||||
}
|
||||
catch (buffer::error& e) {
|
||||
cerr << "error decoding tmap " << pool_name << "/" << oid << std::endl;
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if (!p.end()) {
|
||||
cerr << "error decoding tmap (stray trailing data) in " << pool_name << "/" << oid << std::endl;
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
librados::ObjectWriteOperation wr;
|
||||
wr.omap_set_header(hdr);
|
||||
wr.omap_set(kv);
|
||||
wr.truncate(0); // delete the old tmap data
|
||||
r = io_ctx.operate(oid, &wr);
|
||||
if (r < 0) {
|
||||
ret = r;
|
||||
cerr << "error writing tmap data as omap on " << pool_name << "/" << oid
|
||||
<< ": " << cpp_strerror(ret) << std::endl;
|
||||
goto out;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
else if (strcmp(nargs[0], "cppool") == 0) {
|
||||
bool force = nargs.size() == 4 && !strcmp(nargs[3], "--yes-i-really-mean-it");
|
||||
if (nargs.size() != 3 && !(nargs.size() == 4 && force))
|
||||
|
|
|
@ -1697,94 +1697,6 @@ TRACEPOINT_EVENT(librados, rados_stat_exit,
|
|||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT(librados, rados_tmap_update_enter,
|
||||
TP_ARGS(
|
||||
rados_ioctx_t, ioctx,
|
||||
const char*, oid,
|
||||
const char*, cmdbuf,
|
||||
size_t, cmdbuflen),
|
||||
TP_FIELDS(
|
||||
ctf_integer_hex(rados_ioctx_t, ioctx, ioctx)
|
||||
ctf_string(oid, oid)
|
||||
ctf_sequence(unsigned char, cmdbuf, cmdbuf, size_t, CEPH_MIN(cmdbuflen, CEPH_TRACE_BUF_TRUNC_LEN))
|
||||
ctf_integer(size_t, cmdbuflen, cmdbuflen)
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT(librados, rados_tmap_update_exit,
|
||||
TP_ARGS(
|
||||
int, retval),
|
||||
TP_FIELDS(
|
||||
ctf_integer(int, retval, retval)
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT(librados, rados_tmap_put_enter,
|
||||
TP_ARGS(
|
||||
rados_ioctx_t, ioctx,
|
||||
const char*, oid,
|
||||
const char*, buf,
|
||||
size_t, buflen),
|
||||
TP_FIELDS(
|
||||
ctf_integer_hex(rados_ioctx_t, ioctx, ioctx)
|
||||
ctf_string(oid, oid)
|
||||
ctf_sequence(unsigned char, buf, buf, size_t, CEPH_MIN(buflen, CEPH_TRACE_BUF_TRUNC_LEN))
|
||||
ctf_integer(size_t, buflen, buflen)
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT(librados, rados_tmap_put_exit,
|
||||
TP_ARGS(
|
||||
int, retval),
|
||||
TP_FIELDS(
|
||||
ctf_integer(int, retval, retval)
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT(librados, rados_tmap_get_enter,
|
||||
TP_ARGS(
|
||||
rados_ioctx_t, ioctx,
|
||||
const char*, oid,
|
||||
size_t, buflen),
|
||||
TP_FIELDS(
|
||||
ctf_integer_hex(rados_ioctx_t, ioctx, ioctx)
|
||||
ctf_string(oid, oid)
|
||||
ctf_integer(size_t, buflen, buflen)
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT(librados, rados_tmap_get_exit,
|
||||
TP_ARGS(
|
||||
int, retval,
|
||||
char*, buf,
|
||||
int, len),
|
||||
TP_FIELDS(
|
||||
ctf_integer(int, retval, retval)
|
||||
ctf_sequence(unsigned char, buf, buf, uint32_t, CEPH_MIN((size_t)len, CEPH_TRACE_BUF_TRUNC_LEN))
|
||||
ctf_integer(int, len, len)
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT(librados, rados_tmap_to_omap_enter,
|
||||
TP_ARGS(
|
||||
rados_ioctx_t, ioctx,
|
||||
const char*, oid,
|
||||
char, nullok),
|
||||
TP_FIELDS(
|
||||
ctf_integer_hex(rados_ioctx_t, ioctx, ioctx)
|
||||
ctf_string(oid, oid)
|
||||
ctf_integer(char, nullok, nullok)
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT(librados, rados_tmap_to_omap_exit,
|
||||
TP_ARGS(
|
||||
int, retval),
|
||||
TP_FIELDS(
|
||||
ctf_integer(int, retval, retval)
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT(librados, rados_exec_enter,
|
||||
TP_ARGS(
|
||||
rados_ioctx_t, ioctx,
|
||||
|
|
Loading…
Reference in New Issue