diff options
author | Yehuda Sadeh <yehuda@inktank.com> | 2013-03-14 10:32:00 -0700 |
---|---|---|
committer | Yehuda Sadeh <yehuda@inktank.com> | 2013-04-15 14:23:12 -0700 |
commit | 3a6161dc08d4975fdae34b8997e56df8c0275fbc (patch) | |
tree | 9b5cc11bde1fa00697e494944bc829be4e47520a | |
parent | 281a3c8a2671528c4e18f735cf790761a51a2547 (diff) | |
download | ceph-3a6161dc08d4975fdae34b8997e56df8c0275fbc.tar.gz |
objclass: provide new api for unique subop versioning
We need to be able to generate a unique identifier for
each subop. This can be useful e.g., if we want to keep multiple
omap data entries indexed by the same key. The unique id
is being generated by the current object id and the current
osd subop count. For write operations it's unique.
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r-- | src/objclass/class_api.cc | 27 | ||||
-rw-r--r-- | src/objclass/objclass.h | 7 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/objclass/class_api.cc b/src/objclass/class_api.cc index d49890d2d4a..64d61bdaa13 100644 --- a/src/objclass/class_api.cc +++ b/src/objclass/class_api.cc @@ -575,3 +575,30 @@ int cls_gen_rand_base64(char *dest, int size) /* size should be the required str return 0; } +uint64_t cls_current_version(cls_method_context_t hctx) +{ + ReplicatedPG::OpContext *ctx = *(ReplicatedPG::OpContext **)hctx; + + return ctx->at_version.version; +} + + +int cls_current_subop_num(cls_method_context_t hctx) +{ + ReplicatedPG::OpContext *ctx = *(ReplicatedPG::OpContext **)hctx; + + return ctx->current_osd_subop_num; +} + +void cls_cxx_subop_version(cls_method_context_t hctx, string *s) +{ + if (!s) + return; + + char buf[32]; + uint64_t ver = cls_current_version(hctx); + int subop_num = cls_current_subop_num(hctx); + snprintf(buf, sizeof(buf), "%lld.%d", (long long)ver, subop_num); + + *s = buf; +} diff --git a/src/objclass/objclass.h b/src/objclass/objclass.h index 1acbcfd9be3..6f0de2825c2 100644 --- a/src/objclass/objclass.h +++ b/src/objclass/objclass.h @@ -137,6 +137,13 @@ extern int cls_cxx_map_update(cls_method_context_t hctx, bufferlist *inbl); extern int cls_gen_random_bytes(char *buf, int size); extern int cls_gen_rand_base64(char *dest, int size); /* size should be the required string size + 1 */ +/* environment */ +extern uint64_t cls_current_version(cls_method_context_t hctx); +extern int cls_current_subop_num(cls_method_context_t hctx); + +/* helpers */ +extern void cls_cxx_subop_version(cls_method_context_t hctx, string *s); + /* These are also defined in rados.h and librados.h. Keep them in sync! */ #define CEPH_OSD_TMAP_HDR 'h' #define CEPH_OSD_TMAP_SET 's' |