Skip to content

Commit

Permalink
modules/kvs: avoid extra treeobj_encode in store_cache
Browse files Browse the repository at this point in the history
Problem: treeobj that is to be stored in the cache is encoded
once to calculate its hash, and again to be stored in raw
form.

Just encode the treeobj in raw form, then calculate its
hash and store it raw.
  • Loading branch information
garlick committed Nov 7, 2017
1 parent 2716ed2 commit e937cc7
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions src/modules/kvs/commit.c
Expand Up @@ -206,7 +206,7 @@ static int store_cache (commit_t *c, int current_epoch, json_t *o,
bool is_raw, href_t ref, struct cache_entry **hpp)
{
struct cache_entry *hp;
int saved_errno, rc = -1;
int saved_errno, rc;
const char *xdata;
char *data = NULL;
int xlen, len;
Expand All @@ -231,40 +231,38 @@ static int store_cache (commit_t *c, int current_epoch, json_t *o,
free (data);
data = NULL;
}
blobref_hash (c->cm->hash_name, data, len, ref, sizeof (href_t));
}
else {
if (treeobj_hash (c->cm->hash_name, o, ref, sizeof (href_t)) < 0) {
flux_log_error (c->cm->h, "treeobj_hash");
if (treeobj_validate (o) < 0 || !(data = treeobj_encode (o))) {
flux_log_error (c->cm->h, "%s: treeobj_encode", __FUNCTION__);
goto error;
}
len = strlen (data);
}
if (blobref_hash (c->cm->hash_name, data, len, ref, sizeof (href_t)) < 0) {
flux_log_error (c->cm->h, "%s: blobref_hash", __FUNCTION__);
goto error;
}
if (!(hp = cache_lookup (c->cm->cache, ref, current_epoch))) {
if (!(hp = cache_entry_create ()))
if (!(hp = cache_entry_create ())) {
flux_log_error (c->cm->h, "%s: cache_entry_create", __FUNCTION__);
goto error;
}
cache_insert (c->cm->cache, ref, hp);
}
if (cache_entry_get_valid (hp)) {
c->cm->noop_stores++;
rc = 0;
} else {
if (is_raw) {
if (cache_entry_set_raw (hp, data, len) < 0) {
int ret;
ret = cache_remove_entry (c->cm->cache, ref);
assert (ret == 1);
goto error;
}
}
else {
if (cache_entry_set_treeobj (hp, o) < 0) {
int ret;
ret = cache_remove_entry (c->cm->cache, ref);
assert (ret == 1);
goto error;
}
}
else {
if (cache_entry_set_raw (hp, data, len) < 0) {
int ret;
ret = cache_remove_entry (c->cm->cache, ref);
assert (ret == 1);
goto error;
}
if (cache_entry_set_dirty (hp, true) < 0) {
flux_log_error (c->cm->h, "%s: cache_entry_set_dirty",__FUNCTION__);
int ret;
ret = cache_remove_entry (c->cm->cache, ref);
assert (ret == 1);
Expand All @@ -280,7 +278,7 @@ static int store_cache (commit_t *c, int current_epoch, json_t *o,
saved_errno = errno;
free (data);
errno = saved_errno;
return rc;
return -1;
}

/* Store DIRVAL objects, converting them to DIRREFs.
Expand Down

0 comments on commit e937cc7

Please sign in to comment.