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

Side by Side Diff: impl/memory/gkvlite_utils.go

Issue 2601513007: Remove SetFinalizer from impl/memory. (Closed)
Patch Set: Created 3 years, 12 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 | « impl/memory/datastore_test.go ('k') | no next file » | 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 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
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
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 }
OLDNEW
« no previous file with comments | « impl/memory/datastore_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698