Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "math" | |
| 9 "sync" | 10 "sync" |
| 10 "time" | 11 "time" |
| 11 | 12 |
| 12 "github.com/luci/luci-go/common/clock" | 13 "github.com/luci/luci-go/common/clock" |
| 13 "github.com/luci/luci-go/common/logdog/coordinator" | 14 "github.com/luci/luci-go/common/logdog/coordinator" |
| 14 "github.com/luci/luci-go/common/logdog/fetcher" | 15 "github.com/luci/luci-go/common/logdog/fetcher" |
| 15 "github.com/luci/luci-go/common/logdog/types" | 16 "github.com/luci/luci-go/common/logdog/types" |
| 16 log "github.com/luci/luci-go/common/logging" | 17 log "github.com/luci/luci-go/common/logging" |
| 17 "github.com/luci/luci-go/common/proto/logdog/logpb" | 18 "github.com/luci/luci-go/common/proto/logdog/logpb" |
| 18 "golang.org/x/net/context" | 19 "golang.org/x/net/context" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 35 tidx types.MessageIndex | 36 tidx types.MessageIndex |
| 36 | 37 |
| 37 state coordinator.LogStream | 38 state coordinator.LogStream |
| 38 } | 39 } |
| 39 | 40 |
| 40 func (s *coordinatorSource) LogEntries(c context.Context, req *fetcher.LogReques t) ( | 41 func (s *coordinatorSource) LogEntries(c context.Context, req *fetcher.LogReques t) ( |
| 41 []*logpb.LogEntry, types.MessageIndex, error) { | 42 []*logpb.LogEntry, types.MessageIndex, error) { |
| 42 s.Lock() | 43 s.Lock() |
| 43 defer s.Unlock() | 44 defer s.Unlock() |
| 44 | 45 |
| 45 » p := coordinator.NewGetParams().Limit(int(req.Bytes), req.Count).Index(r eq.Index) | 46 » // Limit our constraints to int32. |
| 47 » bytes, count := req.Bytes, req.Count | |
| 48 » if bytes > math.MaxInt32 { | |
| 49 » » bytes = math.MaxInt32 | |
| 50 » } | |
|
Ryan Tseng
2016/02/08 22:56:55
log warning?
dnj (Google)
2016/02/09 02:50:03
No need. The "bytes" and "count" parameters are pe
| |
| 51 » if count > math.MaxInt32 { | |
| 52 » » count = math.MaxInt32 | |
| 53 » } | |
| 54 | |
| 55 » p := coordinator.NewGetParams().Limit(int32(bytes), int32(count)).Index( req.Index) | |
| 46 | 56 |
| 47 // If we haven't terminated, use this opportunity to fetch/update our st ream | 57 // If we haven't terminated, use this opportunity to fetch/update our st ream |
| 48 // state. | 58 // state. |
| 49 if s.tidx < 0 { | 59 if s.tidx < 0 { |
| 50 p = p.State(&s.state) | 60 p = p.State(&s.state) |
| 51 } | 61 } |
| 52 | 62 |
| 53 for { | 63 for { |
| 54 logs, err := s.stream.Get(c, p) | 64 logs, err := s.stream.Get(c, p) |
| 55 switch err { | 65 switch err { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 84 defer s.Unlock() | 94 defer s.Unlock() |
| 85 return s.state | 95 return s.state |
| 86 } | 96 } |
| 87 | 97 |
| 88 func (s *coordinatorSource) descriptor() (*logpb.LogStreamDescriptor, error) { | 98 func (s *coordinatorSource) descriptor() (*logpb.LogStreamDescriptor, error) { |
| 89 if d := s.state.Desc; d != nil { | 99 if d := s.state.Desc; d != nil { |
| 90 return d, nil | 100 return d, nil |
| 91 } | 101 } |
| 92 return nil, errors.New("no descriptor loaded") | 102 return nil, errors.New("no descriptor loaded") |
| 93 } | 103 } |
| OLD | NEW |