Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: server/logdog/storage/memory/memory.go

Issue 1672833003: LogDog: Add log rendering view. Base URL: https://github.com/luci/luci-go@master
Patch Set: Clean up, add tests, little reorg. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « server/logdog/storage/bigtable/storage_test.go ('k') | server/logdog/storage/storage.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 memory 5 package memory
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "sync" 9 "sync"
10 10
(...skipping 11 matching lines...) Expand all
22 data []byte 22 data []byte
23 } 23 }
24 24
25 // Storage is an implementation of the storage.Storage interface that stores 25 // Storage is an implementation of the storage.Storage interface that stores
26 // data in memory. 26 // data in memory.
27 // 27 //
28 // This is intended for testing, and not intended to be performant. 28 // This is intended for testing, and not intended to be performant.
29 type Storage struct { 29 type Storage struct {
30 // MaxGetCount, if not zero, is the maximum number of records to retriev e from 30 // MaxGetCount, if not zero, is the maximum number of records to retriev e from
31 // a single Get request. 31 // a single Get request.
32 » MaxGetCount int 32 » MaxGetCount int64
33 33
34 stateMu sync.Mutex 34 stateMu sync.Mutex
35 streams map[types.StreamPath]*logStream 35 streams map[types.StreamPath]*logStream
36 closed bool 36 closed bool
37 } 37 }
38 38
39 var _ storage.Storage = (*Storage)(nil) 39 var _ storage.Storage = (*Storage)(nil)
40 40
41 // Close implements storage.Storage. 41 // Close implements storage.Storage.
42 func (s *Storage) Close() { 42 func (s *Storage) Close() {
(...skipping 22 matching lines...) Expand all
65 65
66 // Get implements storage.Storage. 66 // Get implements storage.Storage.
67 func (s *Storage) Get(req *storage.GetRequest, cb storage.GetCallback) error { 67 func (s *Storage) Get(req *storage.GetRequest, cb storage.GetCallback) error {
68 recs := []*rec(nil) 68 recs := []*rec(nil)
69 err := s.run(func() error { 69 err := s.run(func() error {
70 ls := s.getLogStreamLocked(req.Path, false) 70 ls := s.getLogStreamLocked(req.Path, false)
71 if ls == nil { 71 if ls == nil {
72 return storage.ErrDoesNotExist 72 return storage.ErrDoesNotExist
73 } 73 }
74 74
75 » » limit := len(ls.logs) 75 » » limit := int64(len(ls.logs))
76 if req.Limit > 0 && req.Limit < limit { 76 if req.Limit > 0 && req.Limit < limit {
77 limit = req.Limit 77 limit = req.Limit
78 } 78 }
79 if s.MaxGetCount > 0 && s.MaxGetCount < limit { 79 if s.MaxGetCount > 0 && s.MaxGetCount < limit {
80 limit = s.MaxGetCount 80 limit = s.MaxGetCount
81 } 81 }
82 82
83 // Grab all records starting from our start index. 83 // Grab all records starting from our start index.
84 for idx := req.Index; idx <= ls.latestIndex; idx++ { 84 for idx := req.Index; idx <= ls.latestIndex; idx++ {
85 if le, ok := ls.logs[idx]; ok { 85 if le, ok := ls.logs[idx]; ok {
86 recs = append(recs, &rec{ 86 recs = append(recs, &rec{
87 index: idx, 87 index: idx,
88 data: le, 88 data: le,
89 }) 89 })
90 } 90 }
91 91
92 » » » if len(recs) >= limit { 92 » » » if int64(len(recs)) >= limit {
93 break 93 break
94 } 94 }
95 } 95 }
96 return nil 96 return nil
97 }) 97 })
98 if err != nil { 98 if err != nil {
99 return err 99 return err
100 } 100 }
101 101
102 // Punt all of the records upstream. We copy the data to prevent the 102 // Punt all of the records upstream. We copy the data to prevent the
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 178 }
179 179
180 if s.streams == nil { 180 if s.streams == nil {
181 s.streams = map[types.StreamPath]*logStream{} 181 s.streams = map[types.StreamPath]*logStream{}
182 } 182 }
183 s.streams[p] = ls 183 s.streams[p] = ls
184 } 184 }
185 185
186 return ls 186 return ls
187 } 187 }
OLDNEW
« no previous file with comments | « server/logdog/storage/bigtable/storage_test.go ('k') | server/logdog/storage/storage.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698