Skip to content

Commit

Permalink
*: rename preserveKVs to prevKv
Browse files Browse the repository at this point in the history
  • Loading branch information
xiang90 committed Jul 6, 2016
1 parent 929d6ab commit 4da096c
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 352 deletions.
27 changes: 18 additions & 9 deletions Documentation/dev-guide/apispec/swagger/rpc.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -671,10 +671,10 @@
"format": "byte",
"description": "key is the first key to delete in the range."
},
"preserveKVs": {
"prev_kv": {
"type": "boolean",
"format": "boolean",
"description": "If preserveKVs is set, the deleted KVs will be preserved for delete events\nThe preserved KVs will be returned as response.\nIt requires read permission to read the deleted KVs."
"description": "If prev_kv is set, etcd gets the previous key-value pairs before deleting it.\nThe previous key-value pairs will be returned in the delte response."
},
"range_end": {
"type": "string",
Expand All @@ -686,20 +686,20 @@
"etcdserverpbDeleteRangeResponse": {
"type": "object",
"properties": {
"KVs": {
"type": "array",
"items": {
"$ref": "#/definitions/mvccpbKeyValue"
},
"description": "if preserveKVs is set in the request, the deleted KVs will be returned."
},
"deleted": {
"type": "string",
"format": "int64",
"description": "deleted is the number of keys deleted by the delete range request."
},
"header": {
"$ref": "#/definitions/etcdserverpbResponseHeader"
},
"prev_kvs": {
"type": "array",
"items": {
"$ref": "#/definitions/mvccpbKeyValue"
},
"description": "if prev_kv is set in the request, the previous key-value pairs will be returned."
}
}
},
Expand Down Expand Up @@ -933,6 +933,11 @@
"format": "int64",
"description": "lease is the lease ID to associate with the key in the key-value store. A lease\nvalue of 0 indicates no lease."
},
"prev_kv": {
"type": "boolean",
"format": "boolean",
"description": "If prev_kv is set, etcd gets the previous key-value pair before changing it.\nThe previous key-value pair will be returned in the put response."
},
"value": {
"type": "string",
"format": "byte",
Expand All @@ -945,6 +950,10 @@
"properties": {
"header": {
"$ref": "#/definitions/etcdserverpbResponseHeader"
},
"prev_kv": {
"$ref": "#/definitions/mvccpbKeyValue",
"description": "if prev_kv is set in the request, the previous key-value pair will be returned."
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion clientv3/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (kv *kv) do(ctx context.Context, op Op) (OpResponse, error) {
}
case tDeleteRange:
var resp *pb.DeleteRangeResponse
r := &pb.DeleteRangeRequest{Key: op.key, RangeEnd: op.end, PreserveKVs: op.preserveKVs}
r := &pb.DeleteRangeRequest{Key: op.key, RangeEnd: op.end, PrevKv: op.prevKV}
resp, err = kv.remote.DeleteRange(ctx, r)
if err == nil {
return OpResponse{del: (*DeleteResponse)(resp)}, nil
Expand Down
15 changes: 2 additions & 13 deletions clientv3/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ type Op struct {
// for range, watch
rev int64

// for watch, put, delete
prevKV bool

// for delete
preserveKVs bool

// progressNotify is for progress updates.
progressNotify bool

Expand Down Expand Up @@ -79,7 +77,7 @@ func (op Op) toRequestOp() *pb.RequestOp {
r := &pb.PutRequest{Key: op.key, Value: op.val, Lease: int64(op.leaseID)}
return &pb.RequestOp{Request: &pb.RequestOp_RequestPut{RequestPut: r}}
case tDeleteRange:
r := &pb.DeleteRangeRequest{Key: op.key, RangeEnd: op.end, PreserveKVs: op.preserveKVs}
r := &pb.DeleteRangeRequest{Key: op.key, RangeEnd: op.end, PrevKv: op.prevKV}

return &pb.RequestOp{Request: &pb.RequestOp_RequestDeleteRange{RequestDeleteRange: r}}
default:
Expand Down Expand Up @@ -133,8 +131,6 @@ func OpPut(key, val string, opts ...OpOption) Op {
panic("unexpected serializable in put")
case ret.countOnly:
panic("unexpected countOnly in put")
case ret.preserveKVs:
panic("unexpected preserveKVs in put")
}
return ret
}
Expand All @@ -153,8 +149,6 @@ func opWatch(key string, opts ...OpOption) Op {
panic("unexpected serializable in watch")
case ret.countOnly:
panic("unexpected countOnly in watch")
case ret.preserveKVs:
panic("unexpected preserveKVs in watch")
}
return ret
}
Expand Down Expand Up @@ -266,11 +260,6 @@ func withTop(target SortTarget, order SortOrder) []OpOption {
return []OpOption{WithPrefix(), WithSort(target, order), WithLimit(1)}
}

// WithPreserveKVs preserves the deleted KVs for attaching in responses.
func WithPreserveKVs() OpOption {
return func(op *Op) { op.preserveKVs = true }
}

// WithProgressNotify makes watch server send periodic progress updates.
// Progress updates have zero events in WatchResponse.
func WithProgressNotify() OpOption {
Expand Down
8 changes: 4 additions & 4 deletions etcdctl/ctlv3/command/del_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

var (
delPrefix bool
delKVs bool
delPrevKV bool
)

// NewDelCommand returns the cobra command for "del".
Expand All @@ -35,7 +35,7 @@ func NewDelCommand() *cobra.Command {
}

cmd.Flags().BoolVar(&delPrefix, "prefix", false, "delete keys with matching prefix")
cmd.Flags().BoolVar(&delKVs, "preserve-kvs", false, "preserve and return deleted key-value pairs")
cmd.Flags().BoolVar(&delPrevKV, "prev-kv", false, "return deleted key-value pairs")

return cmd
}
Expand Down Expand Up @@ -68,8 +68,8 @@ func getDelOp(cmd *cobra.Command, args []string) (string, []clientv3.OpOption) {
if delPrefix {
opts = append(opts, clientv3.WithPrefix())
}
if delKVs {
opts = append(opts, clientv3.WithPreserveKVs())
if delPrevKV {
opts = append(opts, clientv3.WithPrevKV())
}

return key, opts
Expand Down
2 changes: 1 addition & 1 deletion etcdctl/ctlv3/command/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type simplePrinter struct {

func (s *simplePrinter) Del(resp v3.DeleteResponse) {
fmt.Println(resp.Deleted)
for _, kv := range resp.KVs {
for _, kv := range resp.PrevKvs {
printKV(s.isHex, kv)
}
}
Expand Down
4 changes: 2 additions & 2 deletions etcdserver/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (a *applierV3backend) DeleteRange(txnID int64, dr *pb.DeleteRangeRequest) (
}

var rr *mvcc.RangeResult
if dr.PreserveKVs {
if dr.PrevKv {
if txnID != noTxn {
rr, err = a.s.KV().TxnRange(txnID, dr.Key, dr.RangeEnd, mvcc.RangeOptions{})
if err != nil {
Expand All @@ -218,7 +218,7 @@ func (a *applierV3backend) DeleteRange(txnID int64, dr *pb.DeleteRangeRequest) (
resp.Deleted = n
if rr != nil {
for i := range rr.KVs {
resp.KVs = append(resp.KVs, &rr.KVs[i])
resp.PrevKvs = append(resp.PrevKvs, &rr.KVs[i])
}
}
resp.Header.Revision = rev
Expand Down
4 changes: 2 additions & 2 deletions etcdserver/apply_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (aa *authApplierV3) DeleteRange(txnID int64, r *pb.DeleteRangeRequest) (*pb
if !aa.as.IsDeleteRangePermitted(aa.user, r.Key, r.RangeEnd) {
return nil, auth.ErrPermissionDenied
}
if r.PreserveKVs && !aa.as.IsRangePermitted(aa.user, r.Key, r.RangeEnd) {
if r.PrevKv && !aa.as.IsRangePermitted(aa.user, r.Key, r.RangeEnd) {
return nil, auth.ErrPermissionDenied
}

Expand Down Expand Up @@ -103,7 +103,7 @@ func (aa *authApplierV3) checkTxnReqsPermission(reqs []*pb.RequestOp) bool {
continue
}

if tv.RequestDeleteRange.PreserveKVs && !aa.as.IsRangePermitted(aa.user, tv.RequestDeleteRange.Key, tv.RequestDeleteRange.RangeEnd) {
if tv.RequestDeleteRange.PrevKv && !aa.as.IsRangePermitted(aa.user, tv.RequestDeleteRange.Key, tv.RequestDeleteRange.RangeEnd) {
return false
}

Expand Down
Loading

0 comments on commit 4da096c

Please sign in to comment.