Skip to content

Commit

Permalink
Merge pull request #1300 from chu11/issue1297
Browse files Browse the repository at this point in the history
modules/kvs: Refactor lookup_create()
  • Loading branch information
garlick authored Dec 7, 2017
2 parents 57e24fa + de3cff7 commit 53697fa
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 141 deletions.
4 changes: 1 addition & 3 deletions src/modules/kvs/kvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,7 @@ static void get_request_cb (flux_t *h, flux_msg_handler_t *mh,

if (!(lh = lookup_create (ctx->cache,
ctx->epoch,
root->ref,
root_ref,
root_ref ? root_ref : root->ref,
key,
h,
flags)))
Expand Down Expand Up @@ -886,7 +885,6 @@ static void watch_request_cb (flux_t *h, flux_msg_handler_t *mh,
if (!(lh = lookup_create (ctx->cache,
ctx->epoch,
root->ref,
NULL,
key,
h,
flags)))
Expand Down
33 changes: 5 additions & 28 deletions src/modules/kvs/lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ struct lookup {
struct cache *cache;
int current_epoch;

char *root_dir;
char *root_ref;
char *root_ref_copy;

char *path;

Expand Down Expand Up @@ -378,7 +376,6 @@ static bool walk (lookup_t *lh)

lookup_t *lookup_create (struct cache *cache,
int current_epoch,
const char *root_dir,
const char *root_ref,
const char *path,
flux_t *h,
Expand All @@ -387,7 +384,7 @@ lookup_t *lookup_create (struct cache *cache,
lookup_t *lh = NULL;
int saved_errno;

if (!cache || !root_dir || !path) {
if (!cache || !root_ref || !path) {
errno = EINVAL;
return NULL;
}
Expand All @@ -400,23 +397,11 @@ lookup_t *lookup_create (struct cache *cache,
lh->magic = LOOKUP_MAGIC;
lh->cache = cache;
lh->current_epoch = current_epoch;
/* must duplicate these strings, user may not keep pointer
* alive */
if (!(lh->root_dir = strdup (root_dir))) {
/* must duplicate ref, user may not keep pointer alive */
if (!(lh->root_ref = strdup (root_ref))) {
saved_errno = ENOMEM;
goto cleanup;
}
if (root_ref) {
if (!(lh->root_ref_copy = strdup (root_ref))) {
saved_errno = ENOMEM;
goto cleanup;
}
lh->root_ref = lh->root_ref_copy;
}
else {
lh->root_ref_copy = NULL;
lh->root_ref = lh->root_dir;
}
if (!(lh->path = kvs_util_normalize_key (path, NULL))) {
saved_errno = ENOMEM;
goto cleanup;
Expand Down Expand Up @@ -461,8 +446,7 @@ lookup_t *lookup_create (struct cache *cache,
void lookup_destroy (lookup_t *lh)
{
if (lh && lh->magic == LOOKUP_MAGIC) {
free (lh->root_dir);
free (lh->root_ref_copy);
free (lh->root_ref);
free (lh->path);
json_decref (lh->val);
json_decref (lh->root_dirent);
Expand Down Expand Up @@ -577,13 +561,6 @@ int lookup_get_current_epoch (lookup_t *lh)
return -1;
}

const char *lookup_get_root_dir (lookup_t *lh)
{
if (lh && lh->magic == LOOKUP_MAGIC)
return lh->root_dir;
return NULL;
}

const char *lookup_get_root_ref (lookup_t *lh)
{
if (lh && lh->magic == LOOKUP_MAGIC)
Expand Down Expand Up @@ -792,7 +769,7 @@ bool lookup (lookup_t *lh)
/* special case root */
if (!strcmp (lh->path, ".")) {
if ((lh->flags & FLUX_KVS_TREEOBJ)) {
if (!(lh->val = treeobj_create_dirref (lh->root_dir))) {
if (!(lh->val = treeobj_create_dirref (lh->root_ref))) {
lh->errnum = errno;
goto done;
}
Expand Down
8 changes: 0 additions & 8 deletions src/modules/kvs/lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ typedef int (*lookup_ref_f)(lookup_t *c,
void *data);

/* Initialize a lookup handle
* - If root_ref is same as root_dir, can be set to NULL.
* - flux_t is optional, if NULL logging will go to stderr
*/
lookup_t *lookup_create (struct cache *cache,
int current_epoch,
const char *root_dir,
const char *root_ref,
const char *path,
flux_t *h,
Expand Down Expand Up @@ -64,11 +61,6 @@ struct cache *lookup_get_cache (lookup_t *lh);
*/
int lookup_get_current_epoch (lookup_t *lh);

/* Convenience function to get root dir from earlier instantiation.
* Convenient if replaying RPC and don't have it presently.
*/
const char *lookup_get_root_dir (lookup_t *lh);

/* Convenience function to get root ref from earlier instantiation.
* Convenient if replaying RPC and don't have it presently.
*/
Expand Down
1 change: 0 additions & 1 deletion src/modules/kvs/test/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ void verify_value (struct cache *cache,
ok ((lh = lookup_create (cache,
1,
root_ref,
root_ref,
key,
NULL,
0)) != NULL,
Expand Down
Loading

0 comments on commit 53697fa

Please sign in to comment.