Skip to content

Commit

Permalink
buffer: add a 'deep' append mode
Browse files Browse the repository at this point in the history
Do the copy up-front.  This is useful if we know our target buffer must
be a contiguous buffer (e.g., because it will be passed to a kv store).

Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
liewegas committed Oct 16, 2016
1 parent 5ca65f5 commit f047d57
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions src/include/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,14 @@ namespace buffer CEPH_BUFFER_API {
bufferlist *pbl;
char *pos;
ptr bp;
bool deep;

/// running count of bytes appended that are not reflected by @pos
size_t out_of_band_offset = 0;

contiguous_appender(bufferlist *l, size_t len) : pbl(l) {
contiguous_appender(bufferlist *l, size_t len, bool d)
: pbl(l),
deep(d) {
size_t unused = pbl->append_buffer.unused_tail_length();
if (len > unused) {
// note: if len < the normal append_buffer size it *might*
Expand Down Expand Up @@ -537,14 +540,31 @@ namespace buffer CEPH_BUFFER_API {
}

void append(const bufferptr& p) {
flush_and_continue();
pbl->append(p);
out_of_band_offset += p.length();
if (!p.length()) {
return;
}
if (deep) {
append(p.c_str(), p.length());
} else {
flush_and_continue();
pbl->append(p);
out_of_band_offset += p.length();
}
}
void append(const bufferlist& l) {
flush_and_continue();
pbl->append(l);
out_of_band_offset += l.length();
if (!l.length()) {
return;
}
if (deep) {
for (const auto &p : l._buffers) {
append(p.c_str(), p.length());
}
} else {
flush_and_continue();
pbl->append(l);
out_of_band_offset += l.length();
}
}

size_t get_logical_offset() {
if (bp.have_raw()) {
Expand All @@ -555,8 +575,8 @@ namespace buffer CEPH_BUFFER_API {
}
};

contiguous_appender get_contiguous_appender(size_t len) {
return contiguous_appender(this, len);
contiguous_appender get_contiguous_appender(size_t len, bool deep=false) {
return contiguous_appender(this, len, deep);
}

class page_aligned_appender {
Expand Down

0 comments on commit f047d57

Please sign in to comment.