*: change all ID to uint64

release-2.0
Xiang Li 2014-10-12 08:35:58 +08:00
parent f16a272898
commit 3516cc3ee5
6 changed files with 22 additions and 22 deletions

View File

@ -79,7 +79,7 @@ func (h serverHandler) serveKeys(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(context.Background(), h.timeout)
defer cancel()
rr, err := parseRequest(r, int64(etcdserver.GenID()))
rr, err := parseRequest(r, etcdserver.GenID())
if err != nil {
writeError(w, err)
return
@ -145,7 +145,7 @@ func (h serverHandler) serveRaft(w http.ResponseWriter, r *http.Request) {
// parseRequest converts a received http.Request to a server Request,
// performing validation of supplied fields as appropriate.
// If any validation fails, an empty Request and non-nil error is returned.
func parseRequest(r *http.Request, id int64) (etcdserverpb.Request, error) {
func parseRequest(r *http.Request, id uint64) (etcdserverpb.Request, error) {
emptyReq := etcdserverpb.Request{}
err := r.ParseForm()

View File

@ -29,7 +29,7 @@ var _ = &json.SyntaxError{}
var _ = math.Inf
type Request struct {
ID int64 `protobuf:"varint,1,req" json:"ID"`
ID uint64 `protobuf:"varint,1,req" json:"ID"`
Method string `protobuf:"bytes,2,req" json:"Method"`
Path string `protobuf:"bytes,3,req" json:"Path"`
Val string `protobuf:"bytes,4,req" json:"Val"`
@ -92,7 +92,7 @@ func (m *Request) Unmarshal(data []byte) error {
}
b := data[index]
index++
m.ID |= (int64(b) & 0x7F) << shift
m.ID |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}

View File

@ -8,7 +8,7 @@ option (gogoproto.unmarshaler_all) = true;
option (gogoproto.goproto_getters_all) = false;
message Request {
required int64 ID = 1 [(gogoproto.nullable) = false];
required uint64 ID = 1 [(gogoproto.nullable) = false];
required string Method = 2 [(gogoproto.nullable) = false];
required string Path = 3 [(gogoproto.nullable) = false];
required string Val = 4 [(gogoproto.nullable) = false];

View File

@ -268,7 +268,7 @@ func (s *EtcdServer) run() {
panic("TODO: this is bad, what do we do about it?")
}
s.applyConfChange(cc)
s.w.Trigger(int64(cc.ID), nil)
s.w.Trigger(cc.ID, nil)
default:
panic("unexpected entry type")
}
@ -407,17 +407,17 @@ func (s *EtcdServer) Term() uint64 {
// configure sends configuration change through consensus then performs it.
// It will block until the change is performed or there is an error.
func (s *EtcdServer) configure(ctx context.Context, cc raftpb.ConfChange) error {
ch := s.w.Register(int64(cc.ID))
ch := s.w.Register(cc.ID)
if err := s.node.ProposeConfChange(ctx, cc); err != nil {
log.Printf("configure error: %v", err)
s.w.Trigger(int64(cc.ID), nil)
s.w.Trigger(cc.ID, nil)
return err
}
select {
case <-ch:
return nil
case <-ctx.Done():
s.w.Trigger(int64(cc.ID), nil) // GC wait
s.w.Trigger(cc.ID, nil) // GC wait
return ctx.Err()
case <-s.done:
return ErrStopped
@ -431,7 +431,7 @@ func (s *EtcdServer) sync(timeout time.Duration) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
req := pb.Request{
Method: "SYNC",
ID: int64(GenID()),
ID: GenID(),
Time: time.Now().UnixNano(),
}
data, err := req.Marshal()
@ -459,7 +459,7 @@ func (s *EtcdServer) publish(retryInterval time.Duration) {
return
}
req := pb.Request{
ID: int64(GenID()),
ID: GenID(),
Method: "PUT",
Path: Member{ID: s.id}.storeKey() + attributesSuffix,
Val: string(b),

View File

@ -410,7 +410,7 @@ func testServer(t *testing.T, ns uint64) {
for i := 1; i <= 10; i++ {
r := pb.Request{
Method: "PUT",
ID: int64(i),
ID: uint64(i),
Path: "/foo",
Val: "bar",
}
@ -1086,11 +1086,11 @@ type waitRecorder struct {
action []action
}
func (w *waitRecorder) Register(id int64) <-chan interface{} {
func (w *waitRecorder) Register(id uint64) <-chan interface{} {
w.action = append(w.action, action{name: fmt.Sprint("Register", id)})
return nil
}
func (w *waitRecorder) Trigger(id int64, x interface{}) {
func (w *waitRecorder) Trigger(id uint64, x interface{}) {
w.action = append(w.action, action{name: fmt.Sprint("Trigger", id)})
}
@ -1230,10 +1230,10 @@ type waitWithResponse struct {
ch <-chan interface{}
}
func (w *waitWithResponse) Register(id int64) <-chan interface{} {
func (w *waitWithResponse) Register(id uint64) <-chan interface{} {
return w.ch
}
func (w *waitWithResponse) Trigger(id int64, x interface{}) {}
func (w *waitWithResponse) Trigger(id uint64, x interface{}) {}
type clusterStoreRecorder struct {
recorder

View File

@ -5,20 +5,20 @@ import (
)
type Wait interface {
Register(id int64) <-chan interface{}
Trigger(id int64, x interface{})
Register(id uint64) <-chan interface{}
Trigger(id uint64, x interface{})
}
type List struct {
l sync.Mutex
m map[int64]chan interface{}
m map[uint64]chan interface{}
}
func New() *List {
return &List{m: make(map[int64]chan interface{})}
return &List{m: make(map[uint64]chan interface{})}
}
func (w *List) Register(id int64) <-chan interface{} {
func (w *List) Register(id uint64) <-chan interface{} {
w.l.Lock()
defer w.l.Unlock()
ch := w.m[id]
@ -29,7 +29,7 @@ func (w *List) Register(id int64) <-chan interface{} {
return ch
}
func (w *List) Trigger(id int64, x interface{}) {
func (w *List) Trigger(id uint64, x interface{}) {
w.l.Lock()
ch := w.m[id]
delete(w.m, id)