Skip to content

Commit

Permalink
modules/kvs: add kvs_getat()
Browse files Browse the repository at this point in the history
Add a new function kvs_getat() which is like kvs_get() but has
a new "treeobj" argument that specifies the specific root
(or other directory) "snapshot" that the key will be looked
up in.

Partially fixes flux-framework#64
  • Loading branch information
garlick committed Sep 26, 2016
1 parent 862db5c commit a9eb862
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/modules/kvs/kvs.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ int kvs_get_symlink (flux_t h, const char *key, char **valp);
*/
int kvs_get_treeobj (flux_t h, const char *key, char **treeobj);

/* Like kvs_get() but lookup is relative to 'treeobj'.
*/
int kvs_getat (flux_t h, const char *treeobj,
const char *key, char **json_str);

/* kvs_watch* is like kvs_get* except the registered callback is called
* to set the value. It will be called immediately to set the initial
* value and again each time the value changes.
Expand Down
23 changes: 23 additions & 0 deletions src/modules/kvs/libkvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,29 @@ int kvs_get (flux_t h, const char *key, char **val)
return 0;
}

int kvs_getat (flux_t h, const char *treeobj,
const char *key, char **val)
{
JSON v = NULL;
JSON dirent = NULL;

if (!treeobj || !key || !(dirent = Jfromstr (treeobj))
|| dirent_validate (dirent) < 0) {
errno = EINVAL;
goto error;
}
if (getobj (h, dirent, key, 0, &v) < 0)
goto error;
if (val)
*val = xstrdup (Jtostr (v));
Jput (dirent);
return 0;
error:
Jput (v);
Jput (dirent);
return -1;
}

/* deprecated */
int kvs_get_obj (flux_t h, const char *key, JSON *val)
{
Expand Down

0 comments on commit a9eb862

Please sign in to comment.