diff options
author | Keith Bostic <keith@wiredtiger.com> | 2014-12-11 19:32:50 -0500 |
---|---|---|
committer | Keith Bostic <keith@wiredtiger.com> | 2014-12-11 19:32:50 -0500 |
commit | 4c26d2324bae1d7030b0142d50dbd2ccf11ddeb6 (patch) | |
tree | 2a503b40b20650427eb66039766eb5c9575ce3c7 /src/cursor/cur_std.c | |
parent | 9b33b7c46a2672f36b9673d5e4cbc7315bc9ecf4 (diff) | |
download | mongo-4c26d2324bae1d7030b0142d50dbd2ccf11ddeb6.tar.gz |
Add support for a WT_CURSOR.reconfigure method, reference #1381.
Diffstat (limited to 'src/cursor/cur_std.c')
-rw-r--r-- | src/cursor/cur_std.c | 127 |
1 files changed, 79 insertions, 48 deletions
diff --git a/src/cursor/cur_std.c b/src/cursor/cur_std.c index cba83b1d088..6f7168a5cc6 100644 --- a/src/cursor/cur_std.c +++ b/src/cursor/cur_std.c @@ -58,28 +58,6 @@ __wt_cursor_set_notsup(WT_CURSOR *cursor) } /* - * __wt_cursor_config_readonly -- - * Parse read only configuration and setup cursor appropriately. - */ -int -__wt_cursor_config_readonly(WT_CURSOR *cursor, const char *cfg[], int def) -{ - WT_CONFIG_ITEM cval; - WT_SESSION_IMPL *session; - - session = (WT_SESSION_IMPL *)cursor->session; - - WT_RET(__wt_config_gets_def(session, cfg, "readonly", def, &cval)); - if (cval.val != 0) { - /* Reset all cursor methods that could modify data. */ - cursor->insert = __wt_cursor_notsup; - cursor->update = __wt_cursor_notsup; - cursor->remove = __wt_cursor_notsup; - } - return (0); -} - -/* * __wt_cursor_kv_not_set -- * Standard error message for key/values not set. */ @@ -501,29 +479,72 @@ __wt_cursor_close(WT_CURSOR *cursor) } /* - * __cursor_runtime_config -- + * __wt_cursor_reconfigure -- * Set runtime-configurable settings. */ -static int -__cursor_runtime_config(WT_CURSOR *cursor, const char *cfg[]) +int +__wt_cursor_reconfigure(WT_CURSOR *cursor, const char *config) { WT_CONFIG_ITEM cval; + WT_DECL_RET; WT_SESSION_IMPL *session; session = (WT_SESSION_IMPL *)cursor->session; - /* - * !!! - * There's no way yet to reconfigure cursor flags at runtime; if, in - * the future there is a way to do that, similar support needs to be - * added for data-source cursors, or, this call needs to return an - * error in the case of a data-source cursor. + /* Reconfiguration resets the cursor. */ + WT_RET(cursor->reset(cursor)); + + /* + * append + * Only relevant to column stores. */ - WT_RET(__wt_config_gets_def(session, cfg, "overwrite", 1, &cval)); - if (cval.val) - F_SET(cursor, WT_CURSTD_OVERWRITE); - else - F_CLR(cursor, WT_CURSTD_OVERWRITE); + if (WT_CURSOR_RECNO(cursor)) { + if ((ret = __wt_config_getones( + session, config, "append", &cval)) == 0) { + if (cval.val) + F_SET(cursor, WT_CURSTD_APPEND); + else + F_CLR(cursor, WT_CURSTD_APPEND); + } else + WT_RET_NOTFOUND_OK(ret); + } + + /* + * overwrite + */ + if ((ret = __wt_config_getones( + session, config, "overwrite", &cval)) == 0) { + if (cval.val) + F_SET(cursor, WT_CURSTD_OVERWRITE); + else + F_CLR(cursor, WT_CURSTD_OVERWRITE); + } else + WT_RET_NOTFOUND_OK(ret); + + /* + * readonly + */ + if ((ret = __wt_config_getones( + session, config, "readonly", &cval)) == 0) { + if (cval.val == 0) { + /* + * Fail if the user is turning readonly off and the + * cursor never supported writing in the first place. + */ + if (cursor->insert_orig == + (int (*)(WT_CURSOR *))__wt_cursor_set_notsup) + WT_RET_MSG(session, EINVAL, + "cursor cannot be used for data update"); + cursor->insert = cursor->insert_orig; + cursor->remove = cursor->remove_orig; + cursor->update = cursor->update_orig; + } else { + cursor->insert = __wt_cursor_notsup; + cursor->remove = __wt_cursor_notsup; + cursor->update = __wt_cursor_notsup; + } + } else + WT_RET_NOTFOUND_OK(ret); return (0); } @@ -580,15 +601,13 @@ __wt_cursor_init(WT_CURSOR *cursor, WT_CONFIG_ITEM cval; WT_CURSOR *cdump; WT_SESSION_IMPL *session; + int readonly; session = (WT_SESSION_IMPL *)cursor->session; if (cursor->internal_uri == NULL) WT_RET(__wt_strdup(session, uri, &cursor->internal_uri)); - /* Set runtime-configurable settings. */ - WT_RET(__cursor_runtime_config(cursor, cfg)); - /* * append * The append flag is only relevant to column stores. @@ -600,14 +619,22 @@ __wt_cursor_init(WT_CURSOR *cursor, } /* - * checkpoint - * Checkpoint cursors are read-only. + * checkpoint, readonly + * Checkpoint cursors are read-only, avoid any extra work. */ + readonly = 0; 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; + if (cval.len == 0) { + WT_RET( + __wt_config_gets_def(session, cfg, "readonly", 0, &cval)); + if (cval.val != 0) + readonly = 1; + } else + readonly = 1; + if (readonly) { + cursor->insert = cursor->insert_orig = __wt_cursor_notsup; + cursor->update = cursor->update_orig = __wt_cursor_notsup; + cursor->remove = cursor->remove_orig = __wt_cursor_notsup; } /* @@ -634,14 +661,18 @@ __wt_cursor_init(WT_CURSOR *cursor, } else cdump = NULL; + /* overwrite */ + WT_RET(__wt_config_gets_def(session, cfg, "overwrite", 1, &cval)); + if (cval.val) + F_SET(cursor, WT_CURSTD_OVERWRITE); + else + F_CLR(cursor, WT_CURSTD_OVERWRITE); + /* raw */ WT_RET(__wt_config_gets_def(session, cfg, "raw", 0, &cval)); if (cval.val != 0) F_SET(cursor, WT_CURSTD_RAW); - /* readonly */ - WT_RET(__wt_cursor_config_readonly(cursor, cfg, 0)); - /* * Cursors that are internal to some other cursor (such as file cursors * inside a table cursor) should be closed after the containing cursor. |