mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: QGET
This commit is contained in:
committed by
Yicheng Qin
parent
2d9553cb18
commit
2b260a7ae5
@@ -13,8 +13,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
"crypto/rand"
|
||||
"code.google.com/p/go.net/context"
|
||||
"github.com/coreos/etcd/elog"
|
||||
etcdserver "github.com/coreos/etcd/etcdserver2"
|
||||
"github.com/coreos/etcd/etcdserver2/etcdserverpb"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package etcdhttp
|
||||
|
||||
import (
|
||||
"code.google.com/p/go.net/context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -9,6 +8,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
"code.google.com/p/go.net/context"
|
||||
|
||||
etcdserver "github.com/coreos/etcd/etcdserver2"
|
||||
"github.com/coreos/etcd/etcdserver2/etcdserverpb"
|
||||
|
||||
@@ -41,6 +41,7 @@ type Request struct {
|
||||
Since uint64 `protobuf:"varint,11,req,name=since" json:"since"`
|
||||
Recursive bool `protobuf:"varint,12,req,name=recursive" json:"recursive"`
|
||||
Sorted bool `protobuf:"varint,13,req,name=sorted" json:"sorted"`
|
||||
Quorum bool `protobuf:"varint,14,req,name=quorum" json:"quorum"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
@@ -303,6 +304,23 @@ func (m *Request) Unmarshal(data []byte) error {
|
||||
}
|
||||
}
|
||||
m.Sorted = bool(v != 0)
|
||||
case 14:
|
||||
if wireType != 0 {
|
||||
return code_google_com_p_gogoprotobuf_proto.ErrWrongType
|
||||
}
|
||||
var v int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if index >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := data[index]
|
||||
index++
|
||||
v |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
m.Quorum = bool(v != 0)
|
||||
default:
|
||||
var sizeOfWire int
|
||||
for {
|
||||
@@ -348,6 +366,7 @@ func (m *Request) Size() (n int) {
|
||||
n += 1 + sovEtcdserver(uint64(m.Since))
|
||||
n += 2
|
||||
n += 2
|
||||
n += 2
|
||||
if m.XXX_unrecognized != nil {
|
||||
n += len(m.XXX_unrecognized)
|
||||
}
|
||||
@@ -452,6 +471,14 @@ func (m *Request) MarshalTo(data []byte) (n int, err error) {
|
||||
data[i] = 0
|
||||
}
|
||||
i++
|
||||
data[i] = 0x70
|
||||
i++
|
||||
if m.Quorum {
|
||||
data[i] = 1
|
||||
} else {
|
||||
data[i] = 0
|
||||
}
|
||||
i++
|
||||
if m.XXX_unrecognized != nil {
|
||||
i += copy(data[i:], m.XXX_unrecognized)
|
||||
}
|
||||
|
||||
@@ -21,4 +21,5 @@ message Request {
|
||||
required uint64 since = 11 [(gogoproto.nullable) = false];
|
||||
required bool recursive = 12 [(gogoproto.nullable) = false];
|
||||
required bool sorted = 13 [(gogoproto.nullable) = false];
|
||||
required bool quorum = 14 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
@@ -100,8 +100,11 @@ func (s *Server) Do(ctx context.Context, r pb.Request) (Response, error) {
|
||||
if r.Id == 0 {
|
||||
panic("r.Id cannot be 0")
|
||||
}
|
||||
if r.Method == "GET" && r.Quorum {
|
||||
r.Method = "QGET"
|
||||
}
|
||||
switch r.Method {
|
||||
case "POST", "PUT", "DELETE":
|
||||
case "POST", "PUT", "DELETE", "QGET":
|
||||
data, err := r.Marshal()
|
||||
if err != nil {
|
||||
return Response{}, err
|
||||
@@ -165,6 +168,8 @@ func (s *Server) apply(ctx context.Context, r pb.Request) (*store.Event, error)
|
||||
default:
|
||||
return s.Store.Delete(r.Path, r.Recursive, r.Dir)
|
||||
}
|
||||
case "QGET":
|
||||
return s.Store.Get(r.Path, r.Recursive, r.Sorted)
|
||||
default:
|
||||
// This should never be reached, but just in case:
|
||||
return nil, ErrUnknownMethod
|
||||
|
||||
Reference in New Issue
Block a user