Skip to content

Commit

Permalink
cls_cas: dynamically adjust resolution of chunk_obj_refcount
Browse files Browse the repository at this point in the history
Most objects will have few refs, but some will have many.  Retain as much
information about references as we can for both cases, without exploding
the size of encoded refs.

Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
liewegas committed May 27, 2020
1 parent cc9d83e commit c263117
Show file tree
Hide file tree
Showing 4 changed files with 380 additions and 32 deletions.
21 changes: 6 additions & 15 deletions src/cls/cas/cls_cas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static int chunk_read_refcount(
chunk_obj_refcount *objr)
{
bufferlist bl;
objr->refs.clear();
objr->clear();
int ret = cls_cxx_getxattr(hctx, CHUNK_REFCOUNT_ATTR, &bl);
if (ret == -ENODATA) {
return 0;
Expand Down Expand Up @@ -88,7 +88,7 @@ static int chunk_create_or_get_ref(cls_method_context_t hctx,
if (ret < 0) {
return ret;
}
objr.refs.insert(op.source);
objr.get(op.source);
ret = chunk_set_refcount(hctx, objr);
if (ret < 0) {
return ret;
Expand All @@ -107,10 +107,9 @@ static int chunk_create_or_get_ref(cls_method_context_t hctx,
CLS_LOG(10, "inc ref oid=%s\n",
op.source.oid.name.c_str());

if (objr.refs.count(op.source)) {
if (!objr.get(op.source)) {
return -EEXIST;
}
objr.refs.insert(op.source);

ret = chunk_set_refcount(hctx, objr);
if (ret < 0) {
Expand Down Expand Up @@ -143,10 +142,9 @@ static int chunk_get_ref(cls_method_context_t hctx,
// existing chunk; inc ref
CLS_LOG(10, "oid=%s\n", op.source.oid.name.c_str());

if (objr.refs.count(op.source)) {
if (!objr.get(op.source)) {
return -EEXIST;
}
objr.refs.insert(op.source);

ret = chunk_set_refcount(hctx, objr);
if (ret < 0) {
Expand All @@ -173,19 +171,12 @@ static int chunk_put_ref(cls_method_context_t hctx,
if (ret < 0)
return ret;

if (objr.refs.empty()) {// shouldn't happen!
CLS_LOG(0, "ERROR was called without any references!\n");
return -ENOLINK;
}

auto p = objr.refs.find(op.source);
if (p == objr.refs.end()) {
if (!objr.put(op.source)) {
CLS_LOG(10, "oid=%s (no ref)\n", op.source.oid.name.c_str());
return -ENOLINK;
}
objr.refs.erase(p);

if (objr.refs.empty()) {
if (objr.empty()) {
CLS_LOG(10, "oid=%s (last ref)\n", op.source.oid.name.c_str());
return cls_cxx_remove(hctx);
}
Expand Down
Loading

0 comments on commit c263117

Please sign in to comment.