OLD | NEW |
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 "bytes" | 8 "bytes" |
| 9 "runtime" |
9 "sync" | 10 "sync" |
10 | 11 |
11 "github.com/luci/gkvlite" | 12 "github.com/luci/gkvlite" |
12 ) | 13 ) |
13 | 14 |
14 func gkvCollide(o, n *memCollection, f func(k, ov, nv []byte)) { | 15 func gkvCollide(o, n *memCollection, f func(k, ov, nv []byte)) { |
15 oldItems, newItems := make(chan *gkvlite.Item), make(chan *gkvlite.Item) | 16 oldItems, newItems := make(chan *gkvlite.Item), make(chan *gkvlite.Item) |
16 walker := func(c *memCollection, ch chan<- *gkvlite.Item, wg *sync.WaitG
roup) { | 17 walker := func(c *memCollection, ch chan<- *gkvlite.Item, wg *sync.WaitG
roup) { |
17 defer close(ch) | 18 defer close(ch) |
18 defer wg.Done() | 19 defer wg.Done() |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 69 |
69 func newMemStore() *memStore { | 70 func newMemStore() *memStore { |
70 ret, err := gkvlite.NewStore(nil) | 71 ret, err := gkvlite.NewStore(nil) |
71 if err != nil { | 72 if err != nil { |
72 panic(err) | 73 panic(err) |
73 } | 74 } |
74 return (*memStore)(ret) | 75 return (*memStore)(ret) |
75 } | 76 } |
76 | 77 |
77 func (ms *memStore) Snapshot() *memStore { | 78 func (ms *memStore) Snapshot() *memStore { |
78 » return (*memStore)((*gkvlite.Store)(ms).Snapshot()) | 79 » ret := (*memStore)((*gkvlite.Store)(ms).Snapshot()) |
| 80 » runtime.SetFinalizer((*gkvlite.Store)(ret), func(s *gkvlite.Store) { |
| 81 » » go s.Close() |
| 82 » }) |
| 83 » return ret |
79 } | 84 } |
80 | 85 |
81 func (ms *memStore) MakePrivateCollection(cmp gkvlite.KeyCompare) *memCollection
{ | 86 func (ms *memStore) MakePrivateCollection(cmp gkvlite.KeyCompare) *memCollection
{ |
82 return (*memCollection)((*gkvlite.Store)(ms).MakePrivateCollection(cmp)) | 87 return (*memCollection)((*gkvlite.Store)(ms).MakePrivateCollection(cmp)) |
83 } | 88 } |
84 | 89 |
85 func (ms *memStore) GetCollection(name string) *memCollection { | 90 func (ms *memStore) GetCollection(name string) *memCollection { |
86 return (*memCollection)((*gkvlite.Store)(ms).GetCollection(name)) | 91 return (*memCollection)((*gkvlite.Store)(ms).GetCollection(name)) |
87 } | 92 } |
88 | 93 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } | 147 } |
143 } | 148 } |
144 | 149 |
145 func (mc *memCollection) GetTotals() (numItems, numBytes uint64) { | 150 func (mc *memCollection) GetTotals() (numItems, numBytes uint64) { |
146 numItems, numBytes, err := (*gkvlite.Collection)(mc).GetTotals() | 151 numItems, numBytes, err := (*gkvlite.Collection)(mc).GetTotals() |
147 if err != nil { | 152 if err != nil { |
148 panic(err) | 153 panic(err) |
149 } | 154 } |
150 return | 155 return |
151 } | 156 } |
OLD | NEW |