-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Adds support for atomic transactions spanning multiple KV entries. #2028
Merged
Merged
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
9edca28
Moves KVS-related state store code out into its own set of files.
6c2aeb2
Splits existing KVS operations into *Txn helpers for later reuse.
b7ae973
Adds state store support for atomic KVS ops.
e491245
Performs basic plumbing of KVS transactions through all the layers.
2f51926
Adds an empty get test case.
fcb0c20
Adds internal endpoint read ACL support and full unit tests.
7a797da
Adds unit tests for HTTP endpoint.
44ab1aa
Adds type for API ops and an example transaction.
23545f9
Fixes some go vet findings in a unit test.
1fefdcb
Terminates pretty responses with a newline.
69f58ad
Moves txn code into a new endpoint, not specific to KV.
38d0f66
Refactors TxnRequest/TxnResponse into a form that will allow non-KV ops.
960b9d6
Switches to "KV" instead of "KV" for the KV operations.
4882a9f
De-nests the KV output structure (removes DirEnt member).
04d99cd
Makes get fail a transaction if the key doesn't exist.
17cd0ac
Adds documentation for the transaction endpoint.
8a7428e
Hoists KV processing helper functions up as static functions.
9443c6b
Adds a comment for the txnKVS() function.
a37bf9d
Adds a read-only optimized path for transactions.
fbfb90a
Removes null results for deletes, and preps for more than one result …
570d46a
Adds some size limiting features to transactions to help prevent abuse.
4bbaf1c
Switches GETs to a filtering model for ACLs.
778b975
Adds a get-tree verb to KV transaction operations.
6533876
Reduces the number of operations in a transaction to 64.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,6 +269,8 @@ func (s *HTTPServer) registerHandlers(enableDebug bool) { | |
s.mux.HandleFunc("/v1/query", s.wrap(s.PreparedQueryGeneral)) | ||
s.mux.HandleFunc("/v1/query/", s.wrap(s.PreparedQuerySpecific)) | ||
|
||
s.mux.HandleFunc("/v1/txn", s.wrap(s.Txn)) | ||
|
||
if enableDebug { | ||
s.mux.HandleFunc("/debug/pprof/", pprof.Index) | ||
s.mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) | ||
|
@@ -342,28 +344,39 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque | |
return | ||
} | ||
|
||
prettyPrint := false | ||
if _, ok := req.URL.Query()["pretty"]; ok { | ||
prettyPrint = true | ||
} | ||
// Write out the JSON object | ||
if obj != nil { | ||
var buf []byte | ||
if prettyPrint { | ||
buf, err = json.MarshalIndent(obj, "", " ") | ||
} else { | ||
buf, err = json.Marshal(obj) | ||
} | ||
buf, err = s.marshalJSON(req, obj) | ||
if err != nil { | ||
goto HAS_ERR | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been wanting to do this for a while:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm-a sneak that in since I'm touching that code as part of this change. |
||
resp.Header().Set("Content-Type", "application/json") | ||
resp.Write(buf) | ||
} | ||
} | ||
return f | ||
} | ||
|
||
// marshalJSON marshals the object into JSON, respecting the user's pretty-ness | ||
// configuration. | ||
func (s *HTTPServer) marshalJSON(req *http.Request, obj interface{}) ([]byte, error) { | ||
if _, ok := req.URL.Query()["pretty"]; ok { | ||
buf, err := json.MarshalIndent(obj, "", " ") | ||
if err != nil { | ||
return nil, err | ||
} | ||
buf = append(buf, "\n"...) | ||
return buf, nil | ||
} | ||
|
||
buf, err := json.Marshal(obj) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return buf, err | ||
} | ||
|
||
// Returns true if the UI is enabled. | ||
func (s *HTTPServer) IsUIEnabled() bool { | ||
return s.uiDir != "" || s.agent.config.EnableUi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Basically the previous ~20LOC but added to the function comment block for
Txn
.