diff options
| author | David Hows <david.hows@mongodb.com> | 2017-01-06 12:12:50 +1100 |
|---|---|---|
| committer | David Hows <david.hows@mongodb.com> | 2017-01-06 12:12:50 +1100 |
| commit | d48181f6f4db08761ed7b80b0332908b272ad0d0 (patch) | |
| tree | 38929fdcc5415ee7b001b6f1a406bd5bd777b737 /src/cursor | |
| parent | 040e3d6f764c0fb626cb47fede54469f57d0c6e0 (diff) | |
| parent | 8d2324943364286056ae399043f70b8a937de312 (diff) | |
Merge branch 'mongodb-3.6' into mongodb-3.2mongodb-3.2.12
Diffstat (limited to 'src/cursor')
| -rw-r--r-- | src/cursor/cur_backup.c | 4 | ||||
| -rw-r--r-- | src/cursor/cur_file.c | 2 | ||||
| -rw-r--r-- | src/cursor/cur_index.c | 29 | ||||
| -rw-r--r-- | src/cursor/cur_join.c | 2 | ||||
| -rw-r--r-- | src/cursor/cur_json.c | 16 | ||||
| -rw-r--r-- | src/cursor/cur_log.c | 62 | ||||
| -rw-r--r-- | src/cursor/cur_table.c | 7 |
7 files changed, 55 insertions, 67 deletions
diff --git a/src/cursor/cur_backup.c b/src/cursor/cur_backup.c index 3585082644f..456aa2e0f02 100644 --- a/src/cursor/cur_backup.c +++ b/src/cursor/cur_backup.c @@ -144,8 +144,8 @@ __wt_curbackup_open(WT_SESSION_IMPL *session, * Start the backup and fill in the cursor's list. Acquire the schema * lock, we need a consistent view when creating a copy. */ - WT_WITH_CHECKPOINT_LOCK(session, ret, - WT_WITH_SCHEMA_LOCK(session, ret, + WT_WITH_CHECKPOINT_LOCK(session, + WT_WITH_SCHEMA_LOCK(session, ret = __backup_start(session, cb, cfg))); WT_ERR(ret); diff --git a/src/cursor/cur_file.c b/src/cursor/cur_file.c index 9fc466f4c76..0ec917fbf95 100644 --- a/src/cursor/cur_file.c +++ b/src/cursor/cur_file.c @@ -559,7 +559,7 @@ __wt_curfile_open(WT_SESSION_IMPL *session, const char *uri, * get the handle while holding the checkpoint lock. */ if (LF_ISSET(WT_DHANDLE_EXCLUSIVE) && checkpoint_wait) - WT_WITH_CHECKPOINT_LOCK(session, ret, + WT_WITH_CHECKPOINT_LOCK(session, ret = __wt_session_get_btree_ckpt( session, uri, cfg, flags)); else diff --git a/src/cursor/cur_index.c b/src/cursor/cur_index.c index eb5e15ae5c3..0ab992bc88c 100644 --- a/src/cursor/cur_index.c +++ b/src/cursor/cur_index.c @@ -281,33 +281,38 @@ __curindex_search_near(WT_CURSOR *cursor, int *exact) * (usually) doesn't contain the primary key, so it is just a prefix of * any matching index key. That said, if there is an exact match, we * want to find the first matching index entry and set exact equal to - * zero. Do a search_near, step to the next entry if we land on one - * that is too small, then check that the prefix matches. + * zero. + * + * Do a search_near, and if we find an entry that is too small, step to + * the next one. In the unlikely event of a search past the end of the + * tree, go back to the last key. */ __wt_cursor_set_raw_key(child, &cursor->key); WT_ERR(child->search_near(child, &cmp)); - if (cmp < 0) - WT_ERR(child->next(child)); + if (cmp < 0) { + if ((ret = child->next(child)) == WT_NOTFOUND) + ret = child->prev(child); + WT_ERR(ret); + } /* * We expect partial matches, and want the smallest record with a key * greater than or equal to the search key. * - * If the key we find is shorter than the search key, it can't possibly - * match. + * If the found key starts with the search key, we indicate a match by + * setting exact equal to zero. * - * The only way for the key to be exactly equal is if there is an index - * on the primary key, because otherwise the primary key columns will - * be appended to the index key, but we don't disallow that (odd) case. + * The compare function expects application-supplied keys to come first + * so we flip the sign of the result to match what callers expect. */ found_key = child->key; - if (found_key.size < cursor->key.size) - WT_ERR(WT_NOTFOUND); - found_key.size = cursor->key.size; + if (found_key.size > cursor->key.size) + found_key.size = cursor->key.size; WT_ERR(__wt_compare( session, cindex->index->collator, &cursor->key, &found_key, exact)); + *exact = -*exact; WT_ERR(__curindex_move(cindex)); diff --git a/src/cursor/cur_join.c b/src/cursor/cur_join.c index 2fa2a207c8a..013a64ef2d5 100644 --- a/src/cursor/cur_join.c +++ b/src/cursor/cur_join.c @@ -1333,7 +1333,7 @@ __wt_curjoin_open(WT_SESSION_IMPL *session, WT_ERR(__wt_scr_alloc(session, 0, &tmp)); if (columns != NULL) { WT_ERR(__wt_struct_reformat(session, table, - columns, strlen(columns), NULL, 1, tmp)); + columns, strlen(columns), NULL, false, tmp)); WT_ERR(__wt_strndup( session, tmp->data, tmp->size, &cursor->value_format)); WT_ERR(__wt_strdup(session, columns, &cjoin->projection)); diff --git a/src/cursor/cur_json.c b/src/cursor/cur_json.c index 4ba10ddabb0..a0a3ffdd974 100644 --- a/src/cursor/cur_json.c +++ b/src/cursor/cur_json.c @@ -270,7 +270,6 @@ __wt_json_alloc_unpack(WT_SESSION_IMPL *session, const void *buffer, bool iskey, va_list ap) { WT_CONFIG_ITEM *names; - WT_DECL_RET; size_t needed; char **json_bufp; @@ -288,7 +287,7 @@ __wt_json_alloc_unpack(WT_SESSION_IMPL *session, const void *buffer, WT_RET(__json_struct_unpackv(session, buffer, size, fmt, names, (u_char *)*json_bufp, needed + 1, iskey, ap)); - return (ret); + return (0); } /* @@ -315,6 +314,7 @@ __wt_json_close(WT_SESSION_IMPL *session, WT_CURSOR *cursor) */ size_t __wt_json_unpack_char(u_char ch, u_char *buf, size_t bufsz, bool force_unicode) + WT_GCC_FUNC_ATTRIBUTE((visibility("default"))) { u_char abbrev; @@ -357,8 +357,8 @@ __wt_json_unpack_char(u_char ch, u_char *buf, size_t bufsz, bool force_unicode) *buf++ = 'u'; *buf++ = '0'; *buf++ = '0'; - *buf++ = __wt_hex[(ch & 0xf0) >> 4]; - *buf++ = __wt_hex[ch & 0x0f]; + *buf++ = __wt_hex((ch & 0xf0) >> 4); + *buf++ = __wt_hex(ch & 0x0f); } return (6); } @@ -452,6 +452,7 @@ __wt_json_column_init(WT_CURSOR *cursor, const char *keyformat, int __wt_json_token(WT_SESSION *wt_session, const char *src, int *toktype, const char **tokstart, size_t *toklen) + WT_GCC_FUNC_ATTRIBUTE((visibility("default"))) { WT_SESSION_IMPL *session; int result; @@ -580,6 +581,7 @@ __wt_json_token(WT_SESSION *wt_session, const char *src, int *toktype, */ const char * __wt_json_tokname(int toktype) + WT_GCC_FUNC_ATTRIBUTE((visibility("default"))) { switch (toktype) { case 0: return ("<EOF>"); @@ -817,6 +819,7 @@ __wt_json_to_item(WT_SESSION_IMPL *session, const char *jstr, */ ssize_t __wt_json_strlen(const char *src, size_t srclen) + WT_GCC_FUNC_ATTRIBUTE((visibility("default"))) { const char *srcend; size_t dstlen; @@ -857,8 +860,9 @@ __wt_json_strlen(const char *src, size_t srclen) * bytes. If dstlen is greater than the needed size, the result if zero padded. */ int -__wt_json_strncpy(WT_SESSION *wt_session, char **pdst, size_t dstlen, - const char *src, size_t srclen) +__wt_json_strncpy(WT_SESSION *wt_session, + char **pdst, size_t dstlen, const char *src, size_t srclen) + WT_GCC_FUNC_ATTRIBUTE((visibility("default"))) { WT_SESSION_IMPL *session; char ch, *dst; diff --git a/src/cursor/cur_log.c b/src/cursor/cur_log.c index 21a7f674c68..3ee6554b3c0 100644 --- a/src/cursor/cur_log.c +++ b/src/cursor/cur_log.c @@ -150,18 +150,22 @@ static int __curlog_kv(WT_SESSION_IMPL *session, WT_CURSOR *cursor) { WT_CURSOR_LOG *cl; - WT_ITEM item; - uint32_t fileid, key_count, opsize, optype; + WT_DECL_RET; + uint32_t fileid, key_count, opsize, optype, raw; cl = (WT_CURSOR_LOG *)cursor; + /* Temporarily turn off raw so we can do direct cursor operations. */ + raw = F_MASK(cursor, WT_CURSTD_RAW); + F_CLR(cursor, WT_CURSTD_RAW); + /* * If it is a commit and we have stepped over the header, peek to get * the size and optype and read out any key/value from this operation. */ if ((key_count = cl->step_count++) > 0) { - WT_RET(__wt_logop_read(session, + WT_ERR(__wt_logop_read(session, &cl->stepp, cl->stepp_end, &optype, &opsize)); - WT_RET(__curlog_op_read(session, cl, optype, opsize, &fileid)); + WT_ERR(__curlog_op_read(session, cl, optype, opsize, &fileid)); /* Position on the beginning of the next record part. */ cl->stepp += opsize; } else { @@ -181,39 +185,14 @@ __curlog_kv(WT_SESSION_IMPL *session, WT_CURSOR *cursor) * The log cursor sets the LSN and step count as the cursor key and * and log record related data in the value. The data in the value * contains any operation key/value that was in the log record. - * For the special case that the caller needs the result in raw form, - * we create packed versions of the key/value. */ - if (FLD_ISSET(cursor->flags, WT_CURSTD_RAW)) { - memset(&item, 0, sizeof(item)); - WT_RET(wiredtiger_struct_size((WT_SESSION *)session, - &item.size, WT_LOGC_KEY_FORMAT, cl->cur_lsn->l.file, - cl->cur_lsn->l.offset, key_count)); - WT_RET(__wt_realloc(session, NULL, item.size, &cl->packed_key)); - item.data = cl->packed_key; - WT_RET(wiredtiger_struct_pack((WT_SESSION *)session, - cl->packed_key, item.size, WT_LOGC_KEY_FORMAT, - cl->cur_lsn->l.file, cl->cur_lsn->l.offset, key_count)); - __wt_cursor_set_key(cursor, &item); - - WT_RET(wiredtiger_struct_size((WT_SESSION *)session, - &item.size, WT_LOGC_VALUE_FORMAT, cl->txnid, cl->rectype, - optype, fileid, cl->opkey, cl->opvalue)); - WT_RET(__wt_realloc(session, NULL, item.size, - &cl->packed_value)); - item.data = cl->packed_value; - WT_RET(wiredtiger_struct_pack((WT_SESSION *)session, - cl->packed_value, item.size, WT_LOGC_VALUE_FORMAT, - cl->txnid, cl->rectype, optype, fileid, cl->opkey, - cl->opvalue)); - __wt_cursor_set_value(cursor, &item); - } else { - __wt_cursor_set_key(cursor, cl->cur_lsn->l.file, - cl->cur_lsn->l.offset, key_count); - __wt_cursor_set_value(cursor, cl->txnid, cl->rectype, optype, - fileid, cl->opkey, cl->opvalue); - } - return (0); + __wt_cursor_set_key(cursor, cl->cur_lsn->l.file, cl->cur_lsn->l.offset, + key_count); + __wt_cursor_set_value(cursor, cl->txnid, cl->rectype, optype, fileid, + cl->opkey, cl->opvalue); + +err: F_SET(cursor, raw); + return (ret); } /* @@ -264,17 +243,19 @@ __curlog_search(WT_CURSOR *cursor) WT_DECL_RET; WT_LSN key; WT_SESSION_IMPL *session; - uint32_t counter, key_file, key_offset; + uint32_t counter, key_file, key_offset, raw; cl = (WT_CURSOR_LOG *)cursor; + /* Temporarily turn off raw so we can do direct cursor operations. */ + raw = F_MASK(cursor, WT_CURSTD_RAW); + F_CLR(cursor, WT_CURSTD_RAW); CURSOR_API_CALL(cursor, session, search, NULL); /* * !!! We are ignoring the counter and only searching based on the LSN. */ - WT_ERR(__wt_cursor_get_key((WT_CURSOR *)cl, - &key_file, &key_offset, &counter)); + WT_ERR(__wt_cursor_get_key(cursor, &key_file, &key_offset, &counter)); WT_SET_LSN(&key, key_file, key_offset); ret = __wt_log_scan(session, &key, WT_LOGSCAN_ONE, __curlog_logrec, cl); @@ -285,7 +266,8 @@ __curlog_search(WT_CURSOR *cursor) WT_STAT_CONN_INCR(session, cursor_search); WT_STAT_DATA_INCR(session, cursor_search); -err: API_END_RET(session, ret); +err: F_SET(cursor, raw); + API_END_RET(session, ret); } /* diff --git a/src/cursor/cur_table.c b/src/cursor/cur_table.c index 502d93639a8..fae7667e44f 100644 --- a/src/cursor/cur_table.c +++ b/src/cursor/cur_table.c @@ -763,16 +763,13 @@ err: API_END_RET(session, ret); static int __curtable_complete(WT_SESSION_IMPL *session, WT_TABLE *table) { - WT_DECL_RET; bool complete; if (table->cg_complete) return (0); /* If the table is incomplete, wait on the table lock and recheck. */ - complete = false; - WT_WITH_TABLE_LOCK(session, ret, complete = table->cg_complete); - WT_RET(ret); + WT_WITH_TABLE_LOCK(session, complete = table->cg_complete); if (!complete) WT_RET_MSG(session, EINVAL, "'%s' not available until all column groups are created", @@ -927,7 +924,7 @@ __wt_curtable_open(WT_SESSION_IMPL *session, WT_ERR(__wt_scr_alloc(session, 0, &tmp)); if (columns != NULL) { WT_ERR(__wt_struct_reformat(session, table, - columns, strlen(columns), NULL, true, tmp)); + columns, strlen(columns), NULL, false, tmp)); WT_ERR(__wt_strndup( session, tmp->data, tmp->size, &cursor->value_format)); |
