Browse Source

*: fix watch full key range

Xiang Li 9 years ago
parent
commit
d84811aecf
2 changed files with 9 additions and 2 deletions
  1. 5 2
      clientv3/op.go
  2. 4 0
      etcdserver/api/v3rpc/watch.go

+ 5 - 2
clientv3/op.go

@@ -28,6 +28,10 @@ const (
 	tDeleteRange
 	tDeleteRange
 )
 )
 
 
+var (
+	noPrefixEnd = []byte{0}
+)
+
 // Op represents an Operation that kv can execute.
 // Op represents an Operation that kv can execute.
 type Op struct {
 type Op struct {
 	t   opType
 	t   opType
@@ -175,8 +179,7 @@ func getPrefix(key []byte) []byte {
 	}
 	}
 	// next prefix does not exist (e.g., 0xffff);
 	// next prefix does not exist (e.g., 0xffff);
 	// default to WithFromKey policy
 	// default to WithFromKey policy
-	end = []byte{0}
-	return end
+	return noPrefixEnd
 }
 }
 
 
 // WithPrefix enables 'Get', 'Delete', or 'Watch' requests to operate
 // WithPrefix enables 'Get', 'Delete', or 'Watch' requests to operate

+ 4 - 0
etcdserver/api/v3rpc/watch.go

@@ -111,6 +111,10 @@ func (sws *serverWatchStream) recvLoop() error {
 			}
 			}
 
 
 			creq := uv.CreateRequest
 			creq := uv.CreateRequest
+			if len(creq.Key) == 0 {
+				// \x00 is the smallest key
+				creq.Key = []byte{0}
+			}
 			if len(creq.RangeEnd) == 1 && creq.RangeEnd[0] == 0 {
 			if len(creq.RangeEnd) == 1 && creq.RangeEnd[0] == 0 {
 				// support  >= key queries
 				// support  >= key queries
 				creq.RangeEnd = []byte{}
 				creq.RangeEnd = []byte{}