watch.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. // Copyright 2016 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package clientv3
  15. import (
  16. "fmt"
  17. "sync"
  18. "time"
  19. v3rpc "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes"
  20. pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
  21. mvccpb "github.com/coreos/etcd/mvcc/mvccpb"
  22. "golang.org/x/net/context"
  23. "google.golang.org/grpc"
  24. )
  25. const (
  26. EventTypeDelete = mvccpb.DELETE
  27. EventTypePut = mvccpb.PUT
  28. closeSendErrTimeout = 250 * time.Millisecond
  29. )
  30. type Event mvccpb.Event
  31. type WatchChan <-chan WatchResponse
  32. type Watcher interface {
  33. // Watch watches on a key or prefix. The watched events will be returned
  34. // through the returned channel.
  35. // If the watch is slow or the required rev is compacted, the watch request
  36. // might be canceled from the server-side and the chan will be closed.
  37. // 'opts' can be: 'WithRev' and/or 'WithPrefix'.
  38. Watch(ctx context.Context, key string, opts ...OpOption) WatchChan
  39. // Close closes the watcher and cancels all watch requests.
  40. Close() error
  41. }
  42. type WatchResponse struct {
  43. Header pb.ResponseHeader
  44. Events []*Event
  45. // CompactRevision is the minimum revision the watcher may receive.
  46. CompactRevision int64
  47. // Canceled is used to indicate watch failure.
  48. // If the watch failed and the stream was about to close, before the channel is closed,
  49. // the channel sends a final response that has Canceled set to true with a non-nil Err().
  50. Canceled bool
  51. // Created is used to indicate the creation of the watcher.
  52. Created bool
  53. closeErr error
  54. }
  55. // IsCreate returns true if the event tells that the key is newly created.
  56. func (e *Event) IsCreate() bool {
  57. return e.Type == EventTypePut && e.Kv.CreateRevision == e.Kv.ModRevision
  58. }
  59. // IsModify returns true if the event tells that a new value is put on existing key.
  60. func (e *Event) IsModify() bool {
  61. return e.Type == EventTypePut && e.Kv.CreateRevision != e.Kv.ModRevision
  62. }
  63. // Err is the error value if this WatchResponse holds an error.
  64. func (wr *WatchResponse) Err() error {
  65. switch {
  66. case wr.closeErr != nil:
  67. return v3rpc.Error(wr.closeErr)
  68. case wr.CompactRevision != 0:
  69. return v3rpc.ErrCompacted
  70. case wr.Canceled:
  71. return v3rpc.ErrFutureRev
  72. }
  73. return nil
  74. }
  75. // IsProgressNotify returns true if the WatchResponse is progress notification.
  76. func (wr *WatchResponse) IsProgressNotify() bool {
  77. return len(wr.Events) == 0 && !wr.Canceled && !wr.Created && wr.CompactRevision == 0 && wr.Header.Revision != 0
  78. }
  79. // watcher implements the Watcher interface
  80. type watcher struct {
  81. remote pb.WatchClient
  82. // mu protects the grpc streams map
  83. mu sync.RWMutex
  84. // streams holds all the active grpc streams keyed by ctx value.
  85. streams map[string]*watchGrpcStream
  86. }
  87. // watchGrpcStream tracks all watch resources attached to a single grpc stream.
  88. type watchGrpcStream struct {
  89. owner *watcher
  90. remote pb.WatchClient
  91. // ctx controls internal remote.Watch requests
  92. ctx context.Context
  93. // ctxKey is the key used when looking up this stream's context
  94. ctxKey string
  95. cancel context.CancelFunc
  96. // substreams holds all active watchers on this grpc stream
  97. substreams map[int64]*watcherStream
  98. // resuming holds all resuming watchers on this grpc stream
  99. resuming []*watcherStream
  100. // reqc sends a watch request from Watch() to the main goroutine
  101. reqc chan *watchRequest
  102. // respc receives data from the watch client
  103. respc chan *pb.WatchResponse
  104. // stopc is sent to the main goroutine to stop all processing
  105. stopc chan struct{}
  106. // donec closes to broadcast shutdown
  107. donec chan struct{}
  108. // errc transmits errors from grpc Recv to the watch stream reconn logic
  109. errc chan error
  110. // closingc gets the watcherStream of closing watchers
  111. closingc chan *watcherStream
  112. // resumec closes to signal that all substreams should begin resuming
  113. resumec chan struct{}
  114. // closeErr is the error that closed the watch stream
  115. closeErr error
  116. }
  117. // watchRequest is issued by the subscriber to start a new watcher
  118. type watchRequest struct {
  119. ctx context.Context
  120. key string
  121. end string
  122. rev int64
  123. // send created notification event if this field is true
  124. createdNotify bool
  125. // progressNotify is for progress updates
  126. progressNotify bool
  127. // filters is the list of events to filter out
  128. filters []pb.WatchCreateRequest_FilterType
  129. // get the previous key-value pair before the event happens
  130. prevKV bool
  131. // retc receives a chan WatchResponse once the watcher is established
  132. retc chan chan WatchResponse
  133. }
  134. // watcherStream represents a registered watcher
  135. type watcherStream struct {
  136. // initReq is the request that initiated this request
  137. initReq watchRequest
  138. // outc publishes watch responses to subscriber
  139. outc chan WatchResponse
  140. // recvc buffers watch responses before publishing
  141. recvc chan *WatchResponse
  142. // donec closes when the watcherStream goroutine stops.
  143. donec chan struct{}
  144. // closing is set to true when stream should be scheduled to shutdown.
  145. closing bool
  146. // id is the registered watch id on the grpc stream
  147. id int64
  148. // buf holds all events received from etcd but not yet consumed by the client
  149. buf []*WatchResponse
  150. }
  151. func NewWatcher(c *Client) Watcher {
  152. return NewWatchFromWatchClient(pb.NewWatchClient(c.conn))
  153. }
  154. func NewWatchFromWatchClient(wc pb.WatchClient) Watcher {
  155. return &watcher{
  156. remote: wc,
  157. streams: make(map[string]*watchGrpcStream),
  158. }
  159. }
  160. // never closes
  161. var valCtxCh = make(chan struct{})
  162. var zeroTime = time.Unix(0, 0)
  163. // ctx with only the values; never Done
  164. type valCtx struct{ context.Context }
  165. func (vc *valCtx) Deadline() (time.Time, bool) { return zeroTime, false }
  166. func (vc *valCtx) Done() <-chan struct{} { return valCtxCh }
  167. func (vc *valCtx) Err() error { return nil }
  168. func (w *watcher) newWatcherGrpcStream(inctx context.Context) *watchGrpcStream {
  169. ctx, cancel := context.WithCancel(&valCtx{inctx})
  170. wgs := &watchGrpcStream{
  171. owner: w,
  172. remote: w.remote,
  173. ctx: ctx,
  174. ctxKey: fmt.Sprintf("%v", inctx),
  175. cancel: cancel,
  176. substreams: make(map[int64]*watcherStream),
  177. respc: make(chan *pb.WatchResponse),
  178. reqc: make(chan *watchRequest),
  179. stopc: make(chan struct{}),
  180. donec: make(chan struct{}),
  181. errc: make(chan error, 1),
  182. closingc: make(chan *watcherStream),
  183. resumec: make(chan struct{}),
  184. }
  185. go wgs.run()
  186. return wgs
  187. }
  188. // Watch posts a watch request to run() and waits for a new watcher channel
  189. func (w *watcher) Watch(ctx context.Context, key string, opts ...OpOption) WatchChan {
  190. ow := opWatch(key, opts...)
  191. var filters []pb.WatchCreateRequest_FilterType
  192. if ow.filterPut {
  193. filters = append(filters, pb.WatchCreateRequest_NOPUT)
  194. }
  195. if ow.filterDelete {
  196. filters = append(filters, pb.WatchCreateRequest_NODELETE)
  197. }
  198. wr := &watchRequest{
  199. ctx: ctx,
  200. createdNotify: ow.createdNotify,
  201. key: string(ow.key),
  202. end: string(ow.end),
  203. rev: ow.rev,
  204. progressNotify: ow.progressNotify,
  205. filters: filters,
  206. prevKV: ow.prevKV,
  207. retc: make(chan chan WatchResponse, 1),
  208. }
  209. ok := false
  210. ctxKey := fmt.Sprintf("%v", ctx)
  211. // find or allocate appropriate grpc watch stream
  212. w.mu.Lock()
  213. if w.streams == nil {
  214. // closed
  215. w.mu.Unlock()
  216. ch := make(chan WatchResponse)
  217. close(ch)
  218. return ch
  219. }
  220. wgs := w.streams[ctxKey]
  221. if wgs == nil {
  222. wgs = w.newWatcherGrpcStream(ctx)
  223. w.streams[ctxKey] = wgs
  224. }
  225. donec := wgs.donec
  226. reqc := wgs.reqc
  227. w.mu.Unlock()
  228. // couldn't create channel; return closed channel
  229. closeCh := make(chan WatchResponse, 1)
  230. // submit request
  231. select {
  232. case reqc <- wr:
  233. ok = true
  234. case <-wr.ctx.Done():
  235. case <-donec:
  236. if wgs.closeErr != nil {
  237. closeCh <- WatchResponse{closeErr: wgs.closeErr}
  238. break
  239. }
  240. // retry; may have dropped stream from no ctxs
  241. return w.Watch(ctx, key, opts...)
  242. }
  243. // receive channel
  244. if ok {
  245. select {
  246. case ret := <-wr.retc:
  247. return ret
  248. case <-ctx.Done():
  249. case <-donec:
  250. if wgs.closeErr != nil {
  251. closeCh <- WatchResponse{closeErr: wgs.closeErr}
  252. break
  253. }
  254. // retry; may have dropped stream from no ctxs
  255. return w.Watch(ctx, key, opts...)
  256. }
  257. }
  258. close(closeCh)
  259. return closeCh
  260. }
  261. func (w *watcher) Close() (err error) {
  262. w.mu.Lock()
  263. streams := w.streams
  264. w.streams = nil
  265. w.mu.Unlock()
  266. for _, wgs := range streams {
  267. if werr := wgs.Close(); werr != nil {
  268. err = werr
  269. }
  270. }
  271. return err
  272. }
  273. func (w *watchGrpcStream) Close() (err error) {
  274. close(w.stopc)
  275. <-w.donec
  276. select {
  277. case err = <-w.errc:
  278. default:
  279. }
  280. return toErr(w.ctx, err)
  281. }
  282. func (w *watcher) closeStream(wgs *watchGrpcStream) {
  283. w.mu.Lock()
  284. close(wgs.donec)
  285. wgs.cancel()
  286. if w.streams != nil {
  287. delete(w.streams, wgs.ctxKey)
  288. }
  289. w.mu.Unlock()
  290. }
  291. func (w *watchGrpcStream) addSubstream(resp *pb.WatchResponse, ws *watcherStream) {
  292. if resp.WatchId == -1 {
  293. // failed; no channel
  294. close(ws.recvc)
  295. return
  296. }
  297. ws.id = resp.WatchId
  298. w.substreams[ws.id] = ws
  299. }
  300. func (w *watchGrpcStream) sendCloseSubstream(ws *watcherStream, resp *WatchResponse) {
  301. select {
  302. case ws.outc <- *resp:
  303. case <-ws.initReq.ctx.Done():
  304. case <-time.After(closeSendErrTimeout):
  305. }
  306. close(ws.outc)
  307. }
  308. func (w *watchGrpcStream) closeSubstream(ws *watcherStream) {
  309. // send channel response in case stream was never established
  310. select {
  311. case ws.initReq.retc <- ws.outc:
  312. default:
  313. }
  314. // close subscriber's channel
  315. if closeErr := w.closeErr; closeErr != nil {
  316. go w.sendCloseSubstream(ws, &WatchResponse{closeErr: w.closeErr})
  317. } else {
  318. close(ws.outc)
  319. }
  320. if ws.id != -1 {
  321. delete(w.substreams, ws.id)
  322. return
  323. }
  324. for i := range w.resuming {
  325. if w.resuming[i] == ws {
  326. w.resuming[i] = nil
  327. return
  328. }
  329. }
  330. }
  331. // run is the root of the goroutines for managing a watcher client
  332. func (w *watchGrpcStream) run() {
  333. var wc pb.Watch_WatchClient
  334. var closeErr error
  335. // substreams marked to close but goroutine still running; needed for
  336. // avoiding double-closing recvc on grpc stream teardown
  337. closing := make(map[*watcherStream]struct{})
  338. defer func() {
  339. w.closeErr = closeErr
  340. // shutdown substreams and resuming substreams
  341. for _, ws := range w.substreams {
  342. if _, ok := closing[ws]; !ok {
  343. close(ws.recvc)
  344. }
  345. }
  346. for _, ws := range w.resuming {
  347. if _, ok := closing[ws]; ws != nil && !ok {
  348. close(ws.recvc)
  349. }
  350. }
  351. w.joinSubstreams()
  352. for toClose := len(w.substreams) + len(w.resuming); toClose > 0; toClose-- {
  353. w.closeSubstream(<-w.closingc)
  354. }
  355. w.owner.closeStream(w)
  356. }()
  357. // start a stream with the etcd grpc server
  358. if wc, closeErr = w.newWatchClient(); closeErr != nil {
  359. return
  360. }
  361. cancelSet := make(map[int64]struct{})
  362. for {
  363. select {
  364. // Watch() requested
  365. case wreq := <-w.reqc:
  366. outc := make(chan WatchResponse, 1)
  367. ws := &watcherStream{
  368. initReq: *wreq,
  369. id: -1,
  370. outc: outc,
  371. // unbufffered so resumes won't cause repeat events
  372. recvc: make(chan *WatchResponse),
  373. }
  374. ws.donec = make(chan struct{})
  375. go w.serveSubstream(ws, w.resumec)
  376. // queue up for watcher creation/resume
  377. w.resuming = append(w.resuming, ws)
  378. if len(w.resuming) == 1 {
  379. // head of resume queue, can register a new watcher
  380. wc.Send(ws.initReq.toPB())
  381. }
  382. // New events from the watch client
  383. case pbresp := <-w.respc:
  384. switch {
  385. case pbresp.Created:
  386. // response to head of queue creation
  387. if ws := w.resuming[0]; ws != nil {
  388. w.addSubstream(pbresp, ws)
  389. w.dispatchEvent(pbresp)
  390. w.resuming[0] = nil
  391. }
  392. if ws := w.nextResume(); ws != nil {
  393. wc.Send(ws.initReq.toPB())
  394. }
  395. case pbresp.Canceled:
  396. delete(cancelSet, pbresp.WatchId)
  397. if ws, ok := w.substreams[pbresp.WatchId]; ok {
  398. // signal to stream goroutine to update closingc
  399. close(ws.recvc)
  400. closing[ws] = struct{}{}
  401. }
  402. default:
  403. // dispatch to appropriate watch stream
  404. if ok := w.dispatchEvent(pbresp); ok {
  405. break
  406. }
  407. // watch response on unexpected watch id; cancel id
  408. if _, ok := cancelSet[pbresp.WatchId]; ok {
  409. break
  410. }
  411. cancelSet[pbresp.WatchId] = struct{}{}
  412. cr := &pb.WatchRequest_CancelRequest{
  413. CancelRequest: &pb.WatchCancelRequest{
  414. WatchId: pbresp.WatchId,
  415. },
  416. }
  417. req := &pb.WatchRequest{RequestUnion: cr}
  418. wc.Send(req)
  419. }
  420. // watch client failed to recv; spawn another if possible
  421. case err := <-w.errc:
  422. if isHaltErr(w.ctx, err) || toErr(w.ctx, err) == v3rpc.ErrNoLeader {
  423. closeErr = err
  424. return
  425. }
  426. if wc, closeErr = w.newWatchClient(); closeErr != nil {
  427. return
  428. }
  429. if ws := w.nextResume(); ws != nil {
  430. wc.Send(ws.initReq.toPB())
  431. }
  432. cancelSet = make(map[int64]struct{})
  433. case <-w.stopc:
  434. return
  435. case ws := <-w.closingc:
  436. w.closeSubstream(ws)
  437. delete(closing, ws)
  438. if len(w.substreams)+len(w.resuming) == 0 {
  439. // no more watchers on this stream, shutdown
  440. return
  441. }
  442. }
  443. }
  444. }
  445. // nextResume chooses the next resuming to register with the grpc stream. Abandoned
  446. // streams are marked as nil in the queue since the head must wait for its inflight registration.
  447. func (w *watchGrpcStream) nextResume() *watcherStream {
  448. for len(w.resuming) != 0 {
  449. if w.resuming[0] != nil {
  450. return w.resuming[0]
  451. }
  452. w.resuming = w.resuming[1:len(w.resuming)]
  453. }
  454. return nil
  455. }
  456. // dispatchEvent sends a WatchResponse to the appropriate watcher stream
  457. func (w *watchGrpcStream) dispatchEvent(pbresp *pb.WatchResponse) bool {
  458. ws, ok := w.substreams[pbresp.WatchId]
  459. if !ok {
  460. return false
  461. }
  462. events := make([]*Event, len(pbresp.Events))
  463. for i, ev := range pbresp.Events {
  464. events[i] = (*Event)(ev)
  465. }
  466. wr := &WatchResponse{
  467. Header: *pbresp.Header,
  468. Events: events,
  469. CompactRevision: pbresp.CompactRevision,
  470. Created: pbresp.Created,
  471. Canceled: pbresp.Canceled,
  472. }
  473. select {
  474. case ws.recvc <- wr:
  475. case <-ws.donec:
  476. return false
  477. }
  478. return true
  479. }
  480. // serveWatchClient forwards messages from the grpc stream to run()
  481. func (w *watchGrpcStream) serveWatchClient(wc pb.Watch_WatchClient) {
  482. for {
  483. resp, err := wc.Recv()
  484. if err != nil {
  485. select {
  486. case w.errc <- err:
  487. case <-w.donec:
  488. }
  489. return
  490. }
  491. select {
  492. case w.respc <- resp:
  493. case <-w.donec:
  494. return
  495. }
  496. }
  497. }
  498. // serveSubstream forwards watch responses from run() to the subscriber
  499. func (w *watchGrpcStream) serveSubstream(ws *watcherStream, resumec chan struct{}) {
  500. if ws.closing {
  501. panic("created substream goroutine but substream is closing")
  502. }
  503. // nextRev is the minimum expected next revision
  504. nextRev := ws.initReq.rev
  505. resuming := false
  506. defer func() {
  507. if !resuming {
  508. ws.closing = true
  509. }
  510. close(ws.donec)
  511. if !resuming {
  512. w.closingc <- ws
  513. }
  514. }()
  515. emptyWr := &WatchResponse{}
  516. for {
  517. curWr := emptyWr
  518. outc := ws.outc
  519. if len(ws.buf) > 0 && ws.buf[0].Created {
  520. select {
  521. case ws.initReq.retc <- ws.outc:
  522. // send first creation event and only if requested
  523. if !ws.initReq.createdNotify {
  524. ws.buf = ws.buf[1:]
  525. }
  526. default:
  527. }
  528. }
  529. if len(ws.buf) > 0 {
  530. curWr = ws.buf[0]
  531. } else {
  532. outc = nil
  533. }
  534. select {
  535. case outc <- *curWr:
  536. if ws.buf[0].Err() != nil {
  537. return
  538. }
  539. ws.buf[0] = nil
  540. ws.buf = ws.buf[1:]
  541. case wr, ok := <-ws.recvc:
  542. if !ok {
  543. // shutdown from closeSubstream
  544. return
  545. }
  546. // TODO pause channel if buffer gets too large
  547. ws.buf = append(ws.buf, wr)
  548. nextRev = wr.Header.Revision
  549. if len(wr.Events) > 0 {
  550. nextRev = wr.Events[len(wr.Events)-1].Kv.ModRevision + 1
  551. }
  552. ws.initReq.rev = nextRev
  553. case <-ws.initReq.ctx.Done():
  554. return
  555. case <-resumec:
  556. resuming = true
  557. return
  558. }
  559. }
  560. // lazily send cancel message if events on missing id
  561. }
  562. func (w *watchGrpcStream) newWatchClient() (pb.Watch_WatchClient, error) {
  563. // connect to grpc stream
  564. wc, err := w.openWatchClient()
  565. if err != nil {
  566. return nil, v3rpc.Error(err)
  567. }
  568. // mark all substreams as resuming
  569. if len(w.substreams)+len(w.resuming) > 0 {
  570. close(w.resumec)
  571. w.resumec = make(chan struct{})
  572. w.joinSubstreams()
  573. for _, ws := range w.substreams {
  574. ws.id = -1
  575. w.resuming = append(w.resuming, ws)
  576. }
  577. for _, ws := range w.resuming {
  578. if ws == nil || ws.closing {
  579. continue
  580. }
  581. ws.donec = make(chan struct{})
  582. go w.serveSubstream(ws, w.resumec)
  583. }
  584. }
  585. w.substreams = make(map[int64]*watcherStream)
  586. // receive data from new grpc stream
  587. go w.serveWatchClient(wc)
  588. return wc, nil
  589. }
  590. // joinSubstream waits for all substream goroutines to complete
  591. func (w *watchGrpcStream) joinSubstreams() {
  592. for _, ws := range w.substreams {
  593. <-ws.donec
  594. }
  595. for _, ws := range w.resuming {
  596. if ws != nil {
  597. <-ws.donec
  598. }
  599. }
  600. }
  601. // openWatchClient retries opening a watchclient until retryConnection fails
  602. func (w *watchGrpcStream) openWatchClient() (ws pb.Watch_WatchClient, err error) {
  603. for {
  604. select {
  605. case <-w.stopc:
  606. if err == nil {
  607. return nil, context.Canceled
  608. }
  609. return nil, err
  610. default:
  611. }
  612. if ws, err = w.remote.Watch(w.ctx, grpc.FailFast(false)); ws != nil && err == nil {
  613. break
  614. }
  615. if isHaltErr(w.ctx, err) {
  616. return nil, v3rpc.Error(err)
  617. }
  618. }
  619. return ws, nil
  620. }
  621. // toPB converts an internal watch request structure to its protobuf messagefunc (wr *watchRequest)
  622. func (wr *watchRequest) toPB() *pb.WatchRequest {
  623. req := &pb.WatchCreateRequest{
  624. StartRevision: wr.rev,
  625. Key: []byte(wr.key),
  626. RangeEnd: []byte(wr.end),
  627. ProgressNotify: wr.progressNotify,
  628. Filters: wr.filters,
  629. PrevKv: wr.prevKV,
  630. }
  631. cr := &pb.WatchRequest_CreateRequest{CreateRequest: req}
  632. return &pb.WatchRequest{RequestUnion: cr}
  633. }