summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Bostic <keith@wiredtiger.com>2014-05-08 18:46:24 -0400
committerKeith Bostic <keith@wiredtiger.com>2014-05-08 18:46:24 -0400
commit5d9993d12bd2009005235036f8c7cef30f4ade5d (patch)
tree6eec05ab01a345ded5d05efc9f1aef1c4f216ebb
parent9d03b7c96c8609453a09b4a3a51ddb5a24450c79 (diff)
downloadmongo-5d9993d12bd2009005235036f8c7cef30f4ade5d.tar.gz
Don't do an append test regardless if searching the tree, but more
importantly, don't clear the "appending" flag for a read operation. This makes no difference in terms of performance, but means we don't let read operations interfere with our understanding of an appending workload.
-rw-r--r--src/btree/bt_curprev.c2
-rw-r--r--src/btree/bt_cursor.c21
-rw-r--r--src/btree/rec_split.c2
-rw-r--r--src/btree/row_srch.c31
-rw-r--r--src/include/extern.h6
5 files changed, 36 insertions, 26 deletions
diff --git a/src/btree/bt_curprev.c b/src/btree/bt_curprev.c
index 43e9c1e3647..2b8e7992918 100644
--- a/src/btree/bt_curprev.c
+++ b/src/btree/bt_curprev.c
@@ -51,7 +51,7 @@ restart:
key.data = WT_INSERT_KEY(current);
key.size = WT_INSERT_KEY_SIZE(current);
WT_RET(__wt_search_insert(
- session, cbt, cbt->ins_head, &key));
+ session, cbt, cbt->ins_head, &key, 0));
} else
cbt->ins = __col_insert_search(cbt->ins_head,
cbt->ins_stack, cbt->next_stack,
diff --git a/src/btree/bt_cursor.c b/src/btree/bt_cursor.c
index 4d8d96ab143..bc2629a5540 100644
--- a/src/btree/bt_cursor.c
+++ b/src/btree/bt_cursor.c
@@ -153,9 +153,9 @@ __cursor_col_search(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt)
* Row-store search from an application cursor.
*/
static inline int
-__cursor_row_search(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt)
+__cursor_row_search(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt, int insert)
{
- return (__wt_row_search(session, &cbt->iface.key, NULL, cbt));
+ return (__wt_row_search(session, &cbt->iface.key, NULL, cbt, insert));
}
/*
@@ -228,7 +228,7 @@ __wt_btcur_search(WT_CURSOR_BTREE *cbt)
WT_RET(__cursor_func_init(cbt, 1));
WT_ERR(btree->type == BTREE_ROW ?
- __cursor_row_search(session, cbt) :
+ __cursor_row_search(session, cbt, 0) :
__cursor_col_search(session, cbt));
if (cbt->compare != 0 || __cursor_invalid(cbt)) {
/*
@@ -277,7 +277,7 @@ __wt_btcur_search_near(WT_CURSOR_BTREE *cbt, int *exactp)
WT_RET(__cursor_func_init(cbt, 1));
WT_ERR(btree->type == BTREE_ROW ?
- __cursor_row_search(session, cbt) :
+ __cursor_row_search(session, cbt, 0) :
__cursor_col_search(session, cbt));
/*
@@ -306,8 +306,13 @@ __wt_btcur_search_near(WT_CURSOR_BTREE *cbt, int *exactp)
} else if ((ret = __wt_btcur_next(cbt, 0)) != WT_NOTFOUND)
exact = 1;
else {
+ /*
+ * Set the "insert" flag for the btree row-store search; we are
+ * intending to position our cursor at the end of the tree, not
+ * match an existing record.
+ */
WT_ERR(btree->type == BTREE_ROW ?
- __cursor_row_search(session, cbt) :
+ __cursor_row_search(session, cbt, 1) :
__cursor_col_search(session, cbt));
if (!__cursor_invalid(cbt)) {
exact = cbt->compare;
@@ -390,7 +395,7 @@ retry: WT_RET(__cursor_func_init(cbt, 1));
cbt->iface.recno = cbt->recno;
break;
case BTREE_ROW:
- WT_ERR(__cursor_row_search(session, cbt));
+ WT_ERR(__cursor_row_search(session, cbt, 1));
/*
* If not overwriting, fail if the key exists, else insert the
* key/value pair.
@@ -464,7 +469,7 @@ retry: WT_RET(__cursor_func_init(cbt, 1));
break;
case BTREE_ROW:
/* Remove the record if it exists. */
- WT_ERR(__cursor_row_search(session, cbt));
+ WT_ERR(__cursor_row_search(session, cbt, 0));
if (cbt->compare != 0 || __cursor_invalid(cbt))
WT_ERR(WT_NOTFOUND);
@@ -540,7 +545,7 @@ retry: WT_RET(__cursor_func_init(cbt, 1));
ret = __cursor_col_modify(session, cbt, 0);
break;
case BTREE_ROW:
- WT_ERR(__cursor_row_search(session, cbt));
+ WT_ERR(__cursor_row_search(session, cbt, 1));
/*
* If not overwriting, fail if the key does not exist.
*/
diff --git a/src/btree/rec_split.c b/src/btree/rec_split.c
index 35666789356..b45624c3cb0 100644
--- a/src/btree/rec_split.c
+++ b/src/btree/rec_split.c
@@ -539,7 +539,7 @@ __split_inmem_build(
}
/* Search the page. */
- WT_ERR(__wt_row_search(session, key, ref, &cbt));
+ WT_ERR(__wt_row_search(session, key, ref, &cbt, 1));
/* Apply the modification. */
WT_ERR(
diff --git a/src/btree/row_srch.c b/src/btree/row_srch.c
index 8d324971e60..ee853485642 100644
--- a/src/btree/row_srch.c
+++ b/src/btree/row_srch.c
@@ -12,12 +12,12 @@
* Search a row-store insert list, creating a skiplist stack as we go.
*/
int
-__wt_search_insert(WT_SESSION_IMPL *session,
- WT_CURSOR_BTREE *cbt, WT_INSERT_HEAD *inshead, WT_ITEM *srch_key)
+__wt_search_insert(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt,
+ WT_INSERT_HEAD *inshead, WT_ITEM *srch_key, int insert)
{
WT_BTREE *btree;
WT_INSERT **insp, *last_ins, *ret_ins;
- WT_ITEM insert_key;
+ WT_ITEM key;
size_t match, skiphigh, skiplow;
int cmp, i;
@@ -30,11 +30,13 @@ __wt_search_insert(WT_SESSION_IMPL *session,
return (0);
}
+ key.data = WT_INSERT_KEY(ret_ins);
+ key.size = WT_INSERT_KEY_SIZE(ret_ins);
+
/* Fast-path appends. */
- insert_key.data = WT_INSERT_KEY(ret_ins);
- insert_key.size = WT_INSERT_KEY_SIZE(ret_ins);
- WT_RET(
- WT_LEX_CMP(session, btree->collator, srch_key, &insert_key, cmp));
+ if (!insert)
+ goto skip_append;
+ WT_RET(WT_LEX_CMP(session, btree->collator, srch_key, &key, cmp));
if (cmp >= 0) {
if (btree->appending == 0)
btree->appending = 1;
@@ -60,6 +62,7 @@ __wt_search_insert(WT_SESSION_IMPL *session,
return (0);
}
+skip_append:
/*
* The insert list is a skip list: start at the highest skip level, then
* go as far as possible at each level before stepping down to the next.
@@ -79,12 +82,11 @@ __wt_search_insert(WT_SESSION_IMPL *session,
*/
if (ret_ins != last_ins) {
last_ins = ret_ins;
- insert_key.data = WT_INSERT_KEY(ret_ins);
- insert_key.size = WT_INSERT_KEY_SIZE(ret_ins);
+ key.data = WT_INSERT_KEY(ret_ins);
+ key.size = WT_INSERT_KEY_SIZE(ret_ins);
match = WT_MIN(skiplow, skiphigh);
WT_RET(WT_LEX_CMP_SKIP(session,
- btree->collator,
- srch_key, &insert_key, cmp, &match));
+ btree->collator, srch_key, &key, cmp, &match));
}
if (cmp > 0) { /* Keep going at this level */
@@ -117,7 +119,7 @@ __wt_search_insert(WT_SESSION_IMPL *session,
*/
int
__wt_row_search(WT_SESSION_IMPL *session,
- WT_ITEM *srch_key, WT_REF *leaf, WT_CURSOR_BTREE *cbt)
+ WT_ITEM *srch_key, WT_REF *leaf, WT_CURSOR_BTREE *cbt, int insert)
{
WT_BTREE *btree;
WT_DECL_RET;
@@ -176,7 +178,7 @@ restart: page = parent->page;
goto descend;
/* Fast-path appends. */
- if (btree->appending) {
+ if (insert && btree->appending) {
__wt_ref_key(page, child, &item->data, &item->size);
WT_ERR(WT_LEX_CMP(
session, btree->collator, srch_key, item, cmp));
@@ -397,7 +399,8 @@ leaf_only:
* return insert information appropriately.
*/
cbt->ref = child;
- WT_ERR(__wt_search_insert(session, cbt, cbt->ins_head, srch_key));
+ WT_ERR(
+ __wt_search_insert(session, cbt, cbt->ins_head, srch_key, insert));
return (0);
err: WT_TRET(__wt_page_release(session, child));
diff --git a/src/include/extern.h b/src/include/extern.h
index 8b6a0ade9ec..446100a3937 100644
--- a/src/include/extern.h
+++ b/src/include/extern.h
@@ -506,11 +506,13 @@ extern void __wt_update_obsolete_free( WT_SESSION_IMPL *session,
extern int __wt_search_insert(WT_SESSION_IMPL *session,
WT_CURSOR_BTREE *cbt,
WT_INSERT_HEAD *inshead,
- WT_ITEM *srch_key);
+ WT_ITEM *srch_key,
+ int insert);
extern int __wt_row_search(WT_SESSION_IMPL *session,
WT_ITEM *srch_key,
WT_REF *leaf,
- WT_CURSOR_BTREE *cbt);
+ WT_CURSOR_BTREE *cbt,
+ int insert);
extern int __wt_row_random(WT_SESSION_IMPL *session, WT_CURSOR_BTREE *cbt);
extern int __wt_config_initn( WT_SESSION_IMPL *session,
WT_CONFIG *conf,