Skip to content

Commit e3a6680

Browse files
committed
os: get rid of the Transaction::decode_bp()
`os::Transaction::decode_bp()` has only one user: `_setattrs()` of `BlueStore`. It uses that for optimization purposes: keeping up contigous space instead of potentially fragmented `bufferlist` that would require rectifying memcpy later. The problem is `_setattrs()` also needs to avoid keeping large raw buffers with only small subset being referenced. It achieves this by copying the data if `bufferptr:::is_partial()` returns `true`. However, this means the memcpy happens virtually always as it's hard to even imagine the `val`, decoded from the wire, can fulfill the 0 waste requirement. Therefore the optimization doesn't make sense; it only imposes costs in terms of complexity breaking the symmetry between encode and decode in `os::Transation` (there is no `encode_bp()`). This commit kills the optimization and simplifies `os::Transaction`. Signed-off-by: Radoslaw Zarzynski <[email protected]>
1 parent 327d209 commit e3a6680

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/os/Transaction.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -711,10 +711,6 @@ class Transaction {
711711
decode(s, data_bl_p);
712712
return s;
713713
}
714-
void decode_bp(ceph::buffer::ptr& bp) {
715-
using ceph::decode;
716-
decode(bp, data_bl_p);
717-
}
718714
void decode_bl(ceph::buffer::list& bl) {
719715
using ceph::decode;
720716
decode(bl, data_bl_p);

src/os/bluestore/BlueStore.cc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15690,9 +15690,9 @@ void BlueStore::_txc_add_transaction(TransContext *txc, Transaction *t)
1569015690
case Transaction::OP_SETATTR:
1569115691
{
1569215692
string name = i.decode_string();
15693-
bufferptr bp;
15694-
i.decode_bp(bp);
15695-
r = _setattr(txc, c, o, name, bp);
15693+
bufferlist bl;
15694+
i.decode_bl(bl);
15695+
r = _setattr(txc, c, o, name, bl);
1569615696
}
1569715697
break;
1569815698

@@ -17733,18 +17733,22 @@ int BlueStore::_setattr(TransContext *txc,
1773317733
CollectionRef& c,
1773417734
OnodeRef& o,
1773517735
const string& name,
17736-
bufferptr& val)
17736+
bufferlist& val)
1773717737
{
1773817738
dout(15) << __func__ << " " << c->cid << " " << o->oid
1773917739
<< " " << name << " (" << val.length() << " bytes)"
1774017740
<< dendl;
1774117741
int r = 0;
17742-
if (val.is_partial()) {
17743-
auto& b = o->onode.attrs[name.c_str()] = bufferptr(val.c_str(),
17744-
val.length());
17742+
if (!val.length()) {
17743+
auto& b = o->onode.attrs[name.c_str()] = bufferptr("", 0);
1774517744
b.reassign_to_mempool(mempool::mempool_bluestore_cache_meta);
17746-
} else {
17747-
auto& b = o->onode.attrs[name.c_str()] = val;
17745+
} else if (!val.is_contiguous()) {
17746+
val.rebuild();
17747+
auto& b = o->onode.attrs[name.c_str()] = val.front();
17748+
b.reassign_to_mempool(mempool::mempool_bluestore_cache_meta);
17749+
} else if (val.front().is_partial()) {
17750+
val.rebuild();
17751+
auto& b = o->onode.attrs[name.c_str()] = val.front();
1774817752
b.reassign_to_mempool(mempool::mempool_bluestore_cache_meta);
1774917753
}
1775017754
txc->write_onode(o);

src/os/bluestore/BlueStore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3862,7 +3862,7 @@ class BlueStore : public ObjectStore,
38623862
CollectionRef& c,
38633863
OnodeRef& o,
38643864
const std::string& name,
3865-
ceph::buffer::ptr& val);
3865+
ceph::buffer::list& val);
38663866
int _setattrs(TransContext *txc,
38673867
CollectionRef& c,
38683868
OnodeRef& o,

0 commit comments

Comments
 (0)