diff options
author | Michael Cahill <mjc@wiredtiger.com> | 2012-12-09 22:04:22 -0800 |
---|---|---|
committer | Michael Cahill <mjc@wiredtiger.com> | 2012-12-09 22:04:22 -0800 |
commit | d2a6433d25eb0d77d0ef6542a2ea203fc63d6871 (patch) | |
tree | 16dbd62531184bd71bc0f9b6216741e46d8cd7b6 /src/btree/row_key.c | |
parent | 18b5b115a070150fd9817a1a4d1d9541746e2c94 (diff) | |
parent | cd3efd6ea136aeb5f822559607e52c3b7cd14ae8 (diff) | |
download | mongo-d2a6433d25eb0d77d0ef6542a2ea203fc63d6871.tar.gz |
Merge pull request #408 from wiredtiger/row-key-serial
Replace the row-key-serial function with CAS instruction.
Diffstat (limited to 'src/btree/row_key.c')
-rw-r--r-- | src/btree/row_key.c | 58 |
1 files changed, 16 insertions, 42 deletions
diff --git a/src/btree/row_key.c b/src/btree/row_key.c index 681bf21727b..854f76284ea 100644 --- a/src/btree/row_key.c +++ b/src/btree/row_key.c @@ -306,24 +306,24 @@ next: switch (direction) { if (!is_local) return (0); - /* - * Allocate and initialize a WT_IKEY structure, we're instantiating - * this key. - */ + /* If still needed, instantiate the key. */ key = WT_ROW_KEY_COPY(rip_arg); - WT_ERR(__wt_row_ikey_alloc(session, - WT_PAGE_DISK_OFFSET(page, key), retb->data, retb->size, &ikey)); - - /* Serialize the swap of the key into place. */ - ret = __wt_row_key_serial(session, page, rip_arg, ikey); + if (!__wt_off_page(page, key)) { + WT_ERR(__wt_row_ikey_alloc(session, + WT_PAGE_DISK_OFFSET(page, key), + retb->data, retb->size, &ikey)); - /* - * Free the WT_IKEY structure if the serialized call didn't use it for - * the key. - */ - key = WT_ROW_KEY_COPY(rip_arg); - if (key != ikey) - __wt_free(session, ikey); + /* + * Serialize the swap of the key into place. If we succeed, + * update the page's memory footprint; if we fail, free the + * WT_IKEY structure. + */ + if (WT_ATOMIC_CAS(WT_ROW_KEY_COPY(rip), key, ikey)) + __wt_cache_page_inmem_incr( + session, page, sizeof(WT_IKEY) + ikey->size); + else + __wt_free(session, ikey); + } __wt_scr_free(&retb); @@ -401,29 +401,3 @@ __wt_row_ikey_alloc(WT_SESSION_IMPL *session, *(WT_IKEY **)ikeyp = ikey; return (0); } - -/* - * __wt_row_key_serial_func -- - * Server function to instantiate a key during a row-store search. - */ -int -__wt_row_key_serial_func(WT_SESSION_IMPL *session, void *args) -{ - WT_IKEY *ikey; - WT_PAGE *page; - WT_ROW *rip; - - __wt_row_key_unpack(args, &page, &rip, &ikey); - - /* - * We don't care about the page's write generation -- there's a simpler - * test, if the key we're interested in still needs to be instantiated, - * because it can only be in one of two states. - */ - if (!__wt_off_page(page, WT_ROW_KEY_COPY(rip))) { - WT_ROW_KEY_SET(rip, ikey); - __wt_cache_page_inmem_incr( - session, page, sizeof(WT_IKEY) + ikey->size); - } - return (0); -} |