diff --git a/api/kv.go b/api/kv.go index db6e25b39b..fb35758365 100644 --- a/api/kv.go +++ b/api/kv.go @@ -278,7 +278,7 @@ func (k *KV) deleteInternal(key string, params map[string]string, q *WriteOption // TxnOp is the internal format we send to Consul. It's not specific to KV, // though currently only KV operations are supported. type TxnOp struct { - KVS *KVTxnOp + KV *KVTxnOp } // TxnOps is a list of transaction operations. @@ -286,7 +286,7 @@ type TxnOps []*TxnOp // TxnResult is the internal format we receive from Consul. type TxnResult struct { - KVS *struct{ DirEnt *KVPair } + KV *struct{ DirEnt *KVPair } } // TxnResults is a list of TxnResult objects. @@ -349,8 +349,8 @@ func (k *KV) Txn(txn KVTxnOps, q *WriteOptions) (bool, *KVTxnResponse, *WriteMet // Convert into the internal format since this is an all-KV txn. ops := make(TxnOps, 0, len(txn)) - for _, kvsOp := range txn { - ops = append(ops, &TxnOp{KVS: kvsOp}) + for _, kvOp := range txn { + ops = append(ops, &TxnOp{KV: kvOp}) } r.obj = ops rtt, resp, err := k.c.doRequest(r) @@ -374,8 +374,8 @@ func (k *KV) Txn(txn KVTxnOps, q *WriteOptions) (bool, *KVTxnResponse, *WriteMet } for _, result := range txnResp.Results { var entry *KVPair - if result.KVS != nil { - entry = result.KVS.DirEnt + if result.KV != nil { + entry = result.KV.DirEnt } kvResp.Results = append(kvResp.Results, entry) } diff --git a/command/agent/txn_endpoint.go b/command/agent/txn_endpoint.go index 31a0962a74..11198f5c8f 100644 --- a/command/agent/txn_endpoint.go +++ b/command/agent/txn_endpoint.go @@ -10,14 +10,14 @@ import ( "github.com/hashicorp/consul/consul/structs" ) -// fixupKVSOps takes the raw decoded JSON and base64 decodes all the KVS values, -// replacing them with byte arrays with the data. -func fixupKVSOps(raw interface{}) error { +// fixupKVOps takes the raw decoded JSON and base64 decodes values in KV ops, +// replacing them with byte arrays. +func fixupKVOps(raw interface{}) error { // decodeValue decodes the value member of the given operation. - decodeValue := func(rawKVS interface{}) error { - rawMap, ok := rawKVS.(map[string]interface{}) + decodeValue := func(rawKV interface{}) error { + rawMap, ok := rawKV.(map[string]interface{}) if !ok { - return fmt.Errorf("unexpected raw KVS type: %T", rawKVS) + return fmt.Errorf("unexpected raw KV type: %T", rawKV) } for k, v := range rawMap { switch strings.ToLower(k) { @@ -44,16 +44,16 @@ func fixupKVSOps(raw interface{}) error { return nil } - // fixupKVSOp looks for non-nil KVS operations and passes them on for + // fixupKVOp looks for non-nil KV operations and passes them on for // value conversion. - fixupKVSOp := func(rawOp interface{}) error { + fixupKVOp := func(rawOp interface{}) error { rawMap, ok := rawOp.(map[string]interface{}) if !ok { return fmt.Errorf("unexpected raw op type: %T", rawOp) } for k, v := range rawMap { switch strings.ToLower(k) { - case "kvs": + case "kv": if v == nil { return nil } @@ -68,7 +68,7 @@ func fixupKVSOps(raw interface{}) error { return fmt.Errorf("unexpected raw type: %t", raw) } for _, rawOp := range rawSlice { - if err := fixupKVSOp(rawOp); err != nil { + if err := fixupKVOp(rawOp); err != nil { return err } } @@ -91,34 +91,34 @@ func (s *HTTPServer) Txn(resp http.ResponseWriter, req *http.Request) (interface // decode it, we will return a 400 since we don't have enough context to // associate the error with a given operation. var ops api.TxnOps - if err := decodeBody(req, &ops, fixupKVSOps); err != nil { + if err := decodeBody(req, &ops, fixupKVOps); err != nil { resp.WriteHeader(http.StatusBadRequest) resp.Write([]byte(fmt.Sprintf("Failed to parse body: %v", err))) return nil, nil } - // Convert the KVS API format into the RPC format. Note that fixupKVSOps + // Convert the KV API format into the RPC format. Note that fixupKVOps // above will have already converted the base64 encoded strings into // byte arrays so we can assign right over. for _, in := range ops { - if in.KVS != nil { - if size := len(in.KVS.Value); size > maxKVSize { + if in.KV != nil { + if size := len(in.KV.Value); size > maxKVSize { resp.WriteHeader(http.StatusRequestEntityTooLarge) resp.Write([]byte(fmt.Sprintf("Value for key %q is too large (%d > %d bytes)", - in.KVS.Key, size, maxKVSize))) + in.KV.Key, size, maxKVSize))) return nil, nil } out := &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ - Verb: structs.KVSOp(in.KVS.Verb), + KV: &structs.TxnKVOp{ + Verb: structs.KVSOp(in.KV.Verb), DirEnt: structs.DirEntry{ - Key: in.KVS.Key, - Value: in.KVS.Value, - Flags: in.KVS.Flags, - Session: in.KVS.Session, + Key: in.KV.Key, + Value: in.KV.Value, + Flags: in.KV.Flags, + Session: in.KV.Session, RaftIndex: structs.RaftIndex{ - ModifyIndex: in.KVS.Index, + ModifyIndex: in.KV.Index, }, }, }, diff --git a/command/agent/txn_endpoint_test.go b/command/agent/txn_endpoint_test.go index dd6ad079ae..d891bbca1d 100644 --- a/command/agent/txn_endpoint_test.go +++ b/command/agent/txn_endpoint_test.go @@ -56,7 +56,7 @@ func TestTxnEndpoint_Bad_Size(t *testing.T) { buf := bytes.NewBuffer([]byte(fmt.Sprintf(` [ { - "KVS": { + "KV": { "Verb": "set", "Key": "key", "Value": %q @@ -79,7 +79,7 @@ func TestTxnEndpoint_Bad_Size(t *testing.T) { }) } -func TestTxnEndpoint_KVS_Actions(t *testing.T) { +func TestTxnEndpoint_KV_Actions(t *testing.T) { httpTest(t, func(srv *HTTPServer) { // Make sure all incoming fields get converted properly to the internal // RPC format. @@ -89,7 +89,7 @@ func TestTxnEndpoint_KVS_Actions(t *testing.T) { buf := bytes.NewBuffer([]byte(fmt.Sprintf(` [ { - "KVS": { + "KV": { "Verb": "lock", "Key": "key", "Value": "aGVsbG8gd29ybGQ=", @@ -98,7 +98,7 @@ func TestTxnEndpoint_KVS_Actions(t *testing.T) { } }, { - "KVS": { + "KV": { "Verb": "get", "Key": "key" } @@ -126,11 +126,11 @@ func TestTxnEndpoint_KVS_Actions(t *testing.T) { if len(txnResp.Results) != 2 { t.Fatalf("bad: %v", txnResp) } - index = txnResp.Results[0].KVS.DirEnt.ModifyIndex + index = txnResp.Results[0].KV.DirEnt.ModifyIndex expected := structs.TxnResponse{ Results: structs.TxnResults{ &structs.TxnResult{ - KVS: &structs.TxnKVSResult{ + KV: &structs.TxnKVResult{ DirEnt: &structs.DirEntry{ Key: "key", Value: nil, @@ -145,7 +145,7 @@ func TestTxnEndpoint_KVS_Actions(t *testing.T) { }, }, &structs.TxnResult{ - KVS: &structs.TxnKVSResult{ + KV: &structs.TxnKVResult{ DirEnt: &structs.DirEntry{ Key: "key", Value: []byte("hello world"), @@ -172,7 +172,7 @@ func TestTxnEndpoint_KVS_Actions(t *testing.T) { buf := bytes.NewBuffer([]byte(fmt.Sprintf(` [ { - "KVS": { + "KV": { "Verb": "cas", "Key": "key", "Value": "Z29vZGJ5ZSB3b3JsZA==", @@ -180,7 +180,7 @@ func TestTxnEndpoint_KVS_Actions(t *testing.T) { } }, { - "KVS": { + "KV": { "Verb": "get", "Key": "key" } @@ -208,11 +208,11 @@ func TestTxnEndpoint_KVS_Actions(t *testing.T) { if len(txnResp.Results) != 2 { t.Fatalf("bad: %v", txnResp) } - modIndex := txnResp.Results[0].KVS.DirEnt.ModifyIndex + modIndex := txnResp.Results[0].KV.DirEnt.ModifyIndex expected := structs.TxnResponse{ Results: structs.TxnResults{ &structs.TxnResult{ - KVS: &structs.TxnKVSResult{ + KV: &structs.TxnKVResult{ DirEnt: &structs.DirEntry{ Key: "key", Value: nil, @@ -225,7 +225,7 @@ func TestTxnEndpoint_KVS_Actions(t *testing.T) { }, }, &structs.TxnResult{ - KVS: &structs.TxnKVSResult{ + KV: &structs.TxnKVResult{ DirEnt: &structs.DirEntry{ Key: "key", Value: []byte("goodbye world"), @@ -250,7 +250,7 @@ func TestTxnEndpoint_KVS_Actions(t *testing.T) { buf := bytes.NewBuffer([]byte(` [ { - "KVS": { + "KV": { "Verb": "lock", "Key": "key", "Value": "aGVsbG8gd29ybGQ=", @@ -258,7 +258,7 @@ func TestTxnEndpoint_KVS_Actions(t *testing.T) { } }, { - "KVS": { + "KV": { "Verb": "get", "Key": "key" } diff --git a/consul/fsm_test.go b/consul/fsm_test.go index e478a6b027..44c85e43e2 100644 --- a/consul/fsm_test.go +++ b/consul/fsm_test.go @@ -1252,7 +1252,7 @@ func TestFSM_Txn(t *testing.T) { Datacenter: "dc1", Ops: structs.TxnOps{ &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSSet, DirEnt: structs.DirEntry{ Key: "/test/path", diff --git a/consul/state/txn.go b/consul/state/txn.go index c58f939025..525b0d4b2f 100644 --- a/consul/state/txn.go +++ b/consul/state/txn.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/go-memdb" ) -func (s *StateStore) txnKVS(tx *memdb.Txn, idx uint64, op *structs.TxnKVSOp) (*structs.TxnKVSResult, error) { +func (s *StateStore) txnKVS(tx *memdb.Txn, idx uint64, op *structs.TxnKVOp) (*structs.TxnKVResult, error) { var entry *structs.DirEntry var err error @@ -63,7 +63,7 @@ func (s *StateStore) txnKVS(tx *memdb.Txn, idx uint64, op *structs.TxnKVSOp) (*s entry, err = s.kvsCheckIndexTxn(tx, op.DirEnt.Key, op.DirEnt.ModifyIndex) default: - err = fmt.Errorf("unknown KVS verb %q", op.Verb) + err = fmt.Errorf("unknown KV verb %q", op.Verb) } if err != nil { return nil, err @@ -74,12 +74,12 @@ func (s *StateStore) txnKVS(tx *memdb.Txn, idx uint64, op *structs.TxnKVSOp) (*s // the state store). if entry != nil { if op.Verb == structs.KVSGet { - return &structs.TxnKVSResult{entry}, nil + return &structs.TxnKVResult{entry}, nil } clone := entry.Clone() clone.Value = nil - return &structs.TxnKVSResult{clone}, nil + return &structs.TxnKVResult{clone}, nil } return nil, nil @@ -99,8 +99,8 @@ func (s *StateStore) TxnRun(idx uint64, ops structs.TxnOps) (structs.TxnResults, var err error // Dispatch based on the type of operation. - if op.KVS != nil { - result.KVS, err = s.txnKVS(tx, idx, op.KVS) + if op.KV != nil { + result.KV, err = s.txnKVS(tx, idx, op.KV) } else { err = fmt.Errorf("no operation specified") } diff --git a/consul/state/txn_test.go b/consul/state/txn_test.go index c69516a98c..acf2b5d8ec 100644 --- a/consul/state/txn_test.go +++ b/consul/state/txn_test.go @@ -28,7 +28,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { // Set up a transaction that hits every operation. ops := structs.TxnOps{ &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSSet, DirEnt: structs.DirEntry{ Key: "foo/new", @@ -37,7 +37,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSDelete, DirEnt: structs.DirEntry{ Key: "foo/zorp", @@ -45,7 +45,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSDeleteCAS, DirEnt: structs.DirEntry{ Key: "foo/delete", @@ -56,7 +56,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSDeleteTree, DirEnt: structs.DirEntry{ Key: "foo/bar", @@ -64,7 +64,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSGet, DirEnt: structs.DirEntry{ Key: "foo/update", @@ -72,7 +72,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSCheckIndex, DirEnt: structs.DirEntry{ Key: "foo/update", @@ -83,7 +83,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSCAS, DirEnt: structs.DirEntry{ Key: "foo/update", @@ -95,7 +95,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSGet, DirEnt: structs.DirEntry{ Key: "foo/update", @@ -103,7 +103,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSGet, DirEnt: structs.DirEntry{ Key: "not/there", @@ -111,7 +111,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSCheckIndex, DirEnt: structs.DirEntry{ Key: "foo/update", @@ -122,7 +122,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSGet, DirEnt: structs.DirEntry{ Key: "foo/lock", @@ -130,7 +130,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSLock, DirEnt: structs.DirEntry{ Key: "foo/lock", @@ -139,7 +139,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSCheckSession, DirEnt: structs.DirEntry{ Key: "foo/lock", @@ -148,7 +148,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSUnlock, DirEnt: structs.DirEntry{ Key: "foo/lock", @@ -157,7 +157,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSCheckSession, DirEnt: structs.DirEntry{ Key: "foo/lock", @@ -177,7 +177,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { // Make sure the response looks as expected. expected := structs.TxnResults{ &structs.TxnResult{ - KVS: &structs.TxnKVSResult{ + KV: &structs.TxnKVResult{ DirEnt: &structs.DirEntry{ Key: "foo/new", RaftIndex: structs.RaftIndex{ @@ -191,7 +191,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { &structs.TxnResult{}, // delete tree &structs.TxnResult{}, // delete CAS &structs.TxnResult{ - KVS: &structs.TxnKVSResult{ + KV: &structs.TxnKVResult{ DirEnt: &structs.DirEntry{ Key: "foo/update", Value: []byte("stale"), @@ -203,7 +203,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnResult{ - KVS: &structs.TxnKVSResult{ + KV: &structs.TxnKVResult{ DirEnt: &structs.DirEntry{ Key: "foo/update", @@ -215,7 +215,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnResult{ - KVS: &structs.TxnKVSResult{ + KV: &structs.TxnKVResult{ DirEnt: &structs.DirEntry{ Key: "foo/update", RaftIndex: structs.RaftIndex{ @@ -226,7 +226,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnResult{ - KVS: &structs.TxnKVSResult{ + KV: &structs.TxnKVResult{ DirEnt: &structs.DirEntry{ Key: "foo/update", Value: []byte("new"), @@ -239,7 +239,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, &structs.TxnResult{}, // get on not/there &structs.TxnResult{ - KVS: &structs.TxnKVSResult{ + KV: &structs.TxnKVResult{ DirEnt: &structs.DirEntry{ Key: "foo/update", RaftIndex: structs.RaftIndex{ @@ -251,7 +251,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, &structs.TxnResult{}, // get on foo/lock before it's created &structs.TxnResult{ - KVS: &structs.TxnKVSResult{ + KV: &structs.TxnKVResult{ DirEnt: &structs.DirEntry{ Key: "foo/lock", Session: session, @@ -264,7 +264,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnResult{ - KVS: &structs.TxnKVSResult{ + KV: &structs.TxnKVResult{ DirEnt: &structs.DirEntry{ Key: "foo/lock", Session: session, @@ -277,7 +277,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnResult{ - KVS: &structs.TxnKVSResult{ + KV: &structs.TxnKVResult{ DirEnt: &structs.DirEntry{ Key: "foo/lock", LockIndex: 1, @@ -289,7 +289,7 @@ func TestStateStore_Txn_KVS(t *testing.T) { }, }, &structs.TxnResult{ - KVS: &structs.TxnKVSResult{ + KV: &structs.TxnKVResult{ DirEnt: &structs.DirEntry{ Key: "foo/lock", LockIndex: 1, @@ -431,7 +431,7 @@ func TestStateStore_Txn_KVS_Rollback(t *testing.T) { // Set up a transaction that fails every operation. ops := structs.TxnOps{ &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSCAS, DirEnt: structs.DirEntry{ Key: "foo/update", @@ -443,7 +443,7 @@ func TestStateStore_Txn_KVS_Rollback(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSLock, DirEnt: structs.DirEntry{ Key: "foo/lock", @@ -452,7 +452,7 @@ func TestStateStore_Txn_KVS_Rollback(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSUnlock, DirEnt: structs.DirEntry{ Key: "foo/lock", @@ -461,7 +461,7 @@ func TestStateStore_Txn_KVS_Rollback(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSCheckSession, DirEnt: structs.DirEntry{ Key: "foo/lock", @@ -470,7 +470,7 @@ func TestStateStore_Txn_KVS_Rollback(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSCheckSession, DirEnt: structs.DirEntry{ Key: "nope", @@ -479,7 +479,7 @@ func TestStateStore_Txn_KVS_Rollback(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSCheckIndex, DirEnt: structs.DirEntry{ Key: "foo/lock", @@ -490,7 +490,7 @@ func TestStateStore_Txn_KVS_Rollback(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSCheckIndex, DirEnt: structs.DirEntry{ Key: "nope", @@ -501,7 +501,7 @@ func TestStateStore_Txn_KVS_Rollback(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: "nope", DirEnt: structs.DirEntry{ Key: "foo/delete", @@ -527,7 +527,7 @@ func TestStateStore_Txn_KVS_Rollback(t *testing.T) { `key "nope" doesn't exist`, "current modify index", `key "nope" doesn't exist`, - "unknown KVS verb", + "unknown KV verb", } if len(errors) != len(expected) { t.Fatalf("bad len: %d != %d", len(errors), len(expected)) @@ -552,7 +552,7 @@ func TestStateStore_Txn_Watches(t *testing.T) { verifyWatch(t, s.GetKVSWatch("multi/two"), func() { ops := structs.TxnOps{ &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSSet, DirEnt: structs.DirEntry{ Key: "multi/one", @@ -561,7 +561,7 @@ func TestStateStore_Txn_Watches(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSSet, DirEnt: structs.DirEntry{ Key: "multi/two", @@ -585,7 +585,7 @@ func TestStateStore_Txn_Watches(t *testing.T) { verifyNoWatch(t, s.GetKVSWatch("multi/two"), func() { ops := structs.TxnOps{ &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSSet, DirEnt: structs.DirEntry{ Key: "multi/one", @@ -594,7 +594,7 @@ func TestStateStore_Txn_Watches(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSSet, DirEnt: structs.DirEntry{ Key: "multi/two", @@ -603,7 +603,7 @@ func TestStateStore_Txn_Watches(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSLock, DirEnt: structs.DirEntry{ Key: "multi/nope", diff --git a/consul/structs/txn.go b/consul/structs/txn.go index c7dce6bf37..7ea4a72aab 100644 --- a/consul/structs/txn.go +++ b/consul/structs/txn.go @@ -4,23 +4,23 @@ import ( "fmt" ) -// TxnKVSOp is used to define a single operation on the KVS inside a +// TxnKVOp is used to define a single operation on the KVS inside a // transaction -type TxnKVSOp struct { +type TxnKVOp struct { Verb KVSOp DirEnt DirEntry } -// TxnKVSResult is used to define the result of a single operation on the KVS +// TxnKVResult is used to define the result of a single operation on the KVS // inside a transaction. -type TxnKVSResult struct { +type TxnKVResult struct { DirEnt *DirEntry } // TxnOp is used to define a single operation inside a transaction. Only one // of the types should be filled out per entry. type TxnOp struct { - KVS *TxnKVSOp + KV *TxnKVOp } // TxnOps is a list of operations within a transaction. @@ -56,7 +56,7 @@ type TxnErrors []*TxnError // TxnResult is used to define the result of a given operation inside a // transaction. Only one of the types should be filled out per entry. type TxnResult struct { - KVS *TxnKVSResult + KV *TxnKVResult } // TxnResults is a list of TxnResult entries. diff --git a/consul/txn_endpoint.go b/consul/txn_endpoint.go index 81de6e5541..662b1f683f 100644 --- a/consul/txn_endpoint.go +++ b/consul/txn_endpoint.go @@ -20,18 +20,18 @@ func (t *Txn) Apply(args *structs.TxnRequest, reply *structs.TxnResponse) error } defer metrics.MeasureSince([]string{"consul", "txn", "apply"}, time.Now()) - // Perform the pre-apply checks for any KVS operations. + // Perform the pre-apply checks for any KV operations. acl, err := t.srv.resolveToken(args.Token) if err != nil { return err } for i, op := range args.Ops { - if op.KVS != nil { - ok, err := kvsPreApply(t.srv, acl, op.KVS.Verb, &op.KVS.DirEnt) + if op.KV != nil { + ok, err := kvsPreApply(t.srv, acl, op.KV.Verb, &op.KV.DirEnt) if err != nil { reply.Errors = append(reply.Errors, &structs.TxnError{i, err.Error()}) } else if !ok { - err = fmt.Errorf("failed to lock key %q due to lock delay", op.KVS.DirEnt.Key) + err = fmt.Errorf("failed to lock key %q due to lock delay", op.KV.DirEnt.Key) reply.Errors = append(reply.Errors, &structs.TxnError{i, err.Error()}) } } diff --git a/consul/txn_endpoint_test.go b/consul/txn_endpoint_test.go index 9d4a6b1601..0dd175e118 100644 --- a/consul/txn_endpoint_test.go +++ b/consul/txn_endpoint_test.go @@ -29,7 +29,7 @@ func TestTxn_Apply(t *testing.T) { Datacenter: "dc1", Ops: structs.TxnOps{ &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSSet, DirEnt: structs.DirEntry{ Key: "test", @@ -39,7 +39,7 @@ func TestTxn_Apply(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSGet, DirEnt: structs.DirEntry{ Key: "test", @@ -71,7 +71,7 @@ func TestTxn_Apply(t *testing.T) { expected := structs.TxnResponse{ Results: structs.TxnResults{ &structs.TxnResult{ - KVS: &structs.TxnKVSResult{ + KV: &structs.TxnKVResult{ DirEnt: &structs.DirEntry{ Key: "test", Flags: 42, @@ -84,7 +84,7 @@ func TestTxn_Apply(t *testing.T) { }, }, &structs.TxnResult{ - KVS: &structs.TxnKVSResult{ + KV: &structs.TxnKVResult{ DirEnt: &structs.DirEntry{ Key: "test", Flags: 42, @@ -140,7 +140,7 @@ func TestTxn_Apply_ACLDeny(t *testing.T) { Datacenter: "dc1", Ops: structs.TxnOps{ &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSSet, DirEnt: structs.DirEntry{ Key: "foo", @@ -148,7 +148,7 @@ func TestTxn_Apply_ACLDeny(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSDelete, DirEnt: structs.DirEntry{ Key: "foo", @@ -156,7 +156,7 @@ func TestTxn_Apply_ACLDeny(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSDeleteCAS, DirEnt: structs.DirEntry{ Key: "foo", @@ -164,7 +164,7 @@ func TestTxn_Apply_ACLDeny(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSDeleteTree, DirEnt: structs.DirEntry{ Key: "foo", @@ -172,7 +172,7 @@ func TestTxn_Apply_ACLDeny(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSCAS, DirEnt: structs.DirEntry{ Key: "foo", @@ -180,7 +180,7 @@ func TestTxn_Apply_ACLDeny(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSLock, DirEnt: structs.DirEntry{ Key: "foo", @@ -188,7 +188,7 @@ func TestTxn_Apply_ACLDeny(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSUnlock, DirEnt: structs.DirEntry{ Key: "foo", @@ -196,7 +196,7 @@ func TestTxn_Apply_ACLDeny(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSGet, DirEnt: structs.DirEntry{ Key: "nope", @@ -204,7 +204,7 @@ func TestTxn_Apply_ACLDeny(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSCheckSession, DirEnt: structs.DirEntry{ Key: "nope", @@ -212,7 +212,7 @@ func TestTxn_Apply_ACLDeny(t *testing.T) { }, }, &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSCheckIndex, DirEnt: structs.DirEntry{ Key: "nope", @@ -281,7 +281,7 @@ func TestTxn_Apply_LockDelay(t *testing.T) { Datacenter: "dc1", Ops: structs.TxnOps{ &structs.TxnOp{ - KVS: &structs.TxnKVSOp{ + KV: &structs.TxnKVOp{ Verb: structs.KVSLock, DirEnt: structs.DirEntry{ Key: "test", @@ -315,7 +315,7 @@ func TestTxn_Apply_LockDelay(t *testing.T) { } if len(out.Results) != 1 || len(out.Errors) != 0 || - out.Results[0].KVS.DirEnt.LockIndex != 2 { + out.Results[0].KV.DirEnt.LockIndex != 2 { t.Fatalf("bad: %v", out) } }