Skip to content

Commit

Permalink
libkvs: Support flux_kvs_namespace_create_with()
Browse files Browse the repository at this point in the history
Problem: libkvs does not support a way to initialize a namespace
to a specific rootref.

Solution: Add a new function flux_kvs_namespace_create_with().
  • Loading branch information
chu11 committed Nov 5, 2021
1 parent 7314bca commit f5604ff
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions doc/man3/flux_kvs_namespace_create.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ SYNOPSIS
uint32_t owner,
int flags);

::

flux_future_t *flux_kvs_namespace_create_with (flux_t *h,
const char *namespace,
const char *rootref,
uint32_t owner,
int flags);

::

flux_future_t *flux_kvs_namespace_remove (flux_t *h,
Expand All @@ -32,6 +40,11 @@ other KVS namespaces. An owner of the namespace other than the
instance owner can be chosen by setting *owner*. Otherwise, *owner*
can be set to FLUX_USERID_UNKNOWN.

``flux_kvs_namespace_create_with()`` is identical to
``flux_kvs_namespace_create()`` but will initialize the namespace to
the specified *rootref*. This may be useful in several circumstances,
such as initializing a namespace to an earlier checkpoint.

``flux_kvs_namespace_remove()`` removes a KVS namespace.


Expand Down
18 changes: 18 additions & 0 deletions src/common/libkvs/kvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ flux_future_t *flux_kvs_namespace_create (flux_t *h, const char *ns,
return rv;
}

flux_future_t *flux_kvs_namespace_create_with (flux_t *h, const char *ns,
const char *rootref,
uint32_t owner, int flags)
{
if (!ns || !rootref || flags) {
errno = EINVAL;
return NULL;
}

/* N.B. owner cast to int */
return flux_rpc_pack (h, "kvs.namespace-create", 0, 0,
"{ s:s s:s s:i s:i }",
"namespace", ns,
"rootref", rootref,
"owner", owner,
"flags", flags);
}

flux_future_t *flux_kvs_namespace_remove (flux_t *h, const char *ns)
{
if (!ns) {
Expand Down
3 changes: 3 additions & 0 deletions src/common/libkvs/kvs.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ enum kvs_op {
*/
flux_future_t *flux_kvs_namespace_create (flux_t *h, const char *ns,
uint32_t owner, int flags);
flux_future_t *flux_kvs_namespace_create_with (flux_t *h, const char *ns,
const char *rootref,
uint32_t owner, int flags);
flux_future_t *flux_kvs_namespace_remove (flux_t *h, const char *ns);

/* Synchronization:
Expand Down
5 changes: 5 additions & 0 deletions src/common/libkvs/test/kvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ void errors (void)
ok (flux_kvs_namespace_create (NULL, NULL, 0, 5) == NULL && errno == EINVAL,
"flux_kvs_namespace_create fails on bad input");

errno = 0;
ok (flux_kvs_namespace_create_with (NULL, NULL, NULL, 0, 5) == NULL
&& errno == EINVAL,
"flux_kvs_namespace_create_with fails on bad input");

errno = 0;
ok (flux_kvs_namespace_remove (NULL, NULL) == NULL && errno == EINVAL,
"flux_kvs_namespace_remove fails on bad input");
Expand Down

0 comments on commit f5604ff

Please sign in to comment.