OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package memory | 5 package memory |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "runtime" | |
10 | 9 |
11 "github.com/luci/gae/service/datastore" | 10 "github.com/luci/gae/service/datastore" |
12 "github.com/luci/gkvlite" | 11 "github.com/luci/gkvlite" |
13 ) | 12 ) |
14 | 13 |
15 func gkvCollide(o, n memCollection, f func(k, ov, nv []byte)) { | 14 func gkvCollide(o, n memCollection, f func(k, ov, nv []byte)) { |
16 if o != nil && !o.IsReadOnly() { | 15 if o != nil && !o.IsReadOnly() { |
17 panic("old collection is r/w") | 16 panic("old collection is r/w") |
18 } | 17 } |
19 if n != nil && !n.IsReadOnly() { | 18 if n != nil && !n.IsReadOnly() { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 if *logMemCollectionFolder != "" { | 117 if *logMemCollectionFolder != "" { |
119 ret = wrapTracingMemStore(ret) | 118 ret = wrapTracingMemStore(ret) |
120 } | 119 } |
121 return ret | 120 return ret |
122 } | 121 } |
123 | 122 |
124 func (ms *memStoreImpl) Snapshot() memStore { | 123 func (ms *memStoreImpl) Snapshot() memStore { |
125 if ms.ro { | 124 if ms.ro { |
126 return ms | 125 return ms |
127 } | 126 } |
128 » ret := ms.s.Snapshot() | 127 » return &memStoreImpl{ms.s.Snapshot(), true} |
129 » runtime.SetFinalizer(ret, func(s *gkvlite.Store) { go s.Close() }) | |
130 » return &memStoreImpl{ret, true} | |
131 } | 128 } |
132 | 129 |
133 func (ms *memStoreImpl) GetCollection(name string) memCollection { | 130 func (ms *memStoreImpl) GetCollection(name string) memCollection { |
134 coll := ms.s.GetCollection(name) | 131 coll := ms.s.GetCollection(name) |
135 if coll == nil { | 132 if coll == nil { |
136 return nil | 133 return nil |
137 } | 134 } |
138 return &memCollectionImpl{coll, ms.ro} | 135 return &memCollectionImpl{coll, ms.ro} |
139 } | 136 } |
140 | 137 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 } | 186 } |
190 err := mc.c.VisitItemsAscend(target, withValue, visitor) | 187 err := mc.c.VisitItemsAscend(target, withValue, visitor) |
191 memoryCorruption(err) | 188 memoryCorruption(err) |
192 } | 189 } |
193 | 190 |
194 func (mc *memCollectionImpl) GetTotals() (numItems, numBytes uint64) { | 191 func (mc *memCollectionImpl) GetTotals() (numItems, numBytes uint64) { |
195 numItems, numBytes, err := mc.c.GetTotals() | 192 numItems, numBytes, err := mc.c.GetTotals() |
196 memoryCorruption(err) | 193 memoryCorruption(err) |
197 return | 194 return |
198 } | 195 } |
OLD | NEW |