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

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

Issue 1838803002: LogDog: BigTable batching schema. (Closed) Base URL: https://github.com/luci/luci-go@recordio-split
Patch Set: Minor comments and quality of code tweaks. Created 4 years, 8 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
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 "time" 10 "time"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 // Config implements storage.Storage. 54 // Config implements storage.Storage.
55 func (s *Storage) Config(cfg storage.Config) error { 55 func (s *Storage) Config(cfg storage.Config) error {
56 return s.run(func() error { 56 return s.run(func() error {
57 s.MaxLogAge = cfg.MaxLogAge 57 s.MaxLogAge = cfg.MaxLogAge
58 return nil 58 return nil
59 }) 59 })
60 } 60 }
61 61
62 // Put implements storage.Storage. 62 // Put implements storage.Storage.
63 func (s *Storage) Put(req *storage.PutRequest) error { 63 func (s *Storage) Put(req storage.PutRequest) error {
64 return s.run(func() error { 64 return s.run(func() error {
65 ls := s.getLogStreamLocked(req.Path, true) 65 ls := s.getLogStreamLocked(req.Path, true)
66 66
67 » » if _, ok := ls.logs[req.Index]; ok { 67 » » for i, v := range req.Values {
68 » » » return storage.ErrExists 68 » » » index := req.Index + types.MessageIndex(i)
69 » » } 69 » » » if _, ok := ls.logs[index]; ok {
70 » » » » return storage.ErrExists
71 » » » }
70 72
71 » » ls.logs[req.Index] = []byte(req.Value) 73 » » » clone := make([]byte, len(v))
72 » » if req.Index > ls.latestIndex { 74 » » » copy(clone, v)
73 » » » ls.latestIndex = req.Index 75 » » » ls.logs[index] = clone
76 » » » if index > ls.latestIndex {
77 » » » » ls.latestIndex = index
78 » » » }
74 } 79 }
75 return nil 80 return nil
76 }) 81 })
77 } 82 }
78 83
79 // Get implements storage.Storage. 84 // Get implements storage.Storage.
80 func (s *Storage) Get(req *storage.GetRequest, cb storage.GetCallback) error { 85 func (s *Storage) Get(req storage.GetRequest, cb storage.GetCallback) error {
81 recs := []*rec(nil) 86 recs := []*rec(nil)
82 err := s.run(func() error { 87 err := s.run(func() error {
83 ls := s.getLogStreamLocked(req.Path, false) 88 ls := s.getLogStreamLocked(req.Path, false)
84 if ls == nil { 89 if ls == nil {
85 return storage.ErrDoesNotExist 90 return storage.ErrDoesNotExist
86 } 91 }
87 92
88 limit := len(ls.logs) 93 limit := len(ls.logs)
89 if req.Limit > 0 && req.Limit < limit { 94 if req.Limit > 0 && req.Limit < limit {
90 limit = req.Limit 95 limit = req.Limit
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 196 }
192 197
193 if s.streams == nil { 198 if s.streams == nil {
194 s.streams = map[types.StreamPath]*logStream{} 199 s.streams = map[types.StreamPath]*logStream{}
195 } 200 }
196 s.streams[p] = ls 201 s.streams[p] = ls
197 } 202 }
198 203
199 return ls 204 return ls
200 } 205 }
OLDNEW
« no previous file with comments | « server/logdog/storage/bigtable/storage_test.go ('k') | server/logdog/storage/memory/memory_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698