-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kvs: support append operation #1265
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1265 +/- ##
=========================================
- Coverage 77.96% 77.9% -0.07%
=========================================
Files 154 154
Lines 29018 29093 +75
=========================================
+ Hits 22624 22664 +40
- Misses 6394 6429 +35
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow you got that done quick! Nice!
Couple minor comments inline.
@@ -122,7 +122,7 @@ int flux_kvs_txn_put_raw (flux_kvs_txn_t *txn, int flags, | |||
errno = EINVAL; | |||
goto error; | |||
} | |||
if (validate_flags (flags, 0) < 0) | |||
if (validate_flags (flags, FLUX_KVS_APPEND) < 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should allow append in flux_kvs_txn_put()
also.
src/common/libkvs/kvs_txn.h
Outdated
@@ -7,6 +7,10 @@ extern "C" { | |||
|
|||
#include <stdarg.h> | |||
|
|||
enum { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed all the flags in kvs.h are now lookup specific. I moved them into kvs.h because earlier we alloed the FLUX_KVS_TREEOBJ flag with txn_put.
I guess I'd vote we put all the KVS user flags in the same enum in kvs.h unless others feel they should be split up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh, sounds good to put it all in kvs.h
return -1; | ||
} | ||
else { | ||
char *s = json_dumps (entry, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use treeobj_encode()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is the "corrupt treeobj" path, I think using json_dumps() is the right idea.
Using treeobj_encode() works right now b/c it presently just calls json_dumps() directly and does nothing else. Could treeobj_encode() ever check for treeobj_validate?
doc/man1/flux-kvs.adoc
Outdated
Store 'value' under 'key' and commit it. If it already has a value, | ||
overwrite it. If no options, value is stored directly. If '-j', it is | ||
first encoded as JSON, then stored. If '-r', the value may be read from | ||
standard input if specified as "-", and may include embedded NULL bytes. | ||
If '-t', value is stored as a RFC 11 object. '-n' prevents the commit | ||
from being merged with with other contemporaneous commits. | ||
from being merged with with other contemporaneous commits. '-A' appends the | ||
value to a key instead of overwriting the value. Append only works with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should work with no options, if my suggestion is accepted. JSON is the one that gets weird since a JSON object appended to a JSON object isn't valid JSON.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, I didn't adjust given changes with #1262. Will have to go back and change that.
@@ -94,6 +94,9 @@ static struct optparse_option put_opts[] = { | |||
{ .name = "no-merge", .key = 'n', .has_arg = 0, | |||
.usage = "Set the NO_MERGE flag to ensure commit is standalone", | |||
}, | |||
{ .name = "append", .key = 'A', .has_arg = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to use little a for the short opt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
little a is used for the "at" option throughout flux kvs, so picked big A just to be different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh duh.
repushed with minor fixes as discussed above. Fixed a major bug I found. Required refactoring of |
doc/man1/flux-kvs.adoc
Outdated
@@ -57,8 +57,8 @@ first encoded as JSON, then stored. If '-r', the value may be read from | |||
standard input if specified as "-", and may include embedded NULL bytes. | |||
If '-t', value is stored as a RFC 11 object. '-n' prevents the commit | |||
from being merged with with other contemporaneous commits. '-A' appends the | |||
value to a key instead of overwriting the value. Append only works with the | |||
'-r' option. | |||
value to a key instead of overwriting the value. Append works with no options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe simpler to say
Append is incompatible with the
-j
option.
src/common/libkvs/treeobj.h
Outdated
*/ | ||
json_t *treeobj_copy_dir (json_t *obj); | ||
json_t *treeobj_copy (json_t *obj); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be named so that it's more clear that it makes a thin copy of the data
object?
This property is critical to understanding how commits are processed.
Maybe treeobj_copy_thin()
or similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it is a deep copy as long as it's not a directory that includes "rolled up" subdirectories. Hmm, maybe just need to add a new treeobj_copy()
that makes a deep copy and leave that other one alone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see your point that treeobj_copy()
by itself may be ambiguous. I had wanted to avoid it, perhaps adding separate treeobj_copy_dirref()
and treeobj_copy_valref()
functions would be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about treeobj_copy()
that fully copies any treeobj, and then rename treeobj_copy_dir()
to something more indicitave of what it's doing like treeobj_copy_dir_thin()
? (the rename could be deferred to another PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I think about it, how about just making a function treeobj_copy_shallow()
. It can be made quite clear that it's a shallow copy of the data within a treeobj, regardless of the data it is.
Good job finding that bug! Maybe the json objects returned from the cache should be tagged |
good idea on making the cache returns |
Don't forget to update the FLAGS section of flux_kvs_txn_create.adoc with a description of FLUX_KVS_APPEND. |
just pushed with smaller incremental changes as discussed above. Also completely redid the prior |
src/common/libkvs/treeobj.c
Outdated
@@ -263,6 +263,84 @@ int treeobj_insert_entry (json_t *obj, const char *name, json_t *obj2) | |||
return 0; | |||
} | |||
|
|||
json_t *treeobj_copy (json_t *obj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would json_deep_copy()
work here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming wise? That would follow jansson style naming. Are you thinking treeobj_copy()
would be the shallow equivalent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant could the jansson function json_deep_copy()
do what treeobj_copy()
proposes to do here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohhh, duh! You're right. I'm going to rename to treeobj_deep_copy()
as well, as that would follow the jansson style. treeobj_copy()
will be the treeobj equivalent of shallow copy.
just re-pushed, decided to rename functions, so now we have Also noticed a corner case in |
I occurred to me on the drive home. Given how I implemented |
I may be getting lost here. Why not just have a |
I don't think we're on the same page on this. I'll drop by when I get in. |
Sounds good :-) |
just re-pushed, cleanup |
Ugh ...I forgot to commit --amend something. tiny re-push. |
Add input error check ot treeobj_create_symlink() with appropriate unit test.
OK, ready to merge? |
Add new function to support deep copy of treeobjs.
Change to treeobj_copy() and make function a shallow copy for all treeobj types. Update unit tests appropriately. Update callers appropriately.
Update txn_encode_op, flux_kvs_txn_put, and flux_kvs_txn_put_raw to allow user to set FLUX_KVS_APPEND flag. Add unit tests for corner case tests to bad input in txn_encode_op. Update documentation appropriately.
Split item_callback_list into two lists, missing_refs_list which will hold missing references to look up when user calls commit_iter_missing_refs() and and dirty_cache_entries_list which will have dirty cache entries to flush when user calls commit_iter_dirty_cache_entries().
In both commit API and commit unit tests, pass around/set flags argument from commit operations.
Support ability to append to already existing KVS values. Add new append unit tests.
b93e9af
to
0145b56
Compare
just squashed and re-pushed. Two tiny tweaks in the squash. Removed calls to Also removed a few unit tests for |
Looks good @chu11 - will merge once travis passes. |
one build hung after
restarting. |
hit
i'm assuming slowness and a broker had to be killed. restarting build. |
This PR implements basic append support in the KVS and a basic
--append
option in flux-kvs.