summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/src/cursor/cur_std.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/third_party/wiredtiger/src/cursor/cur_std.c')
-rw-r--r--src/third_party/wiredtiger/src/cursor/cur_std.c126
1 files changed, 122 insertions, 4 deletions
diff --git a/src/third_party/wiredtiger/src/cursor/cur_std.c b/src/third_party/wiredtiger/src/cursor/cur_std.c
index 99a9e373354..91995ab0e0a 100644
--- a/src/third_party/wiredtiger/src/cursor/cur_std.c
+++ b/src/third_party/wiredtiger/src/cursor/cur_std.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2014-2016 MongoDB, Inc.
+ * Copyright (c) 2014-2017 MongoDB, Inc.
* Copyright (c) 2008-2014 WiredTiger, Inc.
* All rights reserved.
*
@@ -90,6 +90,19 @@ __wt_cursor_equals_notsup(WT_CURSOR *cursor, WT_CURSOR *other, int *equalp)
}
/*
+ * __wt_cursor_modify_notsup --
+ * Unsupported cursor modify.
+ */
+int
+__wt_cursor_modify_notsup(WT_CURSOR *cursor, WT_MODIFY *entries, int nentries)
+{
+ WT_UNUSED(entries);
+ WT_UNUSED(nentries);
+
+ return (__wt_cursor_notsup(cursor));
+}
+
+/*
* __wt_cursor_search_near_notsup --
* Unsupported cursor search-near.
*/
@@ -136,6 +149,7 @@ __wt_cursor_set_notsup(WT_CURSOR *cursor)
cursor->insert = __wt_cursor_notsup;
cursor->update = __wt_cursor_notsup;
cursor->remove = __wt_cursor_notsup;
+ cursor->reserve = __wt_cursor_notsup;
}
/*
@@ -275,7 +289,7 @@ __wt_cursor_get_keyv(WT_CURSOR *cursor, uint32_t flags, va_list ap)
const char *fmt;
CURSOR_API_CALL(cursor, session, get_key, NULL);
- if (!F_ISSET(cursor, WT_CURSTD_KEY_EXT | WT_CURSTD_KEY_INT))
+ if (!F_ISSET(cursor, WT_CURSTD_KEY_SET))
WT_ERR(__wt_cursor_kv_not_set(cursor, true));
if (WT_CURSOR_RECNO(cursor)) {
@@ -581,6 +595,100 @@ err: API_END(session, ret);
}
/*
+ * __cursor_modify --
+ * WT_CURSOR->modify default implementation.
+ */
+static int
+__cursor_modify(WT_CURSOR *cursor, WT_MODIFY *entries, int nentries)
+{
+ WT_DECL_RET;
+ WT_SESSION_IMPL *session;
+ WT_DECL_ITEM(ta);
+ WT_DECL_ITEM(tb);
+ WT_DECL_ITEM(tmp);
+ size_t len, size;
+ int i;
+
+ CURSOR_UPDATE_API_CALL(cursor, session, modify);
+ WT_ERR(__cursor_checkkey(cursor));
+
+ /* Check for a rational modify vector count. */
+ if (nentries <= 0)
+ WT_ERR_MSG(
+ session, EINVAL, "Illegal modify vector of %d", nentries);
+
+ WT_STAT_CONN_INCR(session, cursor_modify);
+ WT_STAT_DATA_INCR(session, cursor_modify);
+
+ /* Acquire position and value. */
+ WT_ERR(cursor->search(cursor));
+
+ /*
+ * Process the entries to figure out how large a buffer we need. This is
+ * a bit pessimistic because we're ignoring replacement bytes, but it's
+ * a simpler calculation.
+ */
+ for (size = cursor->value.size, i = 0; i < nentries; ++i) {
+ if (entries[i].offset >= size)
+ size = entries[i].offset;
+ size += entries[i].data.size;
+ }
+
+ /* Allocate a pair of buffers. */
+ WT_ERR(__wt_scr_alloc(session, size, &ta));
+ WT_ERR(__wt_scr_alloc(session, size, &tb));
+
+ /* Apply the change vector to the value. */
+ WT_ERR(__wt_buf_set(
+ session, ta, cursor->value.data, cursor->value.size));
+ for (i = 0; i < nentries; ++i) {
+ /* Take leading bytes from the original, plus any gap bytes. */
+ if (entries[i].offset >= ta->size) {
+ memcpy(tb->mem, ta->mem, ta->size);
+ if (entries[i].offset > ta->size)
+ memset((uint8_t *)tb->mem + ta->size,
+ '\0', entries[i].offset - ta->size);
+ } else
+ if (entries[i].offset > 0)
+ memcpy(tb->mem, ta->mem, entries[i].offset);
+ tb->size = entries[i].offset;
+
+ /* Take replacement bytes. */
+ if (entries[i].data.size > 0) {
+ memcpy((uint8_t *)tb->mem + tb->size,
+ entries[i].data.data, entries[i].data.size);
+ tb->size += entries[i].data.size;
+ }
+
+ /* Take trailing bytes from the original. */
+ len = entries[i].offset + entries[i].size;
+ if (ta->size > len) {
+ memcpy((uint8_t *)tb->mem + tb->size,
+ (uint8_t *)ta->mem + len, ta->size - len);
+ tb->size += ta->size - len;
+ }
+ WT_ASSERT(session, tb->size <= size);
+
+ tmp = ta;
+ ta = tb;
+ tb = tmp;
+ }
+
+ /* Set the cursor's value. */
+ ta->data = ta->mem;
+ cursor->set_value(cursor, ta);
+
+ /* We know both key and value are set, "overwrite" doesn't matter. */
+ ret = cursor->update(cursor);
+
+err: __wt_scr_free(session, &ta);
+ __wt_scr_free(session, &tb);
+
+ CURSOR_UPDATE_API_END(session, ret);
+ return (ret);
+}
+
+/*
* __wt_cursor_reconfigure --
* Set runtime-configurable settings.
*/
@@ -705,15 +813,17 @@ __wt_cursor_init(WT_CURSOR *cursor,
WT_RET(__wt_config_gets_def(session, cfg, "checkpoint", 0, &cval));
if (cval.len != 0) {
cursor->insert = __wt_cursor_notsup;
- cursor->update = __wt_cursor_notsup;
cursor->remove = __wt_cursor_notsup;
+ cursor->reserve = __wt_cursor_notsup;
+ cursor->update = __wt_cursor_notsup;
} else {
WT_RET(
__wt_config_gets_def(session, cfg, "readonly", 0, &cval));
if (cval.val != 0 || F_ISSET(S2C(session), WT_CONN_READONLY)) {
cursor->insert = __wt_cursor_notsup;
- cursor->update = __wt_cursor_notsup;
cursor->remove = __wt_cursor_notsup;
+ cursor->reserve = __wt_cursor_notsup;
+ cursor->update = __wt_cursor_notsup;
}
}
@@ -754,6 +864,14 @@ __wt_cursor_init(WT_CURSOR *cursor,
F_SET(cursor, WT_CURSTD_RAW);
/*
+ * WT_CURSOR.modify supported on 'u' value formats, but may have been
+ * already initialized.
+ */
+ if (WT_STREQ(cursor->value_format, "u") &&
+ cursor->modify == __wt_cursor_modify_notsup)
+ cursor->modify = __cursor_modify;
+
+ /*
* Cursors that are internal to some other cursor (such as file cursors
* inside a table cursor) should be closed after the containing cursor.
* Arrange for that to happen by putting internal cursors after their