diff options
author | Keith Bostic <keith@wiredtiger.com> | 2013-06-04 12:56:26 -0400 |
---|---|---|
committer | Keith Bostic <keith@wiredtiger.com> | 2013-06-04 12:56:26 -0400 |
commit | 7f64e46c56d8dec8970a2873495089040f3f1186 (patch) | |
tree | 8f7c81bc7f91eb4796c99c67190f0b1205acb8b1 | |
parent | 6ec1ffbfb18cd7e9661869b630d9b7538ca141e9 (diff) | |
download | mongo-7f64e46c56d8dec8970a2873495089040f3f1186.tar.gz |
Add examples to the WiredTiger extension methods for accessing the
metadata.
-rw-r--r-- | dist/s_string.ok | 2 | ||||
-rw-r--r-- | examples/c/ex_data_source.c | 90 | ||||
-rw-r--r-- | src/include/wiredtiger_ext.h | 15 |
3 files changed, 104 insertions, 3 deletions
diff --git a/dist/s_string.ok b/dist/s_string.ok index 8a3a2002816..d031f64d8ae 100644 --- a/dist/s_string.ok +++ b/dist/s_string.ok @@ -350,6 +350,7 @@ cxa data's datalen datasets +datasource dbc decl decr @@ -796,6 +797,7 @@ untyped upd upg uri +uri's usedp usr utf diff --git a/examples/c/ex_data_source.c b/examples/c/ex_data_source.c index dd2b56616aa..3372d1825f4 100644 --- a/examples/c/ex_data_source.c +++ b/examples/c/ex_data_source.c @@ -197,6 +197,30 @@ my_open_cursor(WT_DATA_SOURCE *dsrc, WT_SESSION *session, } { + /*! [WT_EXTENSION config_strget] */ + WT_CONFIG_ITEM v; + int64_t my_data_source_page_size; + + /* + * Retrieve the value of the integer type configuration string + * "page_size" from a local string (as opposed to the provided + * WT_CONFIG_ARG reference). + */ + const char *config_string = "path=/dev/loop,page_size=1024"; + + if ((ret = wt_api->config_strget( + wt_api, session, config_string, "page_size", &v)) != 0) { + (void)wt_api->err_printf(wt_api, session, + "page_size configuration: %s", wiredtiger_strerror(ret)); + return (ret); + } + my_data_source_page_size = v.val; + /*! [WT_EXTENSION config_strget] */ + + (void)my_data_source_page_size; + } + + { /*! [WT_EXTENSION config_get] */ WT_CONFIG_ITEM v; const char *my_data_source_key; @@ -262,6 +286,72 @@ my_open_cursor(WT_DATA_SOURCE *dsrc, WT_SESSION *session, } /*! [WT_DATA_SOURCE error message] */ + { + /*! [WT_EXTENSION metadata insert] */ + /* + * Insert a new WiredTiger metadata record. + */ + const char *key = "datasource_uri"; + const char *value = "data source uri's record"; + + if ((ret = wt_api->metadata_insert(wt_api, session, key, value)) != 0) { + (void)wt_api->err_printf(wt_api, session, + "%s: metadata insert: %s", key, wiredtiger_strerror(ret)); + return (ret); + } + /*! [WT_EXTENSION metadata insert] */ + } + + { + /*! [WT_EXTENSION metadata remove] */ + /* + * Remove a WiredTiger metadata record. + */ + const char *key = "datasource_uri"; + + if ((ret = wt_api->metadata_remove(wt_api, session, key)) != 0) { + (void)wt_api->err_printf(wt_api, session, + "%s: metadata remove: %s", key, wiredtiger_strerror(ret)); + return (ret); + } + /*! [WT_EXTENSION metadata remove] */ + } + + { + /*! [WT_EXTENSION metadata search] */ + /* + * Insert a new WiredTiger metadata record. + */ + const char *key = "datasource_uri"; + const char *value; + + if ((ret = + wt_api->metadata_search(wt_api, session, key, &value)) != 0) { + (void)wt_api->err_printf(wt_api, session, + "%s: metadata search: %s", key, wiredtiger_strerror(ret)); + return (ret); + } + printf("metadata: %s has a value of %s\n", key, value); + /*! [WT_EXTENSION metadata search] */ + } + + { + /*! [WT_EXTENSION metadata update] */ + /* + * Update a WiredTiger metadata record (insert it if it does not yet + * exist, update it if it does). + */ + const char *key = "datasource_uri"; + const char *value = "data source uri's record"; + + if ((ret = wt_api->metadata_update(wt_api, session, key, value)) != 0) { + (void)wt_api->err_printf(wt_api, session, + "%s: metadata update: %s", key, wiredtiger_strerror(ret)); + return (ret); + } + /*! [WT_EXTENSION metadata update] */ + } + return (0); } diff --git a/src/include/wiredtiger_ext.h b/src/include/wiredtiger_ext.h index 8682171edf7..021875474e5 100644 --- a/src/include/wiredtiger_ext.h +++ b/src/include/wiredtiger_ext.h @@ -140,7 +140,7 @@ struct __wt_extension_api { * @param value the returned value * @errors * - * @snippet ex_data_source.c WT_EXTENSION config_get + * @snippet ex_data_source.c WT_EXTENSION config_strget */ int (*config_strget)(WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *config, const char *key, WT_CONFIG_ITEM *value); @@ -194,13 +194,15 @@ struct __wt_extension_api { WT_CONFIG_SCAN *scan, WT_CONFIG_ITEM *key, WT_CONFIG_ITEM *value); /*! - * Insert a row into the metadata. + * Insert a row into the metadata if it does not already exist. * * @param wt_api the extension handle * @param session the session handle (or NULL if none available) * @param key row key * @param value row value * @errors + * + * @snippet ex_data_source.c WT_EXTENSION metadata insert */ int (*metadata_insert)(WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *key, const char *value); @@ -212,6 +214,8 @@ struct __wt_extension_api { * @param session the session handle (or NULL if none available) * @param key row key * @errors + * + * @snippet ex_data_source.c WT_EXTENSION metadata remove */ int (*metadata_remove)( WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *key); @@ -224,18 +228,23 @@ struct __wt_extension_api { * @param key row key * @param [out] valuep the row value * @errors + * + * @snippet ex_data_source.c WT_EXTENSION metadata search */ int (*metadata_search)(WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *key, const char **valuep); /*! - * Update a row in the metadata. + * Update a row in the metadata by either inserting a new record or + * updating an existing record. * * @param wt_api the extension handle * @param session the session handle (or NULL if none available) * @param key row key * @param value row value * @errors + * + * @snippet ex_data_source.c WT_EXTENSION metadata update */ int (*metadata_update)(WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *key, const char *value); |